histoire 0.0.0 → 0.0.3

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 (204) hide show
  1. package/LICENSE +21 -0
  2. package/client.d.ts +2 -0
  3. package/dist/client/app/App.vue +84 -21
  4. package/dist/client/app/assets/histoire-text-dark.svg +89 -0
  5. package/dist/client/app/assets/histoire-text.svg +89 -0
  6. package/dist/client/app/assets/histoire.svg +51 -0
  7. package/dist/client/app/codegen/serialize-js.d.ts +1 -0
  8. package/dist/client/app/codegen/serialize-js.js +113 -0
  9. package/dist/client/app/codegen/serialize-js.ts +119 -0
  10. package/dist/client/app/codegen/util.d.ts +10 -0
  11. package/dist/client/app/codegen/util.js +70 -0
  12. package/dist/client/app/codegen/util.ts +79 -0
  13. package/dist/client/app/codegen/vue3.d.ts +2 -0
  14. package/dist/client/app/codegen/vue3.js +238 -0
  15. package/dist/client/app/codegen/vue3.ts +240 -0
  16. package/dist/client/app/components/HomeView.vue +15 -1
  17. package/dist/client/app/components/StoryControls.vue +7 -2
  18. package/dist/client/app/components/StoryList.vue +20 -13
  19. package/dist/client/app/components/StoryListFolder.vue +87 -0
  20. package/dist/client/app/components/StoryListItem.vue +38 -12
  21. package/dist/client/app/components/StorySourceCode.vue +121 -0
  22. package/dist/client/app/components/StoryVariantGridItem.vue +32 -17
  23. package/dist/client/app/components/StoryVariantListItem.vue +46 -0
  24. package/dist/client/app/components/StoryVariantSingleView.vue +145 -15
  25. package/dist/client/app/components/StoryView.vue +88 -54
  26. package/dist/client/app/components/app/AppHeader.vue +56 -0
  27. package/dist/client/app/components/app/AppLogo.vue +24 -0
  28. package/dist/client/app/components/base/BaseEmpty.vue +1 -1
  29. package/dist/client/app/components/base/BaseListItemLink.vue +55 -0
  30. package/dist/client/app/components/base/BaseSplitPane.vue +57 -21
  31. package/dist/client/app/components/exposed/Story.vue +23 -58
  32. package/dist/client/app/components/exposed/Variant.vue +24 -47
  33. package/dist/client/app/components/misc/HatchedPattern.vue +25 -0
  34. package/dist/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
  35. package/dist/client/app/components/search/SearchItem.vue +110 -0
  36. package/dist/client/app/components/search/SearchModal.vue +179 -0
  37. package/dist/client/app/composable/variant.js +0 -1
  38. package/dist/client/app/composable/variant.ts +20 -0
  39. package/dist/client/app/global-components.js +0 -1
  40. package/dist/client/app/global-components.ts +10 -0
  41. package/dist/client/app/index.d.ts +1 -0
  42. package/dist/client/app/index.js +10 -2
  43. package/dist/client/app/index.ts +24 -0
  44. package/dist/client/app/router.js +0 -1
  45. package/dist/client/app/router.ts +17 -0
  46. package/dist/client/app/sandbox.d.ts +1 -0
  47. package/dist/client/app/sandbox.js +53 -0
  48. package/dist/client/app/sandbox.ts +60 -0
  49. package/dist/client/app/stores/story.d.ts +167 -50
  50. package/dist/client/app/stores/story.js +33 -16
  51. package/dist/client/app/stores/story.ts +58 -0
  52. package/dist/client/app/style/floating-vue.css +31 -0
  53. package/dist/client/app/style/main.css +17 -2
  54. package/dist/client/app/style/sandbox.css +14 -0
  55. package/dist/client/app/types.d.ts +36 -4
  56. package/dist/client/app/types.js +0 -1
  57. package/dist/client/app/types.ts +59 -0
  58. package/dist/client/app/util/config.d.ts +3 -0
  59. package/dist/client/app/util/config.js +4 -0
  60. package/dist/client/app/util/config.ts +6 -0
  61. package/dist/client/app/util/const.d.ts +1 -0
  62. package/dist/client/app/util/const.js +1 -0
  63. package/dist/client/app/util/const.ts +1 -0
  64. package/dist/client/app/util/dark.d.ts +2 -0
  65. package/dist/client/app/util/dark.js +3 -0
  66. package/dist/client/app/util/dark.ts +4 -0
  67. package/dist/client/app/util/env.d.ts +1 -0
  68. package/dist/client/app/util/env.js +1 -0
  69. package/dist/client/app/util/env.ts +1 -0
  70. package/dist/client/app/util/keyboard.d.ts +8 -0
  71. package/dist/client/app/util/keyboard.js +82 -0
  72. package/dist/client/app/util/keyboard.ts +99 -0
  73. package/dist/client/app/util/mapping.d.ts +3 -0
  74. package/dist/client/app/util/mapping.js +39 -0
  75. package/dist/client/app/util/mapping.ts +41 -0
  76. package/dist/client/app/util/tooltip.d.ts +6 -0
  77. package/dist/client/app/util/tooltip.js +11 -0
  78. package/dist/client/app/util/tooltip.ts +13 -0
  79. package/dist/client/index.d.ts +8 -0
  80. package/dist/client/index.js +3 -0
  81. package/dist/client/index.ts +12 -0
  82. package/dist/client/server/Story.server.vue +65 -0
  83. package/dist/client/server/Variant.server.vue +50 -0
  84. package/dist/client/server/index.d.ts +2 -0
  85. package/dist/client/server/index.js +25 -0
  86. package/dist/client/server/index.ts +29 -0
  87. package/dist/client/shim.d.ts +5 -0
  88. package/dist/node/alias.js +0 -1
  89. package/dist/node/bin.js +8 -3
  90. package/dist/node/build.d.ts +2 -0
  91. package/dist/node/build.js +71 -0
  92. package/dist/node/collect.d.ts +12 -0
  93. package/dist/node/collect.js +65 -0
  94. package/dist/node/colors.d.ts +286 -0
  95. package/dist/node/colors.js +324 -0
  96. package/dist/node/commands/build.d.ts +1 -0
  97. package/dist/node/commands/build.js +10 -0
  98. package/dist/node/commands/dev.d.ts +1 -1
  99. package/dist/node/commands/dev.js +45 -13
  100. package/dist/node/config.d.ts +112 -1
  101. package/dist/node/config.js +124 -2
  102. package/dist/node/context.d.ts +13 -0
  103. package/dist/node/context.js +12 -2
  104. package/dist/node/dom/dom-keys.d.ts +4 -0
  105. package/dist/node/dom/dom-keys.js +223 -0
  106. package/dist/node/dom/env.d.ts +5 -0
  107. package/dist/node/dom/env.js +22 -0
  108. package/dist/node/index.d.ts +2 -0
  109. package/dist/node/index.js +2 -2
  110. package/dist/node/plugin.d.ts +8 -2
  111. package/dist/node/plugin.js +150 -22
  112. package/dist/node/server.d.ts +4 -1
  113. package/dist/node/server.js +80 -21
  114. package/dist/node/stories.d.ts +8 -9
  115. package/dist/node/stories.js +42 -23
  116. package/dist/node/tree.d.ts +19 -0
  117. package/dist/node/tree.js +54 -0
  118. package/dist/node/types.d.ts +38 -0
  119. package/dist/node/types.js +1 -0
  120. package/dist/style.css +610 -53
  121. package/package.json +45 -25
  122. package/scripts/copy.mjs +11 -0
  123. package/src/client/app/App.vue +84 -21
  124. package/src/client/app/assets/histoire-text-dark.svg +89 -0
  125. package/src/client/app/assets/histoire-text.svg +89 -0
  126. package/src/client/app/assets/histoire.svg +51 -0
  127. package/src/client/app/codegen/serialize-js.ts +119 -0
  128. package/src/client/app/codegen/util.ts +79 -0
  129. package/src/client/app/codegen/vue3.ts +240 -0
  130. package/src/client/app/components/HomeView.vue +15 -1
  131. package/src/client/app/components/StoryControls.vue +7 -2
  132. package/src/client/app/components/StoryList.vue +20 -13
  133. package/src/client/app/components/StoryListFolder.vue +87 -0
  134. package/src/client/app/components/StoryListItem.vue +38 -12
  135. package/src/client/app/components/StorySourceCode.vue +121 -0
  136. package/src/client/app/components/StoryVariantGridItem.vue +32 -17
  137. package/src/client/app/components/StoryVariantListItem.vue +46 -0
  138. package/src/client/app/components/StoryVariantSingleView.vue +145 -15
  139. package/src/client/app/components/StoryView.vue +88 -54
  140. package/src/client/app/components/app/AppHeader.vue +56 -0
  141. package/src/client/app/components/app/AppLogo.vue +24 -0
  142. package/src/client/app/components/base/BaseEmpty.vue +1 -1
  143. package/src/client/app/components/base/BaseListItemLink.vue +55 -0
  144. package/src/client/app/components/base/BaseSplitPane.vue +57 -21
  145. package/src/client/app/components/exposed/Story.vue +23 -58
  146. package/src/client/app/components/exposed/Variant.vue +24 -47
  147. package/src/client/app/components/misc/HatchedPattern.vue +25 -0
  148. package/src/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
  149. package/src/client/app/components/search/SearchItem.vue +110 -0
  150. package/src/client/app/components/search/SearchModal.vue +179 -0
  151. package/src/client/app/index.ts +10 -1
  152. package/src/client/app/sandbox.ts +60 -0
  153. package/src/client/app/stores/story.ts +39 -15
  154. package/src/client/app/style/floating-vue.css +31 -0
  155. package/src/client/app/style/main.css +17 -2
  156. package/src/client/app/style/sandbox.css +14 -0
  157. package/src/client/app/types.ts +42 -4
  158. package/src/client/app/util/config.ts +6 -0
  159. package/src/client/app/util/const.ts +1 -0
  160. package/src/client/app/util/dark.ts +4 -0
  161. package/src/client/app/util/env.ts +1 -0
  162. package/src/client/app/util/keyboard.ts +99 -0
  163. package/src/client/app/util/mapping.ts +41 -0
  164. package/src/client/app/util/tooltip.ts +13 -0
  165. package/src/client/index.ts +12 -0
  166. package/src/client/server/Story.server.vue +65 -0
  167. package/src/client/server/Variant.server.vue +50 -0
  168. package/src/client/server/index.ts +29 -0
  169. package/src/node/bin.ts +9 -2
  170. package/src/node/build.ts +80 -0
  171. package/src/node/collect.ts +78 -0
  172. package/src/node/colors.ts +340 -0
  173. package/src/node/commands/build.ts +12 -0
  174. package/src/node/commands/dev.ts +49 -12
  175. package/src/node/config.ts +240 -1
  176. package/src/node/context.ts +21 -1
  177. package/src/node/dom/dom-keys.ts +227 -0
  178. package/src/node/dom/env.ts +26 -0
  179. package/src/node/index.ts +2 -0
  180. package/src/node/plugin.ts +155 -22
  181. package/src/node/server.ts +95 -20
  182. package/src/node/stories.ts +53 -31
  183. package/src/node/tree.spec.ts +28 -0
  184. package/src/node/tree.ts +88 -0
  185. package/src/node/types.ts +40 -0
  186. package/tailwind.config.cjs +41 -1
  187. package/tsconfig.json +2 -1
  188. package/dist/client/app/components/StoryVariantItem.vue +0 -29
  189. package/dist/client/app/composable/variant.js.map +0 -1
  190. package/dist/client/app/global-components.js.map +0 -1
  191. package/dist/client/app/index.js.map +0 -1
  192. package/dist/client/app/router.js.map +0 -1
  193. package/dist/client/app/stores/story.js.map +0 -1
  194. package/dist/client/app/types.js.map +0 -1
  195. package/dist/node/alias.js.map +0 -1
  196. package/dist/node/bin.js.map +0 -1
  197. package/dist/node/commands/dev.js.map +0 -1
  198. package/dist/node/config.js.map +0 -1
  199. package/dist/node/context.js.map +0 -1
  200. package/dist/node/index.js.map +0 -1
  201. package/dist/node/plugin.js.map +0 -1
  202. package/dist/node/server.js.map +0 -1
  203. package/dist/node/stories.js.map +0 -1
  204. package/src/client/app/components/StoryVariantItem.vue +0 -29
@@ -1,43 +1,62 @@
1
1
  import chokidar from 'chokidar';
2
2
  import { globby } from 'globby';
3
3
  import Case from 'case';
4
- export const stories = [];
4
+ import { join } from 'pathe';
5
5
  const handlers = [];
6
+ let context;
6
7
  export function onStoryChange(handler) {
7
8
  handlers.push(handler);
8
9
  }
9
- export async function watchStories(ctx) {
10
- const watcher = chokidar.watch(ctx.config.storyMatch, {
11
- cwd: ctx.config.sourceDir,
10
+ export async function watchStories(newContext) {
11
+ context = newContext;
12
+ const watcher = chokidar.watch(context.config.storyMatch, {
13
+ cwd: context.root,
14
+ ignored: context.config.storyIgnored,
12
15
  });
13
- watcher.on('add', (file) => {
14
- addStory(file);
15
- notifyChange();
16
- });
17
- watcher.on('unlink', (file) => {
18
- stories.splice(stories.findIndex((story) => story.file === file), 1);
19
- notifyChange();
16
+ watcher
17
+ .on('add', (file) => {
18
+ const storyFile = addStory(file);
19
+ setTimeout(() => notifyStoryChange(storyFile), 100); // Delay in case file renaming fired Add event before Unlink event
20
+ })
21
+ .on('unlink', (file) => {
22
+ removeStory(file);
23
+ notifyStoryChange();
20
24
  });
21
25
  return watcher;
22
26
  }
23
- function notifyChange() {
27
+ export function notifyStoryChange(file) {
24
28
  for (const handler of handlers) {
25
- handler();
29
+ handler(file);
26
30
  }
27
31
  }
28
- function addStory(file) {
29
- stories.push({
30
- id: Case.kebab(file),
31
- file,
32
- });
32
+ function getAbsoluteFilePath(relativeFilePath) {
33
+ return join(context.root, relativeFilePath);
34
+ }
35
+ function addStory(relativeFilePath) {
36
+ const absoluteFilePath = getAbsoluteFilePath(relativeFilePath);
37
+ const fileId = Case.kebab(relativeFilePath);
38
+ const file = {
39
+ id: fileId,
40
+ path: absoluteFilePath,
41
+ moduleId: `/${relativeFilePath}`,
42
+ };
43
+ context.storyFiles.push(file);
44
+ return file;
45
+ }
46
+ function removeStory(relativeFilePath) {
47
+ const fileId = Case.kebab(relativeFilePath);
48
+ const index = context.storyFiles.findIndex((file) => file.id === fileId);
49
+ if (index !== -1)
50
+ context.storyFiles.splice(index, 1);
33
51
  }
34
- export async function findStories(ctx) {
35
- const files = await globby(ctx.config.storyMatch, {
36
- cwd: ctx.config.sourceDir,
52
+ export async function findAllStories(newContext) {
53
+ context = newContext;
54
+ const files = await globby(context.config.storyMatch, {
55
+ cwd: context.root,
56
+ ignore: context.config.storyIgnored,
37
57
  });
38
- stories.splice(0, stories.length);
58
+ context.storyFiles.length = 0;
39
59
  for (const file of files) {
40
60
  addStory(file);
41
61
  }
42
62
  }
43
- //# sourceMappingURL=stories.js.map
@@ -0,0 +1,19 @@
1
+ import { HistoireConfig } from './config.js';
2
+ export declare type TreeFile = {
3
+ title: string;
4
+ path: string;
5
+ };
6
+ export declare type TreeLeaf = {
7
+ title: string;
8
+ index: number;
9
+ };
10
+ export declare type TreeFolder = {
11
+ title: string;
12
+ children: (TreeFolder | TreeLeaf)[];
13
+ };
14
+ export declare type Tree = (TreeFolder | TreeLeaf)[];
15
+ export declare function createPath(config: HistoireConfig, file: TreeFile): string[];
16
+ export declare function makeTree(config: HistoireConfig, files: {
17
+ path: string[];
18
+ index: number;
19
+ }[]): Tree;
@@ -0,0 +1,54 @@
1
+ export function createPath(config, file) {
2
+ if (config.tree.file === 'title') {
3
+ return file.title.split('/');
4
+ }
5
+ if (config.tree.file === 'path') {
6
+ const path = file.path.split('/');
7
+ path.pop();
8
+ path.push(file.title);
9
+ return path;
10
+ }
11
+ return config.tree.file(file);
12
+ }
13
+ export function makeTree(config, files) {
14
+ const treeObject = {};
15
+ for (const file of files) {
16
+ setPath(file.path, file.index, treeObject);
17
+ }
18
+ let sortingFunction = (a, b) => a.localeCompare(b);
19
+ if (config.tree.order !== 'asc') {
20
+ sortingFunction = config.tree.order;
21
+ }
22
+ return buildTree(treeObject);
23
+ // Undefined behavior for folder and file that share the same name under the same directory
24
+ function setPath(path, value, tree) {
25
+ path.reduce((subtree, key, i) => {
26
+ if (!subtree[key]) {
27
+ subtree[key] = {};
28
+ }
29
+ if (i === path.length - 1) {
30
+ subtree[key] = value;
31
+ }
32
+ return subtree[key];
33
+ }, tree);
34
+ }
35
+ function buildTree(treeObject) {
36
+ const tree = [];
37
+ for (const [key, element] of Object.entries(treeObject)) {
38
+ if (Number.isInteger(element)) {
39
+ tree.push({
40
+ title: key,
41
+ index: element,
42
+ });
43
+ }
44
+ else {
45
+ tree.push({
46
+ title: key,
47
+ children: buildTree(element),
48
+ });
49
+ }
50
+ }
51
+ tree.sort((a, b) => sortingFunction(a.title, b.title));
52
+ return tree;
53
+ }
54
+ }
@@ -0,0 +1,38 @@
1
+ export interface StoryFile {
2
+ id: string;
3
+ /**
4
+ * Absolute path
5
+ */
6
+ path: string;
7
+ /**
8
+ * Generated path for tree UI
9
+ */
10
+ treePath?: string[];
11
+ /**
12
+ * Use the module id in imports to allow HMR
13
+ */
14
+ moduleId: string;
15
+ /**
16
+ * Resolved story data from story file execution
17
+ */
18
+ story?: Story;
19
+ }
20
+ export interface Story {
21
+ id: string;
22
+ title: string;
23
+ variants: Variant[];
24
+ layout?: {
25
+ type: 'single';
26
+ } | {
27
+ type: 'grid';
28
+ width: number;
29
+ };
30
+ icon?: string;
31
+ iconColor?: string;
32
+ }
33
+ export interface Variant {
34
+ id: string;
35
+ title: string;
36
+ icon?: string;
37
+ iconColor?: string;
38
+ }
@@ -0,0 +1 @@
1
+ export {};