-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[framework] add ember support #4237
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
## Addon / Framework Support Table | ||
|
||
| | [React](app/react)|[React Native](app/react-native)|[Vue](app/vue)|[Angular](app/angular)| [Polymer](app/polymer)| [Mithril](app/mithril)| [HTML](app/html)| [Marko](app/marko)| [Svelte](app/svelte)| [Riot](app/riot)| | ||
| ----------- |:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:| | ||
|[a11y](addons/a11y) |+| |+|+|+|+|+|+| | | | ||
|[actions](addons/actions) |+|+|+|+|+|+|+|+|+|+| | ||
|[backgrounds](addons/backgrounds) |+| |+|+|+|+|+|+|+|+| | ||
|[centered](addons/centered) |+| |+|+| |+|+| |+| | | ||
|[events](addons/events) |+| |+|+|+|+|+|+| | | | ||
|[graphql](addons/graphql) |+| | | | | | | | | | | ||
|[info](addons/info) |+| | | | | | | | | | | ||
|[jest](addons/jest) |+| | |+| | |+| | | | | ||
|[knobs](addons/knobs) |+|+|+|+|+|+|+|+|+|+| | ||
|[links](addons/links) |+|+|+|+|+|+|+| |+|+| | ||
|[notes](addons/notes) |+| |+|+|+|+|+| |+|+| | ||
|[options](addons/options) |+|+|+|+|+|+|+| |+|+| | ||
|[storyshots](addons/storyshots) |+|+|+|+| | |+| |+|+| | ||
|[storysource](addons/storysource)|+| |+|+|+|+|+|+|+|+| | ||
|[viewport](addons/viewport) |+| |+|+|+|+|+|+|+|+| | ||
| | [React](app/react)|[React Native](app/react-native)|[Vue](app/vue)|[Angular](app/angular)| [Polymer](app/polymer)| [Mithril](app/mithril)| [HTML](app/html)| [Marko](app/marko)| [Svelte](app/svelte)| [Riot](app/riot)| [Ember](app/ember)| | ||
| ----------- |:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:| | ||
|[a11y](addons/a11y) |+| |+|+|+|+|+|+| | |+| | ||
|[actions](addons/actions) |+|+|+|+|+|+|+|+|+|+|+| | ||
|[backgrounds](addons/backgrounds)|+| |+|+|+|+|+|+|+|+|+| | ||
|[centered](addons/centered) |+| |+|+| |+|+| |+| |+| | ||
|[events](addons/events) |+| |+|+|+|+|+|+| | |+| | ||
|[graphql](addons/graphql) |+| | | | | | | | | | | | ||
|[info](addons/info) |+| | | | | | | | | | | | ||
|[jest](addons/jest) |+| | |+| | |+| | | | | | ||
|[knobs](addons/knobs) |+|+|+|+|+|+|+|+|+|+|+| | ||
|[links](addons/links) |+|+|+|+|+|+|+| |+|+|+| | ||
|[notes](addons/notes) |+| |+|+|+|+|+| |+|+|+| | ||
|[options](addons/options) |+|+|+|+|+|+|+| |+|+|+| | ||
|[storyshots](addons/storyshots) |+|+|+|+| | |+| |+|+| | | ||
|[storysource](addons/storysource)|+| |+|+|+|+|+|+|+|+|+| | ||
|[viewport](addons/viewport) |+| |+|+|+|+|+|+|+|+|+| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./dist/ember'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { document } from 'global'; | ||
import styles from './styles'; | ||
|
||
export default function(storyFn) { | ||
const { template, context } = storyFn(); | ||
|
||
const element = document.createElement('div'); | ||
Object.assign(element.style, styles.style); | ||
|
||
const innerElement = document.createElement('div'); | ||
Object.assign(innerElement.style, styles.innerStyle); | ||
|
||
element.appendChild(innerElement); | ||
|
||
// the inner element should append the parent | ||
innerElement.appendTo = function appendTo(el) { | ||
el.appendChild(element); | ||
}; | ||
|
||
return { | ||
template, | ||
context, | ||
element: innerElement, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Storybook for Ember | ||
|
||
Storybook for Ember is a UI development environment for your Ember components. | ||
With it, you can visualize different states of your UI components and develop them interactively. | ||
|
||
 | ||
|
||
Storybook runs outside of your app. | ||
So you can develop UI components in isolation without worrying about app specific dependencies and requirements. | ||
|
||
## Getting Started | ||
|
||
```sh | ||
npm i -g @storybook/cli | ||
cd my-ember-app | ||
storybook init | ||
``` | ||
|
||
For more information visit: [storybook.js.org](https://storybook.js.org) | ||
|
||
* * * | ||
|
||
Storybook also comes with a lot of [addons](https://storybook.js.org/addons/introduction) and a great API to customize as you wish. | ||
You can also build a [static version](https://storybook.js.org/basics/exporting-storybook) of your storybook and deploy it anywhere you want. | ||
|
||
## Docs | ||
|
||
- [Basics](https://storybook.js.org/basics/introduction) | ||
- [Configurations](https://storybook.js.org/configurations/default-config) | ||
- [Addons](https://storybook.js.org/addons/introduction) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env node | ||
|
||
process.env.NODE_ENV = process.env.NODE_ENV || 'production'; | ||
require('../dist/server/build'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env node | ||
|
||
require('../dist/server'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "@storybook/ember", | ||
"version": "4.0.0-alpha.23", | ||
"description": "Storybook for Ember: Develop Ember Component in isolation with Hot Reloading.", | ||
"homepage": "https://github.com/storybooks/storybook/tree/master/app/ember", | ||
"bugs": { | ||
"url": "https://github.com/storybooks/storybook/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/storybooks/storybook.git" | ||
}, | ||
"license": "MIT", | ||
"main": "dist/client/index.js", | ||
"jsnext:main": "src/client/index.js", | ||
"bin": { | ||
"build-storybook": "./bin/build.js", | ||
"start-storybook": "./bin/index.js", | ||
"storybook-server": "./bin/index.js" | ||
}, | ||
"scripts": { | ||
"prepare": "node ../../scripts/prepare.js" | ||
}, | ||
"dependencies": { | ||
"@babel/runtime": "^7.0.0", | ||
"@ember/test-helpers": "^0.7.25", | ||
"@storybook/core": "4.0.0-alpha.23", | ||
"global": "^4.3.2" | ||
}, | ||
"peerDependencies": { | ||
"babel-plugin-ember-modules-api-polyfill": "^2.4.0", | ||
"babel-loader": "^7.0.0 || ^8.0.0", | ||
"common-tags": "^1.8.0", | ||
"ember-cli-htmlbars-inline-precompile": "^1.0.3", | ||
"ember-source": "^3.4.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export { | ||
storiesOf, | ||
setAddon, | ||
addDecorator, | ||
addParameters, | ||
configure, | ||
getStorybook, | ||
forceReRender, | ||
} from './preview'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { window } from 'global'; | ||
|
||
window.STORYBOOK_NAME = process.env.STORYBOOK_NAME; | ||
window.STORYBOOK_ENV = 'ember'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { start } from '@storybook/core/client'; | ||
|
||
import './globals'; | ||
import render from './render'; | ||
|
||
const { clientApi, configApi, forceReRender } = start(render); | ||
|
||
export const { | ||
storiesOf, | ||
setAddon, | ||
addDecorator, | ||
addParameters, | ||
clearDecorators, | ||
getStorybook, | ||
} = clientApi; | ||
|
||
export const { configure } = configApi; | ||
export { forceReRender }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* eslint-disable no-undef */ | ||
import { window, document } from 'global'; | ||
import { stripIndents } from 'common-tags'; | ||
|
||
const rootEl = document.getElementById('root'); | ||
|
||
const config = window.require(`${window.STORYBOOK_NAME}/config/environment`); | ||
const app = window.require(`${window.STORYBOOK_NAME}/app`).default.create({ | ||
autoboot: false, | ||
rootElement: rootEl, | ||
...config.APP, | ||
}); | ||
|
||
let lastPromise = app.boot(); | ||
let hasRendered = false; | ||
|
||
function render(options, el) { | ||
const { template, context = {}, element } = options; | ||
|
||
if (hasRendered) { | ||
lastPromise = lastPromise.then(instance => instance.destroy()); | ||
} | ||
|
||
lastPromise = lastPromise | ||
.then(() => { | ||
const appInstancePrivate = app.buildInstance(); | ||
return appInstancePrivate.boot().then(() => appInstancePrivate); | ||
}) | ||
.then(instance => { | ||
instance.register( | ||
'component:story-mode', | ||
Ember.Component.extend({ | ||
layout: template || options, | ||
...context, | ||
}) | ||
); | ||
|
||
const component = instance.lookup('component:story-mode'); | ||
|
||
if (element) { | ||
component.appendTo(element); | ||
|
||
element.appendTo(el); | ||
} else { | ||
component.appendTo(el); | ||
} | ||
hasRendered = true; | ||
|
||
return instance; | ||
}); | ||
} | ||
|
||
export default function renderMain({ story, selectedKind, selectedStory, showMain, showError }) { | ||
const element = story(); | ||
|
||
if (!element) { | ||
showError({ | ||
title: `Expecting a Ember element from the story: "${selectedStory}" of "${selectedKind}".`, | ||
description: stripIndents` | ||
Did you forget to return the Ember element from the story? | ||
Use "() => hbs('{{component}}')" or "() => { return { | ||
template: hbs\`{{component}}\` | ||
} }" when defining the story. | ||
`, | ||
}); | ||
return; | ||
} | ||
|
||
showMain(); | ||
render(element, rootEl); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { buildStatic } from '@storybook/core/server'; | ||
import options from './options'; | ||
|
||
buildStatic(options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { precompile } from 'ember-source/dist/ember-template-compiler'; | ||
|
||
export function babel(config) { | ||
const babelConfigPlugins = config.plugins || []; | ||
|
||
const extraPlugins = [ | ||
[require.resolve('babel-plugin-htmlbars-inline-precompile'), { precompile }], | ||
[require.resolve('babel-plugin-ember-modules-api-polyfill')], | ||
]; | ||
|
||
return { | ||
...config, | ||
plugins: [].concat(babelConfigPlugins, extraPlugins), | ||
gabrielcsapo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { buildDev } from '@storybook/core/server'; | ||
|
||
import options from './options'; | ||
|
||
buildDev(options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import packageJson from '../../package.json'; | ||
|
||
export default { | ||
packageJson, | ||
defaultConfigName: 'ember-cli', | ||
frameworkPresets: [require.resolve('./framework-preset-babel-ember.js')], | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is essentially the same as how component tests are setup and ran. I'd like to extract a primitive library that can be shared between the main
@ember/test-helpers
and this project so that we can more easily support broad ranges of Ember applications (and reduce specific coupling in storybook itself).Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally think this would be something we could decouple. Something like
@ember/setup
that would just handle setting up and exposing a booted application