feat:增加行布局
This commit is contained in:
+12
-1
@@ -39,7 +39,6 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="menu-item__size-add">
|
<div class="menu-item__size-add">
|
||||||
<i></i>
|
<i></i>
|
||||||
</div>
|
</div>
|
||||||
@@ -70,6 +69,18 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="menu-divider"></div>
|
<div class="menu-divider"></div>
|
||||||
|
<div class="menu-item">
|
||||||
|
<div class="menu-item__left">
|
||||||
|
<i></i>
|
||||||
|
</div>
|
||||||
|
<div class="menu-item__center">
|
||||||
|
<i></i>
|
||||||
|
</div>
|
||||||
|
<div class="menu-item__right">
|
||||||
|
<i></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="menu-divider"></div>
|
||||||
<div class="menu-item">
|
<div class="menu-item">
|
||||||
<div class="menu-item__search">
|
<div class="menu-item__search">
|
||||||
<i></i>
|
<i></i>
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M2 13h12v1H2v-1zm2-3h8v1H4v-1zM2 7h12v1H2V7zm0-6h12v1H2V1zm2 3h8v1H4V4z" fill="#3D4757" fill-rule="evenodd"/></svg>
|
||||||
|
After Width: | Height: | Size: 207 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="M2 13h12v1H2zm0-3h8v1H2zm0-3h12v1H2zm0-6h12v1H2zm0 3h8v1H2z" fill="#3d4757" fill-rule="evenodd"/></svg>
|
||||||
|
After Width: | Height: | Size: 195 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M2 13h12v1H2v-1zm4-3h8v1H6v-1zM2 7h12v1H2V7zm0-6h12v1H2V1zm4 3h8v1H6V4z" fill="#3D4757" fill-rule="evenodd"/></svg>
|
||||||
|
After Width: | Height: | Size: 207 B |
@@ -1,3 +1,4 @@
|
|||||||
|
import { RowFlex } from "../../dataset/enum/Row"
|
||||||
import { CommandAdapt } from "./CommandAdapt"
|
import { CommandAdapt } from "./CommandAdapt"
|
||||||
|
|
||||||
export class Command {
|
export class Command {
|
||||||
@@ -15,6 +16,9 @@ export class Command {
|
|||||||
private static strikeout: Function
|
private static strikeout: Function
|
||||||
private static color: Function
|
private static color: Function
|
||||||
private static highlight: Function
|
private static highlight: Function
|
||||||
|
private static left: Function
|
||||||
|
private static center: Function
|
||||||
|
private static right: Function
|
||||||
private static search: Function
|
private static search: Function
|
||||||
private static print: Function
|
private static print: Function
|
||||||
|
|
||||||
@@ -32,6 +36,9 @@ export class Command {
|
|||||||
Command.strikeout = adapt.strikeout.bind(adapt)
|
Command.strikeout = adapt.strikeout.bind(adapt)
|
||||||
Command.color = adapt.color.bind(adapt)
|
Command.color = adapt.color.bind(adapt)
|
||||||
Command.highlight = adapt.highlight.bind(adapt)
|
Command.highlight = adapt.highlight.bind(adapt)
|
||||||
|
Command.left = adapt.rowFlex.bind(adapt)
|
||||||
|
Command.center = adapt.rowFlex.bind(adapt)
|
||||||
|
Command.right = adapt.rowFlex.bind(adapt)
|
||||||
Command.search = adapt.search.bind(adapt)
|
Command.search = adapt.search.bind(adapt)
|
||||||
Command.print = adapt.print.bind(adapt)
|
Command.print = adapt.print.bind(adapt)
|
||||||
}
|
}
|
||||||
@@ -90,6 +97,18 @@ export class Command {
|
|||||||
return Command.highlight(payload)
|
return Command.highlight(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public executeLeft() {
|
||||||
|
return Command.left(RowFlex.LEFT)
|
||||||
|
}
|
||||||
|
|
||||||
|
public executeCenter() {
|
||||||
|
return Command.center(RowFlex.CENTER)
|
||||||
|
}
|
||||||
|
|
||||||
|
public executeRight() {
|
||||||
|
return Command.right(RowFlex.RIGHT)
|
||||||
|
}
|
||||||
|
|
||||||
// 搜索、打印
|
// 搜索、打印
|
||||||
public executeSearch(payload: string | null) {
|
public executeSearch(payload: string | null) {
|
||||||
return Command.search(payload)
|
return Command.search(payload)
|
||||||
|
|||||||
@@ -1,21 +1,25 @@
|
|||||||
import { ElementStyleKey } from "../../dataset/enum/ElementStyle"
|
import { ElementStyleKey } from "../../dataset/enum/ElementStyle"
|
||||||
|
import { RowFlex } from "../../dataset/enum/Row"
|
||||||
import { IEditorOption } from "../../interface/Editor"
|
import { IEditorOption } from "../../interface/Editor"
|
||||||
import { IElementStyle } from "../../interface/Element"
|
import { IElementStyle } from "../../interface/Element"
|
||||||
import { printImageBase64 } from "../../utils/print"
|
import { printImageBase64 } from "../../utils/print"
|
||||||
import { Draw } from "../draw/Draw"
|
import { Draw } from "../draw/Draw"
|
||||||
import { HistoryManager } from "../history/HistoryManager"
|
import { HistoryManager } from "../history/HistoryManager"
|
||||||
|
import { Position } from "../position/Position"
|
||||||
import { RangeManager } from "../range/RangeManager"
|
import { RangeManager } from "../range/RangeManager"
|
||||||
|
|
||||||
export class CommandAdapt {
|
export class CommandAdapt {
|
||||||
|
|
||||||
private draw: Draw
|
private draw: Draw
|
||||||
private range: RangeManager
|
private range: RangeManager
|
||||||
|
private position: Position
|
||||||
private historyManager: HistoryManager
|
private historyManager: HistoryManager
|
||||||
private options: Required<IEditorOption>
|
private options: Required<IEditorOption>
|
||||||
|
|
||||||
constructor(draw: Draw) {
|
constructor(draw: Draw) {
|
||||||
this.draw = draw
|
this.draw = draw
|
||||||
this.range = draw.getRange()
|
this.range = draw.getRange()
|
||||||
|
this.position = draw.getPosition()
|
||||||
this.historyManager = draw.getHistoryManager()
|
this.historyManager = draw.getHistoryManager()
|
||||||
this.options = draw.getOptions()
|
this.options = draw.getOptions()
|
||||||
}
|
}
|
||||||
@@ -157,6 +161,28 @@ export class CommandAdapt {
|
|||||||
this.draw.render({ isSetCursor: false })
|
this.draw.render({ isSetCursor: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public rowFlex(payload: RowFlex) {
|
||||||
|
const { startIndex, endIndex } = this.range.getRange()
|
||||||
|
if (startIndex === 0 && endIndex === 0) return
|
||||||
|
const positionList = this.position.getPositionList()
|
||||||
|
// 开始/结束行号
|
||||||
|
const startRowNo = positionList[startIndex].rowNo
|
||||||
|
const endRowNo = positionList[endIndex].rowNo
|
||||||
|
const elementList = this.draw.getElementList()
|
||||||
|
// 当前选区所在行
|
||||||
|
for (let p = 0; p < positionList.length; p++) {
|
||||||
|
const postion = positionList[p]
|
||||||
|
if (postion.rowNo > endRowNo) break
|
||||||
|
if (postion.rowNo >= startRowNo && postion.rowNo <= endRowNo) {
|
||||||
|
elementList[p].rowFlex = payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 光标定位
|
||||||
|
const isSetCursor = startIndex === endIndex
|
||||||
|
const curIndex = isSetCursor ? endIndex : startIndex
|
||||||
|
this.draw.render({ curIndex, isSetCursor })
|
||||||
|
}
|
||||||
|
|
||||||
public search(payload: string | null) {
|
public search(payload: string | null) {
|
||||||
if (payload) {
|
if (payload) {
|
||||||
const elementList = this.draw.getElementList()
|
const elementList = this.draw.getElementList()
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { ZERO } from "../../dataset/constant/Common"
|
import { ZERO } from "../../dataset/constant/Common"
|
||||||
|
import { RowFlex } from "../../dataset/enum/Row"
|
||||||
import { IDrawOption } from "../../interface/Draw"
|
import { IDrawOption } from "../../interface/Draw"
|
||||||
import { IEditorOption } from "../../interface/Editor"
|
import { IEditorOption } from "../../interface/Editor"
|
||||||
import { IElement, IElementPosition, IElementStyle } from "../../interface/Element"
|
import { IElement, IElementPosition, IElementStyle } from "../../interface/Element"
|
||||||
@@ -170,7 +171,8 @@ export class Draw {
|
|||||||
width: 0,
|
width: 0,
|
||||||
height: 0,
|
height: 0,
|
||||||
ascent: 0,
|
ascent: 0,
|
||||||
elementList: []
|
elementList: [],
|
||||||
|
rowFlex: this.elementList[0].rowFlex
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
for (let i = 0; i < this.elementList.length; i++) {
|
for (let i = 0; i < this.elementList.length; i++) {
|
||||||
@@ -189,7 +191,8 @@ export class Draw {
|
|||||||
width,
|
width,
|
||||||
height: this.options.defaultSize,
|
height: this.options.defaultSize,
|
||||||
elementList: [lineText],
|
elementList: [lineText],
|
||||||
ascent: fontBoundingBoxAscent
|
ascent: fontBoundingBoxAscent,
|
||||||
|
rowFlex: lineText.rowFlex
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
curRow.width += width
|
curRow.width += width
|
||||||
@@ -207,6 +210,15 @@ export class Draw {
|
|||||||
let index = 0
|
let index = 0
|
||||||
for (let i = 0; i < rowList.length; i++) {
|
for (let i = 0; i < rowList.length; i++) {
|
||||||
const curRow = rowList[i];
|
const curRow = rowList[i];
|
||||||
|
// 计算行偏移量(行居左、居中、居右)
|
||||||
|
if (curRow.rowFlex && curRow.rowFlex !== RowFlex.LEFT) {
|
||||||
|
const canvasInnerWidth = this.canvas.width - margins[1] - margins[3]
|
||||||
|
if (curRow.rowFlex === RowFlex.CENTER) {
|
||||||
|
x += (canvasInnerWidth - curRow.width) / 2
|
||||||
|
} else {
|
||||||
|
x += canvasInnerWidth - curRow.width
|
||||||
|
}
|
||||||
|
}
|
||||||
for (let j = 0; j < curRow.elementList.length; j++) {
|
for (let j = 0; j < curRow.elementList.length; j++) {
|
||||||
this.ctx.save()
|
this.ctx.save()
|
||||||
const element = curRow.elementList[j]
|
const element = curRow.elementList[j]
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ export class GlobalEvent {
|
|||||||
}
|
}
|
||||||
this.cursor.recoveryCursor()
|
this.cursor.recoveryCursor()
|
||||||
this.range.recoveryRangeStyle()
|
this.range.recoveryRangeStyle()
|
||||||
|
this.range.setRange(0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
setDragState() {
|
setDragState() {
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ export class RangeManager {
|
|||||||
let strikeout = !~curElementList.findIndex(el => !el.strikeout)
|
let 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 painter = !!this.draw.getPainterStyle()
|
const painter = !!this.draw.getPainterStyle()
|
||||||
const undo = this.historyManager.isCanUndo()
|
const undo = this.historyManager.isCanUndo()
|
||||||
@@ -73,7 +74,8 @@ export class RangeManager {
|
|||||||
underline,
|
underline,
|
||||||
strikeout,
|
strikeout,
|
||||||
color,
|
color,
|
||||||
highlight
|
highlight,
|
||||||
|
rowFlex
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +95,8 @@ export class RangeManager {
|
|||||||
underline: false,
|
underline: false,
|
||||||
strikeout: false,
|
strikeout: false,
|
||||||
color: null,
|
color: null,
|
||||||
highlight: null
|
highlight: null,
|
||||||
|
rowFlex: null
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
export enum RowFlex {
|
||||||
|
LEFT = 'left',
|
||||||
|
CENTER = 'center',
|
||||||
|
RIGHT = 'right'
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { RowFlex } from "../dataset/enum/Row"
|
||||||
|
|
||||||
export interface IElementStyle {
|
export interface IElementStyle {
|
||||||
font?: string;
|
font?: string;
|
||||||
size?: number;
|
size?: number;
|
||||||
@@ -9,6 +11,7 @@ export interface IElementStyle {
|
|||||||
italic?: boolean;
|
italic?: boolean;
|
||||||
underline?: boolean;
|
underline?: boolean;
|
||||||
strikeout?: boolean;
|
strikeout?: boolean;
|
||||||
|
rowFlex?: RowFlex;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IElementBasic {
|
export interface IElementBasic {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { RowFlex } from "../dataset/enum/Row"
|
||||||
|
|
||||||
export interface IRangeStype {
|
export interface IRangeStype {
|
||||||
undo: boolean;
|
undo: boolean;
|
||||||
redo: boolean;
|
redo: boolean;
|
||||||
@@ -9,6 +11,7 @@ export interface IRangeStype {
|
|||||||
strikeout: boolean;
|
strikeout: boolean;
|
||||||
color: string | null;
|
color: string | null;
|
||||||
highlight: string | null;
|
highlight: string | null;
|
||||||
|
rowFlex: RowFlex | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type IRangeStyleChange = (payload: IRangeStype) => void;
|
export type IRangeStyleChange = (payload: IRangeStype) => void;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { RowFlex } from "../dataset/enum/Row"
|
||||||
import { IElement } from "./Element"
|
import { IElement } from "./Element"
|
||||||
|
|
||||||
export type IRowElement = IElement & {
|
export type IRowElement = IElement & {
|
||||||
@@ -8,5 +9,6 @@ export interface IRow {
|
|||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
ascent: number;
|
ascent: number;
|
||||||
|
rowFlex?: RowFlex
|
||||||
elementList: IRowElement[];
|
elementList: IRowElement[];
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-1
@@ -138,7 +138,22 @@ window.onload = function () {
|
|||||||
console.log('highlight')
|
console.log('highlight')
|
||||||
highlightControlDom?.click()
|
highlightControlDom?.click()
|
||||||
}
|
}
|
||||||
|
// 行布局
|
||||||
|
const leftDom = document.querySelector<HTMLDivElement>('.menu-item__left')!
|
||||||
|
leftDom.onclick = function () {
|
||||||
|
console.log('left')
|
||||||
|
instance.command.executeLeft()
|
||||||
|
}
|
||||||
|
const centerDom = document.querySelector<HTMLDivElement>('.menu-item__center')!
|
||||||
|
centerDom.onclick = function () {
|
||||||
|
console.log('center')
|
||||||
|
instance.command.executeCenter()
|
||||||
|
}
|
||||||
|
const rightDom = document.querySelector<HTMLDivElement>('.menu-item__right')!
|
||||||
|
rightDom.onclick = function () {
|
||||||
|
console.log('right')
|
||||||
|
instance.command.executeRight()
|
||||||
|
}
|
||||||
// 搜索、打印
|
// 搜索、打印
|
||||||
const collspanDom = document.querySelector<HTMLDivElement>('.menu-item__search__collapse')
|
const collspanDom = document.querySelector<HTMLDivElement>('.menu-item__search__collapse')
|
||||||
const searchInputDom = document.querySelector<HTMLInputElement>('.menu-item__search__collapse__search input')
|
const searchInputDom = document.querySelector<HTMLInputElement>('.menu-item__search__collapse__search input')
|
||||||
@@ -193,6 +208,17 @@ window.onload = function () {
|
|||||||
highlightControlDom.value = '#ffff00'
|
highlightControlDom.value = '#ffff00'
|
||||||
highlightSpanDom.style.backgroundColor = '#ffff00'
|
highlightSpanDom.style.backgroundColor = '#ffff00'
|
||||||
}
|
}
|
||||||
|
// 行布局
|
||||||
|
leftDom.classList.remove('active')
|
||||||
|
centerDom.classList.remove('active')
|
||||||
|
rightDom.classList.remove('active')
|
||||||
|
if (payload.rowFlex && payload.rowFlex === 'right') {
|
||||||
|
rightDom.classList.add('active')
|
||||||
|
} else if (payload.rowFlex && payload.rowFlex === 'center') {
|
||||||
|
centerDom.classList.add('active')
|
||||||
|
} else {
|
||||||
|
leftDom.classList.add('active')
|
||||||
|
}
|
||||||
// 功能
|
// 功能
|
||||||
payload.undo ? undoDom.classList.remove('no-allow') : undoDom.classList.add('no-allow')
|
payload.undo ? undoDom.classList.remove('no-allow') : undoDom.classList.add('no-allow')
|
||||||
payload.redo ? redoDom.classList.remove('no-allow') : redoDom.classList.add('no-allow')
|
payload.redo ? redoDom.classList.remove('no-allow') : redoDom.classList.add('no-allow')
|
||||||
|
|||||||
@@ -211,6 +211,18 @@ ul {
|
|||||||
background-color: #ffff00;
|
background-color: #ffff00;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.menu-item__left i {
|
||||||
|
background-image: url('./assets/images/left.svg');
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-item__center i {
|
||||||
|
background-image: url('./assets/images/center.svg');
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-item__right i {
|
||||||
|
background-image: url('./assets/images/right.svg');
|
||||||
|
}
|
||||||
|
|
||||||
.menu-item__search {
|
.menu-item__search {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user