nodes/packages/ui/.histoire/dist/assets/story--eZPzd9h.js

45 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-04-24 19:11:00 +02:00
import { i as defineStore, r as ref, c as computed } from "./vendor-BCKkA27H.js";
import { r as router } from "./GenericMountStory.vue2-BX48YWx2.js";
const useStoryStore = defineStore("story", () => {
const stories = ref([]);
function setStories(value) {
stories.value = value;
}
const currentStory = computed(() => stories.value.find((s) => s.id === router.currentRoute.value.params.storyId));
const currentVariant = computed(() => {
var _a;
return (_a = currentStory.value) == null ? void 0 : _a.variants.find((v) => v.id === router.currentRoute.value.query.variantId);
});
const maps = computed(() => {
const storyMap = /* @__PURE__ */ new Map();
const variantMap = /* @__PURE__ */ new Map();
for (const story of stories.value) {
storyMap.set(story.id, story);
for (const variant of story.variants) {
variantMap.set(`${story.id}:${variant.id}`, variant);
}
}
return {
stories: storyMap,
variants: variantMap
};
});
function getStoryById(id) {
return maps.value.stories.get(id);
}
function getVariantById(idWithStoryId) {
return maps.value.variants.get(idWithStoryId);
}
return {
stories,
setStories,
currentStory,
currentVariant,
getStoryById,
getVariantById
};
});
export {
useStoryStore as u
};