From eb3ea5ed55cdedea0e281d45177c8661f674a280 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Thu, 11 Jul 2024 22:10:18 +0800 Subject: [PATCH 1/6] fix: add control placeholder using default style #691 --- src/editor/core/draw/control/Control.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/editor/core/draw/control/Control.ts b/src/editor/core/draw/control/Control.ts index 709a30c..adcef09 100644 --- a/src/editor/core/draw/control/Control.ts +++ b/src/editor/core/draw/control/Control.ts @@ -23,7 +23,13 @@ import { IEditorData, IEditorOption } from '../../../interface/Editor' import { IElement, IElementPosition } from '../../../interface/Element' import { EventBusMap } from '../../../interface/EventBus' import { IRange } from '../../../interface/Range' -import { deepClone, nextTick, omitObject, splitText } from '../../../utils' +import { + deepClone, + nextTick, + omitObject, + pickObject, + splitText +} from '../../../utils' import { formatElementContext, formatElementList, @@ -510,9 +516,12 @@ export class Control { const control = startElement.control! if (!control.placeholder) return const placeholderStrList = splitText(control.placeholder) + // 优先使用默认控件样式 + const anchorElementStyleAttr = pickObject(startElement, CONTROL_STYLE_ATTR) for (let p = 0; p < placeholderStrList.length; p++) { const value = placeholderStrList[p] const newElement: IElement = { + ...anchorElementStyleAttr, value, controlId: startElement.controlId, type: ElementType.CONTROL, From 3f0a49f56be7060d328a63c994f571b0a35a3521 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Sat, 13 Jul 2024 17:56:08 +0800 Subject: [PATCH 2/6] fix: delete table col boundary error #688 --- src/editor/core/command/CommandAdapt.ts | 32 +++++++------------------ 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index 9139940..9dbf7da 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -1179,37 +1179,23 @@ export class CommandAdapt { this.deleteTable() return } - // 跨列处理 + // 缩小colspan或删除与当前列重叠的单元格 for (let t = 0; t < curTrList.length; t++) { const tr = curTrList[t] for (let d = 0; d < tr.tdList.length; d++) { const td = tr.tdList[d] - if (td.colspan > 1) { - const tdColIndex = td.colIndex! - // 交叉减去一列 - if ( - tdColIndex <= curColIndex && - tdColIndex + td.colspan - 1 >= curColIndex - ) { - td.colspan -= 1 + if ( + td.colIndex! <= curColIndex && + td.colIndex! + td.colspan > curColIndex + ) { + if (td.colspan > 1) { + td.colspan-- + } else { + tr.tdList.splice(d, 1) } } } } - // 删除当前列 - for (let t = 0; t < curTrList.length; t++) { - const tr = curTrList[t] - let start = -1 - for (let d = 0; d < tr.tdList.length; d++) { - const td = tr.tdList[d] - if (td.colIndex === curColIndex) { - start = d - } - } - if (~start) { - tr.tdList.splice(start, 1) - } - } element.colgroup?.splice(curColIndex, 1) // 重新设置上下文 this.position.setPositionContext({ From 2d2ceea946d87a7423a8425cedf40dff3e8c9d2a Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Sat, 13 Jul 2024 18:08:17 +0800 Subject: [PATCH 3/6] release: v0.9.86 --- CHANGELOG.md | 18 ++++++++++++++++++ package.json | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31e030b..96b0ab8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,21 @@ +## [0.9.86](https://github.com/Hufe921/canvas-editor/compare/v0.9.85...v0.9.86) (2024-07-13) + + +### Bug Fixes + +* add control placeholder boundary error #686 ([fac5c5c](https://github.com/Hufe921/canvas-editor/commit/fac5c5c045a30cb5e0c46ef027c83f21e07bcaa8)), closes [#686](https://github.com/Hufe921/canvas-editor/issues/686) +* add control placeholder using default style #691 ([eb3ea5e](https://github.com/Hufe921/canvas-editor/commit/eb3ea5ed55cdedea0e281d45177c8661f674a280)), closes [#691](https://github.com/Hufe921/canvas-editor/issues/691) +* delete table col boundary error #688 ([3f0a49f](https://github.com/Hufe921/canvas-editor/commit/3f0a49f56be7060d328a63c994f571b0a35a3521)), closes [#688](https://github.com/Hufe921/canvas-editor/issues/688) +* refocus when cursor is not focused #685 ([0ac8ae7](https://github.com/Hufe921/canvas-editor/commit/0ac8ae7c4b0b47ee84a9c0f8c37ffde612849957)), closes [#685](https://github.com/Hufe921/canvas-editor/issues/685) +* remove title and list properties from getControlList return value #683 ([b024050](https://github.com/Hufe921/canvas-editor/commit/b024050b3ef7f787079a74b062e5d83085be1a5f)), closes [#683](https://github.com/Hufe921/canvas-editor/issues/683) + + +### Features + +* add executeInsertControl api ([e5b3d05](https://github.com/Hufe921/canvas-editor/commit/e5b3d05991a26dc186cdf63962ca3c7b50a32572)) + + + ## [0.9.85](https://github.com/Hufe921/canvas-editor/compare/v0.9.84...v0.9.85) (2024-07-07) diff --git a/package.json b/package.json index 41122bc..651ae56 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@hufe921/canvas-editor", "author": "Hufe", "license": "MIT", - "version": "0.9.85", + "version": "0.9.86", "description": "rich text editor by canvas/svg", "publishConfig": { "registry": "https://registry.npmjs.org/", From 26a3468f66d67bf8249cdc1a679c740d7cf1a9c9 Mon Sep 17 00:00:00 2001 From: baseWalker <104012756+baseWalker@users.noreply.github.com> Date: Mon, 15 Jul 2024 17:35:04 +0800 Subject: [PATCH 4/6] feat: set control properties in read-only mode #679 --- src/editor/core/command/CommandAdapt.ts | 6 ------ src/editor/core/draw/control/Control.ts | 6 ------ 2 files changed, 12 deletions(-) diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index 9dbf7da..a957f63 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -2453,20 +2453,14 @@ export class CommandAdapt { } public setControlValue(payload: ISetControlValueOption) { - const isReadonly = this.draw.isReadonly() - if (isReadonly) return this.draw.getControl().setValueByConceptId(payload) } public setControlExtension(payload: ISetControlExtensionOption) { - const isReadonly = this.draw.isReadonly() - if (isReadonly) return this.draw.getControl().setExtensionByConceptId(payload) } public setControlProperties(payload: ISetControlProperties) { - const isReadonly = this.draw.isReadonly() - if (isReadonly) return this.draw.getControl().setPropertiesByConceptId(payload) } diff --git a/src/editor/core/draw/control/Control.ts b/src/editor/core/draw/control/Control.ts index adcef09..231a023 100644 --- a/src/editor/core/draw/control/Control.ts +++ b/src/editor/core/draw/control/Control.ts @@ -647,8 +647,6 @@ export class Control { } public setValueByConceptId(payload: ISetControlValueOption) { - const isReadonly = this.draw.isReadonly() - if (isReadonly) return let isExistSet = false const { conceptId, value } = payload // 设置值 @@ -761,8 +759,6 @@ export class Control { } public setExtensionByConceptId(payload: ISetControlExtensionOption) { - const isReadonly = this.draw.isReadonly() - if (isReadonly) return const { conceptId, extension } = payload const setExtension = (elementList: IElement[]) => { let i = 0 @@ -803,8 +799,6 @@ export class Control { } public setPropertiesByConceptId(payload: ISetControlProperties) { - const isReadonly = this.draw.isReadonly() - if (isReadonly) return const { conceptId, properties } = payload let isExistUpdate = false function setProperties(elementList: IElement[]) { From 97ac2daaf8f0688b181cb8baea9ba74ae1664361 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Mon, 15 Jul 2024 22:17:47 +0800 Subject: [PATCH 5/6] feat: optimize text selection at the beginning of a line #695 --- src/editor/core/position/Position.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/editor/core/position/Position.ts b/src/editor/core/position/Position.ts index 8a4a255..dbe0783 100644 --- a/src/editor/core/position/Position.ts +++ b/src/editor/core/position/Position.ts @@ -511,11 +511,17 @@ export class Position { const headIndex = positionList.findIndex( p => p.pageNo === positionNo && p.rowNo === rowNo ) + const headElement = elementList[headIndex] + const headPosition = positionList[headIndex] // 是否在头部 - if (x < this.options.margins[3]) { + const headStartX = + headElement.listStyle === ListStyle.CHECKBOX + ? this.options.margins[3] + : headPosition.coordinate.leftTop[0] + if (x < headStartX) { // 头部元素为空元素时无需选中 if (~headIndex) { - if (positionList[headIndex].value === ZERO) { + if (headPosition.value === ZERO) { curPositionIndex = headIndex } else { curPositionIndex = headIndex - 1 @@ -526,10 +532,7 @@ export class Position { } } else { // 是否是复选框列表 - if ( - elementList[headIndex].listStyle === ListStyle.CHECKBOX && - x < leftTop[0] - ) { + if (headElement.listStyle === ListStyle.CHECKBOX && x < leftTop[0]) { return { index: headIndex, isDirectHit: true, From 67c63f856f2c0e3e8c0644e39694357639c18d7e Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Thu, 18 Jul 2024 18:06:43 +0800 Subject: [PATCH 6/6] feat: add custom field to getValue api #699 --- src/editor/core/draw/Draw.ts | 14 ++++++++++---- src/editor/interface/Draw.ts | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/editor/core/draw/Draw.ts b/src/editor/core/draw/Draw.ts index 1a02e90..4c77789 100644 --- a/src/editor/core/draw/Draw.ts +++ b/src/editor/core/draw/Draw.ts @@ -1005,7 +1005,7 @@ export class Draw { } public getValue(options: IGetValueOption = {}): IEditorResult { - const { pageNo } = options + const { pageNo, extraPickAttrs } = options let mainElementList = this.elementList if ( Number.isInteger(pageNo) && @@ -1017,9 +1017,15 @@ export class Draw { ) } const data: IEditorData = { - header: zipElementList(this.getHeaderElementList()), - main: zipElementList(mainElementList), - footer: zipElementList(this.getFooterElementList()) + header: zipElementList(this.getHeaderElementList(), { + extraPickAttrs + }), + main: zipElementList(mainElementList, { + extraPickAttrs + }), + footer: zipElementList(this.getFooterElementList(), { + extraPickAttrs + }) } return { version, diff --git a/src/editor/interface/Draw.ts b/src/editor/interface/Draw.ts index da5bd9e..06483fb 100644 --- a/src/editor/interface/Draw.ts +++ b/src/editor/interface/Draw.ts @@ -54,6 +54,7 @@ export interface IPainterOption { export interface IGetValueOption { pageNo?: number + extraPickAttrs?: Array } export interface IAppendElementListOption {