feat:add eslint and fix

pr675
黄云飞 4 years ago
parent 764fd8bbad
commit c49b7b5978

@ -0,0 +1,9 @@
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true

@ -0,0 +1,43 @@
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"env": {
"browser": true
},
"rules": {
"linebreak-style": 0,
"no-console": 0,
"no-debugger": 0,
"no-useless-escape": "off",
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-empty-interface": 0,
"@typescript-eslint/no-this-alias": 0,
"@typescript-eslint/ban-ts-comment": 0,
"@typescript-eslint/explicit-module-boundary-types": 0,
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/ban-types": [1, {
"types": {
"Function": false,
"{}": false
},
"extendDefaults": true
}],
"no-constant-condition": ["error", {
"checkLoops": false
}],
"semi": [1, "never"],
"quotes": [1, "single", {
"allowTemplateLiterals": true
}]
},
"ignorePatterns": ["node_modules", "dist", "index.html"]
}

@ -8,6 +8,7 @@
"contextmenu", "contextmenu",
"deletable", "deletable",
"inputarea", "inputarea",
"linebreak",
"prismjs", "prismjs",
"resizer", "resizer",
"richtext", "richtext",
@ -18,5 +19,8 @@
"vite", "vite",
"Yahei" "Yahei"
], ],
"typescript.tsdk": "node_modules/typescript/lib" "typescript.tsdk": "node_modules/typescript/lib",
} "editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}

@ -2,6 +2,7 @@
declare namespace Editor { declare namespace Editor {
import('../src/editor/index') import('../src/editor/index')
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import Editor from '../src/editor/index' import Editor from '../src/editor/index'
} }

@ -34,7 +34,7 @@ describe('菜单-搜索', () => {
value: searchText value: searchText
}, },
{ {
value: "\n", value: '\n',
type, type,
trList: [ trList: [
{ {

@ -2,17 +2,21 @@
"version": "0.8.3", "version": "0.8.3",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"lib": "tsc && vite build --mode lib", "lib": "npm run lint && tsc && vite build --mode lib",
"build": "tsc && vite build --mode app", "build": "npm run lint && tsc && vite build --mode app",
"serve": "vite preview", "serve": "vite preview",
"lint": "eslint .",
"cypress:open": "cypress open", "cypress:open": "cypress open",
"cypress:run": "cypress run" "cypress:run": "cypress run"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^16.11.12", "@types/node": "^16.11.12",
"@types/prismjs": "^1.26.0", "@types/prismjs": "^1.26.0",
"@typescript-eslint/eslint-plugin": "4.33.0",
"@typescript-eslint/parser": "4.33.0",
"cypress": "^9.5.1", "cypress": "^9.5.1",
"cypress-file-upload": "^5.0.8", "cypress-file-upload": "^5.0.8",
"eslint": "7.32.0",
"typescript": "^4.3.2", "typescript": "^4.3.2",
"vite": "^2.4.2" "vite": "^2.4.2"
}, },

@ -1,9 +1,10 @@
import { IElement } from "../.." import { IElement } from '../..'
import { EditorMode } from "../../dataset/enum/Editor" import { EditorMode } from '../../dataset/enum/Editor'
import { RowFlex } from "../../dataset/enum/Row" import { RowFlex } from '../../dataset/enum/Row'
import { IDrawImagePayload } from "../../interface/Draw" import { IDrawImagePayload } from '../../interface/Draw'
import { IWatermark } from "../../interface/Watermark" import { IWatermark } from '../../interface/Watermark'
import { CommandAdapt } from "./CommandAdapt" import { CommandAdapt } from './CommandAdapt'
export class Command { export class Command {

@ -1,26 +1,27 @@
import { WRAP, ZERO } from "../../dataset/constant/Common" import { WRAP, ZERO } from '../../dataset/constant/Common'
import { EDITOR_ELEMENT_STYLE_ATTR } from "../../dataset/constant/Element" import { EDITOR_ELEMENT_STYLE_ATTR } from '../../dataset/constant/Element'
import { defaultWatermarkOption } from "../../dataset/constant/Watermark" import { defaultWatermarkOption } from '../../dataset/constant/Watermark'
import { EditorContext, EditorMode } from "../../dataset/enum/Editor" import { EditorContext, EditorMode } from '../../dataset/enum/Editor'
import { ElementType } from "../../dataset/enum/Element" import { ElementType } from '../../dataset/enum/Element'
import { ElementStyleKey } from "../../dataset/enum/ElementStyle" import { ElementStyleKey } from '../../dataset/enum/ElementStyle'
import { RowFlex } from "../../dataset/enum/Row" import { RowFlex } from '../../dataset/enum/Row'
import { IDrawImagePayload } from "../../interface/Draw" import { IDrawImagePayload } from '../../interface/Draw'
import { IEditorOption } from "../../interface/Editor" import { IEditorOption } from '../../interface/Editor'
import { IElement, IElementStyle } from "../../interface/Element" import { IElement, IElementStyle } from '../../interface/Element'
import { IColgroup } from "../../interface/table/Colgroup" import { IColgroup } from '../../interface/table/Colgroup'
import { ITd } from "../../interface/table/Td" import { ITd } from '../../interface/table/Td'
import { ITr } from "../../interface/table/Tr" import { ITr } from '../../interface/table/Tr'
import { IWatermark } from "../../interface/Watermark" import { IWatermark } from '../../interface/Watermark'
import { getUUID } from "../../utils" import { getUUID } from '../../utils'
import { formatElementList } from "../../utils/element" import { formatElementList } from '../../utils/element'
import { printImageBase64 } from "../../utils/print" import { printImageBase64 } from '../../utils/print'
import { Draw } from "../draw/Draw" import { Draw } from '../draw/Draw'
import { TableTool } from "../draw/particle/table/TableTool" import { TableTool } from '../draw/particle/table/TableTool'
import { CanvasEvent } from "../event/CanvasEvent" import { CanvasEvent } from '../event/CanvasEvent'
import { HistoryManager } from "../history/HistoryManager" import { HistoryManager } from '../history/HistoryManager'
import { Position } from "../position/Position" import { Position } from '../position/Position'
import { RangeManager } from "../range/RangeManager" import { RangeManager } from '../range/RangeManager'
export class CommandAdapt { export class CommandAdapt {
@ -822,7 +823,7 @@ export class CommandAdapt {
const startRowIndex = startTd.rowIndex! const startRowIndex = startTd.rowIndex!
const endRowIndex = endTd.rowIndex! + (endTd.rowspan - 1) const endRowIndex = endTd.rowIndex! + (endTd.rowspan - 1)
// 选区行列 // 选区行列
let rowCol: ITd[][] = [] const rowCol: ITd[][] = []
for (let t = 0; t < curTrList.length; t++) { for (let t = 0; t < curTrList.length; t++) {
const tr = curTrList[t] const tr = curTrList[t]
const tdList: ITd[] = [] const tdList: ITd[] = []
@ -865,7 +866,7 @@ export class CommandAdapt {
} }
} }
// 合并单元格 // 合并单元格
let mergeTdIdList: string[] = [] const mergeTdIdList: string[] = []
const anchorTd = rowCol[0][0] const anchorTd = rowCol[0][0]
for (let t = 0; t < rowCol.length; t++) { for (let t = 0; t < rowCol.length; t++) {
const tr = rowCol[t] const tr = rowCol[t]
@ -1234,7 +1235,7 @@ export class CommandAdapt {
formatElementList(payload, false) formatElementList(payload, false)
const elementList = this.draw.getElementList() const elementList = this.draw.getElementList()
const isCollapsed = startIndex === endIndex const isCollapsed = startIndex === endIndex
let start = startIndex + 1 const start = startIndex + 1
if (!isCollapsed) { if (!isCollapsed) {
elementList.splice(start, endIndex - startIndex) elementList.splice(start, endIndex - startIndex)
} }

@ -1,11 +1,11 @@
import { EDITOR_COMPONENT } from "../../dataset/constant/Editor" import { EDITOR_COMPONENT } from '../../dataset/constant/Editor'
import { EditorComponent } from "../../dataset/enum/Editor" import { EditorComponent } from '../../dataset/enum/Editor'
import { IContextMenuContext, IRegisterContextMenu } from "../../interface/contextmenu/ContextMenu" import { IContextMenuContext, IRegisterContextMenu } from '../../interface/contextmenu/ContextMenu'
import { findParent } from "../../utils" import { findParent } from '../../utils'
import { Command } from "../command/Command" import { Command } from '../command/Command'
import { Draw } from "../draw/Draw" import { Draw } from '../draw/Draw'
import { Position } from "../position/Position" import { Position } from '../position/Position'
import { RangeManager } from "../range/RangeManager" import { RangeManager } from '../range/RangeManager'
interface IRenderPayload { interface IRenderPayload {
contextMenuList: IRegisterContextMenu[]; contextMenuList: IRegisterContextMenu[];
@ -42,7 +42,7 @@ export class ContextMenu {
private _proxyContextMenuEvent(evt: MouseEvent) { private _proxyContextMenuEvent(evt: MouseEvent) {
const context = this._getContext() const context = this._getContext()
let renderList: IRegisterContextMenu[] = [] const renderList: IRegisterContextMenu[] = []
let isRegisterContextMenu = false let isRegisterContextMenu = false
for (let c = 0; c < this.contextMenuList.length; c++) { for (let c = 0; c < this.contextMenuList.length; c++) {
const menu = this.contextMenuList[c] const menu = this.contextMenuList[c]

@ -1,5 +1,5 @@
import { IRegisterContextMenu } from "../../../interface/contextmenu/ContextMenu" import { IRegisterContextMenu } from '../../../interface/contextmenu/ContextMenu'
import { Command } from "../../command/Command" import { Command } from '../../command/Command'
export const globalMenus: IRegisterContextMenu[] = [ export const globalMenus: IRegisterContextMenu[] = [
{ {

@ -1,5 +1,5 @@
import { IRegisterContextMenu } from "../../../interface/contextmenu/ContextMenu" import { IRegisterContextMenu } from '../../../interface/contextmenu/ContextMenu'
import { Command } from "../../command/Command" import { Command } from '../../command/Command'
export const tableMenus: IRegisterContextMenu[] = [ export const tableMenus: IRegisterContextMenu[] = [
{ {

@ -1,9 +1,9 @@
import { CURSOR_AGENT_HEIGHT } from "../../dataset/constant/Cursor" import { CURSOR_AGENT_HEIGHT } from '../../dataset/constant/Cursor'
import { IEditorOption } from "../../interface/Editor" import { IEditorOption } from '../../interface/Editor'
import { Draw } from "../draw/Draw" import { Draw } from '../draw/Draw'
import { CanvasEvent } from "../event/CanvasEvent" import { CanvasEvent } from '../event/CanvasEvent'
import { Position } from "../position/Position" import { Position } from '../position/Position'
import { CursorAgent } from "./CursorAgent" import { CursorAgent } from './CursorAgent'
export class Cursor { export class Cursor {

@ -1,6 +1,6 @@
import { debounce } from "../../utils" import { debounce } from '../../utils'
import { Draw } from "../draw/Draw" import { Draw } from '../draw/Draw'
import { CanvasEvent } from "../event/CanvasEvent" import { CanvasEvent } from '../event/CanvasEvent'
export class CursorAgent { export class CursorAgent {

@ -1,38 +1,38 @@
import { ZERO } from "../../dataset/constant/Common" import { ZERO } from '../../dataset/constant/Common'
import { RowFlex } from "../../dataset/enum/Row" import { RowFlex } from '../../dataset/enum/Row'
import { IDrawOption, IDrawRowPayload, IDrawRowResult } from "../../interface/Draw" import { IDrawOption, IDrawRowPayload, IDrawRowResult } from '../../interface/Draw'
import { IEditorOption } from "../../interface/Editor" import { IEditorOption } from '../../interface/Editor'
import { IElement, IElementMetrics, IElementPosition, IElementFillRect, IElementStyle } from "../../interface/Element" import { IElement, IElementMetrics, IElementPosition, IElementFillRect, IElementStyle } from '../../interface/Element'
import { IRow, IRowElement } from "../../interface/Row" import { IRow, IRowElement } from '../../interface/Row'
import { deepClone, getUUID } from "../../utils" import { deepClone, getUUID } from '../../utils'
import { Cursor } from "../cursor/Cursor" import { Cursor } from '../cursor/Cursor'
import { CanvasEvent } from "../event/CanvasEvent" import { CanvasEvent } from '../event/CanvasEvent'
import { GlobalEvent } from "../event/GlobalEvent" import { GlobalEvent } from '../event/GlobalEvent'
import { HistoryManager } from "../history/HistoryManager" import { HistoryManager } from '../history/HistoryManager'
import { Listener } from "../listener/Listener" import { Listener } from '../listener/Listener'
import { Position } from "../position/Position" import { Position } from '../position/Position'
import { RangeManager } from "../range/RangeManager" import { RangeManager } from '../range/RangeManager'
import { Background } from "./frame/Background" import { Background } from './frame/Background'
import { Highlight } from "./richtext/Highlight" import { Highlight } from './richtext/Highlight'
import { Margin } from "./frame/Margin" import { Margin } from './frame/Margin'
import { Search } from "./interactive/Search" import { Search } from './interactive/Search'
import { Strikeout } from "./richtext/Strikeout" import { Strikeout } from './richtext/Strikeout'
import { Underline } from "./richtext/Underline" import { Underline } from './richtext/Underline'
import { ElementType } from "../../dataset/enum/Element" import { ElementType } from '../../dataset/enum/Element'
import { ImageParticle } from "./particle/ImageParticle" import { ImageParticle } from './particle/ImageParticle'
import { TextParticle } from "./particle/TextParticle" import { TextParticle } from './particle/TextParticle'
import { PageNumber } from "./frame/PageNumber" import { PageNumber } from './frame/PageNumber'
import { GlobalObserver } from "../observer/GlobalObserver" import { GlobalObserver } from '../observer/GlobalObserver'
import { TableParticle } from "./particle/table/TableParticle" import { TableParticle } from './particle/table/TableParticle'
import { TableTool } from "./particle/table/TableTool" import { TableTool } from './particle/table/TableTool'
import { HyperlinkParticle } from "./particle/HyperlinkParticle" import { HyperlinkParticle } from './particle/HyperlinkParticle'
import { Header } from "./frame/Header" import { Header } from './frame/Header'
import { SuperscriptParticle } from "./particle/Superscript" import { SuperscriptParticle } from './particle/Superscript'
import { SubscriptParticle } from "./particle/Subscript" import { SubscriptParticle } from './particle/Subscript'
import { SeparatorParticle } from "./particle/Separator" import { SeparatorParticle } from './particle/Separator'
import { PageBreakParticle } from "./particle/PageBreak" import { PageBreakParticle } from './particle/PageBreak'
import { Watermark } from "./frame/Watermark" import { Watermark } from './frame/Watermark'
import { EditorMode } from "../../dataset/enum/Editor" import { EditorMode } from '../../dataset/enum/Editor'
export class Draw { export class Draw {
@ -383,7 +383,7 @@ export class Draw {
this.ctxList.push(ctx) this.ctxList.push(ctx)
} }
private _getFont(el: IElement, scale: number = 1): string { private _getFont(el: IElement, scale = 1): string {
const { defaultSize, defaultFont } = this.options const { defaultSize, defaultFont } = this.options
const font = el.font || defaultFont const font = el.font || defaultFont
const size = el.actualSize || el.size || defaultSize const size = el.actualSize || el.size || defaultSize
@ -410,7 +410,7 @@ export class Draw {
const curRow: IRow = rowList[rowList.length - 1] const curRow: IRow = rowList[rowList.length - 1]
const element = elementList[i] const element = elementList[i]
const rowMargin = defaultBasicRowMarginHeight * (element.rowMargin || defaultRowMargin) const rowMargin = defaultBasicRowMarginHeight * (element.rowMargin || defaultRowMargin)
let metrics: IElementMetrics = { const metrics: IElementMetrics = {
width: 0, width: 0,
height: 0, height: 0,
boundingBoxAscent: 0, boundingBoxAscent: 0,
@ -612,8 +612,8 @@ export class Draw {
} }
} }
// 当前td所在位置 // 当前td所在位置
let tablePreX = x const tablePreX = x
let tablePreY = y const tablePreY = y
// 选区绘制记录 // 选区绘制记录
const rangeRecord: IElementFillRect = { const rangeRecord: IElementFillRect = {
x: 0, x: 0,
@ -794,12 +794,12 @@ export class Draw {
} }
public render(payload?: IDrawOption) { public render(payload?: IDrawOption) {
let { const {
curIndex,
isSubmitHistory = true, isSubmitHistory = true,
isSetCursor = true, isSetCursor = true,
isComputeRowList = true isComputeRowList = true
} = payload || {} } = payload || {}
let { curIndex } = payload || {}
const height = this.getHeight() const height = this.getHeight()
const innerWidth = this.getInnerWidth() const innerWidth = this.getInnerWidth()
// 计算行信息 // 计算行信息
@ -818,7 +818,7 @@ export class Draw {
const marginHeight = margins[0] + margins[2] const marginHeight = margins[0] + margins[2]
let pageHeight = marginHeight let pageHeight = marginHeight
let pageNo = 0 let pageNo = 0
let pageRowList: IRow[][] = [[]] const pageRowList: IRow[][] = [[]]
for (let i = 0; i < this.rowList.length; i++) { for (let i = 0; i < this.rowList.length; i++) {
const row = this.rowList[i] const row = this.rowList[i]
if (row.height + pageHeight > height || this.rowList[i - 1]?.isPageBreak) { if (row.height + pageHeight > height || this.rowList[i - 1]?.isPageBreak) {

@ -1,5 +1,5 @@
import { IEditorOption } from "../../../interface/Editor" import { IEditorOption } from '../../../interface/Editor'
import { Draw } from "../Draw" import { Draw } from '../Draw'
export class Background { export class Background {

@ -1,6 +1,6 @@
import { DeepRequired } from "../../../interface/Common" import { DeepRequired } from '../../../interface/Common'
import { IEditorOption } from "../../../interface/Editor" import { IEditorOption } from '../../../interface/Editor'
import { Draw } from "../Draw" import { Draw } from '../Draw'
export class Header { export class Header {

@ -1,5 +1,5 @@
import { IEditorOption } from "../../../interface/Editor" import { IEditorOption } from '../../../interface/Editor'
import { Draw } from "../Draw" import { Draw } from '../Draw'
export class Margin { export class Margin {

@ -1,5 +1,5 @@
import { IEditorOption } from "../../../interface/Editor" import { IEditorOption } from '../../../interface/Editor'
import { Draw } from "../Draw" import { Draw } from '../Draw'
export class PageNumber { export class PageNumber {

@ -1,6 +1,6 @@
import { IEditorOption } from "../../.." import { IEditorOption } from '../../..'
import { DeepRequired } from "../../../interface/Common" import { DeepRequired } from '../../../interface/Common'
import { Draw } from "../Draw" import { Draw } from '../Draw'
export class Watermark { export class Watermark {

@ -1,13 +1,13 @@
import { ZERO } from "../../../dataset/constant/Common" import { ZERO } from '../../../dataset/constant/Common'
import { TEXTLIKE_ELEMENT_TYPE } from "../../../dataset/constant/Element" import { TEXTLIKE_ELEMENT_TYPE } from '../../../dataset/constant/Element'
import { EditorContext } from "../../../dataset/enum/Editor" import { EditorContext } from '../../../dataset/enum/Editor'
import { ElementType } from "../../../dataset/enum/Element" import { ElementType } from '../../../dataset/enum/Element'
import { IEditorOption } from "../../../interface/Editor" import { IEditorOption } from '../../../interface/Editor'
import { IElement, IElementPosition } from "../../../interface/Element" import { IElement, IElementPosition } from '../../../interface/Element'
import { ISearchResult, ISearchResultRestArgs } from "../../../interface/Search" import { ISearchResult, ISearchResultRestArgs } from '../../../interface/Search'
import { getUUID } from "../../../utils" import { getUUID } from '../../../utils'
import { Position } from "../../position/Position" import { Position } from '../../position/Position'
import { Draw } from "../Draw" import { Draw } from '../Draw'
export class Search { export class Search {
@ -28,7 +28,7 @@ export class Search {
} }
public compute(payload: string) { public compute(payload: string) {
let searchMatchList: ISearchResult[] = [] const searchMatchList: ISearchResult[] = []
// 分组 // 分组
const elementListGroup: { type: EditorContext, elementList: IElement[], index: number }[] = [] const elementListGroup: { type: EditorContext, elementList: IElement[], index: number }[] = []
const originalElementList = this.draw.getOriginalElementList() const originalElementList = this.draw.getOriginalElementList()
@ -129,7 +129,7 @@ export class Search {
let position: IElementPosition | null = null let position: IElementPosition | null = null
if (searchMatch.type === EditorContext.TABLE) { if (searchMatch.type === EditorContext.TABLE) {
const { tableIndex, trIndex, tdIndex, index } = searchMatch const { tableIndex, trIndex, tdIndex, index } = searchMatch
position = elementList[tableIndex!]?.trList![trIndex!].tdList[tdIndex!]!?.positionList![index] position = elementList[tableIndex!]?.trList![trIndex!].tdList[tdIndex!]?.positionList![index]
} else { } else {
position = positionList[searchMatch.index] position = positionList[searchMatch.index]
} }

@ -1,8 +1,8 @@
import { IElement } from "../../.." import { IElement } from '../../..'
import { IEditorOption } from "../../../interface/Editor" import { IEditorOption } from '../../../interface/Editor'
import { IElementPosition } from "../../../interface/Element" import { IElementPosition } from '../../../interface/Element'
import { IRowElement } from "../../../interface/Row" import { IRowElement } from '../../../interface/Row'
import { Draw } from "../Draw" import { Draw } from '../Draw'
export class HyperlinkParticle { export class HyperlinkParticle {

@ -1,7 +1,7 @@
import { IImageParticleCreateResult } from "../../../interface/Draw" import { IImageParticleCreateResult } from '../../../interface/Draw'
import { IEditorOption } from "../../../interface/Editor" import { IEditorOption } from '../../../interface/Editor'
import { IElement, IElementPosition } from "../../../interface/Element" import { IElement, IElementPosition } from '../../../interface/Element'
import { Draw } from "../Draw" import { Draw } from '../Draw'
export class ImageParticle { export class ImageParticle {
@ -93,7 +93,7 @@ export class ImageParticle {
document.body.style.cursor = cursor document.body.style.cursor = cursor
this.canvas.style.cursor = cursor this.canvas.style.cursor = cursor
// 拖拽图片镜像 // 拖拽图片镜像
this.resizerImage.src = this.curElement?.value! this.resizerImage.src = this.curElement?.value || ''
this.resizerImageContainer.style.display = 'block' this.resizerImageContainer.style.display = 'block'
const { coordinate: { leftTop: [left, top] } } = this.curPosition const { coordinate: { leftTop: [left, top] } } = this.curPosition
const prePageHeight = this.draw.getPageNo() * (height + pageGap) const prePageHeight = this.draw.getPageNo() * (height + pageGap)

@ -1,6 +1,6 @@
import { IEditorOption } from "../../../interface/Editor" import { IEditorOption } from '../../../interface/Editor'
import { IRowElement } from "../../../interface/Row" import { IRowElement } from '../../../interface/Row'
import { Draw } from "../Draw" import { Draw } from '../Draw'
export class PageBreakParticle { export class PageBreakParticle {

@ -1,4 +1,4 @@
import { IRowElement } from "../../../interface/Row" import { IRowElement } from '../../../interface/Row'
export class SeparatorParticle { export class SeparatorParticle {
public render(ctx: CanvasRenderingContext2D, element: IRowElement, x: number, y: number) { public render(ctx: CanvasRenderingContext2D, element: IRowElement, x: number, y: number) {

@ -1,4 +1,4 @@
import { IRowElement } from "../../../interface/Row" import { IRowElement } from '../../../interface/Row'
export class SubscriptParticle { export class SubscriptParticle {

@ -1,4 +1,4 @@
import { IRowElement } from "../../../interface/Row" import { IRowElement } from '../../../interface/Row'
export class SuperscriptParticle { export class SuperscriptParticle {

@ -1,6 +1,6 @@
import { IElement } from "../../.." import { IElement } from '../../..'
import { IRowElement } from "../../../interface/Row" import { IRowElement } from '../../../interface/Row'
import { Draw } from "../Draw" import { Draw } from '../Draw'
export class TextParticle { export class TextParticle {

@ -1,7 +1,7 @@
import { ElementType, IElement } from "../../../.." import { ElementType, IElement } from '../../../..'
import { IEditorOption } from "../../../../interface/Editor" import { IEditorOption } from '../../../../interface/Editor'
import { RangeManager } from "../../../range/RangeManager" import { RangeManager } from '../../../range/RangeManager'
import { Draw } from "../../Draw" import { Draw } from '../../Draw'
export class TableParticle { export class TableParticle {

@ -1,9 +1,9 @@
import { IElement } from "../../../.." import { IElement } from '../../../..'
import { TableOrder } from "../../../../dataset/enum/table/TableTool" import { TableOrder } from '../../../../dataset/enum/table/TableTool'
import { IEditorOption } from "../../../../interface/Editor" import { IEditorOption } from '../../../../interface/Editor'
import { IElementPosition } from "../../../../interface/Element" import { IElementPosition } from '../../../../interface/Element'
import { Position } from "../../../position/Position" import { Position } from '../../../position/Position'
import { Draw } from "../../Draw" import { Draw } from '../../Draw'
interface IAnchorMouseDown { interface IAnchorMouseDown {
evt: MouseEvent; evt: MouseEvent;
@ -188,7 +188,7 @@ export class TableTool {
const innerWidth = this.draw.getInnerWidth() const innerWidth = this.draw.getInnerWidth()
const curColWidth = colgroup[index].width const curColWidth = colgroup[index].width
// 最小移动距离计算 // 最小移动距离计算
let moveColWidth = curColWidth + dx const moveColWidth = curColWidth + dx
if (moveColWidth < this.minTdWidth) { if (moveColWidth < this.minTdWidth) {
dx = this.minTdWidth - curColWidth dx = this.minTdWidth - curColWidth
} }

@ -1,5 +1,5 @@
import { IEditorOption } from "../../../interface/Editor" import { IEditorOption } from '../../../interface/Editor'
import { Draw } from "../Draw" import { Draw } from '../Draw'
export class Highlight { export class Highlight {

@ -1,5 +1,5 @@
import { IEditorOption } from "../../../interface/Editor" import { IEditorOption } from '../../../interface/Editor'
import { Draw } from "../Draw" import { Draw } from '../Draw'
export class Strikeout { export class Strikeout {

@ -1,5 +1,5 @@
import { IEditorOption } from "../../../interface/Editor" import { IEditorOption } from '../../../interface/Editor'
import { Draw } from "../Draw" import { Draw } from '../Draw'
export class Underline { export class Underline {

@ -1,25 +1,25 @@
import { version } from "../../../../package.json" import { version } from '../../../../package.json'
import { ElementType } from "../.." import { ElementType } from '../..'
import { ZERO } from "../../dataset/constant/Common" import { ZERO } from '../../dataset/constant/Common'
import { EDITOR_ELEMENT_COPY_ATTR } from "../../dataset/constant/Element" import { EDITOR_ELEMENT_COPY_ATTR } from '../../dataset/constant/Element'
import { ElementStyleKey } from "../../dataset/enum/ElementStyle" import { ElementStyleKey } from '../../dataset/enum/ElementStyle'
import { MouseEventButton } from "../../dataset/enum/Event" import { MouseEventButton } from '../../dataset/enum/Event'
import { KeyMap } from "../../dataset/enum/Keymap" import { KeyMap } from '../../dataset/enum/Keymap'
import { IEditorResult } from "../../interface/Editor" import { IEditorResult } from '../../interface/Editor'
import { IElement } from "../../interface/Element" import { IElement } from '../../interface/Element'
import { ICurrentPosition } from "../../interface/Position" import { ICurrentPosition } from '../../interface/Position'
import { writeTextByElementList } from "../../utils/clipboard" import { writeTextByElementList } from '../../utils/clipboard'
import { zipElementList } from "../../utils/element" import { zipElementList } from '../../utils/element'
import { Cursor } from "../cursor/Cursor" import { Cursor } from '../cursor/Cursor'
import { Draw } from "../draw/Draw" import { Draw } from '../draw/Draw'
import { HyperlinkParticle } from "../draw/particle/HyperlinkParticle" import { HyperlinkParticle } from '../draw/particle/HyperlinkParticle'
import { ImageParticle } from "../draw/particle/ImageParticle" import { ImageParticle } from '../draw/particle/ImageParticle'
import { TableTool } from "../draw/particle/table/TableTool" import { TableTool } from '../draw/particle/table/TableTool'
import { HistoryManager } from "../history/HistoryManager" import { HistoryManager } from '../history/HistoryManager'
import { Listener } from "../listener/Listener" import { Listener } from '../listener/Listener'
import { Position } from "../position/Position" import { Position } from '../position/Position'
import { RangeManager } from "../range/RangeManager" import { RangeManager } from '../range/RangeManager'
import { LETTER_REG, NUMBER_LIKE_REG } from "../../dataset/constant/Regular" import { LETTER_REG, NUMBER_LIKE_REG } from '../../dataset/constant/Regular'
export class CanvasEvent { export class CanvasEvent {
@ -119,7 +119,7 @@ export class CanvasEvent {
tdIndex: startTdIndex, tdIndex: startTdIndex,
trIndex: startTrIndex trIndex: startTrIndex
} = this.mouseDownStartPosition } = this.mouseDownStartPosition
let endIndex = isTable ? tdValueIndex! : index const endIndex = isTable ? tdValueIndex! : index
// 判断是否是表格跨行/列 // 判断是否是表格跨行/列
if (isTable && startIsTable && (tdIndex !== startTdIndex || trIndex !== startTrIndex)) { if (isTable && startIsTable && (tdIndex !== startTdIndex || trIndex !== startTrIndex)) {
this.range.setRange( this.range.setRange(

@ -1,13 +1,13 @@
import { EDITOR_COMPONENT } from "../../dataset/constant/Editor" import { EDITOR_COMPONENT } from '../../dataset/constant/Editor'
import { IEditorOption } from "../../interface/Editor" import { IEditorOption } from '../../interface/Editor'
import { findParent } from "../../utils" import { findParent } from '../../utils'
import { Cursor } from "../cursor/Cursor" import { Cursor } from '../cursor/Cursor'
import { Draw } from "../draw/Draw" import { Draw } from '../draw/Draw'
import { HyperlinkParticle } from "../draw/particle/HyperlinkParticle" import { HyperlinkParticle } from '../draw/particle/HyperlinkParticle'
import { ImageParticle } from "../draw/particle/ImageParticle" import { ImageParticle } from '../draw/particle/ImageParticle'
import { TableTool } from "../draw/particle/table/TableTool" import { TableTool } from '../draw/particle/table/TableTool'
import { RangeManager } from "../range/RangeManager" import { RangeManager } from '../range/RangeManager'
import { CanvasEvent } from "./CanvasEvent" import { CanvasEvent } from './CanvasEvent'
export class GlobalEvent { export class GlobalEvent {

@ -6,7 +6,7 @@ import {
IRangeStyleChange, IRangeStyleChange,
ISaved, ISaved,
IVisiblePageNoListChange IVisiblePageNoListChange
} from "../../interface/Listener" } from '../../interface/Listener'
export class Listener { export class Listener {

@ -1,6 +1,6 @@
import { IEditorOption } from "../../interface/Editor" import { IEditorOption } from '../../interface/Editor'
import { debounce } from "../../utils" import { debounce } from '../../utils'
import { Draw } from "../draw/Draw" import { Draw } from '../draw/Draw'
export class GlobalObserver { export class GlobalObserver {
@ -30,9 +30,9 @@ export class GlobalObserver {
const bottom = top + window.innerHeight const bottom = top + window.innerHeight
const pageList = this.draw.getPageList() const pageList = this.draw.getPageList()
// 计算显示页 // 计算显示页
let visiblePageNoList: number[] = [] const visiblePageNoList: number[] = []
let intersectionPageNo: number = 0 let intersectionPageNo = 0
let intersectionMaxHeight: number = 0 let intersectionMaxHeight = 0
for (let i = 0; i < pageList.length; i++) { for (let i = 0; i < pageList.length; i++) {
const curTop = i * this.pageHeight const curTop = i * this.pageHeight
const curBottom = (i + 1) * this.pageHeight const curBottom = (i + 1) * this.pageHeight

@ -1,9 +1,9 @@
import { ElementType } from "../.." import { ElementType } from '../..'
import { ZERO } from "../../dataset/constant/Common" import { ZERO } from '../../dataset/constant/Common'
import { IEditorOption } from "../../interface/Editor" import { IEditorOption } from '../../interface/Editor'
import { IElementPosition } from "../../interface/Element" import { IElementPosition } from '../../interface/Element'
import { ICurrentPosition, IGetPositionByXYPayload, IPositionContext } from "../../interface/Position" import { ICurrentPosition, IGetPositionByXYPayload, IPositionContext } from '../../interface/Position'
import { Draw } from "../draw/Draw" import { Draw } from '../draw/Draw'
export class Position { export class Position {

@ -1,10 +1,10 @@
import { ElementType } from "../.." import { ElementType } from '../..'
import { IEditorOption } from "../../interface/Editor" import { IEditorOption } from '../../interface/Editor'
import { IElement } from "../../interface/Element" import { IElement } from '../../interface/Element'
import { IRange } from "../../interface/Range" import { IRange } from '../../interface/Range'
import { Draw } from "../draw/Draw" import { Draw } from '../draw/Draw'
import { HistoryManager } from "../history/HistoryManager" import { HistoryManager } from '../history/HistoryManager'
import { Listener } from "../listener/Listener" import { Listener } from '../listener/Listener'
export class RangeManager { export class RangeManager {
@ -70,10 +70,10 @@ export class RangeManager {
const type = curElement.type || ElementType.TEXT const type = curElement.type || ElementType.TEXT
// 富文本 // 富文本
const font = curElement.font || this.options.defaultFont const font = curElement.font || this.options.defaultFont
let bold = !~curElementList.findIndex(el => !el.bold) const bold = !~curElementList.findIndex(el => !el.bold)
let italic = !~curElementList.findIndex(el => !el.italic) const italic = !~curElementList.findIndex(el => !el.italic)
let underline = !~curElementList.findIndex(el => !el.underline) const underline = !~curElementList.findIndex(el => !el.underline)
let strikeout = !~curElementList.findIndex(el => !el.strikeout) const strikeout = !~curElementList.findIndex(el => !el.strikeout)
const color = curElement.color || null const color = curElement.color || null
const highlight = curElement.highlight || null const highlight = curElement.highlight || null
const rowFlex = curElement.rowFlex || null const rowFlex = curElement.rowFlex || null

@ -1,5 +1,5 @@
import { IRegisterContextMenu } from "../../interface/contextmenu/ContextMenu" import { IRegisterContextMenu } from '../../interface/contextmenu/ContextMenu'
import { ContextMenu } from "../contextmenu/ContextMenu" import { ContextMenu } from '../contextmenu/ContextMenu'
interface IRegisterPayload { interface IRegisterPayload {
contextMenu: ContextMenu contextMenu: ContextMenu

@ -1,5 +1,5 @@
import { ElementType } from "../enum/Element" import { ElementType } from '../enum/Element'
import { IElement } from "../../interface/Element" import { IElement } from '../../interface/Element'
export const EDITOR_ELEMENT_STYLE_ATTR = [ export const EDITOR_ELEMENT_STYLE_ATTR = [
'bold', 'bold',

@ -1,4 +1,4 @@
import { IHeader } from "../../interface/Header" import { IHeader } from '../../interface/Header'
export const defaultHeaderOption: Readonly<Required<IHeader>> = { export const defaultHeaderOption: Readonly<Required<IHeader>> = {
data: '', data: '',

@ -1,4 +1,4 @@
import { IWatermark } from "../../interface/Watermark" import { IWatermark } from '../../interface/Watermark'
export const defaultWatermarkOption: Readonly<Required<IWatermark>> = { export const defaultWatermarkOption: Readonly<Required<IWatermark>> = {
data: '', data: '',

@ -1,15 +1,15 @@
export enum KeyMap { export enum KeyMap {
Delete = 'Delete', Delete = 'Delete',
Backspace = 'Backspace', Backspace = 'Backspace',
Enter = "Enter", Enter = 'Enter',
Left = "ArrowLeft", Left = 'ArrowLeft',
Right = "ArrowRight", Right = 'ArrowRight',
Up = "ArrowUp", Up = 'ArrowUp',
Down = "ArrowDown", Down = 'ArrowDown',
A = "a", A = 'a',
C = "c", C = 'c',
S = "s", S = 's',
X = "x", X = 'x',
Y = "y", Y = 'y',
Z = "z" Z = 'z'
} }

@ -1,5 +1,5 @@
import { IElementPosition } from "./Element" import { IElementPosition } from './Element'
import { IRow } from "./Row" import { IRow } from './Row'
export interface IDrawOption { export interface IDrawOption {
curIndex?: number; curIndex?: number;

@ -1,7 +1,7 @@
import { IElement } from ".." import { IElement } from '..'
import { EditorMode } from "../dataset/enum/Editor" import { EditorMode } from '../dataset/enum/Editor'
import { IHeader } from "./Header" import { IHeader } from './Header'
import { IWatermark } from "./Watermark" import { IWatermark } from './Watermark'
export interface IEditorOption { export interface IEditorOption {
defaultMode?: EditorMode; defaultMode?: EditorMode;

@ -1,7 +1,7 @@
import { ElementType } from "../dataset/enum/Element" import { ElementType } from '../dataset/enum/Element'
import { RowFlex } from "../dataset/enum/Row" import { RowFlex } from '../dataset/enum/Row'
import { IColgroup } from "./table/Colgroup" import { IColgroup } from './table/Colgroup'
import { ITr } from "./table/Tr" import { ITr } from './table/Tr'
export interface IElementBasic { export interface IElementBasic {
id?: string; id?: string;

@ -1,6 +1,6 @@
import { ElementType } from ".." import { ElementType } from '..'
import { RowFlex } from "../dataset/enum/Row" import { RowFlex } from '../dataset/enum/Row'
import { IEditorResult } from "./Editor" import { IEditorResult } from './Editor'
export interface IRangeStyle { export interface IRangeStyle {
type: ElementType | null; type: ElementType | null;

@ -1,6 +1,6 @@
import { IElement } from ".." import { IElement } from '..'
import { IElementPosition } from "./Element" import { IElementPosition } from './Element'
import { ITd } from "./table/Td" import { ITd } from './table/Td'
export interface ICurrentPosition { export interface ICurrentPosition {
index: number; index: number;

@ -1,5 +1,5 @@
import { RowFlex } from "../dataset/enum/Row" import { RowFlex } from '../dataset/enum/Row'
import { IElement, IElementMetrics } from "./Element" import { IElement, IElementMetrics } from './Element'
export type IRowElement = IElement & { export type IRowElement = IElement & {
metrics: IElementMetrics; metrics: IElementMetrics;

@ -1,4 +1,4 @@
import { EditorContext } from "../dataset/enum/Editor" import { EditorContext } from '../dataset/enum/Editor'
export interface ISearchResultBasic { export interface ISearchResultBasic {
type: EditorContext; type: EditorContext;

@ -1,5 +1,5 @@
import { IElement, IElementPosition } from "../Element" import { IElement, IElementPosition } from '../Element'
import { IRow } from "../Row" import { IRow } from '../Row'
export interface ITd { export interface ITd {
id?: string; id?: string;

@ -1,4 +1,4 @@
import { ITd } from "./Td" import { ITd } from './Td'
export interface ITr { export interface ITr {
id?: string; id?: string;

@ -1,7 +1,7 @@
import { IElement } from ".." import { IElement } from '..'
import { HORIZON_TAB, WRAP, ZERO } from "../dataset/constant/Common" import { HORIZON_TAB, WRAP, ZERO } from '../dataset/constant/Common'
import { TEXTLIKE_ELEMENT_TYPE } from "../dataset/constant/Element" import { TEXTLIKE_ELEMENT_TYPE } from '../dataset/constant/Element'
import { ElementType } from "../dataset/enum/Element" import { ElementType } from '../dataset/enum/Element'
export function writeText(text: string) { export function writeText(text: string) {
if (!text) return if (!text) return
@ -9,7 +9,7 @@ export function writeText(text: string) {
} }
export function writeTextByElementList(elementList: IElement[]) { export function writeTextByElementList(elementList: IElement[]) {
let text: string = `` let text = ``
function pickTextFromElement(payload: IElement[]) { function pickTextFromElement(payload: IElement[]) {
for (let e = 0; e < payload.length; e++) { for (let e = 0; e < payload.length; e++) {
const element = payload[e] const element = payload[e]

@ -1,7 +1,7 @@
import { deepClone, getUUID } from "." import { deepClone, getUUID } from '.'
import { ElementType, IElement } from ".." import { ElementType, IElement } from '..'
import { ZERO } from "../dataset/constant/Common" import { ZERO } from '../dataset/constant/Common'
import { EDITOR_ELEMENT_ZIP_ATTR } from "../dataset/constant/Element" import { EDITOR_ELEMENT_ZIP_ATTR } from '../dataset/constant/Element'
export function formatElementList(elementList: IElement[], isHandleFirstElement = true) { export function formatElementList(elementList: IElement[], isHandleFirstElement = true) {
if (isHandleFirstElement && elementList[0]?.value !== ZERO) { if (isHandleFirstElement && elementList[0]?.value !== ZERO) {

@ -50,5 +50,5 @@ export function getUUID(): string {
function S4(): string { function S4(): string {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1) return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)
} }
return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4()) return (S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4())
} }

@ -1,6 +1,6 @@
import { data, options } from './mock' import { data, options } from './mock'
import './style.css' import './style.css'
import prism from "prismjs" import prism from 'prismjs'
import Editor, { EditorMode, ElementType, IElement } from './editor' import Editor, { EditorMode, ElementType, IElement } from './editor'
import { Dialog } from './components/dialog/Dialog' import { Dialog } from './components/dialog/Dialog'
import { formatPrismToken } from './utils/prism' import { formatPrismToken } from './utils/prism'
@ -230,7 +230,7 @@ window.onload = function () {
imageFileDom.click() imageFileDom.click()
} }
imageFileDom.onchange = function () { imageFileDom.onchange = function () {
const file = imageFileDom.files?.[0]! const file = imageFileDom.files![0]!
const fileReader = new FileReader() const fileReader = new FileReader()
fileReader.readAsDataURL(file) fileReader.readAsDataURL(file)
fileReader.onload = function () { fileReader.onload = function () {

@ -1,4 +1,4 @@
import { ElementType, IEditorOption, IElement, RowFlex } from "./editor" import { ElementType, IEditorOption, IElement, RowFlex } from './editor'
const text = `人民医院门诊病历\n主诉\n发热三天咳嗽五天。\n现病史\n患者于三天前无明显诱因感冒后发现面部水肿无皮疹尿量减少出现乏力在外治疗无好转现来我院就诊。\n既往史\n有糖尿病10年有高血压2年有传染性疾病1年。没有报告其他既往疾病。\n流行病史\n否认14天内接触过确诊患者、疑似患者、无症状感染者及其密切接触者否认14天内去过以下场所水产、肉类批发市场农贸市场集市大型超市夜市否认14天内与以下场所工作人员密切接触水产、肉类批发市场农贸市场集市大型超市否认14天内周围如家庭、办公室有2例以上聚集性发病否认14天内接触过有发热或呼吸道症状的人员否认14天内自身有发热或呼吸道症状否认14天内接触过纳入隔离观察的人员及其他可能与新冠肺炎关联的情形陪同家属{有无选择代码}有以上情况。\n体格检查\nT39.5℃P80bpmR20次/分BP120/80mmHg\n辅助检查\n2020年6月10日普放血细胞比容36.50%偏低4050单核细胞绝对值0.75*10/L偏高参考值0.10.6\n门诊诊断\n1.高血压\n2.糖尿病\n3.病毒性感冒\n4.过敏性鼻炎\n5.过敏性鼻息肉\n处置治疗\n1.超声引导下甲状腺细针穿刺术;\n2.乙型肝炎表面抗体测定;\n3.膜式病变细胞采集术、后颈皮下肤层;\n电子签名【】\n其他记录` const text = `人民医院门诊病历\n主诉\n发热三天咳嗽五天。\n现病史\n患者于三天前无明显诱因感冒后发现面部水肿无皮疹尿量减少出现乏力在外治疗无好转现来我院就诊。\n既往史\n有糖尿病10年有高血压2年有传染性疾病1年。没有报告其他既往疾病。\n流行病史\n否认14天内接触过确诊患者、疑似患者、无症状感染者及其密切接触者否认14天内去过以下场所水产、肉类批发市场农贸市场集市大型超市夜市否认14天内与以下场所工作人员密切接触水产、肉类批发市场农贸市场集市大型超市否认14天内周围如家庭、办公室有2例以上聚集性发病否认14天内接触过有发热或呼吸道症状的人员否认14天内自身有发热或呼吸道症状否认14天内接触过纳入隔离观察的人员及其他可能与新冠肺炎关联的情形陪同家属{有无选择代码}有以上情况。\n体格检查\nT39.5℃P80bpmR20次/分BP120/80mmHg\n辅助检查\n2020年6月10日普放血细胞比容36.50%偏低4050单核细胞绝对值0.75*10/L偏高参考值0.10.6\n门诊诊断\n1.高血压\n2.糖尿病\n3.病毒性感冒\n4.过敏性鼻炎\n5.过敏性鼻息肉\n处置治疗\n1.超声引导下甲状腺细针穿刺术;\n2.乙型肝炎表面抗体测定;\n3.膜式病变细胞采集术、后颈皮下肤层;\n电子签名【】\n其他记录`

@ -7,48 +7,48 @@ interface IPrismKindStyle {
export function getPrismKindStyle(payload: string): IPrismKindStyle | null { export function getPrismKindStyle(payload: string): IPrismKindStyle | null {
switch (payload) { switch (payload) {
case "comment": case 'comment':
case "prolog": case 'prolog':
case "doctype": case 'doctype':
case "cdata": case 'cdata':
return { color: "#008000", italic: true } return { color: '#008000', italic: true }
case "namespace": case 'namespace':
return { opacity: 0.7 } return { opacity: 0.7 }
case "string": case 'string':
return { color: "#A31515" } return { color: '#A31515' }
case "punctuation": case 'punctuation':
case "operator": case 'operator':
return { color: "#393A34" } return { color: '#393A34' }
case "url": case 'url':
case "symbol": case 'symbol':
case "number": case 'number':
case "boolean": case 'boolean':
case "variable": case 'variable':
case "constant": case 'constant':
case "inserted": case 'inserted':
return { color: "#36acaa" } return { color: '#36acaa' }
case "atrule": case 'atrule':
case "keyword": case 'keyword':
case "attr-value": case 'attr-value':
return { color: "#0000ff" } return { color: '#0000ff' }
case "function": case 'function':
return { color: "#b9a40a" } return { color: '#b9a40a' }
case "deleted": case 'deleted':
case "tag": case 'tag':
return { color: "#9a050f" } return { color: '#9a050f' }
case "selector": case 'selector':
return { color: "#00009f" } return { color: '#00009f' }
case "important": case 'important':
return { color: "#e90", bold: true } return { color: '#e90', bold: true }
case "italic": case 'italic':
return { italic: true } return { italic: true }
case "class-name": case 'class-name':
case "property": case 'property':
return { color: "#2B91AF" } return { color: '#2B91AF' }
case "attr-name": case 'attr-name':
case "regex": case 'regex':
case "entity": case 'entity':
return { color: "#ff0000" } return { color: '#ff0000' }
default: default:
return null return null
} }

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save