This app provides monitoring and information features for the common freifunk user and the technical stuff of a freifunk community.
Code base is taken from a TUM Practical Course project and added here to see if Freifunk Altdorf can use it.
https://www.freifunk-altdorf.de
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.2 KiB
83 lines
2.2 KiB
'use strict'; |
|
|
|
const printString = require('../printString'); |
|
|
|
const reactElement = Symbol.for('react.element'); |
|
|
|
function traverseChildren(opaqueChildren, cb) { |
|
if (Array.isArray(opaqueChildren)) { |
|
opaqueChildren.forEach(child => traverseChildren(child, cb)); |
|
} else if (opaqueChildren != null && opaqueChildren !== false) { |
|
cb(opaqueChildren); |
|
} |
|
} |
|
|
|
function printChildren(flatChildren, print, indent, opts) { |
|
return flatChildren.map(node => { |
|
if (typeof node === 'object') { |
|
return printElement(node, print, indent, opts); |
|
} else if (typeof node === 'string') { |
|
return printString(node); |
|
} else { |
|
return print(node); |
|
} |
|
}).join(opts.edgeSpacing); |
|
} |
|
|
|
function printProps(props, print, indent, opts) { |
|
return Object.keys(props).sort().map(name => { |
|
if (name === 'children') { |
|
return ''; |
|
} |
|
|
|
const prop = props[name]; |
|
let printed = print(prop); |
|
|
|
if (typeof prop !== 'string') { |
|
if (printed.indexOf('\n') !== -1) { |
|
printed = '{' + opts.edgeSpacing + indent(indent(printed) + opts.edgeSpacing + '}'); |
|
} else { |
|
printed = '{' + printed + '}'; |
|
} |
|
} |
|
|
|
return opts.spacing + indent(name + '=') + printed; |
|
}).join(''); |
|
} |
|
|
|
function printElement(element, print, indent, opts) { |
|
let result = '<'; |
|
let elementName; |
|
if (typeof element.type === 'string') { |
|
elementName = element.type; |
|
} else if (typeof element.type === 'function') { |
|
elementName = element.type.displayName || element.type.name || 'Unknown'; |
|
} else { |
|
elementName = 'Unknown'; |
|
} |
|
result += elementName; |
|
result += printProps(element.props, print, indent, opts); |
|
|
|
const opaqueChildren = element.props.children; |
|
if (opaqueChildren) { |
|
let flatChildren = []; |
|
traverseChildren(opaqueChildren, child => { |
|
flatChildren.push(child); |
|
}); |
|
const children = printChildren(flatChildren, print, indent, opts); |
|
result += '>' + opts.edgeSpacing + indent(children) + opts.edgeSpacing + '</' + elementName + '>'; |
|
} else { |
|
result += ' />'; |
|
} |
|
|
|
return result; |
|
} |
|
|
|
module.exports = { |
|
test(object) { |
|
return object && object.$$typeof === reactElement; |
|
}, |
|
print(val, print, indent, opts) { |
|
return printElement(val, print, indent, opts); |
|
} |
|
};
|
|
|