描述
Bug 1: 样式变更不触发 Quill 事件
触发路径:
右键表格 → 设置边框颜色 / 背景色
tableMenuTools.BorderColor.handle → tableModule.setCellAttrs(tds, 'border-color', color, true)
→ TableCellInnerFormat.setFormatValue → TableCellFormat.setFormatValue
问题代码(node_modules/quill-table-up/src/formats/table-cell-format.ts:106-109):
else if (this.statics.isAllowStyle(name)) {
Object.assign(this.domNode.style, {
[name]: value,
});
}
这里用 Object.assign(domNode.style, ...) 直接修改 DOM,不走 super.setFormatValue(),也不调用 quill.update()。导致:
Quill 的 text-change 事件不被触发
依赖 text-change 读取 innerHTML 并保存到数据库的上层应用拿不到最新 HTML
只有后续其他操作触发了 text-change 时才会"捎带"把之前的样式变更带出去
对比:插入行列、合并拆分等操作使用 quill.updateContents(delta, Quill.sources.USER) 走的是规范路径,事件正确触发。
Bug 2: border-color 不自闭环
同上路径,只设置了 border-color: red,但 CSS 中 border-style 默认值为 none。编辑器内能显示是因为编辑器 CSS 有 .ql-editor td { border: 1px solid #a1a1aa } 补全了 border-style/border-width。但在 H5 等场景下没有这段 CSS,border-color 单独无效。
应同时设置 border-style: solid 和 border-width: 1px。
修复建议
字段 1: 在 TableCellFormat.setFormatValue 设置 isStyle 分支之后调用 quill.update(),或在 table-up.ts 的 setCellAttrs 方法的 for 循环之后追加 this.quill.update(Quill.sources.USER)。
字段 2: 在 TableCellFormat.setFormatValue 中,当 name === 'border-color' 时,同时设置 borderStyle: 'solid' 和 borderWidth: '1px':
if (name === 'border-color') {
if (!this.domNode.style.borderStyle) {
Object.assign(this.domNode.style, { borderStyle: 'solid' });
}
if (!this.domNode.style.borderWidth) {
Object.assign(this.domNode.style, { borderWidth: '1px' });
}
}
环境
quill-table-up: 3.5.2
Quill: 2.x
描述
Bug 1: 样式变更不触发 Quill 事件
触发路径:
右键表格 → 设置边框颜色 / 背景色
tableMenuTools.BorderColor.handle → tableModule.setCellAttrs(tds, 'border-color', color, true)
→ TableCellInnerFormat.setFormatValue → TableCellFormat.setFormatValue
问题代码(node_modules/quill-table-up/src/formats/table-cell-format.ts:106-109):
else if (this.statics.isAllowStyle(name)) {
Object.assign(this.domNode.style, {
[name]: value,
});
}
这里用 Object.assign(domNode.style, ...) 直接修改 DOM,不走 super.setFormatValue(),也不调用 quill.update()。导致:
Quill 的 text-change 事件不被触发
依赖 text-change 读取 innerHTML 并保存到数据库的上层应用拿不到最新 HTML
只有后续其他操作触发了 text-change 时才会"捎带"把之前的样式变更带出去
对比:插入行列、合并拆分等操作使用 quill.updateContents(delta, Quill.sources.USER) 走的是规范路径,事件正确触发。
Bug 2: border-color 不自闭环
同上路径,只设置了 border-color: red,但 CSS 中 border-style 默认值为 none。编辑器内能显示是因为编辑器 CSS 有 .ql-editor td { border: 1px solid #a1a1aa } 补全了 border-style/border-width。但在 H5 等场景下没有这段 CSS,border-color 单独无效。
应同时设置 border-style: solid 和 border-width: 1px。
修复建议
字段 1: 在 TableCellFormat.setFormatValue 设置 isStyle 分支之后调用 quill.update(),或在 table-up.ts 的 setCellAttrs 方法的 for 循环之后追加 this.quill.update(Quill.sources.USER)。
字段 2: 在 TableCellFormat.setFormatValue 中,当 name === 'border-color' 时,同时设置 borderStyle: 'solid' 和 borderWidth: '1px':
if (name === 'border-color') {
if (!this.domNode.style.borderStyle) {
Object.assign(this.domNode.style, { borderStyle: 'solid' });
}
if (!this.domNode.style.borderWidth) {
Object.assign(this.domNode.style, { borderWidth: '1px' });
}
}
环境
quill-table-up: 3.5.2
Quill: 2.x