/** * Copyright (c) 2015-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule AutodocsLayout */ var DocsSidebar = require('DocsSidebar'); var H = require('Header'); var Header = require('Header'); var Marked = require('Marked'); var Prism = require('Prism'); var React = require('React'); var Site = require('Site'); var slugify = require('slugify'); var styleReferencePattern = /^[^.]+\.propTypes\.style$/; var ComponentDoc = React.createClass({ renderType: function(type) { if (type.name === 'enum') { if (typeof type.value === 'string') { return type.value; } return 'enum(' + type.value.map((v => v.value)).join(', ') + ')'; } if (type.name === 'shape') { return '{' + Object.keys(type.value).map((key => key + ': ' + this.renderType(type.value[key]))).join(', ') + '}'; } if (type.name == 'union') { return type.value.map(this.renderType).join(', '); } if (type.name === 'arrayOf') { return '[' + this.renderType(type.value) + ']'; } if (type.name === 'instanceOf') { return type.value; } if (type.name === 'custom') { if (styleReferencePattern.test(type.raw)) { var name = type.raw.substring(0, type.raw.indexOf('.')); return {name}#style } if (type.raw === 'EdgeInsetsPropType') { return '{top: number, left: number, bottom: number, right: number}'; } return type.raw; } if (type.name === 'stylesheet') { return 'style'; } if (type.name === 'func') { return 'function'; } return type.name; }, renderProp: function(name, prop) { return (
{name} {' '} {prop.type && {this.renderType(prop.type)} }
{prop.type && prop.type.name === 'stylesheet' && this.renderStylesheetProps(prop.type.value)} {prop.description && {prop.description}}
); }, renderCompose: function(name) { return (
{name} props...
); }, renderStylesheetProps: function(stylesheetName) { var style = this.props.content.styles[stylesheetName]; return (
{(style.composes || []).map((name) => { var link; if (name === 'LayoutPropTypes') { name = 'Flexbox'; link = {name}...; } else if (name === 'TransformPropTypes') { name = 'Transforms'; link = {name}...; } else { name = name.replace('StylePropTypes', ''); link = {name}#style...; } return (
{link}
); })} {Object.keys(style.props).sort().map((name) =>
{name} {' '} {style.props[name].type && {this.renderType(style.props[name].type)} }
)}
); }, renderProps: function(props, composes) { return (
{(composes || []).map((name) => this.renderCompose(name) )} {Object.keys(props).sort().map((name) => this.renderProp(name, props[name]) )}
); }, render: function() { var content = this.props.content; return (
{content.description} {this.renderProps(content.props, content.composes)}
); } }); var APIDoc = React.createClass({ removeCommentsFromDocblock: function(docblock) { return docblock .trim('\n ') .replace(/^\/\*+/, '') .replace(/\*\/$/, '') .split('\n') .map(function(line) { return line.trim().replace(/^\* ?/, ''); }) .join('\n'); }, renderTypehintRec: function(typehint) { if (typehint.type === 'simple') { return typehint.value; } if (typehint.type === 'generic') { return this.renderTypehintRec(typehint.value[0]) + '<' + this.renderTypehintRec(typehint.value[1]) + '>'; } return JSON.stringify(typehint); }, renderTypehint: function(typehint) { try { var typehint = JSON.parse(typehint); } catch(e) { return typehint; } return this.renderTypehintRec(typehint); }, renderMethod: function(method) { return (
{method.modifiers.length && {method.modifiers.join(' ') + ' '} || ''} {method.name} ({method.params .map((param) => { var res = param.name; if (param.typehint) { res += ': ' + this.renderTypehint(param.typehint); } return res; }) .join(', ')})
{method.docblock && {this.removeCommentsFromDocblock(method.docblock)} }
); }, renderMethods: function(methods) { if (!methods.length) { return null; } return ( Methods
{methods.filter((method) => { return method.name[0] !== '_'; }).map(this.renderMethod)}
); }, render: function() { var content = this.props.content; if (!content.methods) { throw new Error( 'No component methods found for ' + content.componentName ); } return (
{this.removeCommentsFromDocblock(content.docblock)} {this.renderMethods(content.methods)}
); } }); var HeaderWithGithub = React.createClass({ render: function() { return ( Edit on GitHub {this.props.title} ); } }); var Autodocs = React.createClass({ renderFullDescription: function(docs) { if (!docs.fullDescription) { return; } return (
{docs.fullDescription}
); }, renderExample: function(docs) { if (!docs.example) { return; } return (
{docs.example.content.replace(/^[\s\S]*?\*\//, '').trim()}
); }, render: function() { var metadata = this.props.metadata; var docs = JSON.parse(this.props.children); var content = docs.type === 'component' || docs.type === 'style' ? : ; return (
); } }); module.exports = Autodocs;