fix(table):新增行/列无法输入问题
This commit is contained in:
parent
1d97f980de
commit
f829861f3d
|
@ -111,7 +111,7 @@ class TableCommand extends EventEmitter2 implements TableCommandInterface {
|
||||||
const insertIndex = selection.getCellIndex(r, insertCol);
|
const insertIndex = selection.getCellIndex(r, insertCol);
|
||||||
for (let r = 0; r < count; r++) {
|
for (let r = 0; r < count; r++) {
|
||||||
const td = (tr as HTMLTableRowElement).insertCell(insertIndex);
|
const td = (tr as HTMLTableRowElement).insertCell(insertIndex);
|
||||||
td.innerHTML = Template.EmptyCell;
|
td.innerHTML = this.table.template.getEmptyCell();
|
||||||
$(td).attributes(
|
$(td).attributes(
|
||||||
DATA_TRANSIENT_ATTRIBUTES,
|
DATA_TRANSIENT_ATTRIBUTES,
|
||||||
'table-cell-selection',
|
'table-cell-selection',
|
||||||
|
@ -238,7 +238,7 @@ class TableCommand extends EventEmitter2 implements TableCommandInterface {
|
||||||
?.get<HTMLTableRowElement>()
|
?.get<HTMLTableRowElement>()
|
||||||
?.insertCell(insertIndex);
|
?.insertCell(insertIndex);
|
||||||
if (!td) return;
|
if (!td) return;
|
||||||
td.innerHTML = Template.EmptyCell;
|
td.innerHTML = this.table.template.getEmptyCell();
|
||||||
td.colSpan = tdModel.colSpan - cutCount;
|
td.colSpan = tdModel.colSpan - cutCount;
|
||||||
td.rowSpan = tdModel.rowSpan;
|
td.rowSpan = tdModel.rowSpan;
|
||||||
//if(tdModel.element)
|
//if(tdModel.element)
|
||||||
|
@ -324,7 +324,7 @@ class TableCommand extends EventEmitter2 implements TableCommandInterface {
|
||||||
if (!tr) return;
|
if (!tr) return;
|
||||||
insertTdProps.forEach((props) => {
|
insertTdProps.forEach((props) => {
|
||||||
const td = tr.insertCell();
|
const td = tr.insertCell();
|
||||||
td.innerHTML = Template.EmptyCell;
|
td.innerHTML = this.table.template.getEmptyCell();
|
||||||
td.colSpan = props.tdBase.colSpan;
|
td.colSpan = props.tdBase.colSpan;
|
||||||
});
|
});
|
||||||
$(baseRowBar)[insertMethod](
|
$(baseRowBar)[insertMethod](
|
||||||
|
@ -417,7 +417,7 @@ class TableCommand extends EventEmitter2 implements TableCommandInterface {
|
||||||
trs[end.row + 1] as HTMLTableRowElement
|
trs[end.row + 1] as HTMLTableRowElement
|
||||||
).insertCell(insertIndex);
|
).insertCell(insertIndex);
|
||||||
const cutCount = end.row - r + 1;
|
const cutCount = end.row - r + 1;
|
||||||
td.innerHTML = Template.EmptyCell;
|
td.innerHTML = this.table.template.getEmptyCell();
|
||||||
td.colSpan = tdModel.colSpan;
|
td.colSpan = tdModel.colSpan;
|
||||||
td.rowSpan = tdModel.rowSpan - cutCount;
|
td.rowSpan = tdModel.rowSpan - cutCount;
|
||||||
}
|
}
|
||||||
|
@ -526,7 +526,7 @@ class TableCommand extends EventEmitter2 implements TableCommandInterface {
|
||||||
|
|
||||||
selection.each((tdModel) => {
|
selection.each((tdModel) => {
|
||||||
if (!helper.isEmptyModelCol(tdModel) && tdModel.element) {
|
if (!helper.isEmptyModelCol(tdModel) && tdModel.element) {
|
||||||
tdModel.element.innerHTML = Template.EmptyCell;
|
tdModel.element.innerHTML = this.table.template.getEmptyCell();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.emit('actioned', 'clear');
|
this.emit('actioned', 'clear');
|
||||||
|
@ -736,7 +736,7 @@ class TableCommand extends EventEmitter2 implements TableCommandInterface {
|
||||||
const _td2 = (tr as HTMLTableRowElement).insertCell(
|
const _td2 = (tr as HTMLTableRowElement).insertCell(
|
||||||
_insertIndex2,
|
_insertIndex2,
|
||||||
);
|
);
|
||||||
_td2.innerHTML = Template.EmptyCell;
|
_td2.innerHTML = this.table.template.getEmptyCell();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import {
|
||||||
NodeInterface,
|
NodeInterface,
|
||||||
transformCustomTags,
|
transformCustomTags,
|
||||||
EditorInterface,
|
EditorInterface,
|
||||||
|
isEngine,
|
||||||
} from '@aomao/engine';
|
} from '@aomao/engine';
|
||||||
import Template from './template';
|
import Template from './template';
|
||||||
|
|
||||||
|
@ -279,7 +280,11 @@ class Helper implements HelperInterface {
|
||||||
if (editableElement.length === 0) {
|
if (editableElement.length === 0) {
|
||||||
const content = tdNode.html();
|
const content = tdNode.html();
|
||||||
tdNode.empty();
|
tdNode.empty();
|
||||||
tdNode.append(Template.EmptyCell);
|
tdNode.append(
|
||||||
|
Template.EmptyCell(
|
||||||
|
!isEngine(this.#editor) || this.#editor.readonly,
|
||||||
|
),
|
||||||
|
);
|
||||||
editableElement = tdNode.find(EDITABLE_SELECTOR);
|
editableElement = tdNode.find(EDITABLE_SELECTOR);
|
||||||
editableElement.html(content);
|
editableElement.html(content);
|
||||||
}
|
}
|
||||||
|
@ -420,7 +425,11 @@ class Helper implements HelperInterface {
|
||||||
|
|
||||||
let editableElement = to.find(EDITABLE_SELECTOR);
|
let editableElement = to.find(EDITABLE_SELECTOR);
|
||||||
if (editableElement.length === 0) {
|
if (editableElement.length === 0) {
|
||||||
to.html(Template.EmptyCell);
|
to.html(
|
||||||
|
Template.EmptyCell(
|
||||||
|
!isEngine(this.#editor) || this.#editor.readonly,
|
||||||
|
),
|
||||||
|
);
|
||||||
editableElement = to.find(EDITABLE_SELECTOR);
|
editableElement = to.find(EDITABLE_SELECTOR);
|
||||||
}
|
}
|
||||||
editableElement.html(transformCustomTags(from.html()));
|
editableElement.html(transformCustomTags(from.html()));
|
||||||
|
|
|
@ -813,7 +813,8 @@ class TableComponent<V extends TableValue = TableValue>
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
Template.isReadonly = !isEngine(this.editor) || this.editor.readonly;
|
this.template.isReadonly =
|
||||||
|
!isEngine(this.editor) || this.editor.readonly;
|
||||||
// 重新渲染
|
// 重新渲染
|
||||||
if (
|
if (
|
||||||
this.wrapper &&
|
this.wrapper &&
|
||||||
|
@ -879,7 +880,7 @@ class TableComponent<V extends TableValue = TableValue>
|
||||||
if (!editableElement.hasAttribute('contenteditable')) {
|
if (!editableElement.hasAttribute('contenteditable')) {
|
||||||
editableElement.setAttribute(
|
editableElement.setAttribute(
|
||||||
'contenteditable',
|
'contenteditable',
|
||||||
Template.isReadonly ? 'false' : 'true',
|
this.template.isReadonly ? 'false' : 'true',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -70,11 +70,14 @@ class Template implements TemplateInterface {
|
||||||
static readonly TABLE_TD_CONTENT_CLASS = `.${TABLE_TD_CONTENT_CLASS_NAME}`;
|
static readonly TABLE_TD_CONTENT_CLASS = `.${TABLE_TD_CONTENT_CLASS_NAME}`;
|
||||||
static readonly TABLE_TD_BG_CLASS = `.${TABLE_TD_BG_CLASS_NAME}`;
|
static readonly TABLE_TD_BG_CLASS = `.${TABLE_TD_BG_CLASS_NAME}`;
|
||||||
static readonly CellBG = `<div class="${TABLE_TD_BG_CLASS_NAME}"><div class="table-main-border-top"></div><div class="table-main-border-right"></div><div class="table-main-border-bottom"></div><div class="table-main-border-left"></div></div>`;
|
static readonly CellBG = `<div class="${TABLE_TD_BG_CLASS_NAME}"><div class="table-main-border-top"></div><div class="table-main-border-right"></div><div class="table-main-border-bottom"></div><div class="table-main-border-left"></div></div>`;
|
||||||
static isReadonly = false;
|
isReadonly: boolean = false;
|
||||||
static get EmptyCell() {
|
static EmptyCell(readonly: boolean = false) {
|
||||||
return `<div class="${TABLE_TD_CONTENT_CLASS_NAME}" ${DATA_TRANSIENT_ATTRIBUTES}="contenteditable" contenteditable="${
|
return `<div class="${TABLE_TD_CONTENT_CLASS_NAME}" ${DATA_TRANSIENT_ATTRIBUTES}="contenteditable" contenteditable="${
|
||||||
Template.isReadonly ? 'false' : 'true'
|
readonly ? 'false' : 'true'
|
||||||
}" ${DATA_ELEMENT}="${EDITABLE}"><p><br /></p></div>${this.CellBG}`;
|
}" ${DATA_ELEMENT}="${EDITABLE}"><p><br /></p></div>${Template.CellBG}`;
|
||||||
|
}
|
||||||
|
getEmptyCell() {
|
||||||
|
return Template.EmptyCell(this.isReadonly);
|
||||||
}
|
}
|
||||||
private table: TableInterface;
|
private table: TableInterface;
|
||||||
|
|
||||||
|
@ -133,7 +136,7 @@ class Template implements TemplateInterface {
|
||||||
cols = cols === Infinity ? 10 : cols;
|
cols = cols === Infinity ? 10 : cols;
|
||||||
rows = rows === Infinity ? 10 : rows;
|
rows = rows === Infinity ? 10 : rows;
|
||||||
const tds =
|
const tds =
|
||||||
`<td ${DATA_TRANSIENT_ATTRIBUTES}="table-cell-selection">${Template.EmptyCell}</td>`.repeat(
|
`<td ${DATA_TRANSIENT_ATTRIBUTES}="table-cell-selection">${this.getEmptyCell()}</td>`.repeat(
|
||||||
cols,
|
cols,
|
||||||
);
|
);
|
||||||
const trs = `<tr>${tds}</tr>`.repeat(rows);
|
const trs = `<tr>${tds}</tr>`.repeat(rows);
|
||||||
|
|
|
@ -11,15 +11,13 @@ import {
|
||||||
READY_CARD_KEY,
|
READY_CARD_KEY,
|
||||||
decodeCardValue,
|
decodeCardValue,
|
||||||
CARD_VALUE_KEY,
|
CARD_VALUE_KEY,
|
||||||
CARD_SELECTOR,
|
|
||||||
transformCustomTags,
|
transformCustomTags,
|
||||||
READY_CARD_SELECTOR,
|
|
||||||
} from '@aomao/engine';
|
} from '@aomao/engine';
|
||||||
|
import { DATA_ID } from '@aomao/engine';
|
||||||
import TableComponent, { Template, Helper } from './component';
|
import TableComponent, { Template, Helper } from './component';
|
||||||
import locales from './locale';
|
import locales from './locale';
|
||||||
import { TableInterface, TableOptions, TableValue } from './types';
|
import { TableInterface, TableOptions, TableValue } from './types';
|
||||||
import './index.css';
|
import './index.css';
|
||||||
import { DATA_ID } from '@aomao/engine';
|
|
||||||
class Table<T extends TableOptions = TableOptions> extends Plugin<T> {
|
class Table<T extends TableOptions = TableOptions> extends Plugin<T> {
|
||||||
static get pluginName() {
|
static get pluginName() {
|
||||||
return 'table';
|
return 'table';
|
||||||
|
|
|
@ -89,6 +89,10 @@ export interface HelperInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TemplateInterface {
|
export interface TemplateInterface {
|
||||||
|
/**
|
||||||
|
* 是否只读
|
||||||
|
*/
|
||||||
|
isReadonly: boolean;
|
||||||
/**
|
/**
|
||||||
* 用于Card渲染
|
* 用于Card渲染
|
||||||
* @param {object} value 参数
|
* @param {object} value 参数
|
||||||
|
@ -98,11 +102,25 @@ export interface TemplateInterface {
|
||||||
* @return {string} 返回 html 字符串
|
* @return {string} 返回 html 字符串
|
||||||
*/
|
*/
|
||||||
htmlEdit(value: TableValue, menus: TableMenu): string;
|
htmlEdit(value: TableValue, menus: TableMenu): string;
|
||||||
|
/**
|
||||||
|
* 阅读模式渲染
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
htmlView(value: TableValue): string;
|
htmlView(value: TableValue): string;
|
||||||
|
/**
|
||||||
|
* 获取空的单元格模版
|
||||||
|
*/
|
||||||
|
getEmptyCell(): string;
|
||||||
|
/**
|
||||||
|
* 获取指定行数的行 header
|
||||||
|
* @param rows
|
||||||
|
*/
|
||||||
renderRowsHeader(rows: number): string;
|
renderRowsHeader(rows: number): string;
|
||||||
renderColsHeader(rows: number): string;
|
/**
|
||||||
|
* 获取指定列数的列 header
|
||||||
|
* @param cols
|
||||||
|
*/
|
||||||
|
renderColsHeader(cols: number): string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TableValue extends CardValue {
|
export interface TableValue extends CardValue {
|
||||||
|
|
Loading…
Reference in New Issue