-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
322 additions
and
341 deletions.
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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,3 +1 @@ | ||
// NOTE: loading addons using this file is deprecated! | ||
// please use manager.js and preview.js files instead | ||
require('./manager'); | ||
require('./dist/register'); |
5 changes: 4 additions & 1 deletion
5
addons/options/src/shared/index.js → addons/options/src/constants.js
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,3 +1,6 @@ | ||
// addons, panels and events get unique names using a prefix | ||
export const ADDON_ID = 'storybooks/options'; | ||
export const EVENT_ID = `${ADDON_ID}/options-event`; | ||
|
||
export default { | ||
SET: `${ADDON_ID}/options-event`, | ||
}; |
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 was deleted.
Oops, something went wrong.
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,10 @@ | ||
import addons from '@storybook/addons'; | ||
import EVENTS, { ADDON_ID } from './constants'; | ||
|
||
addons.register(ADDON_ID, api => { | ||
const channel = addons.getChannel(); | ||
|
||
channel.on(EVENTS.SET, data => { | ||
api.setOptions(data.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
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
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
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
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
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,35 @@ | ||
import { types } from '@storybook/addons'; | ||
|
||
export function ensurePanel(panels, selectedPanel, currentPanel) { | ||
const keys = Object.keys(panels); | ||
|
||
if (keys.indexOf(selectedPanel) >= 0) { | ||
return selectedPanel; | ||
} | ||
|
||
if (keys.length) { | ||
return keys[0]; | ||
} | ||
return currentPanel; | ||
} | ||
|
||
export default ({ provider, store }) => { | ||
const api = { | ||
getElements: type => provider.getElements(type), | ||
getPanels: () => api.getElements(types.PANEL), | ||
getSelectedPanel: () => { | ||
const { selectedPanel } = store.getState(); | ||
return ensurePanel(api.getPanels(), selectedPanel, selectedPanel); | ||
}, | ||
setSelectedPanel: panelName => { | ||
store.setState({ selectedPanel: panelName }); | ||
}, | ||
}; | ||
|
||
return { | ||
api, | ||
state: { | ||
selectedPanel: ensurePanel(api.getPanels()), | ||
}, | ||
}; | ||
}; |
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,26 @@ | ||
import { STORY_CHANGED } from '@storybook/core-events'; | ||
|
||
export default ({ provider }) => { | ||
const api = { | ||
getChannel: () => provider.channel, | ||
on: (type, cb, peer = true) => { | ||
if (peer) { | ||
provider.channel.addPeerListener(type, cb); | ||
} else { | ||
provider.channel.addListener(type, cb); | ||
} | ||
|
||
return () => provider.channel.removeListener(type, cb); | ||
}, | ||
off: (type, cb) => { | ||
provider.channel.removeListener(type, cb); | ||
}, | ||
emit: (type, event) => { | ||
provider.channel.emit(type, event); | ||
}, | ||
|
||
// TODO: deprecate this | ||
onStory: cb => api.on(STORY_CHANGED, cb), | ||
}; | ||
return { api }; | ||
}; |
Oops, something went wrong.