histoire 0.4.3 → 0.4.6

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 (42) hide show
  1. package/dist/bundled/StoryView.js +376 -136
  2. package/dist/bundled/global-components.js +11 -1
  3. package/dist/bundled/index2.js +3 -0
  4. package/dist/bundled/sandbox.js +2 -10
  5. package/dist/bundled/{reactivity.js → state.js} +27 -1
  6. package/dist/bundled/story.js +1 -1
  7. package/dist/client/app/components/base/BaseSelect.vue +72 -0
  8. package/dist/client/app/components/panel/StatePresets.vue +193 -0
  9. package/dist/client/app/components/panel/StoryControls.vue +15 -1
  10. package/dist/client/app/components/story/StoryVariantSinglePreviewRemote.vue +2 -14
  11. package/dist/client/app/index.js +5 -0
  12. package/dist/client/app/sandbox.js +2 -11
  13. package/dist/client/app/util/mapping.js +11 -1
  14. package/dist/client/app/util/state.d.ts +4 -0
  15. package/dist/client/app/util/state.js +46 -0
  16. package/dist/client/app/util/variant.d.ts +1 -1
  17. package/dist/node/build.js +3 -3
  18. package/dist/node/collect/worker.js +0 -4
  19. package/dist/node/commands/preview.js +1 -1
  20. package/dist/node/server.js +53 -45
  21. package/dist/node/vite.d.ts +1 -1
  22. package/dist/node/vite.js +11 -2
  23. package/dist/style.css +70 -37
  24. package/package.json +4 -4
  25. package/src/client/app/components/base/BaseSelect.vue +72 -0
  26. package/src/client/app/components/panel/StatePresets.vue +193 -0
  27. package/src/client/app/components/panel/StoryControls.vue +15 -1
  28. package/src/client/app/components/story/StoryVariantSinglePreviewRemote.vue +2 -14
  29. package/src/client/app/index.ts +6 -0
  30. package/src/client/app/sandbox.ts +2 -10
  31. package/src/client/app/util/mapping.ts +12 -1
  32. package/src/client/app/util/state.ts +51 -0
  33. package/src/client/app/util/variant.ts +1 -1
  34. package/src/node/build.ts +3 -3
  35. package/src/node/collect/worker.ts +0 -4
  36. package/src/node/commands/preview.ts +1 -1
  37. package/src/node/server.ts +55 -47
  38. package/src/node/vite.ts +12 -2
  39. package/vite.config.ts +25 -0
  40. package/dist/client/app/util/reactivity.d.ts +0 -1
  41. package/dist/client/app/util/reactivity.js +0 -16
  42. package/src/client/app/util/reactivity.ts +0 -22
@@ -1,21 +1,20 @@
1
1
  import { createServer as createViteServer } from 'vite';
2
2
  import { createVitePlugins, RESOLVED_SEARCH_TITLE_DATA_ID, RESOLVED_STORIES_ID } from './vite.js';
3
- import { notifyStoryChange, onStoryChange, watchStories } from './stories.js';
3
+ import { onStoryChange, watchStories } from './stories.js';
4
4
  import { useCollectStories } from './collect/index.js';
5
5
  import { DevPluginApi } from './plugin.js';
6
6
  import { useModuleLoader } from './load.js';
7
7
  export async function createServer(ctx, port) {
8
8
  const server = await createViteServer({
9
- plugins: await createVitePlugins(ctx),
10
- server: {
11
- watch: {
12
- usePolling: true,
13
- },
14
- },
9
+ plugins: await createVitePlugins(false, ctx),
15
10
  });
16
11
  await server.pluginContainer.buildStart({});
12
+ const nodeServer = await createViteServer({
13
+ plugins: await createVitePlugins(true, ctx),
14
+ });
15
+ await nodeServer.pluginContainer.buildStart({});
17
16
  const moduleLoader = useModuleLoader({
18
- server,
17
+ server: nodeServer,
19
18
  });
20
19
  const pluginOnCleanups = [];
21
20
  for (const plugin of ctx.config.plugins) {
@@ -31,17 +30,49 @@ export async function createServer(ctx, port) {
31
30
  // Wait for pre-bundling (in `listen()`)
32
31
  await server.listen(port);
33
32
  const { clearCache, executeStoryFile, destroy: destroyCollectStories, } = useCollectStories({
34
- server,
33
+ server: nodeServer,
35
34
  }, ctx);
36
35
  // onStoryChange debouncing
37
36
  let queue;
38
37
  let queueResolve;
39
38
  let queued = false;
40
39
  let queuedFiles = [];
40
+ let queuedAll = false;
41
+ let didAllStoriesYet = false;
42
+ // Invalidate modules
43
+ const invalidateModule = (id) => {
44
+ const mod = server.moduleGraph.getModuleById(id);
45
+ if (!mod) {
46
+ return;
47
+ }
48
+ server.moduleGraph.invalidateModule(mod);
49
+ // Send HMR update
50
+ const timestamp = Date.now();
51
+ mod.lastHMRTimestamp = timestamp;
52
+ server.ws.send({
53
+ type: 'update',
54
+ updates: [
55
+ {
56
+ type: 'js-update',
57
+ acceptedPath: mod.url,
58
+ path: mod.url,
59
+ timestamp: timestamp,
60
+ },
61
+ ],
62
+ });
63
+ };
41
64
  onStoryChange(async (changedFile) => {
65
+ if (changedFile && !didAllStoriesYet) {
66
+ return;
67
+ }
42
68
  if (queue) {
43
- if (queued && changedFile) {
44
- queuedFiles.push(changedFile);
69
+ if (queued) {
70
+ if (changedFile) {
71
+ queuedFiles.push(changedFile);
72
+ }
73
+ else {
74
+ queuedAll = true;
75
+ }
45
76
  return;
46
77
  }
47
78
  else {
@@ -55,44 +86,27 @@ export async function createServer(ctx, port) {
55
86
  queueResolve = resolve;
56
87
  });
57
88
  clearCache();
58
- if (changedFile) {
89
+ console.log('Collect stories start', changedFile?.path ?? 'all');
90
+ const time = Date.now();
91
+ if (changedFile && !queuedAll) {
59
92
  // Granular update
60
93
  await executeStoryFile(changedFile);
94
+ // Queued updates
95
+ for (const storyFile of queuedFiles) {
96
+ await executeStoryFile(storyFile);
97
+ }
61
98
  }
62
99
  else {
63
100
  // Full update
64
101
  for (const storyFile of ctx.storyFiles) {
65
102
  await executeStoryFile(storyFile);
66
103
  }
104
+ didAllStoriesYet = true;
67
105
  }
68
- // Queued updates
69
- for (const storyFile of queuedFiles) {
70
- await executeStoryFile(storyFile);
71
- }
106
+ console.log('Collect stories end', Date.now() - time, 'ms');
72
107
  queuedFiles = [];
108
+ queuedAll = false;
73
109
  queueResolve();
74
- // Invalidate modules
75
- function invalidateModule(id) {
76
- const mod = server.moduleGraph.getModuleById(id);
77
- if (!mod) {
78
- return;
79
- }
80
- server.moduleGraph.invalidateModule(mod);
81
- // Send HMR update
82
- const timestamp = Date.now();
83
- mod.lastHMRTimestamp = timestamp;
84
- server.ws.send({
85
- type: 'update',
86
- updates: [
87
- {
88
- type: 'js-update',
89
- acceptedPath: mod.url,
90
- path: mod.url,
91
- timestamp: timestamp,
92
- },
93
- ],
94
- });
95
- }
96
110
  invalidateModule(RESOLVED_STORIES_ID);
97
111
  invalidateModule(RESOLVED_SEARCH_TITLE_DATA_ID);
98
112
  });
@@ -101,15 +115,9 @@ export async function createServer(ctx, port) {
101
115
  await cb();
102
116
  }
103
117
  await server.close();
118
+ await nodeServer.close();
104
119
  await destroyCollectStories();
105
120
  }
106
- // On page refresh, refresh stories
107
- // Useful when vite optimizes new dependencies
108
- server.ws.on('connection', (socket) => {
109
- if (socket.protocol === 'vite-hmr') {
110
- notifyStoryChange();
111
- }
112
- });
113
121
  return {
114
122
  server,
115
123
  close,
@@ -12,4 +12,4 @@ export declare const SEARCH_TITLE_DATA_ID = "$histoire-search-title-data";
12
12
  export declare const RESOLVED_SEARCH_TITLE_DATA_ID: string;
13
13
  export declare const SEARCH_DOCS_DATA_ID = "$histoire-search-docs-data";
14
14
  export declare const RESOLVED_SEARCH_DOCS_DATA_ID: string;
15
- export declare function createVitePlugins(ctx: Context): Promise<VitePlugin[]>;
15
+ export declare function createVitePlugins(server: boolean, ctx: Context): Promise<VitePlugin[]>;
package/dist/node/vite.js CHANGED
@@ -21,7 +21,7 @@ export const SEARCH_TITLE_DATA_ID = '$histoire-search-title-data';
21
21
  export const RESOLVED_SEARCH_TITLE_DATA_ID = `/${SEARCH_TITLE_DATA_ID}-resolved`;
22
22
  export const SEARCH_DOCS_DATA_ID = '$histoire-search-docs-data';
23
23
  export const RESOLVED_SEARCH_DOCS_DATA_ID = `/${SEARCH_DOCS_DATA_ID}-resolved`;
24
- export async function createVitePlugins(ctx) {
24
+ export async function createVitePlugins(server, ctx) {
25
25
  const viteConfig = await resolveViteConfig({}, ctx.mode === 'dev' ? 'serve' : 'build');
26
26
  const plugins = [];
27
27
  if (ctx.config.vite) {
@@ -37,9 +37,15 @@ export async function createVitePlugins(ctx) {
37
37
  config() {
38
38
  return {
39
39
  optimizeDeps: {
40
- // force include vue to avoid duplicated copies when linked + optimized
40
+ disabled: server,
41
+ entries: [
42
+ `${APP_PATH}/bundle-main.js`,
43
+ `${APP_PATH}/bundle-sandbox.js`,
44
+ `${APP_PATH}/server/index.js`,
45
+ ],
41
46
  include: [
42
47
  'vue',
48
+ dirname(require.resolve('@vue/runtime-core/package.json')),
43
49
  dirname(require.resolve('shiki/package.json')),
44
50
  dirname(require.resolve('vscode-textmate/package.json')),
45
51
  dirname(require.resolve('vscode-oniguruma/package.json')),
@@ -159,6 +165,9 @@ if (import.meta.hot) {
159
165
  }
160
166
  },
161
167
  configureServer(server) {
168
+ server.ws.on('histoire:mount', () => {
169
+ notifyStoryChange();
170
+ });
162
171
  server.middlewares.use(async (req, res, next) => {
163
172
  if (req.url.startsWith(`${server.config.base}__sandbox`)) {
164
173
  res.statusCode = 200;
package/dist/style.css CHANGED
@@ -891,6 +891,11 @@ button {
891
891
  margin:0.25rem
892
892
  }
893
893
 
894
+ .-htw-my-1{
895
+ margin-top:-0.25rem;
896
+ margin-bottom:-0.25rem
897
+ }
898
+
894
899
  .htw-mx-1{
895
900
  margin-left:0.25rem;
896
901
  margin-right:0.25rem
@@ -921,11 +926,6 @@ button {
921
926
  margin-right:1rem
922
927
  }
923
928
 
924
- .-htw-my-1{
925
- margin-top:-0.25rem;
926
- margin-bottom:-0.25rem
927
- }
928
-
929
929
  .htw-mt-2{
930
930
  margin-top:0.5rem
931
931
  }
@@ -1026,10 +1026,18 @@ button {
1026
1026
  height:2.5rem
1027
1027
  }
1028
1028
 
1029
+ .htw-h-\[27px\]{
1030
+ height:27px
1031
+ }
1032
+
1029
1033
  .htw-h-\[2px\]{
1030
1034
  height:2px
1031
1035
  }
1032
1036
 
1037
+ .htw-h-9{
1038
+ height:2.25rem
1039
+ }
1040
+
1033
1041
  .htw-h-\[51px\]{
1034
1042
  height:51px
1035
1043
  }
@@ -1156,14 +1164,14 @@ button {
1156
1164
  min-width:1rem
1157
1165
  }
1158
1166
 
1159
- .htw-min-w-16{
1160
- min-width:4rem
1161
- }
1162
-
1163
1167
  .htw-min-w-0{
1164
1168
  min-width:0px
1165
1169
  }
1166
1170
 
1171
+ .htw-min-w-16{
1172
+ min-width:4rem
1173
+ }
1174
+
1167
1175
  .htw-max-w-full{
1168
1176
  max-width:100%
1169
1177
  }
@@ -1463,6 +1471,11 @@ button {
1463
1471
  border-color:rgb(0 0 0 / 0.2)
1464
1472
  }
1465
1473
 
1474
+ .htw-border-gray-850{
1475
+ --tw-border-opacity:1;
1476
+ border-color:rgb(var(--_histoire-color-gray-850) / var(--tw-border-opacity))
1477
+ }
1478
+
1466
1479
  .htw-bg-white{
1467
1480
  --tw-bg-opacity:1;
1468
1481
  background-color:rgb(255 255 255 / var(--tw-bg-opacity))
@@ -1478,10 +1491,24 @@ button {
1478
1491
  background-color:rgb(var(--_histoire-color-primary-500) / var(--tw-bg-opacity))
1479
1492
  }
1480
1493
 
1494
+ .htw-bg-gray-50{
1495
+ --tw-bg-opacity:1;
1496
+ background-color:rgb(var(--_histoire-color-gray-50) / var(--tw-bg-opacity))
1497
+ }
1498
+
1499
+ .htw-bg-primary-200{
1500
+ --tw-bg-opacity:1;
1501
+ background-color:rgb(var(--_histoire-color-primary-200) / var(--tw-bg-opacity))
1502
+ }
1503
+
1481
1504
  .htw-bg-primary-500\/25{
1482
1505
  background-color:rgb(var(--_histoire-color-primary-500) / 0.25)
1483
1506
  }
1484
1507
 
1508
+ .htw-bg-transparent{
1509
+ background-color:transparent
1510
+ }
1511
+
1485
1512
  .htw-bg-primary-50{
1486
1513
  --tw-bg-opacity:1;
1487
1514
  background-color:rgb(var(--_histoire-color-primary-50) / var(--tw-bg-opacity))
@@ -1492,10 +1519,6 @@ button {
1492
1519
  background-color:rgb(var(--_histoire-color-gray-100) / var(--tw-bg-opacity))
1493
1520
  }
1494
1521
 
1495
- .htw-bg-transparent{
1496
- background-color:transparent
1497
- }
1498
-
1499
1522
  .htw-bg-white\/80{
1500
1523
  background-color:rgb(255 255 255 / 0.8)
1501
1524
  }
@@ -1505,16 +1528,6 @@ button {
1505
1528
  background-color:rgb(var(--_histoire-color-gray-200) / var(--tw-bg-opacity))
1506
1529
  }
1507
1530
 
1508
- .htw-bg-primary-200{
1509
- --tw-bg-opacity:1;
1510
- background-color:rgb(var(--_histoire-color-primary-200) / var(--tw-bg-opacity))
1511
- }
1512
-
1513
- .htw-bg-gray-50{
1514
- --tw-bg-opacity:1;
1515
- background-color:rgb(var(--_histoire-color-gray-50) / var(--tw-bg-opacity))
1516
- }
1517
-
1518
1531
  .htw-bg-gray-500\/10{
1519
1532
  background-color:rgb(var(--_histoire-color-gray-500) / 0.1)
1520
1533
  }
@@ -1523,6 +1536,11 @@ button {
1523
1536
  background-color:rgb(var(--_histoire-color-gray-500) / 0.5)
1524
1537
  }
1525
1538
 
1539
+ .htw-bg-gray-700{
1540
+ --tw-bg-opacity:1;
1541
+ background-color:rgb(var(--_histoire-color-gray-700) / var(--tw-bg-opacity))
1542
+ }
1543
+
1526
1544
  .htw-stroke-white{
1527
1545
  stroke:#fff
1528
1546
  }
@@ -1568,6 +1586,16 @@ button {
1568
1586
  padding-bottom:3rem
1569
1587
  }
1570
1588
 
1589
+ .htw-px-2{
1590
+ padding-left:0.5rem;
1591
+ padding-right:0.5rem
1592
+ }
1593
+
1594
+ .htw-py-1{
1595
+ padding-top:0.25rem;
1596
+ padding-bottom:0.25rem
1597
+ }
1598
+
1571
1599
  .htw-px-0\.5{
1572
1600
  padding-left:0.125rem;
1573
1601
  padding-right:0.125rem
@@ -1588,11 +1616,6 @@ button {
1588
1616
  padding-bottom:1rem
1589
1617
  }
1590
1618
 
1591
- .htw-px-2{
1592
- padding-left:0.5rem;
1593
- padding-right:0.5rem
1594
- }
1595
-
1596
1619
  .htw-py-0\.5{
1597
1620
  padding-top:0.125rem;
1598
1621
  padding-bottom:0.125rem
@@ -1603,11 +1626,6 @@ button {
1603
1626
  padding-bottom:0px
1604
1627
  }
1605
1628
 
1606
- .htw-py-1{
1607
- padding-top:0.25rem;
1608
- padding-bottom:0.25rem
1609
- }
1610
-
1611
1629
  .htw-pr-2{
1612
1630
  padding-right:0.5rem
1613
1631
  }
@@ -1701,6 +1719,10 @@ button {
1701
1719
  color:rgb(var(--_histoire-color-gray-400) / var(--tw-text-opacity))
1702
1720
  }
1703
1721
 
1722
+ .htw-text-inherit{
1723
+ color:inherit
1724
+ }
1725
+
1704
1726
  .htw-text-red-500{
1705
1727
  --tw-text-opacity:1;
1706
1728
  color:rgb(239 68 68 / var(--tw-text-opacity))
@@ -1719,10 +1741,6 @@ button {
1719
1741
  color:rgb(var(--_histoire-color-primary-800) / var(--tw-text-opacity))
1720
1742
  }
1721
1743
 
1722
- .htw-text-inherit{
1723
- color:inherit
1724
- }
1725
-
1726
1744
  .htw-opacity-25{
1727
1745
  opacity:0.25
1728
1746
  }
@@ -1862,6 +1880,11 @@ body {
1862
1880
  margin-bottom:0px
1863
1881
  }
1864
1882
 
1883
+ .hover\:htw-border-primary-500:hover{
1884
+ --tw-border-opacity:1;
1885
+ border-color:rgb(var(--_histoire-color-primary-500) / var(--tw-border-opacity))
1886
+ }
1887
+
1865
1888
  .hover\:htw-bg-primary-100:hover{
1866
1889
  --tw-bg-opacity:1;
1867
1890
  background-color:rgb(var(--_histoire-color-primary-100) / var(--tw-bg-opacity))
@@ -2010,6 +2033,11 @@ body {
2010
2033
  background-color:rgb(var(--_histoire-color-primary-400) / var(--tw-bg-opacity))
2011
2034
  }
2012
2035
 
2036
+ .htw-dark .dark\:htw-bg-primary-800{
2037
+ --tw-bg-opacity:1;
2038
+ background-color:rgb(var(--_histoire-color-primary-800) / var(--tw-bg-opacity))
2039
+ }
2040
+
2013
2041
  .htw-dark .dark\:htw-bg-primary-600{
2014
2042
  --tw-bg-opacity:1;
2015
2043
  background-color:rgb(var(--_histoire-color-primary-600) / var(--tw-bg-opacity))
@@ -2073,6 +2101,11 @@ body {
2073
2101
  color:rgb(var(--_histoire-color-primary-200) / var(--tw-text-opacity))
2074
2102
  }
2075
2103
 
2104
+ .htw-dark .dark\:hover\:htw-border-primary-500:hover{
2105
+ --tw-border-opacity:1;
2106
+ border-color:rgb(var(--_histoire-color-primary-500) / var(--tw-border-opacity))
2107
+ }
2108
+
2076
2109
  .htw-dark .dark\:hover\:htw-bg-primary-700:hover{
2077
2110
  --tw-bg-opacity:1;
2078
2111
  background-color:rgb(var(--_histoire-color-primary-700) / var(--tw-bg-opacity))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "histoire",
3
- "version": "0.4.3",
3
+ "version": "0.4.6",
4
4
  "description": "A fast story book powered by Vite",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -33,7 +33,7 @@
33
33
  "histoire": "./bin.mjs"
34
34
  },
35
35
  "dependencies": {
36
- "@histoire/controls": "^0.4.3",
36
+ "@histoire/controls": "^0.4.6",
37
37
  "@iconify/vue": "^3.2.1",
38
38
  "@types/markdown-it": "^12.2.3",
39
39
  "@vueuse/core": "^8.2.5",
@@ -61,7 +61,7 @@
61
61
  "shiki": "^0.10.1",
62
62
  "sirv": "^2.0.2",
63
63
  "tinypool": "^0.1.2",
64
- "vite-node": "0.7.6",
64
+ "vite-node": "0.12.1",
65
65
  "vue-router": "^4.0.14",
66
66
  "vue": "^3.2.31"
67
67
  },
@@ -74,7 +74,7 @@
74
74
  "@types/flexsearch": "^0.7.3",
75
75
  "@types/fs-extra": "^9.0.13",
76
76
  "@types/markdown-it": "^12.2.3",
77
- "@types/node": "^17.0.23",
77
+ "@types/node": "^17.0.32",
78
78
  "@vitejs/plugin-vue": "^2.3.1",
79
79
  "autoprefixer": "^10.4.4",
80
80
  "concurrently": "^7.1.0",
@@ -0,0 +1,72 @@
1
+ <script lang="ts" setup>
2
+ import { Dropdown as VDropdown } from 'floating-vue'
3
+ import { computed, ComputedRef } from 'vue'
4
+ import { Icon } from '@iconify/vue'
5
+
6
+ const props = defineProps<{
7
+ modelValue: string
8
+ options: Record<string, string> | Array<string>
9
+ }>()
10
+
11
+ const emits = defineEmits<{
12
+ (e: 'update:modelValue', value: string): void
13
+ (e: 'select', value: string): void
14
+ }>()
15
+
16
+ const formattedOptions: ComputedRef<Record<string, string>> = computed(() => {
17
+ if (Array.isArray(props.options)) {
18
+ return Object.fromEntries(props.options.map((value) => [value, value]))
19
+ }
20
+ return props.options
21
+ })
22
+
23
+ const selectedLabel = computed(() => formattedOptions.value[props.modelValue])
24
+
25
+ function selectValue (value: string, hide: () => void) {
26
+ emits('update:modelValue', value)
27
+ emits('select', value)
28
+ hide()
29
+ }
30
+ </script>
31
+
32
+ <template>
33
+ <VDropdown
34
+ auto-size
35
+ >
36
+ <div
37
+ class="htw-cursor-pointer htw-w-full htw-outline-none htw-px-2 htw-h-[27px] -htw-my-1 htw-border htw-border-solid htw-border-black/25 dark:htw-border-white/25 hover:htw-border-primary-500 dark:hover:htw-border-primary-500 htw-rounded-sm htw-flex htw-gap-2 htw-items-center htw-leading-normal"
38
+ >
39
+ <div class="htw-flex-1 htw-truncate">
40
+ <slot :label="selectedLabel">
41
+ {{ selectedLabel }}
42
+ </slot>
43
+ </div>
44
+ <Icon
45
+ icon="carbon:chevron-sort"
46
+ class="htw-w-4 htw-h-4 htw-flex-none htw-ml-auto"
47
+ />
48
+ </div>
49
+ <template #popper="{ hide }">
50
+ <div class="htw-flex htw-flex-col htw-bg-gray-50 dark:htw-bg-gray-700">
51
+ <div
52
+ v-for="( label, value ) in formattedOptions"
53
+ v-bind="{ ...$attrs, class: null, style: null }"
54
+ :key="label"
55
+ class="htw-px-2 htw-py-1 htw-cursor-pointer hover:htw-bg-primary-100 dark:hover:htw-bg-primary-700"
56
+ :class="{
57
+ 'htw-bg-primary-200 dark:htw-bg-primary-800': props.modelValue === value,
58
+ }"
59
+ @click="selectValue(value, hide)"
60
+ >
61
+ <slot
62
+ name="option"
63
+ :label="label"
64
+ :value="value"
65
+ >
66
+ {{ label }}
67
+ </slot>
68
+ </div>
69
+ </div>
70
+ </template>
71
+ </VDropdown>
72
+ </template>