fix: table & image

This commit is contained in:
yanmao 2022-01-12 01:33:11 +08:00
parent 75fcce2ee3
commit 707c4a5a54
3 changed files with 22 additions and 13 deletions

View File

@ -78,7 +78,7 @@ export type Options = {
* @returns
*/
onBeforeRender?: (status: 'uploading' | 'done', src: string) => string;
onChange?: (size?: Size) => void;
onChange?: (size?: Size, loaded?: boolean) => void;
onError?: () => void;
};
@ -240,7 +240,7 @@ class Image {
this.detail.css('height', '');
const { onChange } = this.options;
if (isEngine(this.editor) && onChange) {
onChange(this.size);
onChange(this.size, true);
}
window.removeEventListener('resize', this.onWindowResize);
window.addEventListener('resize', this.onWindowResize);
@ -414,10 +414,10 @@ class Image {
const imageHeight = parseInt(image.css('height'));
const size = value.size;
const naturalWidth = size
? size.naturalWidth
? size.naturalWidth || this.size.naturalWidth
: imageWidth * winPixelRatio;
const naturalHeight = size
? size.naturalHeight
? size.naturalHeight || this.size.naturalHeight
: imageHeight * winPixelRatio;
let src = value['src'];
const { onBeforeRender } = this.options;

View File

@ -4,9 +4,11 @@ import {
CardToolbarItemOptions,
CardType,
CardValue,
decodeCardValue,
isEngine,
isMobile,
NodeInterface,
TargetOp,
ToolbarItemOptions,
} from '@aomao/engine';
import Image, { Size } from './image';
@ -97,8 +99,8 @@ class ImageComponent<T extends ImageValue = ImageValue> extends Card<T> {
} as T);
}
setSize(size: Size) {
this.setValue({ size } as T);
setSize(size: Size, loaded?: boolean) {
if (!loaded) this.setValue({ size } as T);
if (this.widthInput) {
this.widthInput.get<HTMLInputElement>()!.value =
size.width.toString();
@ -271,8 +273,8 @@ class ImageComponent<T extends ImageValue = ImageValue> extends Card<T> {
}
return src;
},
onChange: (size) => {
if (size) this.setSize(size);
onChange: (size, loaded) => {
if (size) this.setSize(size, loaded);
},
onError: () => {
this.isLocalError = true;

View File

@ -15,7 +15,7 @@ import {
} from '@aomao/engine';
import TableComponent, { Template, Helper } from './component';
import locales from './locale';
import { TableInterface, TableOptions, TableValue } from './types';
import { TableOptions, TableValue } from './types';
import './index.css';
class Table<T extends TableOptions = TableOptions> extends Plugin<T> {
static get pluginName() {
@ -397,14 +397,21 @@ class Table<T extends TableOptions = TableOptions> extends Plugin<T> {
if (background) tds?.css('background', background);
});
this.editor.nodeId.generateAll(node, true);
const children = node.allChildren();
children.forEach((child) => {
if (this.editor.node.isInline(child)) {
this.editor.inline.repairCursor(child);
}
});
const html = node
.get<HTMLElement>()!
.outerHTML.replace(/\n|\r\n/g, '')
.replace(/>\s+</g, '><');
this.editor.card.replaceNode<TableValue>(
node,
TableComponent.cardName,
{
html: node
.get<HTMLElement>()!
.outerHTML.replace(/\n|\r\n/g, '')
.replace(/>\s+</g, '><'),
html,
},
);
});