/** * 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 HeaderWithGithub = require('HeaderWithGithub'); var Marked = require('Marked'); var Prism = require('Prism'); var React = require('React'); var Site = require('Site'); var slugify = require('slugify'); var styleReferencePattern = /^[^.]+\.propTypes\.style$/; function renderEnumValue(value) { // Use single quote strings even when we are given double quotes if (value.match(/^"(.+)"$/)) { return "'" + value.slice(1, -1) + "'"; } return value; } function renderType(type) { if (type.name === 'enum') { if (typeof type.value === 'string') { return type.value; } return 'enum(' + type.value.map((v) => renderEnumValue(v.value)).join(', ') + ')'; } if (type.name === 'shape') { return '{' + Object.keys(type.value).map((key => key + ': ' + renderType(type.value[key]))).join(', ') + '}'; } if (type.name === 'union') { return type.value.map(renderType).join(', '); } if (type.name === 'arrayOf') { return [{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 === 'ColorPropType') { return color; } 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; } function sortByPlatform(props, nameA, nameB) { var a = props[nameA]; var b = props[nameB]; if (a.platforms && !b.platforms) { return 1; } if (b.platforms && !a.platforms) { return -1; } // Cheap hack: use < on arrays of strings to compare the two platforms if (a.platforms < b.platforms) { return -1; } if (a.platforms > b.platforms) { return 1; } if (nameA < nameB) { return -1; } if (nameA > nameB) { return 1; } return 0; } var ComponentDoc = React.createClass({ renderProp: function(name, prop) { return (
{prop.platforms && prop.platforms.map(platform => {platform} )} {name} {' '} {prop.type && {renderType(prop.type)} }
{prop.deprecationMessage &&
Deprecated
{prop.deprecationMessage}
} {prop.type && prop.type.name === 'stylesheet' && this.renderStylesheetProps(prop.type.value)} {prop.description && {prop.description}}
); }, renderCompose: function(name) { return (
{name} props...
); }, renderStylesheetProp: function(name, prop) { return (
{prop.platforms && prop.platforms.map(platform => {platform} )} {name} {' '} {prop.type && {renderType(prop.type)} } {' '} {prop.description && {prop.description}}
); }, renderStylesheetProps: function(stylesheetName) { var style = this.props.content.styles[stylesheetName]; this.extractPlatformFromProps(style.props); 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(sortByPlatform.bind(null, style.props)) .map((name) => this.renderStylesheetProp(name, style.props[name])) }
); }, renderProps: function(props, composes) { return (
{(composes || []).map((name) => this.renderCompose(name) )} {Object.keys(props) .sort(sortByPlatform.bind(null, props)) .map((name) => this.renderProp(name, props[name])) }
); }, extractPlatformFromProps: function(props) { for (var key in props) { var prop = props[key]; var description = prop.description || ''; var platforms = description.match(/\@platform (.+)/); platforms = platforms && platforms[1].replace(/ /g, '').split(','); description = description.replace(/\@platform (.+)/, ''); prop.description = description; prop.platforms = platforms; } }, render: function() { var content = this.props.content; this.extractPlatformFromProps(content.props); return (
{content.description} Props {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)}
); }, renderProperty: function(property) { return (
{property.name} {property.type && {': ' + renderType(property.type)} }
{property.docblock && {this.removeCommentsFromDocblock(property.docblock)} }
); }, renderProperties: function(properties) { if (!properties || !properties.length) { return null; } return ( Properties
{properties.filter((property) => { return property.name[0] !== '_'; }).map(this.renderProperty)}
); }, renderClasses: function(classes) { if (!classes || !classes.length) { return null; } return (
{classes.filter((cls) => { return cls.name[0] !== '_' && cls.ownerProperty[0] !== '_'; }).map((cls) => { return (
class {cls.name}
    {cls.docblock && {this.removeCommentsFromDocblock(cls.docblock)} } {this.renderMethods(cls.methods)} {this.renderProperties(cls.properties)}
); })}
); }, 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)} {this.renderProperties(content.properties)} {this.renderClasses(content.classes)}
); } }); var EmbeddedSimulator = React.createClass({ render: function() { if (!this.props.shouldRender) { return null; } var metadata = this.props.metadata; var imagePreview = metadata.platform === 'android' ? Run example in simulator : Run example in simulator; return (

Run this example

{imagePreview}
); } }); var Modal = React.createClass({ render: function() { var metadata = this.props.metadata; var appParams = {route: metadata.title}; var encodedParams = encodeURIComponent(JSON.stringify(appParams)); var url = metadata.platform === 'android' ? `https://appetize.io/embed/q7wkvt42v6bkr0pzt1n0gmbwfr?device=nexus5&scale=65&autoplay=false&orientation=portrait&osVersion=6.0&deviceColor=white¶ms=${encodedParams}` : `https://appetize.io/embed/7vdfm9h3e6vuf4gfdm7r5rgc48?device=iphone6s&scale=60&autoplay=false&orientation=portrait&osVersion=9.2&deviceColor=white¶ms=${encodedParams}`; return (

Powered by appetize.io

); } }); var Autodocs = React.createClass({ childContextTypes: { permalink: React.PropTypes.string }, getChildContext: function() { return {permalink: this.props.metadata.permalink}; }, renderFullDescription: function(docs) { if (!docs.fullDescription) { return; } return (
{docs.fullDescription}
); }, renderExample: function(docs, metadata) { 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;