} from 'lexical';
import type {EditorConfig} from "lexical/LexicalEditor";
-import {el, setOrRemoveAttribute, sizeToPixels} from "../../utils/dom";
+import {el, setOrRemoveAttribute, sizeToPixels, styleMapToStyleString, styleStringToStyleMap} from "../../utils/dom";
import {
CommonBlockAlignment, deserializeCommonBlockNode,
setCommonBlockPropsFromElement,
return filtered;
}
+function removeStyleFromAttributes(attributes: Record<string, string>, styleName: string): Record<string, string> {
+ const attrCopy = Object.assign({}, attributes);
+ if (!attributes.style) {
+ return attrCopy;
+ }
+
+ const map = styleStringToStyleMap(attributes.style);
+ map.delete(styleName);
+
+ attrCopy.style = styleMapToStyleString(map);
+ return attrCopy;
+}
+
function domElementToNode(tag: MediaNodeTag, element: HTMLElement): MediaNode {
const node = $createMediaNode(tag);
getAttributes(): Record<string, string> {
const self = this.getLatest();
- return self.__attributes;
+ return Object.assign({}, self.__attributes);
}
setSources(sources: MediaNodeSource[]) {
}
setSrc(src: string): void {
- const attrs = Object.assign({}, this.getAttributes());
+ const attrs = this.getAttributes();
if (this.__tag ==='object') {
attrs.data = src;
} else {
}
setWidthAndHeight(width: string, height: string): void {
- const attrs = Object.assign(
- {},
+ let attrs: Record<string, string> = Object.assign(
this.getAttributes(),
{width, height},
);
+
+ attrs = removeStyleFromAttributes(attrs, 'width');
+ attrs = removeStyleFromAttributes(attrs, 'height');
this.setAttributes(attrs);
}
return;
}
- const attrs = Object.assign({}, this.getAttributes(), {height});
- this.setAttributes(attrs);
+ const attrs = Object.assign(this.getAttributes(), {height});
+ this.setAttributes(removeStyleFromAttributes(attrs, 'height'));
}
getHeight(): number {
}
setWidth(width: number): void {
- const attrs = Object.assign({}, this.getAttributes(), {width});
- this.setAttributes(attrs);
+ const existingAttrs = this.getAttributes();
+ const attrs: Record<string, string> = Object.assign(existingAttrs, {width});
+ this.setAttributes(removeStyleFromAttributes(attrs, 'width'));
}
getWidth(): number {