diff --git a/.gitignore b/.gitignore index ab0e6eaa4f..6428bd2fdb 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ docs/src/componentInfo docs/src/componentMenu.json docs/src/behaviorMenu.json docs/src/exampleMenus +docs/src/exampleSources docs/dist/ dll/ node_modules/ diff --git a/build/babel/transform-star-import-plugin.ts b/build/babel/transform-star-import-plugin.ts new file mode 100644 index 0000000000..e59dc3d803 --- /dev/null +++ b/build/babel/transform-star-import-plugin.ts @@ -0,0 +1,36 @@ +import * as T from '@babel/types' +import { BabelPlugin } from './types' + +/** + * Creates an default import: + * - import React from 'react' + */ +const createDefaultImportDeclaration = ( + t: typeof T, + declaration: T.ImportDeclaration, + specifier: T.ImportNamespaceSpecifier, +): T.ImportDeclaration => + t.importDeclaration( + [t.importDefaultSpecifier(t.identifier(specifier.local.name))], + t.stringLiteral(declaration.source.value), + ) + +/** + * A plugin for Babel that performs AST transform: + * - from: import * as _ from 'lodash' + * - to: import _ from 'lodash' + */ +const starImportToDefaultPlugin: BabelPlugin = ({ types: t }) => ({ + visitor: { + ImportDeclaration: path => { + const { specifiers } = path.node + const specifier = specifiers[0] + + if (specifiers.length === 1 && t.isImportNamespaceSpecifier(specifier)) { + path.replaceWith(createDefaultImportDeclaration(t, path.node, specifier)) + } + }, + }, +}) + +export default starImportToDefaultPlugin diff --git a/build/babel/types.ts b/build/babel/types.ts new file mode 100644 index 0000000000..56f6d81505 --- /dev/null +++ b/build/babel/types.ts @@ -0,0 +1,22 @@ +import * as T from '@babel/types' +import { NodePath } from '@babel/traverse' + +export type BabelPluginArguments = { + types: typeof T +} + +type BabelPluginVisitorFunction = (path: NodePath) => void +type BabelPluginVisitor = + | BabelPluginVisitorFunction + | { + exit: BabelPluginVisitorFunction + } + +export type BabelPlugin = ( + options: BabelPluginArguments, +) => { + visitor: { + // This type is extendable, feel to add own visitor types. + ImportDeclaration: BabelPluginVisitor + } +} diff --git a/build/gulp/plugins/gulp-example-source.ts b/build/gulp/plugins/gulp-example-source.ts new file mode 100644 index 0000000000..d1ca9e7cca --- /dev/null +++ b/build/gulp/plugins/gulp-example-source.ts @@ -0,0 +1,55 @@ +import * as Babel from '@babel/core' +import * as gutil from 'gulp-util' +import * as prettier from 'prettier' +import * as through from 'through2' +import * as Vinyl from 'vinyl' + +import * as prettierConfig from '../../../.prettierrc.json' +import { ExampleSource } from '../../../docs/src/types' +import transformStarImportPlugin from '../../babel/transform-star-import-plugin' +import { getRelativePathToSourceFile } from './util' + +const pluginName = 'gulp-example-source' + +const createExampleSourceCode = (file: Vinyl): ExampleSource => { + const tsSource = file.contents.toString() + + const transformResult = Babel.transform(tsSource, { + plugins: [transformStarImportPlugin], + presets: [['@babel/preset-typescript', { allExtensions: true, isTSX: true }]], + sourceType: 'module', + }) + const jsSource = prettier.format(transformResult.code, { + ...prettierConfig, + parser: 'babylon', + }) + + return { + js: jsSource, + ts: tsSource, + } +} + +export default () => + through.obj((file: Vinyl, enc, cb) => { + if (file.isNull()) { + cb(null, file) + return + } + + if (file.isStream()) { + cb(new gutil.PluginError(pluginName, 'Streaming is not supported')) + return + } + + const sourcePath = getRelativePathToSourceFile(file.path) + const source = createExampleSourceCode(file) + + cb( + null, + new Vinyl({ + path: sourcePath, + contents: Buffer.from(JSON.stringify(source, null, 2)), + }), + ) + }) diff --git a/build/gulp/plugins/util/getRelativePathToSourceFile.ts b/build/gulp/plugins/util/getRelativePathToSourceFile.ts new file mode 100644 index 0000000000..374646eede --- /dev/null +++ b/build/gulp/plugins/util/getRelativePathToSourceFile.ts @@ -0,0 +1,13 @@ +import * as path from 'path' +import config from '../../../../config' + +const examplesPath = config.paths.docsSrc('examples', 'components') + +/** + * Generates a relative path to a source file, outputs: + * Chat/Types/ChatExample.shorthand.source.json + */ +const getRelativePathToSourceFile = (filePath: string): string => + `${path.relative(examplesPath, filePath).replace(/\.tsx$/, '')}.source.json` + +export default getRelativePathToSourceFile diff --git a/build/gulp/plugins/util/index.ts b/build/gulp/plugins/util/index.ts index 7562fb1087..d6a291e7d3 100644 --- a/build/gulp/plugins/util/index.ts +++ b/build/gulp/plugins/util/index.ts @@ -1,5 +1,6 @@ export * from './checksumUtils' export { default as getComponentInfo } from './getComponentInfo' +export { default as getRelativePathToSourceFile } from './getRelativePathToSourceFile' export { default as parseDefaultValue } from './parseDefaultValue' export { default as parseDocblock } from './parseDocblock' export { default as parseDocSection } from './parseDocSection' diff --git a/build/gulp/tasks/docs.ts b/build/gulp/tasks/docs.ts index 7375a2a93d..a4396eb948 100644 --- a/build/gulp/tasks/docs.ts +++ b/build/gulp/tasks/docs.ts @@ -2,6 +2,7 @@ import * as historyApiFallback from 'connect-history-api-fallback' import * as express from 'express' import { task, src, dest, lastRun, parallel, series, watch } from 'gulp' import * as remember from 'gulp-remember' +import * as fs from 'fs' import * as path from 'path' import * as rimraf from 'rimraf' import * as through2 from 'through2' @@ -14,7 +15,9 @@ import config from '../../../config' import gulpComponentMenu from '../plugins/gulp-component-menu' import gulpComponentMenuBehaviors from '../plugins/gulp-component-menu-behaviors' import gulpExampleMenu from '../plugins/gulp-example-menu' +import gulpExampleSource from '../plugins/gulp-example-source' import gulpReactDocgen from '../plugins/gulp-react-docgen' +import { getRelativePathToSourceFile } from '../plugins/util' const { paths } = config const g = require('gulp-load-plugins')() @@ -46,6 +49,10 @@ task('clean:docs:example-menus', cb => { rimraf(paths.docsSrc('exampleMenus'), cb) }) +task('clean:docs:example-sources', cb => { + rimraf(paths.docsSrc('exampleSources'), cb) +}) + task( 'clean:docs', parallel( @@ -53,6 +60,7 @@ task( 'clean:docs:component-menu-behaviors', 'clean:docs:dist', 'clean:docs:example-menus', + 'clean:docs:example-sources', ), ) @@ -62,7 +70,8 @@ task( const componentsSrc = [`${paths.posix.src()}/components/*/[A-Z]*.tsx`, '!**/Slot.tsx'] const behaviorSrc = [`${paths.posix.src()}/lib/accessibility/Behaviors/*/[a-z]*.ts`] -const examplesSrc = `${paths.posix.docsSrc()}/examples/*/*/*/index.tsx` +const examplesIndexSrc = `${paths.posix.docsSrc()}/examples/*/*/*/index.tsx` +const examplesSrc = `${paths.posix.docsSrc()}/examples/*/*/*/!(*index|.knobs).tsx` const markdownSrc = [ '.github/CONTRIBUTING.md', '.github/setup-local-development.md', @@ -92,18 +101,25 @@ task('build:docs:component-menu-behaviors', () => ) task('build:docs:example-menu', () => - src(examplesSrc, { since: lastRun('build:docs:example-menu') }) + src(examplesIndexSrc, { since: lastRun('build:docs:example-menu') }) .pipe(remember('example-menu')) // FIXME: with watch this unnecessarily processes index files for all examples .pipe(gulpExampleMenu()) .pipe(dest(paths.docsSrc('exampleMenus'))), ) +task('build:docs:example-sources', () => + src(examplesSrc, { since: lastRun('build:docs:example-sources') }) + .pipe(gulpExampleSource()) + .pipe(dest(paths.docsSrc('exampleSources'))), +) + task( 'build:docs:json', parallel( series('build:docs:docgen', 'build:docs:component-menu'), 'build:docs:component-menu-behaviors', 'build:docs:example-menu', + 'build:docs:example-sources', ), ) @@ -218,10 +234,21 @@ task('watch:docs', cb => { watch(componentsSrc, series('build:docs:docgen')).on('change', handleWatchChange) // rebuild example menus - watch(examplesSrc, series('build:docs:example-menu')) + watch(examplesIndexSrc, series('build:docs:example-menu')) .on('change', handleWatchChange) .on('unlink', path => handleWatchUnlink('example-menu', path)) + watch(examplesSrc, series('build:docs:example-sources')) + .on('change', handleWatchChange) + .on('unlink', filePath => { + log(`File ${filePath} was deleted, running tasks...`) + + const sourceFilename = getRelativePathToSourceFile(filePath) + const sourcePath = config.paths.docsSrc('exampleSources', sourceFilename) + + fs.unlinkSync(sourcePath) + }) + watch(behaviorSrc, series('build:docs:component-menu-behaviors')) .on('change', handleWatchChange) .on('unlink', path => handleWatchUnlink('component-menu-behaviors', path)) diff --git a/docs/src/components/ComponentDoc/ComponentExample/SourceCodeManager.ts b/docs/src/components/ComponentDoc/ComponentExample/SourceCodeManager.ts index fa7f8ae015..3545893e2d 100644 --- a/docs/src/components/ComponentDoc/ComponentExample/SourceCodeManager.ts +++ b/docs/src/components/ComponentDoc/ComponentExample/SourceCodeManager.ts @@ -84,7 +84,9 @@ class SourceCodeManager { private safeRequire = (path: string): string | undefined => { try { - return require(`!raw-loader!../../../examples/${path}`) + const filename = `${path.replace(/^components\//, '')}.source.json` + + return require(`!docs/src/exampleSources/${filename}`).js } catch (e) { return undefined } diff --git a/docs/src/examples/components/Ref/Types/RefExample.tsx b/docs/src/examples/components/Ref/Types/RefExample.tsx index f36982328a..018a4ef88b 100644 --- a/docs/src/examples/components/Ref/Types/RefExample.tsx +++ b/docs/src/examples/components/Ref/Types/RefExample.tsx @@ -1,13 +1,17 @@ -import React from 'react' +import * as React from 'react' import { Button, Grid, Ref, Segment } from '@stardust-ui/react' -class RefExample extends React.Component { +type RefExampleState = { + isMounted: boolean +} + +class RefExample extends React.Component<{}, RefExampleState> { state = { isMounted: false } createdRef = React.createRef() functionalRef = null - handleRef = node => (this.functionalRef = node) + handleRef = (node: HTMLButtonElement) => (this.functionalRef = node) componentDidMount() { this.setState({ isMounted: true }) diff --git a/docs/src/examples/components/Ref/Types/RefForwardingExample.tsx b/docs/src/examples/components/Ref/Types/RefForwardingExample.tsx index e0f9bcbd6a..300d577b41 100644 --- a/docs/src/examples/components/Ref/Types/RefForwardingExample.tsx +++ b/docs/src/examples/components/Ref/Types/RefForwardingExample.tsx @@ -1,13 +1,19 @@ -import React from 'react' +import * as React from 'react' import { Grid, Ref, Segment } from '@stardust-ui/react' -const ExampleButton = React.forwardRef((props, ref) => ( -
-
-)) +type RefForwardingExampleState = { + isMounted: boolean +} + +const ExampleButton = React.forwardRef( + (props, ref) => ( +
+
+ ), +) -class RefForwardingExample extends React.Component { +class RefForwardingExample extends React.Component<{}, RefForwardingExampleState> { forwardedRef = React.createRef() state = { isMounted: false } diff --git a/docs/src/examples/components/Text/States/TextExampleDisabled.shorthand.tsx b/docs/src/examples/components/Text/States/TextExampleDisabled.shorthand.tsx index 85275c7366..7377e42ca6 100644 --- a/docs/src/examples/components/Text/States/TextExampleDisabled.shorthand.tsx +++ b/docs/src/examples/components/Text/States/TextExampleDisabled.shorthand.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import { Text } from '@stardust-ui/react' const TextExampleDisabledShorthand = () => ( diff --git a/docs/src/examples/components/Text/States/TextExampleDisabled.tsx b/docs/src/examples/components/Text/States/TextExampleDisabled.tsx index 97212ded55..9229975e92 100644 --- a/docs/src/examples/components/Text/States/TextExampleDisabled.tsx +++ b/docs/src/examples/components/Text/States/TextExampleDisabled.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import { Text } from '@stardust-ui/react' const TextExampleDisabled = () => This feature has been disabled. diff --git a/docs/src/examples/components/Text/States/TextExampleError.shorthand.tsx b/docs/src/examples/components/Text/States/TextExampleError.shorthand.tsx index 10a35dd38d..612f0fa25a 100644 --- a/docs/src/examples/components/Text/States/TextExampleError.shorthand.tsx +++ b/docs/src/examples/components/Text/States/TextExampleError.shorthand.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import { Text } from '@stardust-ui/react' const TextExampleErrorShorthand = () => diff --git a/docs/src/examples/components/Text/States/TextExampleError.tsx b/docs/src/examples/components/Text/States/TextExampleError.tsx index 73d6654e87..e400914175 100644 --- a/docs/src/examples/components/Text/States/TextExampleError.tsx +++ b/docs/src/examples/components/Text/States/TextExampleError.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import { Text } from '@stardust-ui/react' const TextExampleError = () => There has been an error. diff --git a/docs/src/examples/components/Text/States/TextExampleSuccess.shorthand.tsx b/docs/src/examples/components/Text/States/TextExampleSuccess.shorthand.tsx index 046eeeef30..2bf65afc42 100644 --- a/docs/src/examples/components/Text/States/TextExampleSuccess.shorthand.tsx +++ b/docs/src/examples/components/Text/States/TextExampleSuccess.shorthand.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import { Text } from '@stardust-ui/react' const TextExampleSuccessShorthand = () => ( diff --git a/docs/src/examples/components/Text/States/TextExampleSuccess.tsx b/docs/src/examples/components/Text/States/TextExampleSuccess.tsx index 2fa1f37b8f..202fb67715 100644 --- a/docs/src/examples/components/Text/States/TextExampleSuccess.tsx +++ b/docs/src/examples/components/Text/States/TextExampleSuccess.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import { Text } from '@stardust-ui/react' const TextExampleSuccess = () => Your action has completed successfully. diff --git a/docs/src/examples/components/Text/States/TextExampleTemporary.shorthand.tsx b/docs/src/examples/components/Text/States/TextExampleTemporary.shorthand.tsx index 52ba13efeb..43868a2855 100644 --- a/docs/src/examples/components/Text/States/TextExampleTemporary.shorthand.tsx +++ b/docs/src/examples/components/Text/States/TextExampleTemporary.shorthand.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import { Text } from '@stardust-ui/react' const TextExampleTemporaryShorthand = () => diff --git a/docs/src/examples/components/Text/States/TextExampleTemporary.tsx b/docs/src/examples/components/Text/States/TextExampleTemporary.tsx index 18aa888caa..0017de5c4d 100644 --- a/docs/src/examples/components/Text/States/TextExampleTemporary.tsx +++ b/docs/src/examples/components/Text/States/TextExampleTemporary.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import { Text } from '@stardust-ui/react' const TextExampleTemporary = () => Lorem ipsum dolor diff --git a/docs/src/examples/components/Text/States/TextExampleTruncated.shorthand.tsx b/docs/src/examples/components/Text/States/TextExampleTruncated.shorthand.tsx index f2897c1b05..001a6076a3 100644 --- a/docs/src/examples/components/Text/States/TextExampleTruncated.shorthand.tsx +++ b/docs/src/examples/components/Text/States/TextExampleTruncated.shorthand.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import { Text } from '@stardust-ui/react' const [notTruncatedText, truncatedText] = [ diff --git a/docs/src/examples/components/Text/States/TextExampleTruncated.tsx b/docs/src/examples/components/Text/States/TextExampleTruncated.tsx index dbb858d4b5..dc4898742a 100644 --- a/docs/src/examples/components/Text/States/TextExampleTruncated.tsx +++ b/docs/src/examples/components/Text/States/TextExampleTruncated.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import { Text } from '@stardust-ui/react' const [notTruncatedText, truncatedText] = [ diff --git a/docs/src/examples/components/Text/States/index.tsx b/docs/src/examples/components/Text/States/index.tsx index be2c9d33ce..9ac7d81498 100644 --- a/docs/src/examples/components/Text/States/index.tsx +++ b/docs/src/examples/components/Text/States/index.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' diff --git a/docs/src/examples/components/Text/Types/TextSizesExample.shorthand.tsx b/docs/src/examples/components/Text/Types/TextSizesExample.shorthand.tsx index 509e393189..4213128740 100644 --- a/docs/src/examples/components/Text/Types/TextSizesExample.shorthand.tsx +++ b/docs/src/examples/components/Text/Types/TextSizesExample.shorthand.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import * as _ from 'lodash' import { Provider, Text } from '@stardust-ui/react' diff --git a/docs/src/examples/components/Text/Types/TextSizesExample.tsx b/docs/src/examples/components/Text/Types/TextSizesExample.tsx index 4acd1ec7eb..42447f37b4 100644 --- a/docs/src/examples/components/Text/Types/TextSizesExample.tsx +++ b/docs/src/examples/components/Text/Types/TextSizesExample.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import * as _ from 'lodash' import { Provider, Text } from '@stardust-ui/react' diff --git a/docs/src/examples/components/Text/Types/TextWeightsExample.shorthand.tsx b/docs/src/examples/components/Text/Types/TextWeightsExample.shorthand.tsx index f0d049762a..d5abc08e76 100644 --- a/docs/src/examples/components/Text/Types/TextWeightsExample.shorthand.tsx +++ b/docs/src/examples/components/Text/Types/TextWeightsExample.shorthand.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import { Text } from '@stardust-ui/react' const TextWeightsExampleShorthand = () => ( diff --git a/docs/src/examples/components/Text/Types/TextWeightsExample.tsx b/docs/src/examples/components/Text/Types/TextWeightsExample.tsx index 8059d35902..043ca9523f 100644 --- a/docs/src/examples/components/Text/Types/TextWeightsExample.tsx +++ b/docs/src/examples/components/Text/Types/TextWeightsExample.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import { Text } from '@stardust-ui/react' const TextWeightsExample = () => ( diff --git a/docs/src/examples/components/Text/Types/index.tsx b/docs/src/examples/components/Text/Types/index.tsx index eed2697185..b8275e86e4 100644 --- a/docs/src/examples/components/Text/Types/index.tsx +++ b/docs/src/examples/components/Text/Types/index.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' diff --git a/docs/src/examples/components/Text/Variations/TextExampleAtMention.shorthand.tsx b/docs/src/examples/components/Text/Variations/TextExampleAtMention.shorthand.tsx index 2db91ee587..bd585647f3 100644 --- a/docs/src/examples/components/Text/Variations/TextExampleAtMention.shorthand.tsx +++ b/docs/src/examples/components/Text/Variations/TextExampleAtMention.shorthand.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import { Text } from '@stardust-ui/react' const TextExampleAtMentionShorthand = () => ( diff --git a/docs/src/examples/components/Text/Variations/TextExampleAtMention.tsx b/docs/src/examples/components/Text/Variations/TextExampleAtMention.tsx index c16ce492f4..d9cfbb7a49 100644 --- a/docs/src/examples/components/Text/Variations/TextExampleAtMention.tsx +++ b/docs/src/examples/components/Text/Variations/TextExampleAtMention.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import { Text } from '@stardust-ui/react' const TextExampleAtMention = () => ( diff --git a/docs/src/examples/components/Text/Variations/TextExampleImportant.shorthand.tsx b/docs/src/examples/components/Text/Variations/TextExampleImportant.shorthand.tsx index 4744d6e0ce..0676ec11d5 100644 --- a/docs/src/examples/components/Text/Variations/TextExampleImportant.shorthand.tsx +++ b/docs/src/examples/components/Text/Variations/TextExampleImportant.shorthand.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import { Text } from '@stardust-ui/react' const TextExampleImportantShorthand = () => diff --git a/docs/src/examples/components/Text/Variations/TextExampleImportant.tsx b/docs/src/examples/components/Text/Variations/TextExampleImportant.tsx index fc19e0351f..a62558c782 100644 --- a/docs/src/examples/components/Text/Variations/TextExampleImportant.tsx +++ b/docs/src/examples/components/Text/Variations/TextExampleImportant.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import { Text } from '@stardust-ui/react' const TextExampleImportant = () => This text is important! diff --git a/docs/src/examples/components/Text/Variations/TextExampleTimestamp.shorthand.tsx b/docs/src/examples/components/Text/Variations/TextExampleTimestamp.shorthand.tsx index af36508bff..b8967a0680 100644 --- a/docs/src/examples/components/Text/Variations/TextExampleTimestamp.shorthand.tsx +++ b/docs/src/examples/components/Text/Variations/TextExampleTimestamp.shorthand.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import { Text } from '@stardust-ui/react' const TextExampleTimestampShorthand = () => ( diff --git a/docs/src/examples/components/Text/Variations/TextExampleTimestamp.tsx b/docs/src/examples/components/Text/Variations/TextExampleTimestamp.tsx index f4a901a123..d69d52d9b8 100644 --- a/docs/src/examples/components/Text/Variations/TextExampleTimestamp.tsx +++ b/docs/src/examples/components/Text/Variations/TextExampleTimestamp.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import { Text } from '@stardust-ui/react' const TextExampleTimestamp = () => ( diff --git a/docs/src/examples/components/Text/Variations/index.tsx b/docs/src/examples/components/Text/Variations/index.tsx index 73d9b34082..6f8da3dde3 100644 --- a/docs/src/examples/components/Text/Variations/index.tsx +++ b/docs/src/examples/components/Text/Variations/index.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' diff --git a/docs/src/examples/components/Text/index.tsx b/docs/src/examples/components/Text/index.tsx index 99c54eaa0c..a96a7702b5 100644 --- a/docs/src/examples/components/Text/index.tsx +++ b/docs/src/examples/components/Text/index.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import States from './States' import Types from './Types' import Variations from './Variations' diff --git a/docs/src/types.ts b/docs/src/types.ts new file mode 100644 index 0000000000..cb58586c10 --- /dev/null +++ b/docs/src/types.ts @@ -0,0 +1,4 @@ +export type ExampleSource = { + js: string + ts: string +} diff --git a/package.json b/package.json index d645944e84..0894cd0eb4 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,10 @@ "react-popper": "^1.0.2" }, "devDependencies": { + "@babel/core": "^7.2.0", + "@babel/preset-typescript": "^7.1.0", "@babel/standalone": "^7.1.0", + "@types/babel__traverse": "^7.0.4", "@types/color": "^3.0.0", "@types/enzyme": "^3.1.14", "@types/faker": "^4.1.3", @@ -124,7 +127,6 @@ "merge2": "^1.2.2", "normalize.css": "^8.0.0", "prettier": "^1.15.3", - "raw-loader": "^0.5.1", "react": "^16.0.0", "react-ace": "^5.1.2", "react-custom-scrollbars": "^4.2.1", diff --git a/yarn.lock b/yarn.lock index 25e665d8cb..1b696d9a7d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,13 @@ # yarn lockfile v1 +"@babel/code-frame@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0.tgz#06e2ab19bdb535385559aabb5ba59729482800f8" + integrity sha512-OfC2uemaknXr87bdLUkWog7nYuliM9Ij5HUcajsVcMCpQrcLmtxRbVFTIqmcSkSeYRBFBRxs2FiUqFJDLdiebA== + dependencies: + "@babel/highlight" "^7.0.0" + "@babel/code-frame@^7.0.0-beta.35": version "7.0.0-beta.52" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0-beta.52.tgz#192483bfa0d1e467c101571c21029ccb74af2801" @@ -9,6 +16,74 @@ dependencies: "@babel/highlight" "7.0.0-beta.52" +"@babel/core@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.2.0.tgz#a4dd3814901998e93340f0086e9867fefa163ada" + integrity sha512-7pvAdC4B+iKjFFp9Ztj0QgBndJ++qaMeonT185wAqUnhipw8idm9Rv1UMyBuKtYjfl6ORNkgEgcsYLfHX/GpLw== + dependencies: + "@babel/code-frame" "^7.0.0" + "@babel/generator" "^7.2.0" + "@babel/helpers" "^7.2.0" + "@babel/parser" "^7.2.0" + "@babel/template" "^7.1.2" + "@babel/traverse" "^7.1.6" + "@babel/types" "^7.2.0" + convert-source-map "^1.1.0" + debug "^4.1.0" + json5 "^2.1.0" + lodash "^4.17.10" + resolve "^1.3.2" + semver "^5.4.1" + source-map "^0.5.0" + +"@babel/generator@^7.1.6", "@babel/generator@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.2.0.tgz#eaf3821fa0301d9d4aef88e63d4bcc19b73ba16c" + integrity sha512-BA75MVfRlFQG2EZgFYIwyT1r6xSkwfP2bdkY/kLZusEYWiJs4xCowab/alaEaT0wSvmVuXGqiefeBlP+7V1yKg== + dependencies: + "@babel/types" "^7.2.0" + jsesc "^2.5.1" + lodash "^4.17.10" + source-map "^0.5.0" + trim-right "^1.0.1" + +"@babel/helper-function-name@^7.1.0": + version "7.1.0" + resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.1.0.tgz#a0ceb01685f73355d4360c1247f582bfafc8ff53" + integrity sha512-A95XEoCpb3TO+KZzJ4S/5uW5fNe26DjBGqf1o9ucyLyCmi1dXq/B3c8iaWTfBk3VvetUxl16e8tIrd5teOCfGw== + dependencies: + "@babel/helper-get-function-arity" "^7.0.0" + "@babel/template" "^7.1.0" + "@babel/types" "^7.0.0" + +"@babel/helper-get-function-arity@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0.tgz#83572d4320e2a4657263734113c42868b64e49c3" + integrity sha512-r2DbJeg4svYvt3HOS74U4eWKsUAMRH01Z1ds1zx8KNTPtpTL5JAsdFv8BNyOpVqdFhHkkRDIg5B4AsxmkjAlmQ== + dependencies: + "@babel/types" "^7.0.0" + +"@babel/helper-plugin-utils@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.0.0.tgz#bbb3fbee98661c569034237cc03967ba99b4f250" + integrity sha512-CYAOUCARwExnEixLdB6sDm2dIJ/YgEAKDM1MOeMeZu9Ld/bDgVo8aiWrXwcY7OBh+1Ea2uUcVRcxKk0GJvW7QA== + +"@babel/helper-split-export-declaration@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0.tgz#3aae285c0311c2ab095d997b8c9a94cad547d813" + integrity sha512-MXkOJqva62dfC0w85mEf/LucPPS/1+04nmmRMPEBUB++hiiThQ2zPtX/mEWQ3mtzCEjIJvPY8nuwxXtQeQwUag== + dependencies: + "@babel/types" "^7.0.0" + +"@babel/helpers@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.2.0.tgz#8335f3140f3144270dc63c4732a4f8b0a50b7a21" + integrity sha512-Fr07N+ea0dMcMN8nFpuK6dUIT7/ivt9yKQdEEnjVS83tG2pHwPi03gYmk/tyuwONnZ+sY+GFFPlWGgCtW1hF9A== + dependencies: + "@babel/template" "^7.1.2" + "@babel/traverse" "^7.1.5" + "@babel/types" "^7.2.0" + "@babel/highlight@7.0.0-beta.52": version "7.0.0-beta.52" resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.0.0-beta.52.tgz#ef24931432f06155e7bc39cdb8a6b37b4a28b3d0" @@ -18,6 +93,35 @@ esutils "^2.0.2" js-tokens "^3.0.0" +"@babel/highlight@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.0.0.tgz#f710c38c8d458e6dd9a201afb637fcb781ce99e4" + integrity sha512-UFMC4ZeFC48Tpvj7C8UgLvtkaUuovQX+5xNWrsIoMG8o2z+XFKjKaN9iVmS84dPwVN00W4wPmqvYoZF3EGAsfw== + dependencies: + chalk "^2.0.0" + esutils "^2.0.2" + js-tokens "^4.0.0" + +"@babel/parser@^7.1.2", "@babel/parser@^7.1.6", "@babel/parser@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.2.0.tgz#02d01dbc330b6cbf36b76ac93c50752c69027065" + integrity sha512-M74+GvK4hn1eejD9lZ7967qAwvqTZayQa3g10ag4s9uewgR7TKjeaT0YMyoq+gVfKYABiWZ4MQD701/t5e1Jhg== + +"@babel/plugin-syntax-typescript@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.2.0.tgz#55d240536bd314dcbbec70fd949c5cabaed1de29" + integrity sha512-WhKr6yu6yGpGcNMVgIBuI9MkredpVc7Y3YR4UzEZmDztHoL6wV56YBHLhWnjO1EvId1B32HrD3DRFc+zSoKI1g== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-typescript@^7.1.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.2.0.tgz#bce7c06300434de6a860ae8acf6a442ef74a99d1" + integrity sha512-EnI7i2/gJ7ZNr2MuyvN2Hu+BHJENlxWte5XygPvfj/MbvtOkWor9zcnHpMMQL2YYaaCcqtIvJUyJ7QVfoGs7ew== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-typescript" "^7.2.0" + "@babel/polyfill@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@babel/polyfill/-/polyfill-7.0.0.tgz#c8ff65c9ec3be6a1ba10113ebd40e8750fb90bff" @@ -26,6 +130,14 @@ core-js "^2.5.7" regenerator-runtime "^0.11.1" +"@babel/preset-typescript@^7.1.0": + version "7.1.0" + resolved "https://registry.yarnpkg.com/@babel/preset-typescript/-/preset-typescript-7.1.0.tgz#49ad6e2084ff0bfb5f1f7fb3b5e76c434d442c7f" + integrity sha512-LYveByuF9AOM8WrsNne5+N79k1YxjNB6gmpCQsnuSBAcV8QUeB+ZUxQzL7Rz7HksPbahymKkq2qBR+o36ggFZA== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-transform-typescript" "^7.1.0" + "@babel/runtime@^7.0.0-beta.49": version "7.0.0-beta.52" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.0.0-beta.52.tgz#3f3b42b82b92b4e1a283fc78df1bb2fd4ba8d0c7" @@ -46,6 +158,39 @@ resolved "https://registry.yarnpkg.com/@babel/standalone/-/standalone-7.1.0.tgz#d79774a17e8df4a53def891864882f5d81c42001" integrity sha512-3yROQ+PlAAi2uf3Crpdl11hhrYDQ6af+uNmrpLn26WTSdGkOubMXvJKKmHMmiSm2MlOUVrqyotudpQS3hL9UBg== +"@babel/template@^7.1.0", "@babel/template@^7.1.2": + version "7.1.2" + resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.1.2.tgz#090484a574fef5a2d2d7726a674eceda5c5b5644" + integrity sha512-SY1MmplssORfFiLDcOETrW7fCLl+PavlwMh92rrGcikQaRq4iWPVH0MpwPpY3etVMx6RnDjXtr6VZYr/IbP/Ag== + dependencies: + "@babel/code-frame" "^7.0.0" + "@babel/parser" "^7.1.2" + "@babel/types" "^7.1.2" + +"@babel/traverse@^7.1.5", "@babel/traverse@^7.1.6": + version "7.1.6" + resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.1.6.tgz#c8db9963ab4ce5b894222435482bd8ea854b7b5c" + integrity sha512-CXedit6GpISz3sC2k2FsGCUpOhUqKdyL0lqNrImQojagnUMXf8hex4AxYFRuMkNGcvJX5QAFGzB5WJQmSv8SiQ== + dependencies: + "@babel/code-frame" "^7.0.0" + "@babel/generator" "^7.1.6" + "@babel/helper-function-name" "^7.1.0" + "@babel/helper-split-export-declaration" "^7.0.0" + "@babel/parser" "^7.1.6" + "@babel/types" "^7.1.6" + debug "^4.1.0" + globals "^11.1.0" + lodash "^4.17.10" + +"@babel/types@^7.0.0", "@babel/types@^7.1.2", "@babel/types@^7.1.6", "@babel/types@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.2.0.tgz#7941c5b2d8060e06f9601d6be7c223eef906d5d8" + integrity sha512-b4v7dyfApuKDvmPb+O488UlGuR1WbwMXFsO/cyqMrnfvRAChZKJAYeeglWTjUO1b9UghKKgepAQM5tsvBJca6A== + dependencies: + esutils "^2.0.2" + lodash "^4.17.10" + to-fast-properties "^2.0.0" + "@fimbul/bifrost@^0.15.0": version "0.15.0" resolved "https://registry.yarnpkg.com/@fimbul/bifrost/-/bifrost-0.15.0.tgz#f3a48dee3046681e926c1f970f0b1a67e29e088e" @@ -102,6 +247,13 @@ resolved "https://registry.yarnpkg.com/@snyk/gemfile/-/gemfile-1.1.0.tgz#8c254dfc7739b2e8513c44c976fc41872d5f6af0" integrity sha512-mLwF+ccuvRZMS0SxUAxA3dAp8mB3m2FxIsBIUWFTYvzxl+E4XTZb8uFrUqXHbcxhZH1Z8taHohNTbzXZn3M8ag== +"@types/babel__traverse@^7.0.4": + version "7.0.4" + resolved "https://registry.yarnpkg.com/@types/babel__traverse/-/babel__traverse-7.0.4.tgz#de652399bd8493ab712e4d6b68031b7a2f72ad5f" + integrity sha512-2vARZYqR4Flf59WtqMfa9GgbOjK04xLZaN9+CMf7Cs+4cAhxZBP3K9LYRzsWxOQe402VvqX9+7DdXxB72ujEOg== + dependencies: + "@babel/types" "^7.0.0" + "@types/cheerio@*": version "0.22.9" resolved "https://registry.yarnpkg.com/@types/cheerio/-/cheerio-0.22.9.tgz#b5990152604c2ada749b7f88cab3476f21f39d7b" @@ -2034,6 +2186,13 @@ content-type@~1.0.4: resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.4.tgz#e138cc75e040c727b1966fe5e5f8c9aee256fe3b" integrity sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA== +convert-source-map@^1.1.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.6.0.tgz#51b537a8c43e0f04dec1993bffcdd504e758ac20" + integrity sha512-eFu7XigvxdZ1ETfbgPBohgyQ/Z++C0eEhTor0qRwBw9unw+L0/6V8wkSuGgzdThkiS5lSpdptOQPD8Ak40a+7A== + dependencies: + safe-buffer "~5.1.1" + convert-source-map@^1.4.0, convert-source-map@^1.5.0, convert-source-map@^1.5.1: version "1.5.1" resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.5.1.tgz#b8278097b9bc229365de5c62cf5fcaed8b5599e5" @@ -2374,7 +2533,7 @@ debug@^3, debug@^3.2.5: dependencies: ms "^2.1.1" -debug@^4.0.1: +debug@^4.0.1, debug@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.0.tgz#373687bffa678b38b1cd91f861b63850035ddc87" integrity sha512-heNPJUJIqC+xB6ayLAMHaIrmN9HKa7aQO8MGqKpvCA+uJYVcvR6l5kgdrhRuwPFHU7P5/A1w0BjByPHwpfTDKg== @@ -4045,6 +4204,11 @@ global@^4.3.0: min-document "^2.19.0" process "~0.5.1" +globals@^11.1.0: + version "11.9.0" + resolved "https://registry.yarnpkg.com/globals/-/globals-11.9.0.tgz#bde236808e987f290768a93d065060d78e6ab249" + integrity sha512-5cJVtyXWH8PiJPVLZzzoIizXx944O4OmRro5MWKx5fT4MgcN7OfaMutPeaTdJCCURwbWdhhcCWcKIffPnmTzBg== + globals@^9.18.0: version "9.18.0" resolved "https://registry.yarnpkg.com/globals/-/globals-9.18.0.tgz#aa3896b3e69b487f17e31ed2143d69a8e30c2d8a" @@ -5747,7 +5911,7 @@ js-tokens@^3.0.0, js-tokens@^3.0.2: resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" integrity sha1-mGbfOVECEw449/mWvOtlRDIJwls= -"js-tokens@^3.0.0 || ^4.0.0": +"js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== @@ -5802,6 +5966,11 @@ jsesc@^1.3.0: resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-1.3.0.tgz#46c3fec8c1892b12b0833db9bc7622176dbab34b" integrity sha1-RsP+yMGJKxKwgz25vHYiF226s0s= +jsesc@^2.5.1: + version "2.5.2" + resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-2.5.2.tgz#80564d2e483dacf6e8ef209650a67df3f0c283a4" + integrity sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA== + jsome@^2.3.25: version "2.5.0" resolved "https://registry.yarnpkg.com/jsome/-/jsome-2.5.0.tgz#5e417eef4341ffeb83ee8bfa9265b36d56fe49ed" @@ -8182,11 +8351,6 @@ raw-body@^2.2.0: iconv-lite "0.4.23" unpipe "1.0.0" -raw-loader@^0.5.1: - version "0.5.1" - resolved "https://registry.yarnpkg.com/raw-loader/-/raw-loader-0.5.1.tgz#0c3d0beaed8a01c966d9787bf778281252a979aa" - integrity sha1-DD0L6u2KAclm2Xh793goElKpeao= - rc@^1.0.1, rc@^1.1.6, rc@^1.2.7: version "1.2.8" resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed" @@ -9495,7 +9659,7 @@ source-map-url@^0.4.0: resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3" integrity sha1-PpNdfd1zYxuXZZlW1VEo6HtQhKM= -source-map@0.5.x, source-map@^0.5.3, source-map@^0.5.6, source-map@^0.5.7, source-map@~0.5.1: +source-map@0.5.x, source-map@^0.5.0, source-map@^0.5.3, source-map@^0.5.6, source-map@^0.5.7, source-map@~0.5.1: version "0.5.7" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w= @@ -10062,6 +10226,11 @@ to-fast-properties@^1.0.3: resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47" integrity sha1-uDVx+k2MJbguIxsG46MFXeTKGkc= +to-fast-properties@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e" + integrity sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4= + to-no-case@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/to-no-case/-/to-no-case-1.0.2.tgz#c722907164ef6b178132c8e69930212d1b4aa16a"