histoire 0.2.4 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/dist/client/app/App.vue +9 -4
  2. package/dist/client/app/codegen/const.d.ts +1 -0
  3. package/dist/client/app/codegen/const.js +3 -0
  4. package/dist/client/app/codegen/vue3.js +82 -21
  5. package/dist/client/app/components/app/Breadcrumb.vue +1 -1
  6. package/dist/client/app/components/base/BaseEmpty.vue +17 -1
  7. package/dist/client/app/components/exposed/Story.vue +22 -1
  8. package/dist/client/app/components/exposed/Variant.vue +13 -1
  9. package/dist/client/app/components/sandbox/SandboxVue3.vue +6 -4
  10. package/dist/client/app/components/sandbox/lib.js +2 -1
  11. package/dist/client/app/components/search/SearchItem.vue +1 -0
  12. package/dist/client/app/components/search/SearchLoading.vue +16 -0
  13. package/dist/client/app/components/search/SearchModal.vue +12 -149
  14. package/dist/client/app/components/search/SearchPane.vue +210 -0
  15. package/dist/client/app/components/search/search-data.d.ts +2 -0
  16. package/dist/client/app/components/search/search-data.js +7 -0
  17. package/dist/client/app/components/story/StoryControls.vue +5 -0
  18. package/dist/client/app/components/story/StoryDocs.vue +18 -11
  19. package/dist/client/app/components/story/StoryEvent.vue +53 -0
  20. package/dist/client/app/components/story/StoryEvents.vue +45 -0
  21. package/dist/client/app/components/story/StoryResponsivePreview.vue +41 -8
  22. package/dist/client/app/components/story/StorySidePanel.vue +28 -3
  23. package/dist/client/app/components/story/StorySourceCode.vue +24 -14
  24. package/dist/client/app/components/story/StoryView.vue +16 -2
  25. package/dist/client/app/components/tree/StoryGroup.vue +75 -0
  26. package/dist/client/app/components/{story → tree}/StoryList.vue +8 -2
  27. package/{src/client/app/components/story → dist/client/app/components/tree}/StoryListFolder.vue +10 -8
  28. package/{src/client/app/components/story → dist/client/app/components/tree}/StoryListItem.vue +7 -4
  29. package/dist/client/app/router.d.ts +1 -0
  30. package/dist/client/app/router.js +3 -1
  31. package/dist/client/app/sandbox.js +11 -1
  32. package/dist/client/app/stores/events.d.ts +29 -0
  33. package/dist/client/app/stores/events.js +25 -0
  34. package/dist/client/app/stores/folder.d.ts +10 -0
  35. package/dist/client/app/stores/folder.js +47 -0
  36. package/dist/client/app/stores/story.d.ts +20 -8
  37. package/dist/client/app/stores/story.js +20 -28
  38. package/dist/client/app/style/floating-vue.pcss +3 -1
  39. package/dist/client/app/style/main.pcss +5 -0
  40. package/dist/client/app/style/sandbox.css +2 -0
  41. package/dist/client/app/types.d.ts +9 -1
  42. package/dist/client/app/util/const.d.ts +1 -0
  43. package/dist/client/app/util/const.js +1 -0
  44. package/dist/client/app/util/events.d.ts +1 -0
  45. package/dist/client/app/util/events.js +31 -0
  46. package/dist/client/app/util/mapping.js +2 -2
  47. package/dist/client/index.d.ts +4 -3
  48. package/dist/client/index.js +2 -1
  49. package/dist/client/server/index.d.ts +7 -2
  50. package/dist/client/server/index.js +8 -26
  51. package/{src/client/server/Story.server.vue → dist/client/server/vue3/Story.vue} +21 -4
  52. package/dist/client/server/{Variant.server.vue → vue3/Variant.vue} +0 -0
  53. package/dist/client/server/vue3/run.d.ts +2 -0
  54. package/dist/client/server/vue3/run.js +32 -0
  55. package/dist/node/alias.d.ts +2 -1
  56. package/dist/node/alias.js +3 -2
  57. package/dist/node/build.js +74 -21
  58. package/dist/node/builtin-plugins/tailwind-tokens.d.ts +5 -0
  59. package/dist/node/builtin-plugins/tailwind-tokens.js +510 -0
  60. package/dist/node/collect/index.js +5 -3
  61. package/dist/node/collect/worker.js +6 -2
  62. package/dist/node/commands/preview.js +4 -25
  63. package/dist/node/config.d.ts +111 -5
  64. package/dist/node/config.js +40 -23
  65. package/dist/node/context.d.ts +3 -3
  66. package/dist/node/context.js +1 -1
  67. package/dist/node/index.d.ts +1 -0
  68. package/dist/node/index.js +1 -0
  69. package/dist/node/load.d.ts +12 -0
  70. package/dist/node/load.js +42 -0
  71. package/dist/node/plugin.d.ts +67 -11
  72. package/dist/node/plugin.js +42 -245
  73. package/dist/node/preview.d.ts +8 -0
  74. package/dist/node/preview.js +41 -0
  75. package/dist/node/search.d.ts +2 -0
  76. package/dist/node/search.js +68 -0
  77. package/dist/node/server.js +43 -21
  78. package/dist/node/stories.d.ts +2 -0
  79. package/dist/node/stories.js +9 -4
  80. package/dist/node/tree.d.ts +16 -12
  81. package/dist/node/tree.js +45 -5
  82. package/dist/node/types.d.ts +11 -0
  83. package/dist/node/util/find-up.d.ts +1 -0
  84. package/dist/node/util/find-up.js +20 -0
  85. package/dist/node/vite.d.ts +13 -0
  86. package/dist/node/vite.js +278 -0
  87. package/dist/style.css +174 -36
  88. package/package.json +7 -6
  89. package/scripts/copy.mjs +2 -1
  90. package/src/client/app/App.vue +9 -4
  91. package/src/client/app/codegen/const.ts +3 -0
  92. package/src/client/app/codegen/vue3.ts +80 -22
  93. package/src/client/app/components/app/Breadcrumb.vue +1 -1
  94. package/src/client/app/components/base/BaseEmpty.vue +17 -1
  95. package/src/client/app/components/exposed/Story.vue +22 -1
  96. package/src/client/app/components/exposed/Variant.vue +13 -1
  97. package/src/client/app/components/sandbox/SandboxVue3.vue +6 -4
  98. package/src/client/app/components/sandbox/lib.ts +3 -1
  99. package/src/client/app/components/search/SearchItem.vue +1 -0
  100. package/src/client/app/components/search/SearchLoading.vue +16 -0
  101. package/src/client/app/components/search/SearchModal.vue +12 -149
  102. package/src/client/app/components/search/SearchPane.vue +210 -0
  103. package/src/client/app/components/search/search-data.ts +9 -0
  104. package/src/client/app/components/story/StoryControls.vue +5 -0
  105. package/src/client/app/components/story/StoryDocs.vue +18 -11
  106. package/src/client/app/components/story/StoryEvent.vue +53 -0
  107. package/src/client/app/components/story/StoryEvents.vue +45 -0
  108. package/src/client/app/components/story/StoryResponsivePreview.vue +41 -8
  109. package/src/client/app/components/story/StorySidePanel.vue +28 -3
  110. package/src/client/app/components/story/StorySourceCode.vue +24 -14
  111. package/src/client/app/components/story/StoryView.vue +16 -2
  112. package/src/client/app/components/tree/StoryGroup.vue +75 -0
  113. package/src/client/app/components/{story → tree}/StoryList.vue +8 -2
  114. package/{dist/client/app/components/story → src/client/app/components/tree}/StoryListFolder.vue +10 -8
  115. package/{dist/client/app/components/story → src/client/app/components/tree}/StoryListItem.vue +7 -4
  116. package/src/client/app/router.ts +4 -1
  117. package/src/client/app/sandbox.ts +12 -2
  118. package/src/client/app/stores/events.ts +36 -0
  119. package/src/client/app/stores/folder.ts +59 -0
  120. package/src/client/app/stores/story.ts +20 -35
  121. package/src/client/app/style/floating-vue.pcss +3 -1
  122. package/src/client/app/style/main.pcss +5 -0
  123. package/src/client/app/style/sandbox.css +2 -0
  124. package/src/client/app/types.ts +10 -1
  125. package/src/client/app/util/const.ts +1 -0
  126. package/src/client/app/util/events.ts +30 -0
  127. package/src/client/app/util/mapping.ts +2 -2
  128. package/src/client/index.ts +4 -3
  129. package/src/client/server/index.ts +14 -27
  130. package/{dist/client/server/Story.server.vue → src/client/server/vue3/Story.vue} +21 -4
  131. package/src/client/server/{Variant.server.vue → vue3/Variant.vue} +0 -0
  132. package/{dist/client/server/index.ts → src/client/server/vue3/run.ts} +10 -4
  133. package/src/node/alias.ts +4 -2
  134. package/src/node/build.ts +86 -21
  135. package/src/node/builtin-plugins/tailwind-tokens.ts +521 -0
  136. package/src/node/collect/index.ts +6 -4
  137. package/src/node/collect/worker.ts +7 -2
  138. package/src/node/commands/preview.ts +4 -33
  139. package/src/node/config.ts +62 -29
  140. package/src/node/context.ts +3 -3
  141. package/src/node/index.ts +1 -0
  142. package/src/node/load.ts +63 -0
  143. package/src/node/plugin.ts +75 -252
  144. package/src/node/preview.ts +56 -0
  145. package/src/node/search.ts +75 -0
  146. package/src/node/server.ts +49 -23
  147. package/src/node/stories.ts +9 -4
  148. package/src/node/tree.spec.ts +35 -17
  149. package/src/node/tree.ts +64 -10
  150. package/src/node/types.ts +12 -0
  151. package/src/node/util/find-up.ts +24 -0
  152. package/src/node/vite.ts +296 -0
  153. package/tailwind.config.cjs +1 -0
  154. package/dist/client/app/codegen/serialize-js.ts +0 -119
  155. package/dist/client/app/codegen/util.ts +0 -79
  156. package/dist/client/app/codegen/vue3.ts +0 -276
  157. package/dist/client/app/components/sandbox/lib.ts +0 -8
  158. package/dist/client/app/global-components.ts +0 -13
  159. package/dist/client/app/index.ts +0 -28
  160. package/dist/client/app/router.ts +0 -17
  161. package/dist/client/app/sandbox.ts +0 -94
  162. package/dist/client/app/stores/preview-settings.ts +0 -17
  163. package/dist/client/app/stores/story.ts +0 -62
  164. package/dist/client/app/types.ts +0 -70
  165. package/dist/client/app/util/config.ts +0 -6
  166. package/dist/client/app/util/const.ts +0 -3
  167. package/dist/client/app/util/dark.ts +0 -4
  168. package/dist/client/app/util/env.ts +0 -1
  169. package/dist/client/app/util/keyboard.ts +0 -99
  170. package/dist/client/app/util/mapping.ts +0 -48
  171. package/dist/client/app/util/preview-settings.ts +0 -8
  172. package/dist/client/app/util/reactivity.ts +0 -22
  173. package/dist/client/app/util/responsive.ts +0 -3
  174. package/dist/client/app/util/scroll.ts +0 -31
  175. package/dist/client/app/util/tooltip.ts +0 -13
  176. package/dist/client/app/util/variant.ts +0 -20
  177. package/dist/client/index.ts +0 -12
  178. package/dist/client/shim.d.ts +0 -5
@@ -1,7 +1,8 @@
1
1
  <script lang="ts" setup>
2
- import type { Story, Tree, TreeFolder, TreeLeaf } from '../../types'
2
+ import type { Story, Tree, TreeGroup, TreeFolder, TreeLeaf } from '../../types'
3
3
  import StoryListItem from './StoryListItem.vue'
4
4
  import StoryListFolder from './StoryListFolder.vue'
5
+ import StoryGroup from './StoryGroup.vue'
5
6
 
6
7
  const props = defineProps<{
7
8
  tree: Tree
@@ -15,8 +16,13 @@ const props = defineProps<{
15
16
  v-for="element of tree"
16
17
  :key="element.title"
17
18
  >
19
+ <StoryGroup
20
+ v-if="(element as TreeGroup).group"
21
+ :group="(element as TreeGroup)"
22
+ :stories="stories"
23
+ />
18
24
  <StoryListFolder
19
- v-if="(element as TreeFolder).children"
25
+ v-else-if="(element as TreeFolder).children"
20
26
  :folder="(element as TreeFolder)"
21
27
  :stories="stories"
22
28
  />
@@ -3,7 +3,7 @@ import type { Story, TreeFolder, TreeLeaf } from '../../types'
3
3
  import StoryListItem from './StoryListItem.vue'
4
4
  import { Icon } from '@iconify/vue'
5
5
  import { computed, withDefaults } from 'vue'
6
- import { useStoryStore } from '../../stores/story'
6
+ import { useFolderStore } from '../../stores/folder'
7
7
 
8
8
  const props = withDefaults(defineProps<{
9
9
  path?: Array<string>
@@ -15,17 +15,17 @@ const props = withDefaults(defineProps<{
15
15
  path: () => [],
16
16
  })
17
17
 
18
- const storyStore = useStoryStore()
18
+ const folderStore = useFolderStore()
19
19
 
20
20
  const folderPath = computed(() => [...props.path, props.folder.title])
21
- const isFolderOpen = computed(() => storyStore.isFolderOpened(folderPath.value))
21
+ const isFolderOpen = computed(() => folderStore.isFolderOpened(folderPath.value))
22
22
 
23
23
  function toggleOpen () {
24
- storyStore.toggleFolder(folderPath.value)
24
+ folderStore.toggleFolder(folderPath.value)
25
25
  }
26
26
 
27
27
  const folderPadding = computed(() => {
28
- return (props.depth * 16) + 'px'
28
+ return (props.depth * 12) + 'px'
29
29
  })
30
30
  </script>
31
31
 
@@ -34,13 +34,13 @@ const folderPadding = computed(() => {
34
34
  <div
35
35
  role="button"
36
36
  tabindex="0"
37
- class="htw-px-0.5 htw-py-2 md:htw-py-1.5 htw-m-1 htw-rounded-sm hover:htw-bg-primary-100 dark:hover:htw-bg-primary-900 htw-cursor-pointer htw-select-none htw-flex"
37
+ class="htw-px-0.5 htw-py-2 md:htw-py-1.5 htw-mx-1 htw-rounded-sm hover:htw-bg-primary-100 dark:hover:htw-bg-primary-900 htw-cursor-pointer htw-select-none htw-flex"
38
38
  @click="toggleOpen"
39
39
  @keyup.enter="toggleOpen"
40
40
  @keyup.space="toggleOpen"
41
41
  >
42
42
  <span class="bind-tree-padding htw-flex htw-items-center htw-gap-2 htw-min-w-0">
43
- <span class="htw-flex htw-gap-1 htw-flex-none htw-items-center">
43
+ <span class="htw-flex htw-flex-none htw-items-center">
44
44
  <Icon
45
45
  icon="carbon:caret-right"
46
46
  class="htw-w-4 htw-h-4 htw-transition-transform htw-duration-150 htw-opacity-30"
@@ -56,6 +56,8 @@ const folderPadding = computed(() => {
56
56
  <span class="htw-truncate">{{ folder.title }}</span>
57
57
  </span>
58
58
  </div>
59
+
60
+ <!-- Children -->
59
61
  <div
60
62
  v-if="isFolderOpen"
61
63
  >
@@ -66,7 +68,7 @@ const folderPadding = computed(() => {
66
68
  <StoryListFolder
67
69
  v-if="(element as TreeFolder).children"
68
70
  :path="folderPath"
69
- :folder="element"
71
+ :folder="(element as TreeFolder)"
70
72
  :stories="stories"
71
73
  :depth="depth + 1"
72
74
  />
@@ -14,7 +14,7 @@ const props = withDefaults(defineProps<{
14
14
  })
15
15
 
16
16
  const filePadding = computed(() => {
17
- return (props.depth * 16) + 'px'
17
+ return (props.depth * 12) + 'px'
18
18
  })
19
19
 
20
20
  const route = useRoute()
@@ -36,9 +36,9 @@ useScrollOnActive(active, el)
36
36
  storyId: story.id,
37
37
  },
38
38
  }"
39
- class="htw-pl-0.5 htw-pr-2 htw-py-2 md:htw-py-1.5 htw-m-1 htw-rounded-sm"
39
+ class="htw-pl-0.5 htw-pr-2 htw-py-2 md:htw-py-1.5 htw-mx-1 htw-rounded-sm"
40
40
  >
41
- <span class="bind-tree-margin htw-flex htw-items-center htw-gap-2 htw-pl-5 htw-min-w-0">
41
+ <span class="bind-tree-margin htw-flex htw-items-center htw-gap-2 htw-pl-4 htw-min-w-0">
42
42
  <Icon
43
43
  :icon="story.icon ?? 'carbon:cube'"
44
44
  class="base-list-item-link-icon htw-w-5 htw-h-5 sm:htw-w-4 sm:htw-h-4 htw-flex-none"
@@ -50,7 +50,10 @@ useScrollOnActive(active, el)
50
50
  <span class="htw-truncate">{{ story.title }}</span>
51
51
  </span>
52
52
 
53
- <span class="htw-opacity-40 htw-text-sm">
53
+ <span
54
+ v-if="!story.docsOnly"
55
+ class="htw-opacity-40 htw-text-sm"
56
+ >
54
57
  {{ story.variants.length }}
55
58
  </span>
56
59
  </BaseListItemLink>
@@ -1 +1,2 @@
1
+ export declare const base: any;
1
2
  export declare const router: import("vue-router").Router;
@@ -1,6 +1,8 @@
1
1
  import { createRouter, createWebHistory } from 'vue-router';
2
+ // @ts-expect-error env not defined
3
+ export const base = import.meta.env.BASE_URL;
2
4
  export const router = createRouter({
3
- history: createWebHistory(),
5
+ history: createWebHistory(base),
4
6
  routes: [
5
7
  {
6
8
  path: '/',
@@ -15,6 +15,7 @@ import { toRawDeep } from './util/reactivity';
15
15
  const query = parseQuery(window.location.search);
16
16
  const file = ref(mapFile(files.find(f => f.id === query.storyId)));
17
17
  const app = createApp({
18
+ name: 'SandboxApp',
18
19
  setup() {
19
20
  const story = computed(() => file.value.story);
20
21
  const variant = computed(() => story.value?.variants.find(v => v.id === query.variantId));
@@ -25,7 +26,16 @@ const app = createApp({
25
26
  if (!mounted)
26
27
  return;
27
28
  synced = true;
28
- Object.assign(variant.value.state, event.data.state);
29
+ if (variant.value.state) {
30
+ for (const key in event.data.state) {
31
+ if (typeof variant.value.state[key] === 'object') {
32
+ Object.assign(variant.value.state[key], event.data.state[key]);
33
+ }
34
+ else {
35
+ variant.value.state[key] = event.data.state[key];
36
+ }
37
+ }
38
+ }
29
39
  }
30
40
  else if (event.data?.type === PREVIEW_SETTINGS_SYNC) {
31
41
  applyPreviewSettings(event.data.settings);
@@ -0,0 +1,29 @@
1
+ export declare type HstEvent = {
2
+ name: string;
3
+ argument: unknown;
4
+ };
5
+ export declare const useEventsStore: import("pinia").StoreDefinition<"events", import("pinia")._UnwrapAll<Pick<{
6
+ addEvent: (event: HstEvent) => void;
7
+ reset: () => void;
8
+ events: {
9
+ name: string;
10
+ argument: unknown;
11
+ }[];
12
+ unseen: import("vue").Ref<number>;
13
+ }, "events" | "unseen">>, import("pinia")._UnwrapAll<Pick<{
14
+ addEvent: (event: HstEvent) => void;
15
+ reset: () => void;
16
+ events: {
17
+ name: string;
18
+ argument: unknown;
19
+ }[];
20
+ unseen: import("vue").Ref<number>;
21
+ }, never>>, Pick<{
22
+ addEvent: (event: HstEvent) => void;
23
+ reset: () => void;
24
+ events: {
25
+ name: string;
26
+ argument: unknown;
27
+ }[];
28
+ unseen: import("vue").Ref<number>;
29
+ }, "addEvent" | "reset">>;
@@ -0,0 +1,25 @@
1
+ import { defineStore } from 'pinia';
2
+ import { ref, reactive, watch } from 'vue';
3
+ import { useStoryStore } from './story.js';
4
+ export const useEventsStore = defineStore('events', () => {
5
+ const storyStore = useStoryStore();
6
+ const events = reactive([]);
7
+ const unseen = ref(0);
8
+ function addEvent(event) {
9
+ events.push(event);
10
+ unseen.value++;
11
+ }
12
+ function reset() {
13
+ events.length = 0;
14
+ unseen.value = 0;
15
+ }
16
+ watch(() => storyStore.currentVariant, () => {
17
+ reset();
18
+ });
19
+ return {
20
+ addEvent,
21
+ reset,
22
+ events,
23
+ unseen,
24
+ };
25
+ });
@@ -0,0 +1,10 @@
1
+ export declare const useFolderStore: import("pinia").StoreDefinition<"folder", import("pinia")._UnwrapAll<Pick<{
2
+ isFolderOpened: (path: Array<string>, defaultValue?: boolean) => boolean;
3
+ toggleFolder: (path: Array<string>, defaultToggleValue?: boolean) => void;
4
+ }, never>>, import("pinia")._UnwrapAll<Pick<{
5
+ isFolderOpened: (path: Array<string>, defaultValue?: boolean) => boolean;
6
+ toggleFolder: (path: Array<string>, defaultToggleValue?: boolean) => void;
7
+ }, never>>, Pick<{
8
+ isFolderOpened: (path: Array<string>, defaultValue?: boolean) => boolean;
9
+ toggleFolder: (path: Array<string>, defaultToggleValue?: boolean) => void;
10
+ }, "isFolderOpened" | "toggleFolder">>;
@@ -0,0 +1,47 @@
1
+ import { defineStore } from 'pinia';
2
+ import { watch } from 'vue';
3
+ import { useStorage } from '@vueuse/core';
4
+ import { useStoryStore } from './story';
5
+ export const useFolderStore = defineStore('folder', () => {
6
+ const openedFolders = useStorage('_histoire-tree-state', new Map());
7
+ function getStringPath(path) {
8
+ return path.join('␜');
9
+ }
10
+ function toggleFolder(path, defaultToggleValue = true) {
11
+ const stringPath = getStringPath(path);
12
+ const currentValue = openedFolders.value.get(stringPath);
13
+ if (currentValue == null) {
14
+ setFolderOpen(stringPath, defaultToggleValue);
15
+ }
16
+ else if (currentValue) {
17
+ setFolderOpen(stringPath, false);
18
+ }
19
+ else {
20
+ setFolderOpen(stringPath, true);
21
+ }
22
+ }
23
+ function setFolderOpen(path, value) {
24
+ const stringPath = typeof path === 'string' ? path : getStringPath(path);
25
+ openedFolders.value.set(stringPath, value);
26
+ }
27
+ function isFolderOpened(path, defaultValue = false) {
28
+ const value = openedFolders.value.get(getStringPath(path));
29
+ if (value == null) {
30
+ return defaultValue;
31
+ }
32
+ return value;
33
+ }
34
+ function openFileFolders(path) {
35
+ for (let pathLength = 1; pathLength < path.length; pathLength++) {
36
+ setFolderOpen(path.slice(0, pathLength), true);
37
+ }
38
+ }
39
+ const storyStore = useStoryStore();
40
+ watch(() => storyStore.currentStory, (story) => {
41
+ openFileFolders(story.file.path);
42
+ });
43
+ return {
44
+ isFolderOpened,
45
+ toggleFolder,
46
+ };
47
+ });
@@ -1,8 +1,9 @@
1
- import { Story } from '../types';
1
+ import { Story, Variant } from '../types';
2
2
  export declare const useStoryStore: import("pinia").StoreDefinition<"story", import("pinia")._UnwrapAll<Pick<{
3
3
  stories: import("vue").Ref<{
4
4
  id: string;
5
5
  title: string;
6
+ group?: string;
6
7
  variants: {
7
8
  id: string;
8
9
  title: string;
@@ -24,6 +25,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
24
25
  };
25
26
  icon?: string;
26
27
  iconColor?: string;
28
+ docsOnly?: boolean;
27
29
  file?: {
28
30
  id: string;
29
31
  framework: string;
@@ -49,6 +51,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
49
51
  currentStory: import("vue").ComputedRef<{
50
52
  id: string;
51
53
  title: string;
54
+ group?: string;
52
55
  variants: {
53
56
  id: string;
54
57
  title: string;
@@ -70,6 +73,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
70
73
  };
71
74
  icon?: string;
72
75
  iconColor?: string;
76
+ docsOnly?: boolean;
73
77
  file?: {
74
78
  id: string;
75
79
  framework: string;
@@ -104,12 +108,13 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
104
108
  configReady?: boolean;
105
109
  previewReady?: boolean;
106
110
  }>;
107
- isFolderOpened: (path: Array<string>) => boolean;
108
- toggleFolder: (path: Array<string>, force?: boolean) => void;
111
+ getStoryById: (id: string) => Story;
112
+ getVariantById: (idWithStoryId: string) => Variant;
109
113
  }, "stories">>, import("pinia")._UnwrapAll<Pick<{
110
114
  stories: import("vue").Ref<{
111
115
  id: string;
112
116
  title: string;
117
+ group?: string;
113
118
  variants: {
114
119
  id: string;
115
120
  title: string;
@@ -131,6 +136,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
131
136
  };
132
137
  icon?: string;
133
138
  iconColor?: string;
139
+ docsOnly?: boolean;
134
140
  file?: {
135
141
  id: string;
136
142
  framework: string;
@@ -156,6 +162,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
156
162
  currentStory: import("vue").ComputedRef<{
157
163
  id: string;
158
164
  title: string;
165
+ group?: string;
159
166
  variants: {
160
167
  id: string;
161
168
  title: string;
@@ -177,6 +184,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
177
184
  };
178
185
  icon?: string;
179
186
  iconColor?: string;
187
+ docsOnly?: boolean;
180
188
  file?: {
181
189
  id: string;
182
190
  framework: string;
@@ -211,12 +219,13 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
211
219
  configReady?: boolean;
212
220
  previewReady?: boolean;
213
221
  }>;
214
- isFolderOpened: (path: Array<string>) => boolean;
215
- toggleFolder: (path: Array<string>, force?: boolean) => void;
222
+ getStoryById: (id: string) => Story;
223
+ getVariantById: (idWithStoryId: string) => Variant;
216
224
  }, "currentStory" | "currentVariant">>, Pick<{
217
225
  stories: import("vue").Ref<{
218
226
  id: string;
219
227
  title: string;
228
+ group?: string;
220
229
  variants: {
221
230
  id: string;
222
231
  title: string;
@@ -238,6 +247,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
238
247
  };
239
248
  icon?: string;
240
249
  iconColor?: string;
250
+ docsOnly?: boolean;
241
251
  file?: {
242
252
  id: string;
243
253
  framework: string;
@@ -263,6 +273,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
263
273
  currentStory: import("vue").ComputedRef<{
264
274
  id: string;
265
275
  title: string;
276
+ group?: string;
266
277
  variants: {
267
278
  id: string;
268
279
  title: string;
@@ -284,6 +295,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
284
295
  };
285
296
  icon?: string;
286
297
  iconColor?: string;
298
+ docsOnly?: boolean;
287
299
  file?: {
288
300
  id: string;
289
301
  framework: string;
@@ -318,6 +330,6 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
318
330
  configReady?: boolean;
319
331
  previewReady?: boolean;
320
332
  }>;
321
- isFolderOpened: (path: Array<string>) => boolean;
322
- toggleFolder: (path: Array<string>, force?: boolean) => void;
323
- }, "setStories" | "isFolderOpened" | "toggleFolder">>;
333
+ getStoryById: (id: string) => Story;
334
+ getVariantById: (idWithStoryId: string) => Variant;
335
+ }, "setStories" | "getStoryById" | "getVariantById">>;
@@ -1,7 +1,6 @@
1
1
  import { defineStore } from 'pinia';
2
- import { computed, ref, watch } from 'vue';
2
+ import { computed, ref } from 'vue';
3
3
  import { router } from '../router';
4
- import { useStorage } from '@vueuse/core';
5
4
  export const useStoryStore = defineStore('story', () => {
6
5
  const stories = ref([]);
7
6
  function setStories(value) {
@@ -9,39 +8,32 @@ export const useStoryStore = defineStore('story', () => {
9
8
  }
10
9
  const currentStory = computed(() => stories.value.find(s => s.id === router.currentRoute.value.params.storyId));
11
10
  const currentVariant = computed(() => currentStory.value?.variants.find(v => v.id === router.currentRoute.value.query.variantId));
12
- const openedFolders = useStorage('_histoire-tree-state', new Map());
13
- function getStringPath(path) {
14
- return path.join('␜');
15
- }
16
- function toggleFolder(path, force) {
17
- const stringPath = getStringPath(path);
18
- if (force === undefined) {
19
- force = !openedFolders.value.get(stringPath);
20
- }
21
- if (force) {
22
- openedFolders.value.set(stringPath, true);
11
+ const maps = computed(() => {
12
+ const storyMap = new Map();
13
+ const variantMap = new Map();
14
+ for (const story of stories.value) {
15
+ storyMap.set(story.id, story);
16
+ for (const variant of story.variants) {
17
+ variantMap.set(`${story.id}:${variant.id}`, variant);
18
+ }
23
19
  }
24
- else {
25
- openedFolders.value.delete(stringPath);
26
- }
27
- }
28
- function isFolderOpened(path) {
29
- return openedFolders.value.get(getStringPath(path));
20
+ return {
21
+ stories: storyMap,
22
+ variants: variantMap,
23
+ };
24
+ });
25
+ function getStoryById(id) {
26
+ return maps.value.stories.get(id);
30
27
  }
31
- function openFileFolders(path) {
32
- for (let pathLength = 1; pathLength < path.length; pathLength++) {
33
- toggleFolder(path.slice(0, pathLength), true);
34
- }
28
+ function getVariantById(idWithStoryId) {
29
+ return maps.value.variants.get(idWithStoryId);
35
30
  }
36
- watch(currentStory, () => {
37
- openFileFolders(currentStory.value.file.path);
38
- });
39
31
  return {
40
32
  stories,
41
33
  setStories,
42
34
  currentStory,
43
35
  currentVariant,
44
- isFolderOpened,
45
- toggleFolder,
36
+ getStoryById,
37
+ getVariantById,
46
38
  };
47
39
  });
@@ -29,4 +29,6 @@
29
29
  }
30
30
  }
31
31
 
32
-
32
+ .v-popper__popper:focus-visible {
33
+ outline: none;
34
+ }
@@ -1,5 +1,6 @@
1
1
  @import url('https://fonts.googleapis.com/css2?family=Lato&display=swap');
2
2
  @import 'floating-vue/dist/style.css';
3
+ @import '@histoire/controls/dist/style.css';
3
4
 
4
5
  @import 'floating-vue.pcss';
5
6
  @import 'transitions.pcss';
@@ -78,4 +79,8 @@ body {
78
79
  }
79
80
  }
80
81
  }
82
+
83
+ hr {
84
+ margin: 1rem 0;
85
+ }
81
86
  }
@@ -1,3 +1,5 @@
1
+ @import '@histoire/controls/dist/style.css';
2
+
1
3
  html,
2
4
  body {
3
5
  background: transparent !important;
@@ -9,6 +9,7 @@ export interface StoryFile {
9
9
  export interface Story {
10
10
  id: string;
11
11
  title: string;
12
+ group?: string;
12
13
  variants: Variant[];
13
14
  layout?: {
14
15
  type: 'single';
@@ -18,6 +19,7 @@ export interface Story {
18
19
  };
19
20
  icon?: string;
20
21
  iconColor?: string;
22
+ docsOnly?: boolean;
21
23
  file?: StoryFile;
22
24
  lastSelectedVariant?: Variant;
23
25
  }
@@ -42,7 +44,13 @@ export declare type TreeFolder = {
42
44
  title: string;
43
45
  children: (TreeFolder | TreeLeaf)[];
44
46
  };
45
- export declare type Tree = (TreeFolder | TreeLeaf)[];
47
+ export interface TreeGroup {
48
+ group: true;
49
+ id: string;
50
+ title: string;
51
+ children: (TreeFolder | TreeLeaf)[];
52
+ }
53
+ export declare type Tree = (TreeGroup | TreeFolder | TreeLeaf)[];
46
54
  export interface SearchResult {
47
55
  kind: 'story' | 'variant';
48
56
  rank: number;
@@ -1,3 +1,4 @@
1
1
  export declare const STATE_SYNC = "__histoire:state-sync";
2
2
  export declare const SANDBOX_READY = "__histoire:sandbox-ready";
3
+ export declare const EVENT_SEND = "__histoire:event";
3
4
  export declare const PREVIEW_SETTINGS_SYNC = "__histoire:preview-settings-sync";
@@ -1,3 +1,4 @@
1
1
  export const STATE_SYNC = '__histoire:state-sync';
2
2
  export const SANDBOX_READY = '__histoire:sandbox-ready';
3
+ export const EVENT_SEND = '__histoire:event';
3
4
  export const PREVIEW_SETTINGS_SYNC = '__histoire:preview-settings-sync';
@@ -0,0 +1 @@
1
+ export declare function hstEvent(name: string, argument: any): void;
@@ -0,0 +1,31 @@
1
+ import { useEventsStore } from '../stores/events.js';
2
+ import { EVENT_SEND } from './const';
3
+ export function hstEvent(name, argument) {
4
+ console.log('[histoire] Event fired', { name, argument });
5
+ const event = {
6
+ name,
7
+ argument: JSON.parse(stringifyEvent(argument)), // Needed for HTMLEvent that can't be cloned
8
+ };
9
+ if (location.href.includes('__sandbox')) {
10
+ window.parent?.postMessage({
11
+ type: EVENT_SEND,
12
+ event,
13
+ });
14
+ }
15
+ else {
16
+ useEventsStore().addEvent(event);
17
+ }
18
+ }
19
+ function stringifyEvent(e) {
20
+ const obj = {};
21
+ for (const k in e) {
22
+ obj[k] = e[k];
23
+ }
24
+ return JSON.stringify(obj, (k, v) => {
25
+ if (v instanceof Node)
26
+ return 'Node';
27
+ if (v instanceof Window)
28
+ return 'Window';
29
+ return v;
30
+ }, ' ');
31
+ }
@@ -18,7 +18,7 @@ export function mapFile(file, existingFile) {
18
18
  for (const key in existingVariant) {
19
19
  if (typeof existingVariant[key] !== 'undefined') {
20
20
  if (key === 'state') {
21
- Object.assign(variant.state, existingVariant.state);
21
+ variant.state = existingVariant.state;
22
22
  continue;
23
23
  }
24
24
  variant[key] = existingVariant[key];
@@ -35,7 +35,7 @@ export function mapFile(file, existingFile) {
35
35
  export function mapVariant(variant) {
36
36
  return {
37
37
  ...variant,
38
- state: {},
38
+ state: null,
39
39
  initState: null,
40
40
  slots: () => ({}),
41
41
  previewReady: false,
@@ -1,8 +1,9 @@
1
1
  import type { App } from 'vue';
2
2
  import type { Story, Variant } from './app/types.js';
3
+ export { hstEvent } from './app/util/events';
3
4
  export declare type Vue3StorySetupHandler = (payload: {
4
5
  app: App;
5
- story: Story;
6
- variant: Variant;
6
+ story?: Story;
7
+ variant?: Variant;
7
8
  }) => Promise<void> | void;
8
- export declare function defineVue3StorySetup(handler: Vue3StorySetupHandler): Vue3StorySetupHandler;
9
+ export declare function defineSetupVue3(handler: Vue3StorySetupHandler): Vue3StorySetupHandler;
@@ -1,3 +1,4 @@
1
- export function defineVue3StorySetup(handler) {
1
+ export { hstEvent } from './app/util/events';
2
+ export function defineSetupVue3(handler) {
2
3
  return handler;
3
4
  }
@@ -1,2 +1,7 @@
1
- import type { StoryFile } from '../../node/types';
2
- export declare function run(file: StoryFile, storyData: any, el: any): Promise<void>;
1
+ import type { StoryFile, Story } from '../../node/types';
2
+ export interface ServerRunPayload {
3
+ file: StoryFile;
4
+ storyData: Story[];
5
+ el: HTMLElement;
6
+ }
7
+ export declare function run(payload: ServerRunPayload): Promise<any>;