This commit is contained in:
Mirco Wittrien 2020-02-07 18:48:59 +01:00
parent 5d2082d799
commit e5d171c9a0
2 changed files with 8 additions and 5 deletions

View File

@ -1617,14 +1617,14 @@
if (BDFDB.ReactUtils.isValidElement(node)) return node;
else if (!Node.prototype.isPrototypeOf(node)) return null;
else if (node.nodeType == Node.TEXT_NODE) return node.nodeValue;
let attributes = {}, importantStyles = {};
let attributes = {}, importantStyles = [];
for (let attr of node.attributes) attributes[attr.name] = attr.value;
if (node.attributes.style) attributes.style = BDFDB.ObjectUtils.filter(node.style, n => node.style[n] && isNaN(parseInt(n)), true);
attributes.children = [];
if (node.style && node.style.cssText) for (let propstr of node.style.cssText.split(";")) if (propstr.endsWith("!important")) {
let key = propstr.split(":")[0];
let camelprop = key.replace(/-([a-z]?)/g, (m, g) => g.toUpperCase());
if (attributes.style[camelprop] != null) importantStyles[key] = attributes.style[camelprop];
if (attributes.style[camelprop] != null) importantStyles.push(key);
}
for (let child of node.childNodes) attributes.children.push(BDFDB.ReactUtils.elementToReact(child));
let reactEle = BDFDB.ReactUtils.createElement(node.tagName, attributes);
@ -1632,12 +1632,15 @@
return reactEle;
};
BDFDB.ReactUtils.forceStyle = function (reactEle, styles) {
if (!BDFDB.ReactUtils.isValidElement(reactEle) || !BDFDB.ObjectUtils.is(styles) || BDFDB.ObjectUtils.isEmpty(styles)) return;
if (!BDFDB.ReactUtils.isValidElement(reactEle) || !BDFDB.ObjectUtils.is(reactEle.props.style) || !BDFDB.ArrayUtils.is(styles) || !styles.length) return;
let ref = reactEle.ref;
reactEle.ref = instance => {
if (typeof ref == "function") ref(instance);
let node = BDFDB.ReactUtils.findDOMNode(instance);
if (Node.prototype.isPrototypeOf(node)) for (let key in styles) node.style.setProperty(key, styles[key], "important");
if (Node.prototype.isPrototypeOf(node)) for (let key of styles) {
let propValue = reactEle.props.style[key.replace(/-([a-z]?)/g, (m, g) => g.toUpperCase())];
if (propValue != null) node.style.setProperty(key, propValue, "important");
}
};
};
BDFDB.ReactUtils.findChildren = function (nodeOrInstance, config) {

File diff suppressed because one or more lines are too long