@stories-js/core
Version:
Stories web components to build stories
84 lines (78 loc) • 2.59 kB
JavaScript
/*!
* (C) StoriesJS https://storiesjs.org - GPL-2.0 License
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
const index = require('./index-c25eada5.js');
const index$2 = require('./index-92599979.js');
const index$1 = require('./index-ad63dbd0.js');
const appCss = ":host{height:100%;width:100%;background-color:coral}";
const App = class {
constructor(hostRef) {
index.registerInstance(this, hostRef);
this.storyChange = index.createEvent(this, "storyChange", 7);
this.storyContextChange = index.createEvent(this, "storyContextChange", 7);
/**
* Story Modules
*/
this.modules = [];
/**
* Story Modules
*/
this.store = index$1.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 = index$2.api.getStoryIdFromURL();
// Set story in state
const story = index$1.state.story = (storyId ? index$1.state.stories[storyId] : undefined);
console.log('onHash', storyId, story);
// We have to update the URL's hash to keep it in sync
index$2.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;
index$1.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);
index$2.api.setStories(this.modules);
// Update internal state and sync it with hash
this.onHash();
}
render() {
return (index.h("slot", null));
}
};
App.style = appCss;
exports.stories_app = App;
//# sourceMappingURL=stories-app.cjs.entry.js.map