@stories-js/core
Version:
Stories web components to build stories
80 lines (76 loc) • 2.47 kB
JavaScript
/*!
* (C) StoriesJS https://storiesjs.org - GPL-2.0 License
*/
import { r as registerInstance, i as createEvent, h } from './index-49238f69.js';
import { a as api } from './index-aaa78d22.js';
import { s as state } from './index-f706f0f6.js';
const appCss = ":host{height:100%;width:100%;background-color:coral}";
const App = class {
constructor(hostRef) {
registerInstance(this, hostRef);
this.storyChange = createEvent(this, "storyChange", 7);
this.storyContextChange = createEvent(this, "storyContextChange", 7);
/**
* Story Modules
*/
this.modules = [];
/**
* Story Modules
*/
this.store = state;
}
/**
* AddonsManager instance
*/
// @Prop() addons: AddonsManager = addonsManager;
/**
* Create story context
*/
createContext(story) {
const context = {
args: Object.assign({}, story.args),
argTypes: Object.assign({}, story.argTypes),
parameters: Object.assign({}, story.parameters),
initialArgs: Object.assign({}, story.args),
};
return context;
}
/**
* Listen the 'hashchange' event and get path from URL.
* First available story could be selected if there is no one was specified in the URL's path after hash
* Method will emmit the 'story' event
*/
onHash() {
// Get path from URL's hash or default value based on first story
const storyId = api.getStoryIdFromURL();
// Set story in state
const story = state.story = (storyId ? state.stories[storyId] : undefined);
console.log('onHash', storyId, story);
// We have to update the URL's hash to keep it in sync
api.selectStory(storyId);
// Send custom event about selected story
this.storyChange.emit(story);
console.log('storyChange emit', story);
// Create context for story
const context = story ? this.createContext(story) : undefined;
state.context = context;
// Send custom event about selected story
this.storyContextChange.emit(context);
console.log('storyContextChange emit', story);
// Inform Addons about changes
// this.addons.storyContextChanged(story, context);
}
;
componentDidLoad() {
console.log('componentDidLoad', this.modules);
api.setStories(this.modules);
// Update internal state and sync it with hash
this.onHash();
}
render() {
return (h("slot", null));
}
};
App.style = appCss;
export { App as stories_app };
//# sourceMappingURL=stories-app.entry.js.map