histoire 0.7.6 → 0.7.9

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.
@@ -596,7 +596,7 @@ function getSandboxUrl(story, variant) {
596
596
  const url = new URLSearchParams();
597
597
  url.append("storyId", story.id);
598
598
  url.append("variantId", variant.id);
599
- return `${base}__sandbox?${url.toString()}`;
599
+ return `${base}__sandbox.html?${url.toString()}`;
600
600
  }
601
601
  const _hoisted_1$l = ["href"];
602
602
  const _sfc_main$n = /* @__PURE__ */ defineComponent({
@@ -2,7 +2,8 @@ import { isRef, unref } from "vue";
2
2
  const isObject = (val) => val !== null && typeof val === "object";
3
3
  function toRawDeep(val, seen = /* @__PURE__ */ new Set()) {
4
4
  const unwrappedValue = isRef(val) ? unref(val) : val;
5
- if (typeof unwrappedValue === "symbol") {
5
+ const valueType = typeof unwrappedValue;
6
+ if (valueType === "symbol" || valueType === "function") {
6
7
  return unwrappedValue.toString();
7
8
  }
8
9
  if (!isObject(unwrappedValue)) {
@@ -1,9 +1,19 @@
1
1
  import { defineStore } from "pinia";
2
2
  import { ref, computed } from "vue";
3
- import { createRouter, createWebHistory } from "vue-router";
3
+ import { createWebHistory, createWebHashHistory, createRouter } from "vue-router";
4
+ import { h as histoireConfig } from "./config.js";
4
5
  const base = import.meta.env.BASE_URL;
6
+ function createRouterHistory() {
7
+ switch (histoireConfig.routerMode) {
8
+ case "hash":
9
+ return createWebHashHistory(base);
10
+ case "history":
11
+ default:
12
+ return createWebHistory(base);
13
+ }
14
+ }
5
15
  const router = createRouter({
6
- history: createWebHistory(base),
16
+ history: createRouterHistory(),
7
17
  routes: [
8
18
  {
9
19
  path: "/",
@@ -1,7 +1,16 @@
1
- import { createRouter, createWebHistory } from 'vue-router';
1
+ import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router';
2
+ import { histoireConfig } from './util/config';
2
3
  export const base = import.meta.env.BASE_URL;
4
+ function createRouterHistory() {
5
+ switch (histoireConfig.routerMode) {
6
+ case 'hash': return createWebHashHistory(base);
7
+ case 'history':
8
+ default:
9
+ return createWebHistory(base);
10
+ }
11
+ }
3
12
  export const router = createRouter({
4
- history: createWebHistory(base),
13
+ history: createRouterHistory(),
5
14
  routes: [
6
15
  {
7
16
  path: '/',
@@ -3,5 +3,5 @@ export function getSandboxUrl(story, variant) {
3
3
  const url = new URLSearchParams();
4
4
  url.append('storyId', story.id);
5
5
  url.append('variantId', variant.id);
6
- return `${base}__sandbox?${url.toString()}`;
6
+ return `${base}__sandbox.html?${url.toString()}`;
7
7
  }
@@ -2,7 +2,8 @@ import { unref, isRef } from 'vue';
2
2
  const isObject = (val) => val !== null && typeof val === 'object';
3
3
  export function toRawDeep(val, seen = new Set()) {
4
4
  const unwrappedValue = isRef(val) ? unref(val) : val;
5
- if (typeof unwrappedValue === 'symbol') {
5
+ const valueType = typeof unwrappedValue;
6
+ if (valueType === 'symbol' || valueType === 'function') {
6
7
  return unwrappedValue.toString();
7
8
  }
8
9
  if (!isObject(unwrappedValue)) {
@@ -81,7 +81,7 @@ export async function build(ctx) {
81
81
  const vuePlugin = config.plugins.find((p) => p.name === 'vite:vue');
82
82
  if (vuePlugin) {
83
83
  const original = vuePlugin.configureServer.bind(vuePlugin);
84
- vuePlugin.configureServer = () => {
84
+ vuePlugin.configureServer = (s) => {
85
85
  original({
86
86
  ...server,
87
87
  config: {
@@ -93,10 +93,17 @@ export async function build(ctx) {
93
93
  },
94
94
  });
95
95
  };
96
- vuePlugin.configureServer();
96
+ vuePlugin.configureServer(server);
97
97
  }
98
98
  },
99
99
  });
100
+ buildViteConfig.plugins.push({
101
+ name: 'histoire-build-config-override',
102
+ config(config) {
103
+ // Don't externalize
104
+ config.build.rollupOptions.external = [];
105
+ },
106
+ });
100
107
  const results = await viteBuild(buildViteConfig);
101
108
  const result = Array.isArray(results) ? results[0] : results;
102
109
  const styleOutput = result.output.find(o => o.name === 'style.css' && o.type === 'asset');
@@ -130,7 +137,7 @@ export async function build(ctx) {
130
137
  const query = new URLSearchParams();
131
138
  query.append('storyId', story.id);
132
139
  query.append('variantId', variant.id);
133
- const url = `${baseUrl}__sandbox?${query.toString()}`;
140
+ const url = `${baseUrl}__sandbox.html?${query.toString()}`;
134
141
  for (const fn of previewStoryCallbacks) {
135
142
  await fn({
136
143
  file: storyFile.path,
@@ -29,7 +29,7 @@ export async function devCommand(options) {
29
29
  async function restart(source) {
30
30
  if (stop) {
31
31
  console.log(pc.blue(`${source} config changed, restarting...`));
32
- stop();
32
+ await stop();
33
33
  stop = null; // Don't call stop again until new start() is done
34
34
  stop = await start();
35
35
  }
@@ -126,6 +126,12 @@ export interface HistoireConfig {
126
126
  * Customize the markdown-it renderer
127
127
  */
128
128
  markdown?: (md: MarkdownIt) => MarkdownIt | Promise<MarkdownIt>;
129
+ /**
130
+ * Change the router mode.
131
+ * - history: use HTML history with cleaner URLs
132
+ * - hash: use hashtag hack in the URL to support more hosting services
133
+ */
134
+ routerMode?: 'history' | 'hash';
129
135
  /**
130
136
  * Vite config override
131
137
  */
@@ -94,6 +94,12 @@ export function getDefaultConfig() {
94
94
  },
95
95
  ],
96
96
  sandboxDarkClass: 'dark',
97
+ routerMode: 'history',
98
+ vite: {
99
+ build: {
100
+ lib: false,
101
+ },
102
+ },
97
103
  };
98
104
  }
99
105
  export const configFileNames = [
@@ -4,6 +4,7 @@ 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
+ import { wrapLogError } from './util/log.js';
7
8
  export async function createServer(ctx, port) {
8
9
  const server = await createViteServer(await getViteConfigWithPlugins(false, ctx));
9
10
  await server.pluginContainer.buildStart({});
@@ -119,11 +120,11 @@ export async function createServer(ctx, port) {
119
120
  });
120
121
  async function close() {
121
122
  for (const cb of pluginOnCleanups) {
122
- await cb();
123
+ await wrapLogError('plugin.onDev.onCleanup', () => cb());
123
124
  }
124
- await server.close();
125
- await nodeServer.close();
126
- await destroyCollectStories();
125
+ await wrapLogError('server.close', () => server.close());
126
+ await wrapLogError('nodeServer', () => nodeServer.close());
127
+ await wrapLogError('destroyCollectStories', () => destroyCollectStories());
127
128
  }
128
129
  return {
129
130
  server,
@@ -0,0 +1 @@
1
+ export declare function wrapLogError(id: string, cb: () => unknown): Promise<void>;
@@ -0,0 +1,9 @@
1
+ import pc from 'picocolors';
2
+ export async function wrapLogError(id, cb) {
3
+ try {
4
+ await cb();
5
+ }
6
+ catch (e) {
7
+ console.error(pc.red(`[Error] ${id}: ${e}`));
8
+ }
9
+ }
package/dist/node/vite.js CHANGED
@@ -84,7 +84,7 @@ export async function getViteConfigWithPlugins(server, ctx) {
84
84
  allow: [DIST_PATH, TEMP_PATH, resolvedViteConfig.root, process.cwd()],
85
85
  },
86
86
  watch: {
87
- ignored: [`!**/node_modules/.histoire/**`],
87
+ ignored: [`!**/node_modules/.histoire/**`, '**/vite.config.*'],
88
88
  },
89
89
  },
90
90
  define: {
package/dist/style.css CHANGED
@@ -1057,6 +1057,10 @@ button {
1057
1057
  margin-bottom:0.5rem
1058
1058
  }
1059
1059
 
1060
+ .htw-mr-2{
1061
+ margin-right:0.5rem
1062
+ }
1063
+
1060
1064
  .htw-box-border{
1061
1065
  box-sizing:border-box
1062
1066
  }
@@ -1681,6 +1685,14 @@ button {
1681
1685
  background-color:rgb(var(--_histoire-color-primary-500) / var(--tw-bg-opacity)) !important
1682
1686
  }
1683
1687
 
1688
+ .htw-fill-primary-500{
1689
+ fill:rgb(var(--_histoire-color-primary-500))
1690
+ }
1691
+
1692
+ .htw-fill-transparent{
1693
+ fill:transparent
1694
+ }
1695
+
1684
1696
  .htw-stroke-white{
1685
1697
  stroke:#fff
1686
1698
  }
@@ -1980,6 +1992,10 @@ button {
1980
1992
  transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1)
1981
1993
  }
1982
1994
 
1995
+ .htw-will-change-transform{
1996
+ will-change:transform
1997
+ }
1998
+
1983
1999
  body,
1984
2000
  pre {
1985
2001
  margin: 0;
@@ -2091,6 +2107,11 @@ body {
2091
2107
  background-color:rgb(var(--_histoire-color-gray-100) / 0.5)
2092
2108
  }
2093
2109
 
2110
+ .htw-group:hover .group-hover\:htw-border-primary-500{
2111
+ --tw-border-opacity:1;
2112
+ border-color:rgb(var(--_histoire-color-primary-500) / var(--tw-border-opacity))
2113
+ }
2114
+
2094
2115
  .htw-group:hover .group-hover\:htw-bg-primary-100{
2095
2116
  --tw-bg-opacity:1;
2096
2117
  background-color:rgb(var(--_histoire-color-primary-100) / var(--tw-bg-opacity))
package/index.d.ts CHANGED
@@ -1,3 +1 @@
1
- import './src/components'
2
-
3
1
  export * from './dist/node/index'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "histoire",
3
- "version": "0.7.6",
3
+ "version": "0.7.9",
4
4
  "description": "A fast story book powered by Vite",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -33,9 +33,9 @@
33
33
  "histoire": "./bin.mjs"
34
34
  },
35
35
  "dependencies": {
36
- "@histoire/controls": "^0.7.6",
37
- "@histoire/plugin-vue": "^0.7.6",
38
- "@histoire/shared": "^0.7.6",
36
+ "@histoire/controls": "^0.7.9",
37
+ "@histoire/plugin-vue": "^0.7.9",
38
+ "@histoire/shared": "^0.7.9",
39
39
  "@iconify/vue": "^3.2.1",
40
40
  "@types/markdown-it": "^12.2.3",
41
41
  "@vueuse/core": "^8.2.5",
@@ -1,9 +1,19 @@
1
- import { createRouter, createWebHistory } from 'vue-router'
1
+ import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
2
+ import { histoireConfig } from './util/config'
2
3
 
3
4
  export const base = import.meta.env.BASE_URL as string
4
5
 
6
+ function createRouterHistory () {
7
+ switch (histoireConfig.routerMode) {
8
+ case 'hash': return createWebHashHistory(base)
9
+ case 'history':
10
+ default:
11
+ return createWebHistory(base)
12
+ }
13
+ }
14
+
5
15
  export const router = createRouter({
6
- history: createWebHistory(base),
16
+ history: createRouterHistory(),
7
17
  routes: [
8
18
  {
9
19
  path: '/',
@@ -6,5 +6,5 @@ export function getSandboxUrl (story: Story, variant: Variant) {
6
6
  const url = new URLSearchParams()
7
7
  url.append('storyId', story.id)
8
8
  url.append('variantId', variant.id)
9
- return `${base}__sandbox?${url.toString()}`
9
+ return `${base}__sandbox.html?${url.toString()}`
10
10
  }
@@ -4,8 +4,9 @@ const isObject = (val) => val !== null && typeof val === 'object'
4
4
 
5
5
  export function toRawDeep (val, seen = new Set()) {
6
6
  const unwrappedValue = isRef(val) ? unref(val) : val
7
+ const valueType = typeof unwrappedValue
7
8
 
8
- if (typeof unwrappedValue === 'symbol') {
9
+ if (valueType === 'symbol' || valueType === 'function') {
9
10
  return unwrappedValue.toString()
10
11
  }
11
12
 
package/src/node/build.ts CHANGED
@@ -2,8 +2,10 @@ import { join } from 'pathe'
2
2
  import {
3
3
  build as viteBuild,
4
4
  createServer as createViteServer,
5
+ InlineConfig as ViteInlineConfig,
5
6
  ResolvedConfig as ViteConfig,
6
7
  mergeConfig as mergeViteConfig,
8
+ Plugin as VitePlugin,
7
9
  } from 'vite'
8
10
  import fs from 'fs-extra'
9
11
  import { lookup as lookupMime } from 'mrmime'
@@ -65,7 +67,7 @@ export async function build (ctx: Context) {
65
67
  const variantCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ?? 0), 0)
66
68
  const emptyStoryCount = ctx.storyFiles.length - storyCount
67
69
 
68
- const buildViteConfig = mergeViteConfig(await getViteConfigWithPlugins(false, ctx), {
70
+ const buildViteConfig: ViteInlineConfig = mergeViteConfig(await getViteConfigWithPlugins(false, ctx), {
69
71
  mode: 'development',
70
72
  build: {
71
73
  rollupOptions: {
@@ -95,10 +97,10 @@ export async function build (ctx: Context) {
95
97
  buildViteConfig.plugins.push({
96
98
  name: 'histoire-vue-plugin-override',
97
99
  config (config) {
98
- const vuePlugin = config.plugins.find((p: any) => p.name === 'vite:vue')
100
+ const vuePlugin = config.plugins.find((p: any) => p.name === 'vite:vue') as VitePlugin
99
101
  if (vuePlugin) {
100
102
  const original = vuePlugin.configureServer.bind(vuePlugin)
101
- vuePlugin.configureServer = () => {
103
+ vuePlugin.configureServer = (s) => {
102
104
  original({
103
105
  ...server,
104
106
  config: {
@@ -110,11 +112,19 @@ export async function build (ctx: Context) {
110
112
  },
111
113
  })
112
114
  }
113
- vuePlugin.configureServer()
115
+ vuePlugin.configureServer(server)
114
116
  }
115
117
  },
116
118
  })
117
119
 
120
+ buildViteConfig.plugins.push({
121
+ name: 'histoire-build-config-override',
122
+ config (config) {
123
+ // Don't externalize
124
+ config.build.rollupOptions.external = []
125
+ },
126
+ })
127
+
118
128
  const results = await viteBuild(buildViteConfig)
119
129
  const result = Array.isArray(results) ? results[0] : results as RollupOutput
120
130
 
@@ -155,7 +165,7 @@ export async function build (ctx: Context) {
155
165
  const query = new URLSearchParams()
156
166
  query.append('storyId', story.id)
157
167
  query.append('variantId', variant.id)
158
- const url = `${baseUrl}__sandbox?${query.toString()}`
168
+ const url = `${baseUrl}__sandbox.html?${query.toString()}`
159
169
  for (const fn of previewStoryCallbacks) {
160
170
  await fn({
161
171
  file: storyFile.path,
@@ -38,7 +38,7 @@ export async function devCommand (options: DevOptions) {
38
38
  async function restart (source: string) {
39
39
  if (stop) {
40
40
  console.log(pc.blue(`${source} config changed, restarting...`))
41
- stop()
41
+ await stop()
42
42
  stop = null // Don't call stop again until new start() is done
43
43
  stop = await start()
44
44
  }
@@ -145,6 +145,12 @@ export interface HistoireConfig {
145
145
  * Customize the markdown-it renderer
146
146
  */
147
147
  markdown?: (md: MarkdownIt) => MarkdownIt | Promise<MarkdownIt>
148
+ /**
149
+ * Change the router mode.
150
+ * - history: use HTML history with cleaner URLs
151
+ * - hash: use hashtag hack in the URL to support more hosting services
152
+ */
153
+ routerMode?: 'history' | 'hash'
148
154
  /**
149
155
  * Vite config override
150
156
  */
@@ -264,6 +270,12 @@ export function getDefaultConfig (): HistoireConfig {
264
270
  },
265
271
  ],
266
272
  sandboxDarkClass: 'dark',
273
+ routerMode: 'history',
274
+ vite: {
275
+ build: {
276
+ lib: false,
277
+ },
278
+ },
267
279
  }
268
280
  }
269
281
 
@@ -6,6 +6,7 @@ import { onStoryChange, watchStories } from './stories.js'
6
6
  import { useCollectStories } from './collect/index.js'
7
7
  import { DevPluginApi } from './plugin.js'
8
8
  import { useModuleLoader } from './load.js'
9
+ import { wrapLogError } from './util/log.js'
9
10
 
10
11
  export async function createServer (ctx: Context, port: number) {
11
12
  const server = await createViteServer(await getViteConfigWithPlugins(false, ctx))
@@ -143,11 +144,11 @@ export async function createServer (ctx: Context, port: number) {
143
144
 
144
145
  async function close () {
145
146
  for (const cb of pluginOnCleanups) {
146
- await cb()
147
+ await wrapLogError('plugin.onDev.onCleanup', () => cb())
147
148
  }
148
- await server.close()
149
- await nodeServer.close()
150
- await destroyCollectStories()
149
+ await wrapLogError('server.close', () => server.close())
150
+ await wrapLogError('nodeServer', () => nodeServer.close())
151
+ await wrapLogError('destroyCollectStories', () => destroyCollectStories())
151
152
  }
152
153
 
153
154
  return {
@@ -0,0 +1,9 @@
1
+ import pc from 'picocolors'
2
+
3
+ export async function wrapLogError (id: string, cb: () => unknown) {
4
+ try {
5
+ await cb()
6
+ } catch (e) {
7
+ console.error(pc.red(`[Error] ${id}: ${e}`))
8
+ }
9
+ }
package/src/node/vite.ts CHANGED
@@ -100,7 +100,7 @@ export async function getViteConfigWithPlugins (server: boolean, ctx: Context):
100
100
  allow: [DIST_PATH, TEMP_PATH, resolvedViteConfig.root, process.cwd()],
101
101
  },
102
102
  watch: {
103
- ignored: [`!**/node_modules/.histoire/**`],
103
+ ignored: [`!**/node_modules/.histoire/**`, '**/vite.config.*'],
104
104
  },
105
105
  },
106
106
  define: {
package/vue.d.ts ADDED
@@ -0,0 +1 @@
1
+ import '@histoire/plugin-vue/components'