Compare commits

...

7 Commits

5263
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -1,11 +1,11 @@
{
"name": "@hufe921/canvas-editor",
"name": "@liushuai05/canvas-editor",
"author": "Hufe",
"license": "MIT",
"version": "0.9.91",
"version": "0.9.95",
"description": "rich text editor by canvas/svg",
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"registry": "https://registry.yarnpkg.com/",
"access": "public"
},
"files": [
@ -18,10 +18,10 @@
"typings": "./dist/src/editor/index.d.ts",
"main": "./dist/canvas-editor.umd.js",
"module": "./dist/canvas-editor.es.js",
"homepage": "https://github.com/Hufe921/canvas-editor",
"homepage": "https://git.liushuai.cq.cn/lsadmin/canvas-editor_fex675",
"repository": {
"type": "git",
"url": "https://github.com/Hufe921/canvas-editor.git"
"url": "git+https://git.liushuai.cq.cn/lsadmin/canvas-editor_fex675.git"
},
"keywords": [
"canvas-editor",
@ -70,5 +70,11 @@
"simple-git-hooks": {
"pre-commit": "npm run lint && npm run type:check",
"commit-msg": "node scripts/verifyCommit.js"
},
"directories": {
"doc": "docs"
},
"bugs": {
"url": "https://github.com/Hufe921/canvas-editor/issues"
}
}

File diff suppressed because it is too large Load Diff

@ -1413,11 +1413,16 @@ export class Draw {
if (curPagePreHeight + rowMarginHeight + elementHeight > height) {
const trList = element.trList!
// 计算需要移除的行数
let deleteStart = 0
let deleteCount = 0
let preTrHeight = 0
let deleteStart = 0 //拆分开始行
let deleteCount = 0 //拆分行数
let preTrHeight = 0 //前面tr的高度
const colInfoCache = new Map() //缓存需要加临时td的信息
// 大于一行时再拆分避免循环
if (trList.length > 1) {
// 拆分后剩余高度
// 思路改变tr的结构 得到第几行开始删除删除的第一行添加rowspan: rowspan - 前面的tr的row,
// 添加临时td开始分页的head的上一级判断最大的colspan记录最大colspan在td的index
// 在分页的第一行的index位置添加临时td
for (let r = 0; r < trList.length; r++) {
const tr = trList[r]
const trHeight = tr.height * scale
@ -1425,19 +1430,123 @@ export class Draw {
curPagePreHeight + rowMarginHeight + preTrHeight + trHeight >
height
) {
// 当前行存在跨行中断-暂时忽略分页
const rowColCount = tr.tdList.reduce(
(pre, cur) => pre + cur.colspan,
0
)
if (element.colgroup?.length !== rowColCount) {
deleteCount = 0
}
// 开始计算添加临时td
colInfoCache.forEach((item, key) => {
const mdRowIndex = parseInt(key.split('-')[1], 10)
const mdColIndex = parseInt(key.split('-')[0], 10)
// 确保 mdRowIndex 和 mdColIndex 是有效的索引
if (
!trList[mdRowIndex] ||
!trList[mdRowIndex].tdList[mdColIndex]
) {
console.error(
`Invalid index: mdRowIndex=${mdRowIndex}, mdColIndex=${mdColIndex}`
)
return
}
// 计算要被分割的rowspan
const cell = trList[mdRowIndex].tdList[mdColIndex]
const newRowspan = cell.rowspan - (item.row - item.count)
cell.rowspan = newRowspan
let initHeight = 0
let initRealHeight = 0
let initRealMinHeight = 0
for (let i = mdRowIndex; i < newRowspan; i++) {
if (trList[i]?.tdList[mdColIndex]?.height) {
const td = trList[i]?.tdList[mdColIndex]
if (td && td.height) {
initHeight += td.height
} else if (td && td.realHeight) {
initRealHeight += td.realHeight
} else if (td && td.realMinHeight) {
initRealMinHeight += td.realMinHeight
} else {
console.error('td.height is undefined')
}
}
}
tr.tdList.splice(item.col, 0, tr.tdList[tr.tdList.length - 1])
const tempRow = item.row - item.count
tr.tdList[mdColIndex] = {
...cell,
id: getUUID(),
rowspan: tempRow,
height: height - initHeight,
realHeight: height - initRealHeight,
realMinHeight: height - initRealMinHeight,
temporaryFlag: true,
parentTr: `${mdColIndex}-${mdRowIndex}`,
value: cell.value.map(item => ({ ...item, value: '' }))
}
cell.height = initHeight
cell.realHeight = initRealHeight
cell.realMinHeight = initRealMinHeight
this.tableParticle.computeRowColInfo(element)
})
break
} else {
deleteStart = r + 1
deleteCount = trList.length - deleteStart
preTrHeight += trHeight
// 重新记录临时的td
for (let i = 0; i < trList.length; i++) {
for (let j = trList[i]?.tdList.length - 1; j >= 0; j--) {
if (trList[i]?.tdList[j]?.temporaryFlag) {
const tempTd = trList[i].tdList[j]
if (tempTd.parentTr) {
const mdRowIndex = parseInt(
tempTd?.parentTr.split('-')[1],
10
)
const mdColIndex = parseInt(
tempTd?.parentTr.split('-')[0],
10
)
const cell = trList[mdRowIndex].tdList[mdColIndex]
cell.rowspan += trList[i]?.tdList[j].rowspan
let initHeight = 0
let initRealHeight = 0
let initRealMinHeight = 0
for (let i = mdRowIndex; i < tempTd.rowspan; i++) {
if (trList[i]?.tdList[mdColIndex]?.height) {
const td = trList[i]?.tdList[mdColIndex]
if (td && td.height) {
initHeight += td.height
} else if (td && td.realHeight) {
initRealHeight += td.realHeight
} else if (td && td.realMinHeight) {
initRealMinHeight += td.realMinHeight
} else {
console.error('td.height is undefined')
}
}
}
cell.height = initHeight
cell.realHeight = initRealHeight
cell.realMinHeight = initRealMinHeight
trList[i]?.tdList.splice(j, 1)
}
}
}
}
// 找到要分页的位置存入Map
tr.tdList.forEach((td, index) => {
if (td.rowspan > 1) {
colInfoCache.set(`${index}-${r}`, {
col: index,
row: td.rowspan,
count: 0
})
}
})
// 计算分页是否需要添加临时td
colInfoCache.forEach((item, index) => {
++item.count
if (item.count >= item.row) {
colInfoCache.delete(index)
}
})
}
}
}

@ -29,4 +29,6 @@ export interface ITd {
mainHeight?: number // 内容 + 内边距高度
realHeight?: number // 真实高度(包含跨列)
realMinHeight?: number // 真实最小高度(包含跨列)
temporaryFlag?: boolean, // 临时单元格标识
parentTr?: string // 记录临时单元格的父级tr用于合并单元格
}

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