histoire 0.0.1 → 0.0.4

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 (186) hide show
  1. package/README.md +11 -0
  2. package/dist/client/app/App.vue +8 -8
  3. package/dist/client/app/codegen/serialize-js.js +0 -1
  4. package/dist/client/app/codegen/util.js +0 -1
  5. package/dist/client/app/codegen/vue3.js +28 -5
  6. package/dist/client/app/codegen/vue3.ts +32 -4
  7. package/dist/client/app/components/app/AppHeader.vue +10 -3
  8. package/dist/client/app/components/base/BaseTab.vue +46 -0
  9. package/dist/client/app/components/exposed/Story.vue +21 -1
  10. package/dist/client/app/components/exposed/Variant.vue +1 -0
  11. package/dist/client/app/components/misc/CheckerboardPattern.vue +32 -0
  12. package/dist/client/app/components/sandbox/SandboxVue3.vue +6 -0
  13. package/dist/client/app/components/search/SearchItem.vue +5 -9
  14. package/{src/client/app/components → dist/client/app/components/story}/StoryControls.vue +3 -3
  15. package/dist/client/app/components/story/StoryDocs.vue +37 -0
  16. package/dist/client/app/components/{StoryList.vue → story/StoryList.vue} +4 -4
  17. package/dist/client/app/components/{StoryListFolder.vue → story/StoryListFolder.vue} +13 -6
  18. package/dist/client/app/components/{StoryListItem.vue → story/StoryListItem.vue} +11 -6
  19. package/dist/client/app/components/story/StoryResponsivePreview.vue +214 -0
  20. package/{src/client/app/components → dist/client/app/components/story}/StorySourceCode.vue +4 -8
  21. package/{src/client/app/components → dist/client/app/components/story}/StoryVariantGridItem.vue +14 -6
  22. package/dist/client/app/components/{StoryVariantListItem.vue → story/StoryVariantListItem.vue} +9 -8
  23. package/dist/client/app/components/story/StoryVariantSingleView.vue +182 -0
  24. package/dist/client/app/components/{StoryView.vue → story/StoryView.vue} +37 -10
  25. package/dist/client/app/global-components.js +2 -1
  26. package/dist/client/app/global-components.ts +3 -0
  27. package/dist/client/app/index.js +10 -1
  28. package/dist/client/app/index.ts +10 -0
  29. package/dist/client/app/router.js +1 -2
  30. package/dist/client/app/router.ts +1 -1
  31. package/dist/client/app/sandbox.js +37 -4
  32. package/dist/client/app/sandbox.ts +37 -3
  33. package/dist/client/app/stores/story.d.ts +22 -1
  34. package/dist/client/app/stores/story.js +30 -2
  35. package/dist/client/app/stores/story.ts +37 -1
  36. package/dist/client/app/style/floating-vue.css +31 -0
  37. package/dist/client/app/style/main.css +17 -1
  38. package/dist/client/app/style/sandbox.css +5 -0
  39. package/dist/client/app/style/transitions.css +12 -0
  40. package/dist/client/app/types.d.ts +1 -0
  41. package/dist/client/app/types.js +0 -1
  42. package/dist/client/app/types.ts +15 -0
  43. package/dist/client/app/util/config.js +0 -1
  44. package/dist/client/app/util/const.d.ts +2 -0
  45. package/dist/client/app/util/const.js +2 -1
  46. package/dist/client/app/util/const.ts +2 -0
  47. package/dist/client/app/util/dark.js +0 -1
  48. package/dist/client/app/util/env.js +0 -1
  49. package/dist/client/app/util/env.ts +1 -0
  50. package/dist/client/app/util/keyboard.js +0 -1
  51. package/dist/client/app/util/keyboard.ts +99 -0
  52. package/dist/client/app/util/mapping.js +6 -1
  53. package/dist/client/app/util/mapping.ts +5 -0
  54. package/dist/client/app/util/preview-settings.d.ts +16 -0
  55. package/dist/client/app/util/preview-settings.js +15 -0
  56. package/dist/client/app/util/preview-settings.ts +26 -0
  57. package/dist/client/app/util/reactivity.d.ts +1 -0
  58. package/dist/client/app/util/reactivity.js +16 -0
  59. package/dist/client/app/util/reactivity.ts +22 -0
  60. package/dist/client/app/util/scroll.d.ts +2 -0
  61. package/dist/client/app/util/scroll.js +24 -0
  62. package/dist/client/app/util/scroll.ts +27 -0
  63. package/dist/client/app/util/tooltip.js +0 -1
  64. package/dist/client/app/util/tooltip.ts +13 -0
  65. package/dist/client/app/{composable → util}/variant.d.ts +0 -0
  66. package/dist/client/app/{composable → util}/variant.js +0 -1
  67. package/dist/client/app/{composable → util}/variant.ts +0 -0
  68. package/dist/client/index.js +0 -1
  69. package/dist/client/server/Story.server.vue +25 -2
  70. package/dist/client/server/index.js +2 -1
  71. package/dist/client/server/index.ts +3 -0
  72. package/dist/controls.d.ts +1 -0
  73. package/dist/controls.js +1 -0
  74. package/dist/node/alias.js +0 -1
  75. package/dist/node/bin.js +0 -1
  76. package/dist/node/build.js +13 -9
  77. package/dist/node/collect.js +12 -4
  78. package/dist/node/colors.d.ts +12 -0
  79. package/dist/node/colors.js +12 -1
  80. package/dist/node/commands/build.js +0 -1
  81. package/dist/node/commands/dev.js +43 -6
  82. package/dist/node/config.d.ts +35 -0
  83. package/dist/node/config.js +75 -2
  84. package/dist/node/context.js +0 -1
  85. package/dist/node/dom/dom-keys.js +0 -1
  86. package/dist/node/dom/env.js +0 -1
  87. package/dist/node/index.js +0 -1
  88. package/dist/node/markdown.d.ts +2 -0
  89. package/dist/node/markdown.js +48 -0
  90. package/dist/node/plugin.js +35 -1
  91. package/dist/node/server.js +0 -1
  92. package/dist/node/stories.js +0 -1
  93. package/dist/node/tree.js +0 -1
  94. package/dist/node/types.js +0 -1
  95. package/dist/node/util/slugify.d.ts +1 -0
  96. package/dist/node/util/slugify.js +22 -0
  97. package/dist/style.css +863 -157
  98. package/package.json +17 -4
  99. package/src/client/app/App.vue +8 -8
  100. package/src/client/app/codegen/vue3.ts +32 -4
  101. package/src/client/app/components/app/AppHeader.vue +10 -3
  102. package/src/client/app/components/base/BaseTab.vue +46 -0
  103. package/src/client/app/components/exposed/Story.vue +21 -1
  104. package/src/client/app/components/exposed/Variant.vue +1 -0
  105. package/src/client/app/components/misc/CheckerboardPattern.vue +32 -0
  106. package/src/client/app/components/sandbox/SandboxVue3.vue +6 -0
  107. package/src/client/app/components/search/SearchItem.vue +5 -9
  108. package/{dist/client/app/components → src/client/app/components/story}/StoryControls.vue +3 -3
  109. package/src/client/app/components/story/StoryDocs.vue +37 -0
  110. package/src/client/app/components/{StoryList.vue → story/StoryList.vue} +4 -4
  111. package/src/client/app/components/{StoryListFolder.vue → story/StoryListFolder.vue} +13 -6
  112. package/src/client/app/components/{StoryListItem.vue → story/StoryListItem.vue} +11 -6
  113. package/src/client/app/components/story/StoryResponsivePreview.vue +214 -0
  114. package/{dist/client/app/components → src/client/app/components/story}/StorySourceCode.vue +4 -8
  115. package/{dist/client/app/components → src/client/app/components/story}/StoryVariantGridItem.vue +14 -6
  116. package/src/client/app/components/{StoryVariantListItem.vue → story/StoryVariantListItem.vue} +9 -8
  117. package/src/client/app/components/story/StoryVariantSingleView.vue +182 -0
  118. package/src/client/app/components/{StoryView.vue → story/StoryView.vue} +37 -10
  119. package/src/client/app/global-components.ts +3 -0
  120. package/src/client/app/index.ts +10 -0
  121. package/src/client/app/router.ts +1 -1
  122. package/src/client/app/sandbox.ts +37 -3
  123. package/src/client/app/stores/story.ts +37 -1
  124. package/src/client/app/style/floating-vue.css +31 -0
  125. package/src/client/app/style/main.css +17 -1
  126. package/src/client/app/style/sandbox.css +5 -0
  127. package/src/client/app/style/transitions.css +12 -0
  128. package/src/client/app/types.ts +1 -0
  129. package/src/client/app/util/const.ts +2 -0
  130. package/src/client/app/util/mapping.ts +5 -0
  131. package/src/client/app/util/preview-settings.ts +26 -0
  132. package/src/client/app/util/reactivity.ts +22 -0
  133. package/src/client/app/util/scroll.ts +27 -0
  134. package/src/client/app/{composable → util}/variant.ts +0 -0
  135. package/src/client/server/Story.server.vue +25 -2
  136. package/src/client/server/index.ts +3 -0
  137. package/src/controls.ts +1 -0
  138. package/src/node/build.ts +15 -8
  139. package/src/node/collect.ts +12 -3
  140. package/src/node/colors.ts +12 -0
  141. package/src/node/commands/dev.ts +49 -5
  142. package/src/node/config.ts +112 -2
  143. package/src/node/markdown.ts +56 -0
  144. package/src/node/plugin.ts +38 -0
  145. package/src/node/tree.spec.ts +28 -0
  146. package/src/node/util/slugify.ts +26 -0
  147. package/tailwind.config.cjs +79 -4
  148. package/tsconfig.json +2 -1
  149. package/dist/client/app/codegen/serialize-js.js.map +0 -1
  150. package/dist/client/app/codegen/util.js.map +0 -1
  151. package/dist/client/app/codegen/vue3.js.map +0 -1
  152. package/dist/client/app/components/StoryVariantSingleView.vue +0 -145
  153. package/dist/client/app/composable/variant.js.map +0 -1
  154. package/dist/client/app/global-components.js.map +0 -1
  155. package/dist/client/app/index.js.map +0 -1
  156. package/dist/client/app/router.js.map +0 -1
  157. package/dist/client/app/sandbox.js.map +0 -1
  158. package/dist/client/app/stores/story.js.map +0 -1
  159. package/dist/client/app/types.js.map +0 -1
  160. package/dist/client/app/util/config.js.map +0 -1
  161. package/dist/client/app/util/const.js.map +0 -1
  162. package/dist/client/app/util/dark.js.map +0 -1
  163. package/dist/client/app/util/env.js.map +0 -1
  164. package/dist/client/app/util/keyboard.js.map +0 -1
  165. package/dist/client/app/util/mapping.js.map +0 -1
  166. package/dist/client/app/util/tooltip.js.map +0 -1
  167. package/dist/client/index.js.map +0 -1
  168. package/dist/client/server/index.js.map +0 -1
  169. package/dist/node/alias.js.map +0 -1
  170. package/dist/node/bin.js.map +0 -1
  171. package/dist/node/build.js.map +0 -1
  172. package/dist/node/collect.js.map +0 -1
  173. package/dist/node/colors.js.map +0 -1
  174. package/dist/node/commands/build.js.map +0 -1
  175. package/dist/node/commands/dev.js.map +0 -1
  176. package/dist/node/config.js.map +0 -1
  177. package/dist/node/context.js.map +0 -1
  178. package/dist/node/dom/dom-keys.js.map +0 -1
  179. package/dist/node/dom/env.js.map +0 -1
  180. package/dist/node/index.js.map +0 -1
  181. package/dist/node/plugin.js.map +0 -1
  182. package/dist/node/server.js.map +0 -1
  183. package/dist/node/stories.js.map +0 -1
  184. package/dist/node/tree.js.map +0 -1
  185. package/dist/node/types.js.map +0 -1
  186. package/src/client/app/components/StoryVariantSingleView.vue +0 -145
@@ -22,6 +22,71 @@ export function getDefaultConfig() {
22
22
  gray: defaultColors.zinc,
23
23
  },
24
24
  },
25
+ responsivePresets: [
26
+ {
27
+ label: 'Mobile (Small)',
28
+ width: 320,
29
+ height: 560,
30
+ },
31
+ {
32
+ label: 'Mobile (Medium)',
33
+ width: 360,
34
+ height: 640,
35
+ },
36
+ {
37
+ label: 'Mobile (Large)',
38
+ width: 414,
39
+ height: 896,
40
+ },
41
+ {
42
+ label: 'Tablet',
43
+ width: 768,
44
+ height: 1024,
45
+ },
46
+ {
47
+ label: 'Laptop (Small)',
48
+ width: 1024,
49
+ height: null,
50
+ },
51
+ {
52
+ label: 'Laptop (Large)',
53
+ width: 1366,
54
+ height: null,
55
+ },
56
+ {
57
+ label: 'Desktop',
58
+ width: 1920,
59
+ height: null,
60
+ },
61
+ {
62
+ label: '4K',
63
+ width: 3840,
64
+ height: null,
65
+ },
66
+ ],
67
+ backgroundPresets: [
68
+ {
69
+ label: 'Transparent',
70
+ color: 'transparent',
71
+ },
72
+ {
73
+ label: 'White',
74
+ color: '#fff',
75
+ },
76
+ {
77
+ label: 'Light gray',
78
+ color: '#aaa',
79
+ },
80
+ {
81
+ label: 'Dark gray',
82
+ color: '#333',
83
+ },
84
+ {
85
+ label: 'Black',
86
+ color: '#000',
87
+ },
88
+ ],
89
+ sandboxDarkClass: 'dark',
25
90
  };
26
91
  }
27
92
  export const configFileNames = [
@@ -52,12 +117,21 @@ export async function loadConfigFile(configFile) {
52
117
  try {
53
118
  const server = await createServer();
54
119
  await server.pluginContainer.buildStart({});
55
- const node = new ViteNodeServer(server);
120
+ const node = new ViteNodeServer(server, {
121
+ deps: {
122
+ inline: [
123
+ /histoire\/dist/,
124
+ ],
125
+ },
126
+ });
56
127
  const runner = new ViteNodeRunner({
57
128
  root: path.dirname(configFile),
58
129
  fetchModule(id) {
59
130
  return node.fetchModule(id);
60
131
  },
132
+ resolveId(id, importer) {
133
+ return node.resolveId(id, importer);
134
+ },
61
135
  });
62
136
  const result = await runner.executeFile(configFile);
63
137
  await server.close();
@@ -88,4 +162,3 @@ export function processConfig(config) {
88
162
  export function defineConfig(config) {
89
163
  return config;
90
164
  }
91
- //# sourceMappingURL=config.js.map
@@ -10,4 +10,3 @@ export async function createContext(options) {
10
10
  storyFiles: [],
11
11
  };
12
12
  }
13
- //# sourceMappingURL=context.js.map
@@ -221,4 +221,3 @@ const OTHER_KEYS = [
221
221
  'window',
222
222
  ];
223
223
  export const KEYS = LIVING_KEYS.concat(OTHER_KEYS);
224
- //# sourceMappingURL=dom-keys.js.map
@@ -20,4 +20,3 @@ export function createDomEnv() {
20
20
  destroy,
21
21
  };
22
22
  }
23
- //# sourceMappingURL=env.js.map
@@ -1,3 +1,2 @@
1
1
  export * from './config.js';
2
2
  export { defaultColors } from './colors.js';
3
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ import MarkdownIt from 'markdown-it';
2
+ export declare function createMarkdownRenderer(): Promise<MarkdownIt>;
@@ -0,0 +1,48 @@
1
+ import MarkdownIt from 'markdown-it';
2
+ import shiki from 'shiki';
3
+ import anchor from 'markdown-it-anchor';
4
+ import attrs from 'markdown-it-attrs';
5
+ import emoji from 'markdown-it-emoji';
6
+ import { slugify } from './util/slugify.js';
7
+ export async function createMarkdownRenderer() {
8
+ const highlighter = await shiki.getHighlighter({
9
+ theme: 'github-dark',
10
+ });
11
+ const md = new MarkdownIt({
12
+ highlight: (code, lang) => `<div class="htw-relative htw-not-prose __histoire-code"><div class="htw-absolute htw-top-0 htw-right-0 htw-text-xs htw-text-white/40">${lang}</div>${highlighter.codeToHtml(code, {
13
+ lang,
14
+ })}</div>`,
15
+ linkify: true,
16
+ html: true,
17
+ breaks: true,
18
+ });
19
+ md.use(anchor, {
20
+ slugify,
21
+ permalink: anchor.permalink.ariaHidden({}),
22
+ })
23
+ .use(attrs)
24
+ .use(emoji);
25
+ // External links
26
+ {
27
+ const defaultRender = md.renderer.rules.link_open || function (tokens, idx, options, env, self) {
28
+ return self.renderToken(tokens, idx, options);
29
+ };
30
+ md.renderer.rules.link_open = function (tokens, idx, options, env, self) {
31
+ const hrefIndex = tokens[idx].attrIndex('href');
32
+ const classIndex = tokens[idx].attrIndex('class');
33
+ if (hrefIndex >= 0 && !tokens[idx].attrs[hrefIndex][1].startsWith('/') && (classIndex < 0 || !tokens[idx].attrs[classIndex][1].includes('header-anchor'))) {
34
+ // If you are sure other plugins can't add `target` - drop check below
35
+ const aIndex = tokens[idx].attrIndex('target');
36
+ if (aIndex < 0) {
37
+ tokens[idx].attrPush(['target', '_blank']); // add new attribute
38
+ }
39
+ else {
40
+ tokens[idx].attrs[aIndex][1] = '_blank'; // replace value of existing attr
41
+ }
42
+ }
43
+ // pass token to default renderer.
44
+ return defaultRender(tokens, idx, options, env, self);
45
+ };
46
+ }
47
+ return md;
48
+ }
@@ -5,6 +5,7 @@ import { APP_PATH, DIST_CLIENT_PATH } from './alias.js';
5
5
  import { notifyStoryChange } from './stories.js';
6
6
  import { makeTree } from './tree.js';
7
7
  import { parseColor } from './colors.js';
8
+ import { createMarkdownRenderer } from './markdown.js';
8
9
  export const STORIES_ID = '$histoire-stories';
9
10
  export const RESOLVED_STORIES_ID = `/${STORIES_ID}-resolved`;
10
11
  export const SETUP_ID = '$histoire-setup';
@@ -20,6 +21,14 @@ export async function createVitePlugins(ctx) {
20
21
  if (!hasVuePlugin) {
21
22
  plugins.push((await import('@vitejs/plugin-vue')).default());
22
23
  }
24
+ if (ctx.config.vite) {
25
+ plugins.push({
26
+ name: 'histoire-vite-config-override',
27
+ config(config, env) {
28
+ return typeof ctx.config.vite === 'function' ? ctx.config.vite(config, env) : ctx.config.vite;
29
+ },
30
+ });
31
+ }
23
32
  plugins.push({
24
33
  name: 'histoire-vite-plugin',
25
34
  config() {
@@ -180,6 +189,8 @@ if (import.meta.hot) {
180
189
  };
181
190
  },
182
191
  });
192
+ // Custom blocks
193
+ plugins.push(...await createCustomBlocksPlugins(ctx));
183
194
  if (ctx.mode === 'build') {
184
195
  // Add file name in build mode to have components names instead of <Anonymous>
185
196
  const include = [/\.vue$/];
@@ -201,4 +212,27 @@ if (import.meta.hot) {
201
212
  }
202
213
  return plugins;
203
214
  }
204
- //# sourceMappingURL=plugin.js.map
215
+ async function createCustomBlocksPlugins(ctx) {
216
+ const plugins = [];
217
+ let md = await createMarkdownRenderer();
218
+ if (ctx.config.markdown) {
219
+ const result = await ctx.config.markdown(md);
220
+ if (result) {
221
+ md = result;
222
+ }
223
+ }
224
+ plugins.push({
225
+ name: 'histoire-vue-docs-block',
226
+ transform(code, id) {
227
+ if (!id.includes('?vue&type=docs'))
228
+ return;
229
+ if (!id.includes('lang.md'))
230
+ return;
231
+ const html = md.render(code);
232
+ return `export default Comp => {
233
+ Comp.doc = ${JSON.stringify(html)}
234
+ }`;
235
+ },
236
+ });
237
+ return plugins;
238
+ }
@@ -93,4 +93,3 @@ export async function createServer(ctx, port) {
93
93
  close,
94
94
  };
95
95
  }
96
- //# sourceMappingURL=server.js.map
@@ -60,4 +60,3 @@ export async function findAllStories(newContext) {
60
60
  addStory(file);
61
61
  }
62
62
  }
63
- //# sourceMappingURL=stories.js.map
package/dist/node/tree.js CHANGED
@@ -52,4 +52,3 @@ export function makeTree(config, files) {
52
52
  return tree;
53
53
  }
54
54
  }
55
- //# sourceMappingURL=tree.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ export declare const slugify: (str: string) => string;
@@ -0,0 +1,22 @@
1
+ // From vitepress
2
+ // string.js slugify drops non ascii chars so we have to
3
+ // use a custom implementation here
4
+ import { remove as removeDiacritics } from 'diacritics';
5
+ // eslint-disable-next-line no-control-regex
6
+ const rControl = /[\u0000-\u001f]/g;
7
+ const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.?/]+/g;
8
+ export const slugify = (str) => {
9
+ return (removeDiacritics(str)
10
+ // Remove control characters
11
+ .replace(rControl, '')
12
+ // Replace special characters
13
+ .replace(rSpecial, '-')
14
+ // Remove continuous separators
15
+ .replace(/-{2,}/g, '-')
16
+ // Remove prefixing and trailing separators
17
+ .replace(/^-+|-+$/g, '')
18
+ // ensure it doesn't start with a number (#121)
19
+ .replace(/^(\d)/, '_$1')
20
+ // lowercase
21
+ .toLowerCase());
22
+ };