Skip to content
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

Svelte support #3770

Merged
merged 98 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
1381b93
Basic Svelte support
plumpNation Jun 16, 2018
40660ea
Added knob addon example
plumpNation Jun 17, 2018
306b580
Centered addon working with Svelte
plumpNation Jun 17, 2018
5f64ea3
Added background addon support
plumpNation Jun 17, 2018
f64ec68
Added support for actions addon
plumpNation Jun 17, 2018
295f4e2
Easier to see the centering when we break the sentences
plumpNation Jun 17, 2018
adabc88
Updating root README with svelte links
plumpNation Jun 17, 2018
9acf5f5
File not required
plumpNation Jun 17, 2018
ce09ea7
No longer using this file for svelte, refactor not required for review
plumpNation Jun 17, 2018
cf72ffd
File not required
plumpNation Jun 17, 2018
ba11d16
File was changed by accident
plumpNation Jun 17, 2018
cecc676
referencing incorrect app
plumpNation Jun 17, 2018
bab002e
File not required
plumpNation Jun 17, 2018
0eed975
Add jest support for svelte files
plumpNation Jun 17, 2018
a677702
Svelte stories don't support these addons yet
plumpNation Jun 17, 2018
43b3660
linting and using global document
plumpNation Jun 17, 2018
1035614
Unnecessary code
plumpNation Jun 17, 2018
e65573e
Creating svelte test and integration locations to match vue
plumpNation Jun 17, 2018
3dbe010
incorrect app name
plumpNation Jun 17, 2018
43986fb
Remove experimental code
plumpNation Jun 17, 2018
037187e
Should use the same styles as all the other frameworks
plumpNation Jun 17, 2018
09ca251
Overwriting internal methods is an antipattern
plumpNation Jun 17, 2018
75e1fd4
Missing function to export
plumpNation Jun 17, 2018
0f4f756
Added addon link example
plumpNation Jun 17, 2018
0228962
Added addon notes example
plumpNation Jun 18, 2018
3844c54
Wrapping up the mount in a named function
plumpNation Jun 18, 2018
27104f8
Viewport addon support added
plumpNation Jun 18, 2018
03c6c0c
Readded addon options support
plumpNation Jun 18, 2018
63f09e0
Framework support lists should be in chronological order
plumpNation Jun 19, 2018
0afd157
Guide was quite wrong in places
plumpNation Jun 19, 2018
17cb74f
Build works fine in kitchen sink without peer deps, afaict
plumpNation Jun 19, 2018
bad4b31
We are not just returning a component
plumpNation Jun 19, 2018
1a4cc60
local eslint config not required
plumpNation Jun 19, 2018
15ee3c6
Since yarn seems to be the package manager of choice
plumpNation Jun 19, 2018
ef2e19c
I wish I'd known this at the start.
plumpNation Jun 19, 2018
a7dd460
I think this project recommends yarn
plumpNation Jun 19, 2018
284a443
Editing the welcome text a little
plumpNation Jun 19, 2018
2f8a3ad
Title meant nothing
plumpNation Jun 19, 2018
edd4770
npm to yarn, and commands were likely wrong
plumpNation Jun 19, 2018
3ca5be1
Starting to reduce the complexity of the example
plumpNation Jun 19, 2018
f5e5c62
Stories had misleading details
plumpNation Jun 19, 2018
02bc696
Tested story source addon
plumpNation Jun 19, 2018
05f01ad
This is not necessarily just a svelte helper
plumpNation Jun 19, 2018
cf7b724
Less confusing to follow the same property names as styles.json
plumpNation Jun 19, 2018
e33d5f2
Snapshots were not being rendered, so were useless
plumpNation Jun 24, 2018
a953fce
I am not making a good point
plumpNation Jun 24, 2018
35b477f
Storyshot support marked as supported
plumpNation Jun 24, 2018
042ca5d
Tidying up the centered addon functionality and adding comments
plumpNation Jun 24, 2018
63b568f
Trying to be clearer in snapshot markup explanation
plumpNation Jun 24, 2018
e84768b
Added unit test for example component
plumpNation Jun 24, 2018
ef4a5eb
Merge branch 'master' into svelte-support
Hypnosphi Jun 26, 2018
33006b8
Teamcity: Build for svelte
Hypnosphi Jun 26, 2018
28a4bef
Teamcity: Remove duplicate
Hypnosphi Jun 26, 2018
73f5951
Merge branch 'master' into svelte-support
Hypnosphi Jun 28, 2018
b2912e7
Merge branch 'master' into svelte-support
Hypnosphi Jun 28, 2018
157a580
fix actions not working with centered
ekhaled Jul 23, 2018
bed1a50
cleanup wrapper when available
ekhaled Jul 23, 2018
b848466
Added my name to the CODEOWNERS file
plumpNation Jul 24, 2018
c636cb5
This seems unnecessary
plumpNation Jul 24, 2018
82f8119
Need to clean up previous manually added events on rerender
plumpNation Jul 24, 2018
ec832b4
Updating deps to alpha 10
plumpNation Jul 24, 2018
fb333e2
Merge branch 'svelte-support' into further-svelte-support-help
ekhaled Jul 24, 2018
2282813
Behaviour when onclick was not explicit enough
plumpNation Jul 24, 2018
59ce0d9
Missing reference to myself
plumpNation Jul 24, 2018
2bc8353
Confusing label on button referencing incorrect location.
plumpNation Jul 24, 2018
dd1e609
Componnents must be destroyed when mounting a new story to clean up a…
plumpNation Jul 24, 2018
cabb323
Merge branch 'svelte-support' into further-svelte-support-help
plumpNation Jul 24, 2018
2c8b958
Merge pull request #1 from ekhaled/further-svelte-support-help
plumpNation Jul 24, 2018
57c24b3
Merge branch 'master' into svelte-support
plumpNation Jul 25, 2018
1b46de2
4.0.0-alpha.14
plumpNation Jul 25, 2018
6096035
Added env setup to honour #3744
plumpNation Jul 25, 2018
7fc81d9
Added example for centred with actions
plumpNation Jul 25, 2018
b5bd22b
Updating snapshots
plumpNation Jul 25, 2018
06b0ac7
Aligning unit test to updated Button component textContent
plumpNation Jul 25, 2018
d842cea
Note is not relevant to bold text, rather to the ButtonView
plumpNation Jul 25, 2018
9a4e2db
Missing svelte editor config
plumpNation Jul 25, 2018
209ae29
Svelte missing from autolabeler
plumpNation Jul 25, 2018
dc2beac
Svelte missing from markdown spell check
plumpNation Jul 25, 2018
f79c35b
Svelte community uses both svelte and html extensions
plumpNation Jul 25, 2018
f41eb61
Missing centered documentation for Svelte
plumpNation Jul 25, 2018
450e4a6
Missing links to svelte guides and examples in docs
plumpNation Jul 25, 2018
5c3dbf2
Running svelte tests was undocumented in CONTRIBUTING guide
plumpNation Jul 25, 2018
57f1b09
Contributors should have a clear list of ideas to work on
plumpNation Jul 25, 2018
b97bb40
Another todo suggestion added and list checkbox formatted
plumpNation Jul 26, 2018
13d09e6
Merge remote-tracking branch 'origin/master' into svelte-support
igor-dv Jul 30, 2018
c94f632
Commit something to trigger full netlify build
igor-dv Jul 30, 2018
9464939
Update CLI
igor-dv Jul 30, 2018
c173e40
Merge remote-tracking branch 'origin/master' into svelte-support
igor-dv Aug 1, 2018
846ed34
Remove badges and docs
igor-dv Aug 1, 2018
c60fe16
Move Svelte to the end of the list for the chronology
igor-dv Aug 1, 2018
37c1f5f
Add missing svelte-kitchen-sink in built-storybooks
igor-dv Aug 2, 2018
0b9f38a
Update CLI
igor-dv Aug 2, 2018
70b4dd1
Merge branch 'master' into svelte-support
ndelangen Aug 6, 2018
0fffe6e
Bring "tslint-plugin-prettier" back
igor-dv Aug 6, 2018
86afcac
FIX versions in package.json
ndelangen Aug 6, 2018
2a5e762
Delete false symlink =/
igor-dv Aug 7, 2018
60ff6ab
Added symlink to svelte example
tmeasday Aug 9, 2018
fb28658
fix svelte symlink
tmeasday Aug 9, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 17 additions & 17 deletions ADDONS_SUPPORT.md
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)|
| ----------- |:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|
|[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)|
| ----------- |:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|
|[a11y](addons/a11y) |+| |+|+|+|+|+|+| |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addon-a11y works, but it shows an ugly error in the console.

Error: Expect axe._selectorData to be set up
    at generateSelector (axe.js:2810)

The error does not seem to affect functionality though

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm that's unfortunate, I wonder if axe is actively maintained and we could open a ticket with the maintainers..

|[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) |+|+|+|+| | |+| | |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please mark all the supported addons

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm working my way through them, marking them off and committing as I go. I think I've marked off everything I've tested so far.

|[storysource](addons/storysource)|+| |+|+|+|+|+|+| |
|[viewport](addons/viewport) |+| |+|+|+|+|+|+| |
1 change: 1 addition & 0 deletions addons/backgrounds/svelte.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/deprecated');
Copy link
Member

@igor-dv igor-dv Jun 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is deprecated, so you don't need to add a new one. You should just import from the @storybook/addon-backgrounds

34 changes: 34 additions & 0 deletions addons/centered/src/components/Centered.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<div class="style">
<div class="inner-style">
<svelte:component this="{Story}" {...data} />
</div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not work in conjunction with actions as events are not forwarded from the inner component.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be fixed in plumpNation#1

</div>

<style>
.style {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could styles be imported from the ./styles.js ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can, but it will make the svelte template "worse". The style attribute doesn't work the same way as in react or vue, so I can't just pass the object in there.

I'll have a go, and see what you think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm adding a small helper function to convert it to plain CSS strings before applying it inline in the component. Not very pretty but solves the problem. It doesn't make the component 'worse', so I guess there's that.

position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
display: flex;
align-items: center;
overflow: auto;
}

.inner-style {
margin: auto;
max-height: 100%; /* Hack for centering correctly in IE11 */
}
</style>

<script>
export default {
data() {
return {
Story: null,
style: {}
}
}
};
</script>
12 changes: 11 additions & 1 deletion addons/centered/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,15 @@ import { window } from 'global';
import ReactCentered from './react';
import VueCentered from './vue';

const Centered = window.STORYBOOK_ENV === 'vue' ? VueCentered : ReactCentered;
function getCentered(env) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the purpose of this refactoring?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this is from when I didn't understand that the other frameworks are importing the centered addon directly.

I have used Vue as the main starting point since it works in the closest way. So I had svelte in here too, but didn't like it.

I'll checkout this file again from master.

switch (env) {
case 'vue':
return VueCentered;
default:
return ReactCentered;
}
}

const Centered = getCentered(window.STORYBOOK_ENV);

export default Centered;
9 changes: 9 additions & 0 deletions addons/centered/src/svelte.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Centered from './components/Centered.svelte';

export default function(storyFn) {
const { Component, data } = storyFn();

data.Story = Component;

return { Component: Centered, data };
}
1 change: 1 addition & 0 deletions addons/centered/svelte.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/svelte');
1 change: 1 addition & 0 deletions addons/knobs/svelte.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/deprecated');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, knobs are framework agnostic.

1 change: 1 addition & 0 deletions addons/storyshots/storyshots-core/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
'@storybook/react',
'@storybook/react-native',
'@storybook/vue',
'@storybook/svelte',
'enzyme',
],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import global from 'global';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any committed snapshots, does this addon really work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet, I had to stop and sleep yesterday, got a bit late 😸

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should now be generating snapshots.

import hasDependency from '../hasDependency';
import configure from '../configure';

function test(options) {
return (
options.framework === 'svelte' || (!options.framework && hasDependency('@storybook/svelte'))
);
}

function load(options) {
global.STORYBOOK_ENV = 'svelte';

const { configPath, config } = options;
const storybook = require.requireActual('@storybook/svelte');

configure({ configPath, config, storybook });

return {
framework: 'svelte',
renderTree: require.requireActual('./renderTree').default,
renderShallowTree: () => {
throw new Error('Shallow renderer is not supported for svelte');
},
storybook,
};
}

export default {
load,
test,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function getRenderedTree(story, context) {
const storyElement = story.render(context);

return storyElement;
}

export default getRenderedTree;
2 changes: 2 additions & 0 deletions app/svelte/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docs
.babelrc
33 changes: 33 additions & 0 deletions app/svelte/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Storybook for Svelte

[![Build Status on CircleCI](https://circleci.com/gh/storybooks/storybook.svg?style=shield)](https://circleci.com/gh/storybooks/storybook)
[![CodeFactor](https://www.codefactor.io/repository/github/storybooks/storybook/badge)](https://www.codefactor.io/repository/github/storybooks/storybook)
[![Known Vulnerabilities](https://snyk.io/test/github/storybooks/storybook/8f36abfd6697e58cd76df3526b52e4b9dc894847/badge.svg)](https://snyk.io/test/github/storybooks/storybook/8f36abfd6697e58cd76df3526b52e4b9dc894847)
[![BCH compliance](https://bettercodehub.com/edge/badge/storybooks/storybook)](https://bettercodehub.com/results/storybooks/storybook) [![codecov](https://codecov.io/gh/storybooks/storybook/branch/master/graph/badge.svg)](https://codecov.io/gh/storybooks/storybook)
[![Storybook Slack](https://now-examples-slackin-rrirkqohko.now.sh/badge.svg)](https://now-examples-slackin-rrirkqohko.now.sh/)
[![Backers on Open Collective](https://opencollective.com/storybook/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/storybook/sponsors/badge.svg)](#sponsors)

* * *

Storybook for Svelte is a UI development environment for your Svelte components.
With it, you can visualize different states of your UI components and develop them interactively.

![Storybook Screenshot](https://github.com/storybooks/storybook/blob/master/app/svelte/docs/demo.gif)

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-svelte-app
getstorybook
```

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.
3 changes: 3 additions & 0 deletions app/svelte/bin/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('../dist/server/build');
3 changes: 3 additions & 0 deletions app/svelte/bin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('../dist/server');
Binary file added app/svelte/docs/demo.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/svelte/docs/react_storybook_screenshot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/svelte/docs/storybooks_io_logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions app/svelte/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@storybook/svelte",
"version": "4.0.0-alpha.9",
"description": "Storybook for Svelte: Develop Svelte Component in isolation with Hot Reloading.",
"homepage": "https://github.com/storybooks/storybook/tree/master/apps/vue",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vue?

"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": {
"@storybook/core": "4.0.0-alpha.9",
"common-tags": "^1.8.0",
"global": "^4.3.2",
"react": "^16.4.0",
"react-dom": "^16.4.0"
},
"devDependencies": {
"svelte": "^2.7.2",
"svelte-loader": "^2.9.1"
},
"peerDependencies": {
"svelte": "2.7.2",
"svelte-loader": "2.9.1"
}
}
8 changes: 8 additions & 0 deletions app/svelte/src/client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export {
storiesOf,
setAddon,
addDecorator,
addParameters,
configure,
getStorybook,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also export here the forceReRender.

} from './preview';
4 changes: 4 additions & 0 deletions app/svelte/src/client/preview/globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { window } from 'global';

window.STORYBOOK_REACT_CLASSES = {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be needed here

window.STORYBOOK_ENV = 'svelte';
26 changes: 26 additions & 0 deletions app/svelte/src/client/preview/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { start } from '@storybook/core/client';

import './globals';
import render from './render';

// const createWrapperComponent = Target => ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant?

// functional: true,
// render(h, c) {
// return h(Target, c.data, c.children);
// },
// });

const { clientApi, configApi, forceReRender } = start(render);
// const { clientApi, configApi, forceReRender } = start(render, { decorateStory });

export const {
storiesOf,
setAddon,
addDecorator,
addParameters,
clearDecorators,
getStorybook,
} = clientApi;

export const { configure } = configApi;
export { forceReRender };
39 changes: 39 additions & 0 deletions app/svelte/src/client/preview/render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { stripIndents } from 'common-tags';

const target = document.getElementById('root'); // eslint-disable-line

export default function render({
story,
selectedKind,
selectedStory,
showMain,
showError,
// showException,
}) {
const { Component, data, methods } = story();

target.innerHTML = '';

if (!Component) {
showError({
title: `Expecting a Svelte component from the story: "${selectedStory}" of "${selectedKind}".`,
description: stripIndents`
Did you forget to return the Svelte component from the story?
Use "() => ({ Component: YourComponent, data: {} })"
when defining the story.
`,
});

return;
}

const component = new Component({target, data}); // eslint-disable-line

if (methods) {
Object.keys(methods).forEach(methodName => {
component[methodName] = methods[methodName];
});
}

showMain();
}
5 changes: 5 additions & 0 deletions app/svelte/src/server/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { buildStatic } from '@storybook/core/server';

import options from './options';

buildStatic(options);
5 changes: 5 additions & 0 deletions app/svelte/src/server/index.js
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);
8 changes: 8 additions & 0 deletions app/svelte/src/server/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import packageJson from '../../package.json';

import wrapInitialConfig from './wrapInitialConfig';

export default {
packageJson,
wrapInitialConfig,
};
19 changes: 19 additions & 0 deletions app/svelte/src/server/wrapInitialConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export default config => ({
...config,
module: {
...config.module,
rules: [
...config.module.rules,
{
test: /\.svelte$/,
loader: require.resolve('svelte-loader'),
options: {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also support .html files here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can. I'm wondering if they will match other loaders elsewhere in the webpack config, haven't looked into these overrides enough yet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested.. and putting this:

test: /\.(svelte|html)$/,

works without causing any issues with other loaders.

Maybe check it out from your side.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking that out. Will do.

},
],
},
resolve: {
...config.resolve,
extensions: [...config.resolve.extensions, '.svelte'],
alias: config.resolve.alias,
},
});