histoire 0.0.0 → 0.0.3

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 (204) hide show
  1. package/LICENSE +21 -0
  2. package/client.d.ts +2 -0
  3. package/dist/client/app/App.vue +84 -21
  4. package/dist/client/app/assets/histoire-text-dark.svg +89 -0
  5. package/dist/client/app/assets/histoire-text.svg +89 -0
  6. package/dist/client/app/assets/histoire.svg +51 -0
  7. package/dist/client/app/codegen/serialize-js.d.ts +1 -0
  8. package/dist/client/app/codegen/serialize-js.js +113 -0
  9. package/dist/client/app/codegen/serialize-js.ts +119 -0
  10. package/dist/client/app/codegen/util.d.ts +10 -0
  11. package/dist/client/app/codegen/util.js +70 -0
  12. package/dist/client/app/codegen/util.ts +79 -0
  13. package/dist/client/app/codegen/vue3.d.ts +2 -0
  14. package/dist/client/app/codegen/vue3.js +238 -0
  15. package/dist/client/app/codegen/vue3.ts +240 -0
  16. package/dist/client/app/components/HomeView.vue +15 -1
  17. package/dist/client/app/components/StoryControls.vue +7 -2
  18. package/dist/client/app/components/StoryList.vue +20 -13
  19. package/dist/client/app/components/StoryListFolder.vue +87 -0
  20. package/dist/client/app/components/StoryListItem.vue +38 -12
  21. package/dist/client/app/components/StorySourceCode.vue +121 -0
  22. package/dist/client/app/components/StoryVariantGridItem.vue +32 -17
  23. package/dist/client/app/components/StoryVariantListItem.vue +46 -0
  24. package/dist/client/app/components/StoryVariantSingleView.vue +145 -15
  25. package/dist/client/app/components/StoryView.vue +88 -54
  26. package/dist/client/app/components/app/AppHeader.vue +56 -0
  27. package/dist/client/app/components/app/AppLogo.vue +24 -0
  28. package/dist/client/app/components/base/BaseEmpty.vue +1 -1
  29. package/dist/client/app/components/base/BaseListItemLink.vue +55 -0
  30. package/dist/client/app/components/base/BaseSplitPane.vue +57 -21
  31. package/dist/client/app/components/exposed/Story.vue +23 -58
  32. package/dist/client/app/components/exposed/Variant.vue +24 -47
  33. package/dist/client/app/components/misc/HatchedPattern.vue +25 -0
  34. package/dist/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
  35. package/dist/client/app/components/search/SearchItem.vue +110 -0
  36. package/dist/client/app/components/search/SearchModal.vue +179 -0
  37. package/dist/client/app/composable/variant.js +0 -1
  38. package/dist/client/app/composable/variant.ts +20 -0
  39. package/dist/client/app/global-components.js +0 -1
  40. package/dist/client/app/global-components.ts +10 -0
  41. package/dist/client/app/index.d.ts +1 -0
  42. package/dist/client/app/index.js +10 -2
  43. package/dist/client/app/index.ts +24 -0
  44. package/dist/client/app/router.js +0 -1
  45. package/dist/client/app/router.ts +17 -0
  46. package/dist/client/app/sandbox.d.ts +1 -0
  47. package/dist/client/app/sandbox.js +53 -0
  48. package/dist/client/app/sandbox.ts +60 -0
  49. package/dist/client/app/stores/story.d.ts +167 -50
  50. package/dist/client/app/stores/story.js +33 -16
  51. package/dist/client/app/stores/story.ts +58 -0
  52. package/dist/client/app/style/floating-vue.css +31 -0
  53. package/dist/client/app/style/main.css +17 -2
  54. package/dist/client/app/style/sandbox.css +14 -0
  55. package/dist/client/app/types.d.ts +36 -4
  56. package/dist/client/app/types.js +0 -1
  57. package/dist/client/app/types.ts +59 -0
  58. package/dist/client/app/util/config.d.ts +3 -0
  59. package/dist/client/app/util/config.js +4 -0
  60. package/dist/client/app/util/config.ts +6 -0
  61. package/dist/client/app/util/const.d.ts +1 -0
  62. package/dist/client/app/util/const.js +1 -0
  63. package/dist/client/app/util/const.ts +1 -0
  64. package/dist/client/app/util/dark.d.ts +2 -0
  65. package/dist/client/app/util/dark.js +3 -0
  66. package/dist/client/app/util/dark.ts +4 -0
  67. package/dist/client/app/util/env.d.ts +1 -0
  68. package/dist/client/app/util/env.js +1 -0
  69. package/dist/client/app/util/env.ts +1 -0
  70. package/dist/client/app/util/keyboard.d.ts +8 -0
  71. package/dist/client/app/util/keyboard.js +82 -0
  72. package/dist/client/app/util/keyboard.ts +99 -0
  73. package/dist/client/app/util/mapping.d.ts +3 -0
  74. package/dist/client/app/util/mapping.js +39 -0
  75. package/dist/client/app/util/mapping.ts +41 -0
  76. package/dist/client/app/util/tooltip.d.ts +6 -0
  77. package/dist/client/app/util/tooltip.js +11 -0
  78. package/dist/client/app/util/tooltip.ts +13 -0
  79. package/dist/client/index.d.ts +8 -0
  80. package/dist/client/index.js +3 -0
  81. package/dist/client/index.ts +12 -0
  82. package/dist/client/server/Story.server.vue +65 -0
  83. package/dist/client/server/Variant.server.vue +50 -0
  84. package/dist/client/server/index.d.ts +2 -0
  85. package/dist/client/server/index.js +25 -0
  86. package/dist/client/server/index.ts +29 -0
  87. package/dist/client/shim.d.ts +5 -0
  88. package/dist/node/alias.js +0 -1
  89. package/dist/node/bin.js +8 -3
  90. package/dist/node/build.d.ts +2 -0
  91. package/dist/node/build.js +71 -0
  92. package/dist/node/collect.d.ts +12 -0
  93. package/dist/node/collect.js +65 -0
  94. package/dist/node/colors.d.ts +286 -0
  95. package/dist/node/colors.js +324 -0
  96. package/dist/node/commands/build.d.ts +1 -0
  97. package/dist/node/commands/build.js +10 -0
  98. package/dist/node/commands/dev.d.ts +1 -1
  99. package/dist/node/commands/dev.js +45 -13
  100. package/dist/node/config.d.ts +112 -1
  101. package/dist/node/config.js +124 -2
  102. package/dist/node/context.d.ts +13 -0
  103. package/dist/node/context.js +12 -2
  104. package/dist/node/dom/dom-keys.d.ts +4 -0
  105. package/dist/node/dom/dom-keys.js +223 -0
  106. package/dist/node/dom/env.d.ts +5 -0
  107. package/dist/node/dom/env.js +22 -0
  108. package/dist/node/index.d.ts +2 -0
  109. package/dist/node/index.js +2 -2
  110. package/dist/node/plugin.d.ts +8 -2
  111. package/dist/node/plugin.js +150 -22
  112. package/dist/node/server.d.ts +4 -1
  113. package/dist/node/server.js +80 -21
  114. package/dist/node/stories.d.ts +8 -9
  115. package/dist/node/stories.js +42 -23
  116. package/dist/node/tree.d.ts +19 -0
  117. package/dist/node/tree.js +54 -0
  118. package/dist/node/types.d.ts +38 -0
  119. package/dist/node/types.js +1 -0
  120. package/dist/style.css +610 -53
  121. package/package.json +45 -25
  122. package/scripts/copy.mjs +11 -0
  123. package/src/client/app/App.vue +84 -21
  124. package/src/client/app/assets/histoire-text-dark.svg +89 -0
  125. package/src/client/app/assets/histoire-text.svg +89 -0
  126. package/src/client/app/assets/histoire.svg +51 -0
  127. package/src/client/app/codegen/serialize-js.ts +119 -0
  128. package/src/client/app/codegen/util.ts +79 -0
  129. package/src/client/app/codegen/vue3.ts +240 -0
  130. package/src/client/app/components/HomeView.vue +15 -1
  131. package/src/client/app/components/StoryControls.vue +7 -2
  132. package/src/client/app/components/StoryList.vue +20 -13
  133. package/src/client/app/components/StoryListFolder.vue +87 -0
  134. package/src/client/app/components/StoryListItem.vue +38 -12
  135. package/src/client/app/components/StorySourceCode.vue +121 -0
  136. package/src/client/app/components/StoryVariantGridItem.vue +32 -17
  137. package/src/client/app/components/StoryVariantListItem.vue +46 -0
  138. package/src/client/app/components/StoryVariantSingleView.vue +145 -15
  139. package/src/client/app/components/StoryView.vue +88 -54
  140. package/src/client/app/components/app/AppHeader.vue +56 -0
  141. package/src/client/app/components/app/AppLogo.vue +24 -0
  142. package/src/client/app/components/base/BaseEmpty.vue +1 -1
  143. package/src/client/app/components/base/BaseListItemLink.vue +55 -0
  144. package/src/client/app/components/base/BaseSplitPane.vue +57 -21
  145. package/src/client/app/components/exposed/Story.vue +23 -58
  146. package/src/client/app/components/exposed/Variant.vue +24 -47
  147. package/src/client/app/components/misc/HatchedPattern.vue +25 -0
  148. package/src/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
  149. package/src/client/app/components/search/SearchItem.vue +110 -0
  150. package/src/client/app/components/search/SearchModal.vue +179 -0
  151. package/src/client/app/index.ts +10 -1
  152. package/src/client/app/sandbox.ts +60 -0
  153. package/src/client/app/stores/story.ts +39 -15
  154. package/src/client/app/style/floating-vue.css +31 -0
  155. package/src/client/app/style/main.css +17 -2
  156. package/src/client/app/style/sandbox.css +14 -0
  157. package/src/client/app/types.ts +42 -4
  158. package/src/client/app/util/config.ts +6 -0
  159. package/src/client/app/util/const.ts +1 -0
  160. package/src/client/app/util/dark.ts +4 -0
  161. package/src/client/app/util/env.ts +1 -0
  162. package/src/client/app/util/keyboard.ts +99 -0
  163. package/src/client/app/util/mapping.ts +41 -0
  164. package/src/client/app/util/tooltip.ts +13 -0
  165. package/src/client/index.ts +12 -0
  166. package/src/client/server/Story.server.vue +65 -0
  167. package/src/client/server/Variant.server.vue +50 -0
  168. package/src/client/server/index.ts +29 -0
  169. package/src/node/bin.ts +9 -2
  170. package/src/node/build.ts +80 -0
  171. package/src/node/collect.ts +78 -0
  172. package/src/node/colors.ts +340 -0
  173. package/src/node/commands/build.ts +12 -0
  174. package/src/node/commands/dev.ts +49 -12
  175. package/src/node/config.ts +240 -1
  176. package/src/node/context.ts +21 -1
  177. package/src/node/dom/dom-keys.ts +227 -0
  178. package/src/node/dom/env.ts +26 -0
  179. package/src/node/index.ts +2 -0
  180. package/src/node/plugin.ts +155 -22
  181. package/src/node/server.ts +95 -20
  182. package/src/node/stories.ts +53 -31
  183. package/src/node/tree.spec.ts +28 -0
  184. package/src/node/tree.ts +88 -0
  185. package/src/node/types.ts +40 -0
  186. package/tailwind.config.cjs +41 -1
  187. package/tsconfig.json +2 -1
  188. package/dist/client/app/components/StoryVariantItem.vue +0 -29
  189. package/dist/client/app/composable/variant.js.map +0 -1
  190. package/dist/client/app/global-components.js.map +0 -1
  191. package/dist/client/app/index.js.map +0 -1
  192. package/dist/client/app/router.js.map +0 -1
  193. package/dist/client/app/stores/story.js.map +0 -1
  194. package/dist/client/app/types.js.map +0 -1
  195. package/dist/node/alias.js.map +0 -1
  196. package/dist/node/bin.js.map +0 -1
  197. package/dist/node/commands/dev.js.map +0 -1
  198. package/dist/node/config.js.map +0 -1
  199. package/dist/node/context.js.map +0 -1
  200. package/dist/node/index.js.map +0 -1
  201. package/dist/node/plugin.js.map +0 -1
  202. package/dist/node/server.js.map +0 -1
  203. package/dist/node/stories.js.map +0 -1
  204. package/src/client/app/components/StoryVariantItem.vue +0 -29
@@ -0,0 +1,60 @@
1
+ import './style/sandbox.css'
2
+ import { parseQuery } from 'vue-router'
3
+ import { computed, createApp, h, ref, toRaw, watch } from 'vue'
4
+ import { createPinia } from 'pinia'
5
+ import { registerGlobalComponents } from './global-components'
6
+ import SandboxVue3 from './components/sandbox/SandboxVue3.vue'
7
+ import type { StoryFile } from './types'
8
+ import { mapFile } from './util/mapping'
9
+ // @ts-expect-error virtual module
10
+ import { files } from '$histoire-stories'
11
+ import { STATE_SYNC } from './util/const.js'
12
+
13
+ const query = parseQuery(window.location.search)
14
+ const file = ref<StoryFile>(mapFile(files.find(f => f.id === query.storyId)))
15
+
16
+ const app = createApp({
17
+ setup () {
18
+ const story = computed(() => file.value.story)
19
+ const variant = computed(() => story.value?.variants.find(v => v.id === query.variantId))
20
+
21
+ window.addEventListener('message', event => {
22
+ if (event.data?.type === STATE_SYNC) {
23
+ Object.assign(variant.value.state, event.data.state)
24
+ }
25
+ })
26
+
27
+ watch(() => variant.value.state, value => {
28
+ window.parent?.postMessage({
29
+ type: STATE_SYNC,
30
+ state: toRaw(value),
31
+ })
32
+ }, {
33
+ deep: true,
34
+ })
35
+
36
+ return {
37
+ story,
38
+ variant,
39
+ }
40
+ },
41
+
42
+ render () {
43
+ return [
44
+ h('div', { class: 'htw-sandbox-hidden' }, [
45
+ h(file.value.component, {
46
+ story: file.value.story,
47
+ }),
48
+ ]),
49
+ this.story && this.variant
50
+ ? h(SandboxVue3, {
51
+ story: this.story,
52
+ variant: this.variant,
53
+ })
54
+ : null,
55
+ ]
56
+ },
57
+ })
58
+ app.use(createPinia())
59
+ registerGlobalComponents(app)
60
+ app.mount('#app')
@@ -6,9 +6,12 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
6
6
  variants: {
7
7
  id: string;
8
8
  title: string;
9
- initState: () => any;
10
- slots: () => Readonly<any>;
11
- state: any;
9
+ icon?: string;
10
+ iconColor?: string;
11
+ initState?: () => any;
12
+ slots?: () => Readonly<any>;
13
+ state?: any;
14
+ source?: string;
12
15
  }[];
13
16
  layout?: {
14
17
  type: "single";
@@ -16,26 +19,39 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
16
19
  type: "grid";
17
20
  width: number;
18
21
  };
22
+ icon?: string;
23
+ iconColor?: string;
24
+ file?: {
25
+ id: string;
26
+ framework: string;
27
+ component: any;
28
+ story: any;
29
+ path: string[];
30
+ };
19
31
  lastSelectedVariant?: {
20
32
  id: string;
21
33
  title: string;
22
- initState: () => any;
23
- slots: () => Readonly<any>;
24
- state: any;
34
+ icon?: string;
35
+ iconColor?: string;
36
+ initState?: () => any;
37
+ slots?: () => Readonly<any>;
38
+ state?: any;
39
+ source?: string;
25
40
  };
26
- mountTime: number;
27
41
  }[]>;
28
- addStory: (story: Story) => Story;
29
- removeStory: (story: Story) => void;
42
+ setStories: (value: Story[]) => void;
30
43
  currentStory: import("vue").ComputedRef<{
31
44
  id: string;
32
45
  title: string;
33
46
  variants: {
34
47
  id: string;
35
48
  title: string;
36
- initState: () => any;
37
- slots: () => Readonly<any>;
38
- state: any;
49
+ icon?: string;
50
+ iconColor?: string;
51
+ initState?: () => any;
52
+ slots?: () => Readonly<any>;
53
+ state?: any;
54
+ source?: string;
39
55
  }[];
40
56
  layout?: {
41
57
  type: "single";
@@ -43,15 +59,38 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
43
59
  type: "grid";
44
60
  width: number;
45
61
  };
62
+ icon?: string;
63
+ iconColor?: string;
64
+ file?: {
65
+ id: string;
66
+ framework: string;
67
+ component: any;
68
+ story: any;
69
+ path: string[];
70
+ };
46
71
  lastSelectedVariant?: {
47
72
  id: string;
48
73
  title: string;
49
- initState: () => any;
50
- slots: () => Readonly<any>;
51
- state: any;
74
+ icon?: string;
75
+ iconColor?: string;
76
+ initState?: () => any;
77
+ slots?: () => Readonly<any>;
78
+ state?: any;
79
+ source?: string;
52
80
  };
53
- mountTime: number;
54
81
  }>;
82
+ currentVariant: import("vue").ComputedRef<{
83
+ id: string;
84
+ title: string;
85
+ icon?: string;
86
+ iconColor?: string;
87
+ initState?: () => any;
88
+ slots?: () => Readonly<any>;
89
+ state?: any;
90
+ source?: string;
91
+ }>;
92
+ isFolderOpened: (path: Array<string>) => boolean;
93
+ toggleFolder: (path: Array<string>, force?: boolean) => void;
55
94
  }, "stories">>, import("pinia")._UnwrapAll<Pick<{
56
95
  stories: import("vue").Ref<{
57
96
  id: string;
@@ -59,9 +98,12 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
59
98
  variants: {
60
99
  id: string;
61
100
  title: string;
62
- initState: () => any;
63
- slots: () => Readonly<any>;
64
- state: any;
101
+ icon?: string;
102
+ iconColor?: string;
103
+ initState?: () => any;
104
+ slots?: () => Readonly<any>;
105
+ state?: any;
106
+ source?: string;
65
107
  }[];
66
108
  layout?: {
67
109
  type: "single";
@@ -69,26 +111,39 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
69
111
  type: "grid";
70
112
  width: number;
71
113
  };
114
+ icon?: string;
115
+ iconColor?: string;
116
+ file?: {
117
+ id: string;
118
+ framework: string;
119
+ component: any;
120
+ story: any;
121
+ path: string[];
122
+ };
72
123
  lastSelectedVariant?: {
73
124
  id: string;
74
125
  title: string;
75
- initState: () => any;
76
- slots: () => Readonly<any>;
77
- state: any;
126
+ icon?: string;
127
+ iconColor?: string;
128
+ initState?: () => any;
129
+ slots?: () => Readonly<any>;
130
+ state?: any;
131
+ source?: string;
78
132
  };
79
- mountTime: number;
80
133
  }[]>;
81
- addStory: (story: Story) => Story;
82
- removeStory: (story: Story) => void;
134
+ setStories: (value: Story[]) => void;
83
135
  currentStory: import("vue").ComputedRef<{
84
136
  id: string;
85
137
  title: string;
86
138
  variants: {
87
139
  id: string;
88
140
  title: string;
89
- initState: () => any;
90
- slots: () => Readonly<any>;
91
- state: any;
141
+ icon?: string;
142
+ iconColor?: string;
143
+ initState?: () => any;
144
+ slots?: () => Readonly<any>;
145
+ state?: any;
146
+ source?: string;
92
147
  }[];
93
148
  layout?: {
94
149
  type: "single";
@@ -96,25 +151,51 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
96
151
  type: "grid";
97
152
  width: number;
98
153
  };
154
+ icon?: string;
155
+ iconColor?: string;
156
+ file?: {
157
+ id: string;
158
+ framework: string;
159
+ component: any;
160
+ story: any;
161
+ path: string[];
162
+ };
99
163
  lastSelectedVariant?: {
100
164
  id: string;
101
165
  title: string;
102
- initState: () => any;
103
- slots: () => Readonly<any>;
104
- state: any;
166
+ icon?: string;
167
+ iconColor?: string;
168
+ initState?: () => any;
169
+ slots?: () => Readonly<any>;
170
+ state?: any;
171
+ source?: string;
105
172
  };
106
- mountTime: number;
107
173
  }>;
108
- }, "currentStory">>, Pick<{
174
+ currentVariant: import("vue").ComputedRef<{
175
+ id: string;
176
+ title: string;
177
+ icon?: string;
178
+ iconColor?: string;
179
+ initState?: () => any;
180
+ slots?: () => Readonly<any>;
181
+ state?: any;
182
+ source?: string;
183
+ }>;
184
+ isFolderOpened: (path: Array<string>) => boolean;
185
+ toggleFolder: (path: Array<string>, force?: boolean) => void;
186
+ }, "currentStory" | "currentVariant">>, Pick<{
109
187
  stories: import("vue").Ref<{
110
188
  id: string;
111
189
  title: string;
112
190
  variants: {
113
191
  id: string;
114
192
  title: string;
115
- initState: () => any;
116
- slots: () => Readonly<any>;
117
- state: any;
193
+ icon?: string;
194
+ iconColor?: string;
195
+ initState?: () => any;
196
+ slots?: () => Readonly<any>;
197
+ state?: any;
198
+ source?: string;
118
199
  }[];
119
200
  layout?: {
120
201
  type: "single";
@@ -122,26 +203,39 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
122
203
  type: "grid";
123
204
  width: number;
124
205
  };
206
+ icon?: string;
207
+ iconColor?: string;
208
+ file?: {
209
+ id: string;
210
+ framework: string;
211
+ component: any;
212
+ story: any;
213
+ path: string[];
214
+ };
125
215
  lastSelectedVariant?: {
126
216
  id: string;
127
217
  title: string;
128
- initState: () => any;
129
- slots: () => Readonly<any>;
130
- state: any;
218
+ icon?: string;
219
+ iconColor?: string;
220
+ initState?: () => any;
221
+ slots?: () => Readonly<any>;
222
+ state?: any;
223
+ source?: string;
131
224
  };
132
- mountTime: number;
133
225
  }[]>;
134
- addStory: (story: Story) => Story;
135
- removeStory: (story: Story) => void;
226
+ setStories: (value: Story[]) => void;
136
227
  currentStory: import("vue").ComputedRef<{
137
228
  id: string;
138
229
  title: string;
139
230
  variants: {
140
231
  id: string;
141
232
  title: string;
142
- initState: () => any;
143
- slots: () => Readonly<any>;
144
- state: any;
233
+ icon?: string;
234
+ iconColor?: string;
235
+ initState?: () => any;
236
+ slots?: () => Readonly<any>;
237
+ state?: any;
238
+ source?: string;
145
239
  }[];
146
240
  layout?: {
147
241
  type: "single";
@@ -149,13 +243,36 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
149
243
  type: "grid";
150
244
  width: number;
151
245
  };
246
+ icon?: string;
247
+ iconColor?: string;
248
+ file?: {
249
+ id: string;
250
+ framework: string;
251
+ component: any;
252
+ story: any;
253
+ path: string[];
254
+ };
152
255
  lastSelectedVariant?: {
153
256
  id: string;
154
257
  title: string;
155
- initState: () => any;
156
- slots: () => Readonly<any>;
157
- state: any;
258
+ icon?: string;
259
+ iconColor?: string;
260
+ initState?: () => any;
261
+ slots?: () => Readonly<any>;
262
+ state?: any;
263
+ source?: string;
158
264
  };
159
- mountTime: number;
160
265
  }>;
161
- }, "addStory" | "removeStory">>;
266
+ currentVariant: import("vue").ComputedRef<{
267
+ id: string;
268
+ title: string;
269
+ icon?: string;
270
+ iconColor?: string;
271
+ initState?: () => any;
272
+ slots?: () => Readonly<any>;
273
+ state?: any;
274
+ source?: string;
275
+ }>;
276
+ isFolderOpened: (path: Array<string>) => boolean;
277
+ toggleFolder: (path: Array<string>, force?: boolean) => void;
278
+ }, "setStories" | "isFolderOpened" | "toggleFolder">>;
@@ -1,29 +1,46 @@
1
1
  import { defineStore } from 'pinia';
2
- import { computed, ref } from 'vue';
2
+ import { computed, ref, watch } from 'vue';
3
3
  import { router } from '../router';
4
4
  export const useStoryStore = defineStore('story', () => {
5
5
  const stories = ref([]);
6
- function addStory(story) {
7
- const existing = stories.value.find(s => s.id === story.id);
8
- if (existing) {
9
- Object.assign(existing, story);
10
- return existing;
6
+ function setStories(value) {
7
+ stories.value = value;
8
+ }
9
+ const currentStory = computed(() => stories.value.find(s => s.id === router.currentRoute.value.params.storyId));
10
+ const currentVariant = computed(() => currentStory.value?.variants.find(v => v.id === router.currentRoute.value.query.variantId));
11
+ const openedFolders = ref(new Map());
12
+ function getStringPath(path) {
13
+ return path.join('␜');
14
+ }
15
+ function toggleFolder(path, force) {
16
+ const stringPath = getStringPath(path);
17
+ if (force === undefined) {
18
+ force = !openedFolders.value.get(stringPath);
19
+ }
20
+ if (force) {
21
+ openedFolders.value.set(stringPath, true);
11
22
  }
12
- stories.value.push(story);
13
- return story;
23
+ else {
24
+ openedFolders.value.delete(stringPath);
25
+ }
26
+ }
27
+ function isFolderOpened(path) {
28
+ return openedFolders.value.get(getStringPath(path));
14
29
  }
15
- function removeStory(story) {
16
- const index = stories.value.findIndex(s => s.id === story.id);
17
- if (index !== -1) {
18
- stories.value.splice(index, 1);
30
+ function openFileFolders(path) {
31
+ for (let pathLength = 1; pathLength < path.length; pathLength++) {
32
+ toggleFolder(path.slice(0, pathLength), true);
19
33
  }
20
34
  }
21
- const currentStory = computed(() => stories.value.find(s => s.id === router.currentRoute.value.params.storyId));
35
+ watch(currentStory, () => {
36
+ openFileFolders(currentStory.value.file.path);
37
+ });
22
38
  return {
23
39
  stories,
24
- addStory,
25
- removeStory,
40
+ setStories,
26
41
  currentStory,
42
+ currentVariant,
43
+ isFolderOpened,
44
+ toggleFolder,
27
45
  };
28
46
  });
29
- //# sourceMappingURL=story.js.map
@@ -0,0 +1,58 @@
1
+ import { defineStore } from 'pinia'
2
+ import { computed, reactive, ref, watch } from 'vue'
3
+ import { router } from '../router'
4
+ import { Story } from '../types'
5
+
6
+ export const useStoryStore = defineStore('story', () => {
7
+ const stories = ref<Story[]>([])
8
+ function setStories (value: Story[]) {
9
+ stories.value = value
10
+ }
11
+
12
+ const currentStory = computed(() => stories.value.find(s => s.id === router.currentRoute.value.params.storyId))
13
+
14
+ const currentVariant = computed(() => currentStory.value?.variants.find(v => v.id === router.currentRoute.value.query.variantId))
15
+
16
+ const openedFolders = ref(new Map() as Map<string, boolean>)
17
+
18
+ function getStringPath (path: Array<string>) {
19
+ return path.join('␜')
20
+ }
21
+
22
+ function toggleFolder (path: Array<string>, force?: boolean) {
23
+ const stringPath = getStringPath(path)
24
+
25
+ if (force === undefined) {
26
+ force = !openedFolders.value.get(stringPath)
27
+ }
28
+
29
+ if (force) {
30
+ openedFolders.value.set(stringPath, true)
31
+ } else {
32
+ openedFolders.value.delete(stringPath)
33
+ }
34
+ }
35
+
36
+ function isFolderOpened (path: Array<string>) {
37
+ return openedFolders.value.get(getStringPath(path))
38
+ }
39
+
40
+ function openFileFolders (path: Array<string>) {
41
+ for (let pathLength = 1; pathLength < path.length; pathLength++) {
42
+ toggleFolder(path.slice(0, pathLength), true)
43
+ }
44
+ }
45
+
46
+ watch(currentStory, () => {
47
+ openFileFolders(currentStory.value.file.path)
48
+ })
49
+
50
+ return {
51
+ stories,
52
+ setStories,
53
+ currentStory,
54
+ currentVariant,
55
+ isFolderOpened,
56
+ toggleFolder,
57
+ }
58
+ })
@@ -1 +1,32 @@
1
1
  /* @TODO custom themes */
2
+
3
+ .v-popper {
4
+ line-height: 0;
5
+ }
6
+
7
+ .v-popper--theme-dropdown {
8
+ .htw-dark & {
9
+ .v-popper__inner {
10
+ @apply htw-bg-gray-700 htw-border-gray-850 htw-text-gray-100;
11
+ }
12
+
13
+ .v-popper__arrow-inner {
14
+ @apply htw-border-gray-700;
15
+ }
16
+
17
+ .v-popper__arrow-outer {
18
+ @apply htw-border-gray-850;
19
+ }
20
+ }
21
+
22
+ &.v-popper__popper--show-from .v-popper__wrapper {
23
+ transform: scale(.75);
24
+ }
25
+
26
+ &.v-popper__popper--show-to .v-popper__wrapper {
27
+ transform: none;
28
+ transition: transform .15s cubic-bezier(0, 1, .5, 1);
29
+ }
30
+ }
31
+
32
+
@@ -11,16 +11,31 @@
11
11
  border-color: #e5e7eb;
12
12
  }
13
13
 
14
- a {
14
+ a,
15
+ input,
16
+ button {
15
17
  color: inherit;
18
+ }
19
+
20
+ a {
16
21
  text-decoration: inherit;
17
22
  }
18
23
 
24
+ input {
25
+ font-family: inherit;
26
+ }
27
+
28
+ a,
29
+ button {
30
+ user-select: none;
31
+ }
32
+
19
33
  @tailwind base;
20
34
  @tailwind components;
21
35
  @tailwind utilities;
22
36
 
23
- body {
37
+ body,
38
+ pre {
24
39
  margin: 0;
25
40
  }
26
41
 
@@ -0,0 +1,14 @@
1
+ body {
2
+ margin: 0;
3
+ }
4
+
5
+ html,
6
+ body,
7
+ #app {
8
+ font-family: 'Lato', sans-serif;
9
+ font-size: 14px;
10
+ }
11
+
12
+ .htw-sandbox-hidden {
13
+ display: none;
14
+ }
@@ -1,3 +1,11 @@
1
+ import type { RouteLocationRaw } from 'vue-router';
2
+ export interface StoryFile {
3
+ id: string;
4
+ framework: string;
5
+ component: any;
6
+ story: Story;
7
+ path: string[];
8
+ }
1
9
  export interface Story {
2
10
  id: string;
3
11
  title: string;
@@ -8,13 +16,37 @@ export interface Story {
8
16
  type: 'grid';
9
17
  width: number;
10
18
  };
19
+ icon?: string;
20
+ iconColor?: string;
21
+ file?: StoryFile;
11
22
  lastSelectedVariant?: Variant;
12
- mountTime: number;
13
23
  }
14
24
  export interface Variant {
15
25
  id: string;
16
26
  title: string;
17
- initState: () => any;
18
- slots: () => Readonly<any>;
19
- state: any;
27
+ icon?: string;
28
+ iconColor?: string;
29
+ initState?: () => any;
30
+ slots?: () => Readonly<any>;
31
+ state?: any;
32
+ source?: string;
33
+ }
34
+ export declare type TreeLeaf = {
35
+ title: string;
36
+ index: number;
37
+ };
38
+ export declare type TreeFolder = {
39
+ title: string;
40
+ children: (TreeFolder | TreeLeaf)[];
41
+ };
42
+ export declare type Tree = (TreeFolder | TreeLeaf)[];
43
+ export interface SearchResult {
44
+ kind: 'story' | 'variant';
45
+ rank: number;
46
+ id: string;
47
+ title: string;
48
+ route: RouteLocationRaw;
49
+ path?: string[];
50
+ icon?: string;
51
+ iconColor?: string;
20
52
  }
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=types.js.map