fix: table to html

This commit is contained in:
yanmao 2022-01-05 00:41:46 +08:00
parent c67f1bc250
commit 6a87ef0e30
4 changed files with 48 additions and 52 deletions

View File

@ -12,7 +12,6 @@ import {
DATA_ELEMENT, DATA_ELEMENT,
DATA_ID, DATA_ID,
DATA_TRANSIENT_ELEMENT, DATA_TRANSIENT_ELEMENT,
EDITABLE_SELECTOR,
UI, UI,
} from './constants/root'; } from './constants/root';
import Selection from './selection'; import Selection from './selection';

View File

@ -17,6 +17,7 @@ import { DATA_ID } from './constants';
/** /**
* *
*/ */
const SCHEMA_KEYS = ['blocks', 'inlines', 'marks', 'globals'];
class Schema implements SchemaInterface { class Schema implements SchemaInterface {
private _all: Array<SchemaRule> = []; private _all: Array<SchemaRule> = [];
private _typeMap: { private _typeMap: {
@ -150,7 +151,7 @@ class Schema implements SchemaInterface {
*/ */
find(callback: (rule: SchemaRule) => boolean): Array<SchemaRule> { find(callback: (rule: SchemaRule) => boolean): Array<SchemaRule> {
const schemas: Array<SchemaRule> = []; const schemas: Array<SchemaRule> = [];
Object.keys(this.data).forEach((key) => { SCHEMA_KEYS.forEach((key) => {
if (key !== 'globals') { if (key !== 'globals') {
const rules = (this.data[key] as Array<SchemaRule>).filter( const rules = (this.data[key] as Array<SchemaRule>).filter(
callback, callback,
@ -368,9 +369,7 @@ class Schema implements SchemaInterface {
const rule = this.getRule(node); const rule = this.getRule(node);
if (!rule) return; if (!rule) return;
const { globals } = this.data; const { globals } = this.data;
const globalRule = Object.keys(globals).find( const globalRule = globals[rule.type] ? rule.type : undefined;
(dataType) => rule.type === dataType,
);
const allRule = { const allRule = {
...omit(rule, 'attributes'), ...omit(rule, 'attributes'),
attributes: merge( attributes: merge(

View File

@ -469,8 +469,8 @@ div[data-card-key="table"].card-selected .data-table, div[data-card-key="table"]
} }
.table-wrapper .table-main-content { .table-wrapper .table-main-content {
margin: 4px 4px; margin: 2px 2px;
padding: 0 2px; padding: 4px 4px;
position: relative; position: relative;
z-index: 3; z-index: 3;
overflow: hidden; overflow: hidden;

View File

@ -377,12 +377,12 @@ class Table<T extends TableOptions = TableOptions> extends Plugin<T> {
`[${CARD_KEY}="${TableComponent.cardName}"],[${READY_CARD_KEY}="${TableComponent.cardName}"]`, `[${CARD_KEY}="${TableComponent.cardName}"],[${READY_CARD_KEY}="${TableComponent.cardName}"]`,
).each((tableNode) => { ).each((tableNode) => {
const node = $(tableNode); const node = $(tableNode);
let table = node.find('table');
if (table.length === 0) {
const value = decodeCardValue<TableValue>( const value = decodeCardValue<TableValue>(
node.attributes(CARD_VALUE_KEY), node.attributes(CARD_VALUE_KEY),
); );
if (value && value.html) { if (!value || !value.html) return;
let table = node.find('table');
if (table.length === 0) {
// 表格值里面的卡片都是没有被转换过的,所以需要先把卡片转换过来 // 表格值里面的卡片都是没有被转换过的,所以需要先把卡片转换过来
table = $(value.html); table = $(value.html);
if (table.length === 0) { if (table.length === 0) {
@ -415,8 +415,7 @@ class Table<T extends TableOptions = TableOptions> extends Plugin<T> {
: '1px solid #d9d9d9', : '1px solid #d9d9d9',
padding: '4px 8px', padding: '4px 8px',
cursor: 'default', cursor: 'default',
'vertical-align': 'vertical-align': tdElement.css('vertical-align') || 'top',
tdElement.css('vertical-align') || 'top',
}); });
}); });
table.find(Template.TABLE_TD_BG_CLASS).remove(); table.find(Template.TABLE_TD_BG_CLASS).remove();
@ -424,7 +423,6 @@ class Table<T extends TableOptions = TableOptions> extends Plugin<T> {
this.editor.node.unwrap($(content)); this.editor.node.unwrap($(content));
}); });
node.replaceWith(table); node.replaceWith(table);
}
}); });
} }