chore: format

This commit is contained in:
Nathan Walker
2020-07-05 14:57:06 -07:00
parent 8f2900ad0b
commit da3c0b973d
379 changed files with 71587 additions and 54582 deletions

View File

@@ -10,90 +10,94 @@ const getAppRootView = () => require("../application").getRootView();
let unsetValue;
function unsetViewValue(view, name) {
if (!unsetValue) {
unsetValue = require("../ui/core/properties").unsetValue;
}
if (!unsetValue) {
unsetValue = require("../ui/core/properties").unsetValue;
}
view[name] = unsetValue;
view[name] = unsetValue;
}
function getViewById(nodeId: number): ViewBase {
const node = getNodeById(nodeId);
let view;
if (node) {
view = node.viewRef.get();
}
const node = getNodeById(nodeId);
let view;
if (node) {
view = node.viewRef.get();
}
return view;
return view;
}
export function getDocument() {
const appRoot = getAppRootView();
if (!appRoot) {
return undefined;
}
const appRoot = getAppRootView();
if (!appRoot) {
return undefined;
}
try {
appRoot.ensureDomNode();
try {
appRoot.ensureDomNode();
} catch (e) {
console.log("ERROR in getDocument(): " + e);
}
} catch (e) {
console.log("ERROR in getDocument(): " + e);
}
return appRoot.domNode.toObject();
return appRoot.domNode.toObject();
}
export function getComputedStylesForNode(nodeId): Array<{ name: string, value: string }> {
const view = getViewById(nodeId);
if (view) {
return view.domNode.getComputedProperties();
}
export function getComputedStylesForNode(
nodeId
): Array<{ name: string; value: string }> {
const view = getViewById(nodeId);
if (view) {
return view.domNode.getComputedProperties();
}
return [];
return [];
}
export const removeNode = mainThreadify(function removeNode(nodeId) {
const view = getViewById(nodeId);
if (view) {
// Avoid importing layout and content view
let parent = <any>view.parent;
if (parent.removeChild) {
parent.removeChild(view);
} else if (parent.content === view) {
parent.content = null;
}
else {
console.log("Can't remove child from " + parent);
}
}
const view = getViewById(nodeId);
if (view) {
// Avoid importing layout and content view
let parent = <any>view.parent;
if (parent.removeChild) {
parent.removeChild(view);
} else if (parent.content === view) {
parent.content = null;
} else {
console.log("Can't remove child from " + parent);
}
}
});
export const setAttributeAsText = mainThreadify(function setAttributeAsText(nodeId, text, name) {
const view = getViewById(nodeId);
if (view) {
// attribute is registered for the view instance
let hasOriginalAttribute = !!name.trim();
export const setAttributeAsText = mainThreadify(function setAttributeAsText(
nodeId,
text,
name
) {
const view = getViewById(nodeId);
if (view) {
// attribute is registered for the view instance
let hasOriginalAttribute = !!name.trim();
if (text) {
let textParts = text.split("=");
if (text) {
let textParts = text.split("=");
if (textParts.length === 2) {
let attrName = textParts[0];
let attrValue = textParts[1].replace(/['"]+/g, "");
if (textParts.length === 2) {
let attrName = textParts[0];
let attrValue = textParts[1].replace(/['"]+/g, "");
// if attr name is being replaced with another
if (name !== attrName && hasOriginalAttribute) {
unsetViewValue(view, name);
view[attrName] = attrValue;
} else {
view[hasOriginalAttribute ? name : attrName] = attrValue;
}
}
} else {
// delete attribute
unsetViewValue(view, name);
}
// if attr name is being replaced with another
if (name !== attrName && hasOriginalAttribute) {
unsetViewValue(view, name);
view[attrName] = attrValue;
} else {
view[hasOriginalAttribute ? name : attrName] = attrValue;
}
}
} else {
// delete attribute
unsetViewValue(view, name);
}
view.domNode.loadAttributes();
}
view.domNode.loadAttributes();
}
});