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,9 +1,14 @@
1
+ import type { TreeFile } from './tree.js';
1
2
  export interface StoryFile {
2
3
  id: string;
3
4
  /**
4
5
  * Absolute path
5
6
  */
6
7
  path: string;
8
+ /**
9
+ * File name without extension
10
+ */
11
+ fileName: string;
7
12
  /**
8
13
  * Generated path for tree UI
9
14
  */
@@ -16,10 +21,15 @@ export interface StoryFile {
16
21
  * Resolved story data from story file execution
17
22
  */
18
23
  story?: Story;
24
+ /**
25
+ * Data sent to user tree config functions
26
+ */
27
+ treeFile?: TreeFile;
19
28
  }
20
29
  export interface Story {
21
30
  id: string;
22
31
  title: string;
32
+ group?: string;
23
33
  variants: Variant[];
24
34
  layout?: {
25
35
  type: 'single';
@@ -29,6 +39,7 @@ export interface Story {
29
39
  };
30
40
  icon?: string;
31
41
  iconColor?: string;
42
+ docsOnly?: boolean;
32
43
  }
33
44
  export interface Variant {
34
45
  id: string;
@@ -0,0 +1 @@
1
+ export declare function findUp(cwd: string, fileNames: string[]): string;
@@ -0,0 +1,20 @@
1
+ import path from 'pathe';
2
+ import fs from 'fs';
3
+ export function findUp(cwd = process.cwd(), fileNames) {
4
+ let { root } = path.parse(cwd);
5
+ let dir = cwd;
6
+ // Fix for windows, waiting for pathe to fix this: https://github.com/unjs/pathe/issues/5
7
+ if (root === '' && dir[1] === ':') {
8
+ root = dir.substring(0, 2);
9
+ }
10
+ while (dir !== root) {
11
+ for (const fileName of fileNames) {
12
+ const searchPath = path.join(dir, fileName);
13
+ if (fs.existsSync(searchPath)) {
14
+ return searchPath;
15
+ }
16
+ }
17
+ dir = path.dirname(dir);
18
+ }
19
+ return null;
20
+ }
@@ -0,0 +1,13 @@
1
+ import { Plugin as VitePlugin } from 'vite';
2
+ import { Context } from './context.js';
3
+ export declare const STORIES_ID = "$histoire-stories";
4
+ export declare const RESOLVED_STORIES_ID: string;
5
+ export declare const SETUP_ID = "$histoire-setup";
6
+ export declare const NOOP_ID = "/$histoire-noop";
7
+ export declare const CONFIG_ID = "$histoire-config";
8
+ export declare const RESOLVED_CONFIG_ID: string;
9
+ export declare const THEME_ID = "$histoire-theme";
10
+ export declare const RESOLVED_THEME_ID: string;
11
+ export declare const SEARCH_DATA_ID = "$histoire-search-data";
12
+ export declare const RESOLVED_SEARCH_DATA_ID: string;
13
+ export declare function createVitePlugins(ctx: Context): Promise<VitePlugin[]>;
@@ -0,0 +1,278 @@
1
+ import { createRequire } from 'module';
2
+ import { relative, dirname } from 'pathe';
3
+ import { resolveConfig as resolveViteConfig } from 'vite';
4
+ import { lookup as lookupMime } from 'mrmime';
5
+ import { APP_PATH, DIST_PATH, TEMP_PATH } from './alias.js';
6
+ import { notifyStoryChange } from './stories.js';
7
+ import { makeTree } from './tree.js';
8
+ import { parseColor } from './colors.js';
9
+ import { createMarkdownRenderer } from './markdown.js';
10
+ import { generateSearchData } from './search.js';
11
+ const require = createRequire(import.meta.url);
12
+ export const STORIES_ID = '$histoire-stories';
13
+ export const RESOLVED_STORIES_ID = `/${STORIES_ID}-resolved`;
14
+ export const SETUP_ID = '$histoire-setup';
15
+ export const NOOP_ID = '/$histoire-noop';
16
+ export const CONFIG_ID = '$histoire-config';
17
+ export const RESOLVED_CONFIG_ID = `/${CONFIG_ID}-resolved`;
18
+ export const THEME_ID = '$histoire-theme';
19
+ export const RESOLVED_THEME_ID = `/${THEME_ID}-resolved.css`;
20
+ export const SEARCH_DATA_ID = '$histoire-search-data';
21
+ export const RESOLVED_SEARCH_DATA_ID = `/${SEARCH_DATA_ID}-resolved`;
22
+ export async function createVitePlugins(ctx) {
23
+ const viteConfig = await resolveViteConfig({}, ctx.mode === 'dev' ? 'serve' : 'build');
24
+ const hasVuePlugin = viteConfig.plugins.find(p => p.name === 'vite:vue');
25
+ const plugins = [];
26
+ if (!hasVuePlugin) {
27
+ plugins.push((await import('@vitejs/plugin-vue')).default());
28
+ }
29
+ if (ctx.config.vite) {
30
+ plugins.push({
31
+ name: 'histoire-vite-config-override',
32
+ config(config, env) {
33
+ return typeof ctx.config.vite === 'function' ? ctx.config.vite(config, env) : ctx.config.vite;
34
+ },
35
+ });
36
+ }
37
+ plugins.push({
38
+ name: 'histoire-vite-plugin',
39
+ config() {
40
+ return {
41
+ optimizeDeps: {
42
+ // force include vue to avoid duplicated copies when linked + optimized
43
+ include: [
44
+ 'vue',
45
+ dirname(require.resolve('@vue/runtime-core/package.json')),
46
+ dirname(require.resolve('shiki/package.json')),
47
+ dirname(require.resolve('vscode-textmate/package.json')),
48
+ dirname(require.resolve('vscode-oniguruma/package.json')),
49
+ dirname(require.resolve('case/package.json')),
50
+ ],
51
+ },
52
+ server: {
53
+ fs: {
54
+ allow: [DIST_PATH, TEMP_PATH, viteConfig.root, process.cwd()],
55
+ },
56
+ },
57
+ define: {
58
+ // We need to force this to be able to use `devtoolsRawSetupState`
59
+ __VUE_PROD_DEVTOOLS__: 'true',
60
+ },
61
+ };
62
+ },
63
+ async resolveId(id, importer) {
64
+ if (id.startsWith(STORIES_ID)) {
65
+ return RESOLVED_STORIES_ID;
66
+ }
67
+ if (id.startsWith(SETUP_ID)) {
68
+ if (ctx.config.setupFile) {
69
+ return this.resolve(ctx.config.setupFile, importer, {
70
+ skipSelf: true,
71
+ });
72
+ }
73
+ else {
74
+ return NOOP_ID;
75
+ }
76
+ }
77
+ if (id.startsWith(CONFIG_ID)) {
78
+ return RESOLVED_CONFIG_ID;
79
+ }
80
+ if (id.startsWith(THEME_ID)) {
81
+ return RESOLVED_THEME_ID;
82
+ }
83
+ if (id.startsWith(SEARCH_DATA_ID)) {
84
+ return RESOLVED_SEARCH_DATA_ID;
85
+ }
86
+ },
87
+ async load(id) {
88
+ if (id === RESOLVED_STORIES_ID) {
89
+ const resolvedStories = ctx.storyFiles.filter(s => !!s.story);
90
+ const files = resolvedStories.map((file, index) => {
91
+ return {
92
+ id: file.id,
93
+ path: file.treePath,
94
+ story: file.story,
95
+ framework: 'vue3',
96
+ index,
97
+ };
98
+ });
99
+ return `import { defineAsyncComponent } from 'vue'
100
+ ${resolvedStories.map((file, index) => `const Comp${index} = defineAsyncComponent(() => import('${file.path}'))`).join('\n')}
101
+ export let files = [${files.map((file) => `{${JSON.stringify(file).slice(1, -1)}, component: Comp${file.index}}`).join(',\n')}]
102
+ export let tree = ${JSON.stringify(makeTree(ctx.config, resolvedStories))}
103
+ const handlers = []
104
+ export function onUpdate (cb) {
105
+ handlers.push(cb)
106
+ }
107
+ if (import.meta.hot) {
108
+ import.meta.hot.accept(newModule => {
109
+ files = newModule.files
110
+ tree = newModule.tree
111
+ handlers.forEach(h => {
112
+ h(newModule.files, newModule.tree)
113
+ newModule.onUpdate(h)
114
+ })
115
+ })
116
+ }`;
117
+ }
118
+ if (id === NOOP_ID) {
119
+ return `export default () => {}`;
120
+ }
121
+ if (id === RESOLVED_CONFIG_ID) {
122
+ let js = `export const config = ${JSON.stringify(ctx.config)}\n`;
123
+ if (ctx.config.theme?.logo) {
124
+ for (const key in ctx.config.theme.logo) {
125
+ js += `import Logo_${key} from '${ctx.config.theme.logo[key]}'\n`;
126
+ }
127
+ }
128
+ js += `export const logos = {${Object.keys(ctx.config.theme?.logo ?? {}).map(key => `${key}: Logo_${key}`).join(', ')}}\n`;
129
+ return js;
130
+ }
131
+ if (id === RESOLVED_THEME_ID) {
132
+ let css = '*, ::before, ::after {';
133
+ // Colors
134
+ for (const color in ctx.config.theme?.colors ?? {}) {
135
+ for (const key in ctx.config.theme.colors[color]) {
136
+ css += `--_histoire-color-${color}-${key}: ${parseColor(ctx.config.theme.colors[color][key]).color.join(' ')};`;
137
+ }
138
+ }
139
+ css += '}';
140
+ return css;
141
+ }
142
+ if (id === RESOLVED_SEARCH_DATA_ID) {
143
+ return `export let searchData = ${JSON.stringify(await generateSearchData(ctx))}
144
+ const handlers = []
145
+ export function onUpdate (cb) {
146
+ handlers.push(cb)
147
+ }
148
+ if (import.meta.hot) {
149
+ import.meta.hot.accept(newModule => {
150
+ searchData = newModule.searchData
151
+ handlers.forEach(h => {
152
+ h(newModule.searchData)
153
+ newModule.onUpdate(h)
154
+ })
155
+ })
156
+ }`;
157
+ }
158
+ },
159
+ handleHotUpdate(updateContext) {
160
+ const story = ctx.storyFiles.find(file => file.path === updateContext.file);
161
+ if (story) {
162
+ notifyStoryChange(story);
163
+ }
164
+ },
165
+ configureServer(server) {
166
+ server.middlewares.use(async (req, res, next) => {
167
+ if (req.url.startsWith(`${server.config.base}__sandbox`)) {
168
+ res.statusCode = 200;
169
+ let html = `
170
+ <!DOCTYPE html>
171
+ <html>
172
+ <head>
173
+ <title></title>
174
+ <meta charset="utf-8">
175
+ <meta name="viewport" content="width=device-width,initial-scale=1">
176
+ <meta name="description" content="">
177
+ </head>
178
+ <body>
179
+ <div id="app"></div>
180
+ <script>
181
+ // Hide spammy vite messages
182
+ const origConsoleLog = console.log
183
+ console.log = (...args) => {
184
+ if (typeof args[0] !== 'string' || !args[0].startsWith('[vite] connect')) {
185
+ origConsoleLog(...args)
186
+ }
187
+ }
188
+ </script>
189
+ <script type="module" src="/@fs/${APP_PATH}/sandbox.js"></script>
190
+ </body>
191
+ </html>`;
192
+ // Apply Vite HTML transforms. This injects the Vite HMR client, and
193
+ // also applies HTML transforms from Vite plugins
194
+ html = await server.transformIndexHtml(req.url, html);
195
+ res.end(html);
196
+ return;
197
+ }
198
+ next();
199
+ });
200
+ // serve our index.html after vite history fallback
201
+ return () => {
202
+ server.middlewares.use(async (req, res, next) => {
203
+ if (req.url.endsWith('.html')) {
204
+ res.statusCode = 200;
205
+ let html = `
206
+ <!DOCTYPE html>
207
+ <html>
208
+ <head>
209
+ <title></title>
210
+ <link rel="icon" href=""/>
211
+ <meta charset="utf-8">
212
+ <meta name="viewport" content="width=device-width,initial-scale=1">
213
+ <meta name="description" content="">
214
+ ${ctx.config.theme?.favicon ? `<link rel="icon" type="${lookupMime(ctx.config.theme.favicon)}" href="${server.config.base}${ctx.config.theme.favicon}"/>` : ''}
215
+ </head>
216
+ <body>
217
+ <div id="app"></div>
218
+ <script type="module" src="/@fs/${APP_PATH}/index.js"></script>
219
+ </body>
220
+ </html>`;
221
+ // Apply Vite HTML transforms. This injects the Vite HMR client, and
222
+ // also applies HTML transforms from Vite plugins
223
+ html = await server.transformIndexHtml(req.url, html);
224
+ res.end(html);
225
+ return;
226
+ }
227
+ next();
228
+ });
229
+ };
230
+ },
231
+ });
232
+ // Custom blocks
233
+ plugins.push(...await createCustomBlocksPlugins(ctx));
234
+ if (ctx.mode === 'build') {
235
+ // Add file name in build mode to have components names instead of <Anonymous>
236
+ const include = [/\.vue$/];
237
+ const exclude = [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/, /[\\/]\.nuxt[\\/]/];
238
+ plugins.push({
239
+ name: 'histoire-file-name-plugin',
240
+ enforce: 'post',
241
+ transform(code, id) {
242
+ if (exclude.some(r => r.test(id)))
243
+ return;
244
+ if (include.some(r => r.test(id))) {
245
+ const file = relative(viteConfig.root, id);
246
+ const index = code.indexOf('export default');
247
+ const result = `${code.substring(0, index)}_sfc_main.__file = '${file}'\n${code.substring(index)}`;
248
+ return result;
249
+ }
250
+ },
251
+ });
252
+ }
253
+ return plugins;
254
+ }
255
+ async function createCustomBlocksPlugins(ctx) {
256
+ const plugins = [];
257
+ let md = await createMarkdownRenderer();
258
+ if (ctx.config.markdown) {
259
+ const result = await ctx.config.markdown(md);
260
+ if (result) {
261
+ md = result;
262
+ }
263
+ }
264
+ plugins.push({
265
+ name: 'histoire-vue-docs-block',
266
+ transform(code, id) {
267
+ if (!id.includes('?vue&type=docs'))
268
+ return;
269
+ if (!id.includes('lang.md'))
270
+ return;
271
+ const html = md.render(code);
272
+ return `export default Comp => {
273
+ Comp.doc = ${JSON.stringify(html)}
274
+ }`;
275
+ },
276
+ });
277
+ return plugins;
278
+ }