histoire 0.0.2 → 0.0.5

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 (119) hide show
  1. package/README.md +11 -0
  2. package/dist/client/app/App.vue +8 -8
  3. package/dist/client/app/codegen/vue3.js +28 -4
  4. package/dist/client/app/codegen/vue3.ts +32 -4
  5. package/dist/client/app/components/app/AppHeader.vue +10 -3
  6. package/dist/client/app/components/base/BaseTab.vue +46 -0
  7. package/dist/client/app/components/exposed/Story.vue +21 -1
  8. package/dist/client/app/components/exposed/Variant.vue +1 -0
  9. package/dist/client/app/components/misc/CheckerboardPattern.vue +32 -0
  10. package/dist/client/app/components/sandbox/SandboxVue3.vue +6 -0
  11. package/dist/client/app/components/search/SearchItem.vue +5 -9
  12. package/dist/client/app/components/{StoryControls.vue → story/StoryControls.vue} +3 -3
  13. package/dist/client/app/components/story/StoryDocs.vue +37 -0
  14. package/dist/client/app/components/{StoryList.vue → story/StoryList.vue} +4 -4
  15. package/{src/client/app/components → dist/client/app/components/story}/StoryListFolder.vue +5 -5
  16. package/{src/client/app/components → dist/client/app/components/story}/StoryListItem.vue +11 -6
  17. package/dist/client/app/components/story/StoryResponsivePreview.vue +214 -0
  18. package/dist/client/app/components/{StorySourceCode.vue → story/StorySourceCode.vue} +4 -8
  19. package/{src/client/app/components → dist/client/app/components/story}/StoryVariantGridItem.vue +14 -6
  20. package/dist/client/app/components/{StoryVariantListItem.vue → story/StoryVariantListItem.vue} +9 -8
  21. package/dist/client/app/components/story/StoryVariantSingleView.vue +182 -0
  22. package/dist/client/app/components/{StoryView.vue → story/StoryView.vue} +37 -10
  23. package/dist/client/app/global-components.js +2 -0
  24. package/dist/client/app/global-components.ts +3 -0
  25. package/dist/client/app/index.js +10 -0
  26. package/dist/client/app/index.ts +10 -0
  27. package/dist/client/app/router.js +1 -1
  28. package/dist/client/app/router.ts +1 -1
  29. package/dist/client/app/sandbox.js +37 -3
  30. package/dist/client/app/sandbox.ts +37 -3
  31. package/dist/client/app/stores/story.d.ts +15 -0
  32. package/dist/client/app/style/floating-vue.css +31 -0
  33. package/dist/client/app/style/main.css +17 -1
  34. package/dist/client/app/style/sandbox.css +5 -0
  35. package/dist/client/app/style/transitions.css +12 -0
  36. package/dist/client/app/types.d.ts +1 -0
  37. package/dist/client/app/types.ts +1 -0
  38. package/dist/client/app/util/const.d.ts +2 -0
  39. package/dist/client/app/util/const.js +2 -0
  40. package/dist/client/app/util/const.ts +2 -0
  41. package/dist/client/app/util/mapping.js +6 -0
  42. package/dist/client/app/util/mapping.ts +5 -0
  43. package/dist/client/app/util/preview-settings.d.ts +16 -0
  44. package/dist/client/app/util/preview-settings.js +15 -0
  45. package/dist/client/app/util/preview-settings.ts +26 -0
  46. package/dist/client/app/util/reactivity.d.ts +1 -0
  47. package/dist/client/app/util/reactivity.js +16 -0
  48. package/dist/client/app/util/reactivity.ts +22 -0
  49. package/dist/client/app/util/scroll.d.ts +2 -0
  50. package/dist/client/app/util/scroll.js +24 -0
  51. package/dist/client/app/util/scroll.ts +27 -0
  52. package/dist/client/app/{composable → util}/variant.d.ts +0 -0
  53. package/dist/client/app/{composable → util}/variant.js +0 -0
  54. package/dist/client/app/{composable → util}/variant.ts +0 -0
  55. package/dist/client/server/Story.server.vue +25 -2
  56. package/dist/client/server/index.js +2 -0
  57. package/dist/client/server/index.ts +3 -0
  58. package/dist/controls.d.ts +1 -0
  59. package/dist/controls.js +1 -0
  60. package/dist/node/build.js +36 -11
  61. package/dist/node/collect.js +12 -3
  62. package/dist/node/commands/dev.js +43 -5
  63. package/dist/node/config.d.ts +35 -0
  64. package/dist/node/config.js +75 -1
  65. package/dist/node/markdown.d.ts +2 -0
  66. package/dist/node/markdown.js +48 -0
  67. package/dist/node/plugin.js +35 -0
  68. package/dist/node/util/slugify.d.ts +1 -0
  69. package/dist/node/util/slugify.js +22 -0
  70. package/dist/style.css +869 -159
  71. package/package.json +15 -6
  72. package/src/client/app/App.vue +8 -8
  73. package/src/client/app/codegen/vue3.ts +32 -4
  74. package/src/client/app/components/app/AppHeader.vue +10 -3
  75. package/src/client/app/components/base/BaseTab.vue +46 -0
  76. package/src/client/app/components/exposed/Story.vue +21 -1
  77. package/src/client/app/components/exposed/Variant.vue +1 -0
  78. package/src/client/app/components/misc/CheckerboardPattern.vue +32 -0
  79. package/src/client/app/components/sandbox/SandboxVue3.vue +6 -0
  80. package/src/client/app/components/search/SearchItem.vue +5 -9
  81. package/src/client/app/components/{StoryControls.vue → story/StoryControls.vue} +3 -3
  82. package/src/client/app/components/story/StoryDocs.vue +37 -0
  83. package/src/client/app/components/{StoryList.vue → story/StoryList.vue} +4 -4
  84. package/{dist/client/app/components → src/client/app/components/story}/StoryListFolder.vue +5 -5
  85. package/{dist/client/app/components → src/client/app/components/story}/StoryListItem.vue +11 -6
  86. package/src/client/app/components/story/StoryResponsivePreview.vue +214 -0
  87. package/src/client/app/components/{StorySourceCode.vue → story/StorySourceCode.vue} +4 -8
  88. package/{dist/client/app/components → src/client/app/components/story}/StoryVariantGridItem.vue +14 -6
  89. package/src/client/app/components/{StoryVariantListItem.vue → story/StoryVariantListItem.vue} +9 -8
  90. package/src/client/app/components/story/StoryVariantSingleView.vue +182 -0
  91. package/src/client/app/components/{StoryView.vue → story/StoryView.vue} +37 -10
  92. package/src/client/app/global-components.ts +3 -0
  93. package/src/client/app/index.ts +10 -0
  94. package/src/client/app/router.ts +1 -1
  95. package/src/client/app/sandbox.ts +37 -3
  96. package/src/client/app/style/floating-vue.css +31 -0
  97. package/src/client/app/style/main.css +17 -1
  98. package/src/client/app/style/sandbox.css +5 -0
  99. package/src/client/app/style/transitions.css +12 -0
  100. package/src/client/app/types.ts +1 -0
  101. package/src/client/app/util/const.ts +2 -0
  102. package/src/client/app/util/mapping.ts +5 -0
  103. package/src/client/app/util/preview-settings.ts +26 -0
  104. package/src/client/app/util/reactivity.ts +22 -0
  105. package/src/client/app/util/scroll.ts +27 -0
  106. package/src/client/app/{composable → util}/variant.ts +0 -0
  107. package/src/client/server/Story.server.vue +25 -2
  108. package/src/client/server/index.ts +3 -0
  109. package/src/controls.ts +1 -0
  110. package/src/node/build.ts +43 -11
  111. package/src/node/collect.ts +12 -3
  112. package/src/node/commands/dev.ts +49 -5
  113. package/src/node/config.ts +112 -2
  114. package/src/node/markdown.ts +56 -0
  115. package/src/node/plugin.ts +38 -0
  116. package/src/node/util/slugify.ts +26 -0
  117. package/tailwind.config.cjs +79 -4
  118. package/dist/client/app/components/StoryVariantSingleView.vue +0 -145
  119. package/src/client/app/components/StoryVariantSingleView.vue +0 -145
@@ -1,32 +1,51 @@
1
1
  import './style/sandbox.css';
2
2
  import { parseQuery } from 'vue-router';
3
- import { computed, createApp, h, ref, toRaw, watch } from 'vue';
3
+ import { computed, createApp, h, onMounted, ref, watch } from 'vue';
4
4
  import { createPinia } from 'pinia';
5
5
  import { registerGlobalComponents } from './global-components';
6
6
  import SandboxVue3 from './components/sandbox/SandboxVue3.vue';
7
7
  import { mapFile } from './util/mapping';
8
8
  // @ts-expect-error virtual module
9
9
  import { files } from '$histoire-stories';
10
- import { STATE_SYNC } from './util/const.js';
10
+ import { PREVIEW_SETTINGS_SYNC, STATE_SYNC, SANDBOX_READY } from './util/const.js';
11
+ import { applyPreviewSettings } from './util/preview-settings.js';
12
+ import { isDark } from './util/dark.js';
13
+ import { histoireConfig } from './util/config.js';
14
+ import { toRawDeep } from './util/reactivity';
11
15
  const query = parseQuery(window.location.search);
12
16
  const file = ref(mapFile(files.find(f => f.id === query.storyId)));
13
17
  const app = createApp({
14
18
  setup() {
15
19
  const story = computed(() => file.value.story);
16
20
  const variant = computed(() => story.value?.variants.find(v => v.id === query.variantId));
21
+ let synced = false;
22
+ let mounted = false;
17
23
  window.addEventListener('message', event => {
18
24
  if (event.data?.type === STATE_SYNC) {
25
+ if (!mounted)
26
+ return;
27
+ synced = true;
19
28
  Object.assign(variant.value.state, event.data.state);
20
29
  }
30
+ else if (event.data?.type === PREVIEW_SETTINGS_SYNC) {
31
+ applyPreviewSettings(event.data.settings);
32
+ }
21
33
  });
22
34
  watch(() => variant.value.state, value => {
35
+ if (synced && mounted) {
36
+ synced = false;
37
+ return;
38
+ }
23
39
  window.parent?.postMessage({
24
40
  type: STATE_SYNC,
25
- state: toRaw(value),
41
+ state: toRawDeep(value),
26
42
  });
27
43
  }, {
28
44
  deep: true,
29
45
  });
46
+ onMounted(() => {
47
+ mounted = true;
48
+ });
30
49
  return {
31
50
  story,
32
51
  variant,
@@ -43,6 +62,11 @@ const app = createApp({
43
62
  ? h(SandboxVue3, {
44
63
  story: this.story,
45
64
  variant: this.variant,
65
+ onReady: () => {
66
+ window.parent?.postMessage({
67
+ type: SANDBOX_READY,
68
+ });
69
+ },
46
70
  })
47
71
  : null,
48
72
  ];
@@ -51,3 +75,13 @@ const app = createApp({
51
75
  app.use(createPinia());
52
76
  registerGlobalComponents(app);
53
77
  app.mount('#app');
78
+ watch(isDark, value => {
79
+ if (value) {
80
+ document.documentElement.classList.add(histoireConfig.sandboxDarkClass);
81
+ }
82
+ else {
83
+ document.documentElement.classList.remove(histoireConfig.sandboxDarkClass);
84
+ }
85
+ }, {
86
+ immediate: true,
87
+ });
@@ -1,6 +1,6 @@
1
1
  import './style/sandbox.css'
2
2
  import { parseQuery } from 'vue-router'
3
- import { computed, createApp, h, ref, toRaw, watch } from 'vue'
3
+ import { computed, createApp, h, onMounted, ref, watch } from 'vue'
4
4
  import { createPinia } from 'pinia'
5
5
  import { registerGlobalComponents } from './global-components'
6
6
  import SandboxVue3 from './components/sandbox/SandboxVue3.vue'
@@ -8,7 +8,11 @@ import type { StoryFile } from './types'
8
8
  import { mapFile } from './util/mapping'
9
9
  // @ts-expect-error virtual module
10
10
  import { files } from '$histoire-stories'
11
- import { STATE_SYNC } from './util/const.js'
11
+ import { PREVIEW_SETTINGS_SYNC, STATE_SYNC, SANDBOX_READY } from './util/const.js'
12
+ import { applyPreviewSettings } from './util/preview-settings.js'
13
+ import { isDark } from './util/dark.js'
14
+ import { histoireConfig } from './util/config.js'
15
+ import { toRawDeep } from './util/reactivity'
12
16
 
13
17
  const query = parseQuery(window.location.search)
14
18
  const file = ref<StoryFile>(mapFile(files.find(f => f.id === query.storyId)))
@@ -18,21 +22,36 @@ const app = createApp({
18
22
  const story = computed(() => file.value.story)
19
23
  const variant = computed(() => story.value?.variants.find(v => v.id === query.variantId))
20
24
 
25
+ let synced = false
26
+ let mounted = false
27
+
21
28
  window.addEventListener('message', event => {
22
29
  if (event.data?.type === STATE_SYNC) {
30
+ if (!mounted) return
31
+ synced = true
23
32
  Object.assign(variant.value.state, event.data.state)
33
+ } else if (event.data?.type === PREVIEW_SETTINGS_SYNC) {
34
+ applyPreviewSettings(event.data.settings)
24
35
  }
25
36
  })
26
37
 
27
38
  watch(() => variant.value.state, value => {
39
+ if (synced && mounted) {
40
+ synced = false
41
+ return
42
+ }
28
43
  window.parent?.postMessage({
29
44
  type: STATE_SYNC,
30
- state: toRaw(value),
45
+ state: toRawDeep(value),
31
46
  })
32
47
  }, {
33
48
  deep: true,
34
49
  })
35
50
 
51
+ onMounted(() => {
52
+ mounted = true
53
+ })
54
+
36
55
  return {
37
56
  story,
38
57
  variant,
@@ -50,6 +69,11 @@ const app = createApp({
50
69
  ? h(SandboxVue3, {
51
70
  story: this.story,
52
71
  variant: this.variant,
72
+ onReady: () => {
73
+ window.parent?.postMessage({
74
+ type: SANDBOX_READY,
75
+ })
76
+ },
53
77
  })
54
78
  : null,
55
79
  ]
@@ -58,3 +82,13 @@ const app = createApp({
58
82
  app.use(createPinia())
59
83
  registerGlobalComponents(app)
60
84
  app.mount('#app')
85
+
86
+ watch(isDark, value => {
87
+ if (value) {
88
+ document.documentElement.classList.add(histoireConfig.sandboxDarkClass)
89
+ } else {
90
+ document.documentElement.classList.remove(histoireConfig.sandboxDarkClass)
91
+ }
92
+ }, {
93
+ immediate: true,
94
+ })
@@ -12,6 +12,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
12
12
  slots?: () => Readonly<any>;
13
13
  state?: any;
14
14
  source?: string;
15
+ ready?: boolean;
15
16
  }[];
16
17
  layout?: {
17
18
  type: "single";
@@ -37,6 +38,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
37
38
  slots?: () => Readonly<any>;
38
39
  state?: any;
39
40
  source?: string;
41
+ ready?: boolean;
40
42
  };
41
43
  }[]>;
42
44
  setStories: (value: Story[]) => void;
@@ -52,6 +54,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
52
54
  slots?: () => Readonly<any>;
53
55
  state?: any;
54
56
  source?: string;
57
+ ready?: boolean;
55
58
  }[];
56
59
  layout?: {
57
60
  type: "single";
@@ -77,6 +80,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
77
80
  slots?: () => Readonly<any>;
78
81
  state?: any;
79
82
  source?: string;
83
+ ready?: boolean;
80
84
  };
81
85
  }>;
82
86
  currentVariant: import("vue").ComputedRef<{
@@ -88,6 +92,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
88
92
  slots?: () => Readonly<any>;
89
93
  state?: any;
90
94
  source?: string;
95
+ ready?: boolean;
91
96
  }>;
92
97
  isFolderOpened: (path: Array<string>) => boolean;
93
98
  toggleFolder: (path: Array<string>, force?: boolean) => void;
@@ -104,6 +109,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
104
109
  slots?: () => Readonly<any>;
105
110
  state?: any;
106
111
  source?: string;
112
+ ready?: boolean;
107
113
  }[];
108
114
  layout?: {
109
115
  type: "single";
@@ -129,6 +135,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
129
135
  slots?: () => Readonly<any>;
130
136
  state?: any;
131
137
  source?: string;
138
+ ready?: boolean;
132
139
  };
133
140
  }[]>;
134
141
  setStories: (value: Story[]) => void;
@@ -144,6 +151,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
144
151
  slots?: () => Readonly<any>;
145
152
  state?: any;
146
153
  source?: string;
154
+ ready?: boolean;
147
155
  }[];
148
156
  layout?: {
149
157
  type: "single";
@@ -169,6 +177,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
169
177
  slots?: () => Readonly<any>;
170
178
  state?: any;
171
179
  source?: string;
180
+ ready?: boolean;
172
181
  };
173
182
  }>;
174
183
  currentVariant: import("vue").ComputedRef<{
@@ -180,6 +189,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
180
189
  slots?: () => Readonly<any>;
181
190
  state?: any;
182
191
  source?: string;
192
+ ready?: boolean;
183
193
  }>;
184
194
  isFolderOpened: (path: Array<string>) => boolean;
185
195
  toggleFolder: (path: Array<string>, force?: boolean) => void;
@@ -196,6 +206,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
196
206
  slots?: () => Readonly<any>;
197
207
  state?: any;
198
208
  source?: string;
209
+ ready?: boolean;
199
210
  }[];
200
211
  layout?: {
201
212
  type: "single";
@@ -221,6 +232,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
221
232
  slots?: () => Readonly<any>;
222
233
  state?: any;
223
234
  source?: string;
235
+ ready?: boolean;
224
236
  };
225
237
  }[]>;
226
238
  setStories: (value: Story[]) => void;
@@ -236,6 +248,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
236
248
  slots?: () => Readonly<any>;
237
249
  state?: any;
238
250
  source?: string;
251
+ ready?: boolean;
239
252
  }[];
240
253
  layout?: {
241
254
  type: "single";
@@ -261,6 +274,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
261
274
  slots?: () => Readonly<any>;
262
275
  state?: any;
263
276
  source?: string;
277
+ ready?: boolean;
264
278
  };
265
279
  }>;
266
280
  currentVariant: import("vue").ComputedRef<{
@@ -272,6 +286,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
272
286
  slots?: () => Readonly<any>;
273
287
  state?: any;
274
288
  source?: string;
289
+ ready?: boolean;
275
290
  }>;
276
291
  isFolderOpened: (path: Array<string>) => boolean;
277
292
  toggleFolder: (path: Array<string>, force?: boolean) => void;
@@ -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
+
@@ -1,6 +1,7 @@
1
1
  @import url('https://fonts.googleapis.com/css2?family=Lato&display=swap');
2
2
  @import 'floating-vue/dist/style.css';
3
3
  @import 'floating-vue.css';
4
+ @import 'transitions.css';
4
5
 
5
6
  *,
6
7
  ::before,
@@ -12,7 +13,8 @@
12
13
  }
13
14
 
14
15
  a,
15
- input {
16
+ input,
17
+ button {
16
18
  color: inherit;
17
19
  }
18
20
 
@@ -49,3 +51,17 @@ body,
49
51
  .__histoire-sandbox {
50
52
  contain: content;
51
53
  }
54
+
55
+ .__histoire-code .shiki {
56
+ background: transparent !important;
57
+ }
58
+
59
+ .htw-prose {
60
+ h1, h2, h3, h4 {
61
+ &:not(:hover) {
62
+ .header-anchor[aria-hidden="true"] {
63
+ visibility: hidden;
64
+ }
65
+ }
66
+ }
67
+ }
@@ -1,3 +1,8 @@
1
+ html,
2
+ body {
3
+ background: transparent !important;
4
+ }
5
+
1
6
  body {
2
7
  margin: 0;
3
8
  }
@@ -0,0 +1,12 @@
1
+ .__histoire-scale-x {
2
+ &-enter-active,
3
+ &-leave-active {
4
+ transition: transform .15s, opacity .15s;
5
+ }
6
+
7
+ &-enter-from,
8
+ &-leave-to {
9
+ transform: scaleX(0);
10
+ opacity: 0;
11
+ }
12
+ }
@@ -30,6 +30,7 @@ export interface Variant {
30
30
  slots?: () => Readonly<any>;
31
31
  state?: any;
32
32
  source?: string;
33
+ ready?: boolean;
33
34
  }
34
35
  export declare type TreeLeaf = {
35
36
  title: string;
@@ -33,6 +33,7 @@ export interface Variant {
33
33
  slots?: () => Readonly<any>
34
34
  state?: any
35
35
  source?: string
36
+ ready?: boolean
36
37
  }
37
38
 
38
39
  export type TreeLeaf = {
@@ -1 +1,3 @@
1
1
  export declare const STATE_SYNC = "__histoire:state-sync";
2
+ export declare const SANDBOX_READY = "__histoire:sandbox-ready";
3
+ export declare const PREVIEW_SETTINGS_SYNC = "__histoire:preview-settings-sync";
@@ -1 +1,3 @@
1
1
  export const STATE_SYNC = '__histoire:state-sync';
2
+ export const SANDBOX_READY = '__histoire:sandbox-ready';
3
+ export const PREVIEW_SETTINGS_SYNC = '__histoire:preview-settings-sync';
@@ -1 +1,3 @@
1
1
  export const STATE_SYNC = '__histoire:state-sync'
2
+ export const SANDBOX_READY = '__histoire:sandbox-ready'
3
+ export const PREVIEW_SETTINGS_SYNC = '__histoire:preview-settings-sync'
@@ -21,8 +21,13 @@ export function mapFile(file, existingFile) {
21
21
  variant.initState = existingVariant.initState;
22
22
  if (existingVariant.slots)
23
23
  variant.slots = existingVariant.slots;
24
+ if (existingVariant.ready)
25
+ variant.ready = existingVariant.ready;
24
26
  }
25
27
  }
28
+ if (existingFile.story.lastSelectedVariant) {
29
+ result.story.lastSelectedVariant = result.story.variants.find(v => v.id === existingFile.story.lastSelectedVariant.id);
30
+ }
26
31
  }
27
32
  return result;
28
33
  }
@@ -32,5 +37,6 @@ export function mapVariant(variant) {
32
37
  state: {},
33
38
  initState: null,
34
39
  slots: () => ({}),
40
+ ready: false,
35
41
  };
36
42
  }
@@ -21,8 +21,12 @@ export function mapFile (file: StoryFile, existingFile?: StoryFile): StoryFile {
21
21
  if (existingVariant.state) Object.assign(variant.state, existingVariant.state)
22
22
  if (existingVariant.initState) variant.initState = existingVariant.initState
23
23
  if (existingVariant.slots) variant.slots = existingVariant.slots
24
+ if (existingVariant.ready) variant.ready = existingVariant.ready
24
25
  }
25
26
  }
27
+ if (existingFile.story.lastSelectedVariant) {
28
+ result.story.lastSelectedVariant = result.story.variants.find(v => v.id === existingFile.story.lastSelectedVariant.id)
29
+ }
26
30
  }
27
31
 
28
32
  return result
@@ -34,5 +38,6 @@ export function mapVariant (variant: Variant): Variant {
34
38
  state: {},
35
39
  initState: null,
36
40
  slots: () => ({}),
41
+ ready: false,
37
42
  }
38
43
  }
@@ -0,0 +1,16 @@
1
+ export interface PreviewSettings {
2
+ responsiveWidth: number;
3
+ responsiveHeight: number;
4
+ rotate: boolean;
5
+ backgroundColor: string;
6
+ checkerboard: boolean;
7
+ }
8
+ export declare function usePreviewSettings(): import("@vueuse/shared").RemovableRef<PreviewSettings>;
9
+ export declare const receivedSettings: {
10
+ responsiveWidth: number;
11
+ responsiveHeight: number;
12
+ rotate: boolean;
13
+ backgroundColor: string;
14
+ checkerboard: boolean;
15
+ };
16
+ export declare function applyPreviewSettings(settings: PreviewSettings): void;
@@ -0,0 +1,15 @@
1
+ import { useStorage } from '@vueuse/core';
2
+ import { reactive } from 'vue';
3
+ export function usePreviewSettings() {
4
+ return useStorage('_histoire-sandbox-settings-v1', {
5
+ responsiveWidth: 720,
6
+ responsiveHeight: null,
7
+ rotate: false,
8
+ backgroundColor: 'transparent',
9
+ checkerboard: false,
10
+ });
11
+ }
12
+ export const receivedSettings = reactive({});
13
+ export function applyPreviewSettings(settings) {
14
+ Object.assign(receivedSettings, settings);
15
+ }
@@ -0,0 +1,26 @@
1
+ import { useStorage } from '@vueuse/core'
2
+ import { reactive } from 'vue'
3
+
4
+ export interface PreviewSettings {
5
+ responsiveWidth: number
6
+ responsiveHeight: number
7
+ rotate: boolean
8
+ backgroundColor: string
9
+ checkerboard: boolean
10
+ }
11
+
12
+ export function usePreviewSettings () {
13
+ return useStorage<PreviewSettings>('_histoire-sandbox-settings-v1', {
14
+ responsiveWidth: 720,
15
+ responsiveHeight: null,
16
+ rotate: false,
17
+ backgroundColor: 'transparent',
18
+ checkerboard: false,
19
+ })
20
+ }
21
+
22
+ export const receivedSettings = reactive<PreviewSettings>({} as PreviewSettings)
23
+
24
+ export function applyPreviewSettings (settings: PreviewSettings) {
25
+ Object.assign(receivedSettings, settings)
26
+ }
@@ -0,0 +1 @@
1
+ export declare function toRawDeep(val: any): any;
@@ -0,0 +1,16 @@
1
+ import { unref, isRef } from 'vue';
2
+ const isObject = (val) => val !== null && typeof val === 'object';
3
+ export function toRawDeep(val) {
4
+ const unwrappedValue = isRef(val) ? unref(val) : val;
5
+ if (!isObject(unwrappedValue)) {
6
+ return unwrappedValue;
7
+ }
8
+ if (Array.isArray(unwrappedValue)) {
9
+ return unwrappedValue.map(toRawDeep);
10
+ }
11
+ return toRawObject(unwrappedValue);
12
+ }
13
+ const toRawObject = (obj) => Object.keys(obj).reduce((raw, key) => {
14
+ raw[key] = toRawDeep(obj[key]);
15
+ return raw;
16
+ }, {});
@@ -0,0 +1,22 @@
1
+ import { unref, isRef } from 'vue'
2
+
3
+ const isObject = (val) => val !== null && typeof val === 'object'
4
+
5
+ export function toRawDeep (val) {
6
+ const unwrappedValue = isRef(val) ? unref(val) : val
7
+
8
+ if (!isObject(unwrappedValue)) {
9
+ return unwrappedValue
10
+ }
11
+
12
+ if (Array.isArray(unwrappedValue)) {
13
+ return unwrappedValue.map(toRawDeep)
14
+ }
15
+
16
+ return toRawObject(unwrappedValue)
17
+ }
18
+
19
+ const toRawObject = (obj: Record<any, any>) => Object.keys(obj).reduce((raw, key) => {
20
+ raw[key] = toRawDeep(obj[key])
21
+ return raw
22
+ }, {})
@@ -0,0 +1,2 @@
1
+ import { Ref } from 'vue';
2
+ export declare function useScrollOnActive(active: Ref<boolean>, el: Ref<HTMLElement>): void;
@@ -0,0 +1,24 @@
1
+ import { watch, onMounted } from 'vue';
2
+ import scrollIntoView from 'scroll-into-view-if-needed';
3
+ export function useScrollOnActive(active, el) {
4
+ watch(active, value => {
5
+ if (value) {
6
+ autoScroll();
7
+ }
8
+ });
9
+ function autoScroll() {
10
+ if (el.value) {
11
+ scrollIntoView(el.value, {
12
+ scrollMode: 'if-needed',
13
+ block: 'center',
14
+ inline: 'nearest',
15
+ behavior: 'smooth',
16
+ });
17
+ }
18
+ }
19
+ onMounted(() => {
20
+ if (active.value) {
21
+ autoScroll();
22
+ }
23
+ });
24
+ }
@@ -0,0 +1,27 @@
1
+ import { watch, onMounted, Ref } from 'vue'
2
+ import scrollIntoView from 'scroll-into-view-if-needed'
3
+
4
+ export function useScrollOnActive (active: Ref<boolean>, el: Ref<HTMLElement>) {
5
+ watch(active, value => {
6
+ if (value) {
7
+ autoScroll()
8
+ }
9
+ })
10
+
11
+ function autoScroll () {
12
+ if (el.value) {
13
+ scrollIntoView(el.value, {
14
+ scrollMode: 'if-needed',
15
+ block: 'center',
16
+ inline: 'nearest',
17
+ behavior: 'smooth',
18
+ })
19
+ }
20
+ }
21
+
22
+ onMounted(() => {
23
+ if (active.value) {
24
+ autoScroll()
25
+ }
26
+ })
27
+ }
File without changes
File without changes
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { defineComponent, inject, PropType, provide, useAttrs } from 'vue'
2
+ import { defineComponent, inject, onMounted, PropType, provide, useAttrs } from 'vue'
3
3
  import type { StoryFile, Story, Variant } from '../../node/types'
4
4
 
5
5
  export default defineComponent({
@@ -53,13 +53,36 @@ export default defineComponent({
53
53
  story.variants.push(variant)
54
54
  })
55
55
 
56
+ onMounted(() => {
57
+ if (!story.variants.length) {
58
+ story.variants.push({
59
+ id: '_default',
60
+ title: 'default',
61
+ })
62
+ }
63
+ })
64
+
56
65
  return {
57
66
  story,
58
67
  }
59
68
  },
60
69
 
61
70
  render () {
62
- return this.$slots.default()
71
+ let suppressError = false
72
+ try {
73
+ return this.$slots.default({
74
+ get state () {
75
+ // No variant tags
76
+ suppressError = true
77
+ return {}
78
+ },
79
+ })
80
+ } catch (e) {
81
+ if (!suppressError) {
82
+ console.error(e)
83
+ }
84
+ return null
85
+ }
63
86
  },
64
87
  })
65
88
  </script>
@@ -1,4 +1,5 @@
1
1
  import { createApp, h } from 'vue';
2
+ import { registerVueComponents } from '@histoire/controls';
2
3
  import Story from './Story.server.vue';
3
4
  import Variant from './Variant.server.vue';
4
5
  export async function run(file, storyData, el) {
@@ -20,6 +21,7 @@ export async function run(file, storyData, el) {
20
21
  app.component('Story', Story);
21
22
  // eslint-disable-next-line vue/multi-word-component-names
22
23
  app.component('Variant', Variant);
24
+ registerVueComponents(app);
23
25
  app.mount(el);
24
26
  app.unmount();
25
27
  }