histoire 0.4.5 → 0.5.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 (67) hide show
  1. package/client.d.ts +2 -0
  2. package/dist/bundled/HomeView.js +1 -0
  3. package/dist/bundled/MobileOverlay.js +3 -1
  4. package/dist/bundled/SandboxVue3.js +649 -0
  5. package/dist/bundled/SearchPane.js +2 -0
  6. package/dist/bundled/StoryView.js +551 -622
  7. package/dist/bundled/global-components.js +5 -5
  8. package/dist/bundled/index2.js +111 -43
  9. package/dist/bundled/sandbox.js +3 -11
  10. package/dist/bundled/state.js +55 -0
  11. package/dist/client/app/App.vue +18 -0
  12. package/dist/client/app/codegen/serialize-js.js +1 -1
  13. package/dist/client/app/codegen/vue3.d.ts +2 -0
  14. package/dist/client/app/codegen/vue3.js +37 -12
  15. package/dist/client/app/components/app/InitialLoading.vue +46 -0
  16. package/dist/client/app/components/app/MobileOverlay.vue +1 -1
  17. package/dist/client/app/components/base/BaseSelect.vue +72 -0
  18. package/dist/client/app/components/exposed/Story.vue +2 -1
  19. package/dist/client/app/components/exposed/Variant.vue +4 -4
  20. package/dist/client/app/components/panel/ControlsComponentPropItem.vue +96 -0
  21. package/dist/client/app/components/panel/ControlsComponentProps.vue +33 -0
  22. package/dist/client/app/components/panel/StatePresets.vue +195 -0
  23. package/dist/client/app/components/panel/StoryControls.vue +31 -2
  24. package/dist/client/app/components/sandbox/SandboxVue3.vue +70 -2
  25. package/dist/client/app/components/story/StoryVariantSinglePreviewRemote.vue +2 -14
  26. package/dist/client/app/sandbox.js +2 -11
  27. package/dist/client/app/style/transitions.pcss +12 -0
  28. package/dist/client/app/types.d.ts +19 -7
  29. package/dist/client/app/util/state.d.ts +5 -0
  30. package/dist/client/app/util/state.js +55 -0
  31. package/dist/client/app/util/variant.d.ts +1 -1
  32. package/dist/node/build.js +1 -3
  33. package/dist/node/collect/index.js +6 -0
  34. package/dist/node/config.d.ts +23 -23
  35. package/dist/node/plugin.d.ts +2 -2
  36. package/dist/node/server.js +16 -5
  37. package/dist/style.css +162 -50
  38. package/index.d.ts +3 -0
  39. package/package.json +4 -4
  40. package/src/client/app/App.vue +18 -0
  41. package/src/client/app/codegen/serialize-js.ts +1 -1
  42. package/src/client/app/codegen/vue3.ts +40 -12
  43. package/src/client/app/components/app/InitialLoading.vue +46 -0
  44. package/src/client/app/components/app/MobileOverlay.vue +1 -1
  45. package/src/client/app/components/base/BaseSelect.vue +72 -0
  46. package/src/client/app/components/exposed/Story.vue +2 -1
  47. package/src/client/app/components/exposed/Variant.vue +4 -4
  48. package/src/client/app/components/panel/ControlsComponentPropItem.vue +96 -0
  49. package/src/client/app/components/panel/ControlsComponentProps.vue +33 -0
  50. package/src/client/app/components/panel/StatePresets.vue +195 -0
  51. package/src/client/app/components/panel/StoryControls.vue +31 -2
  52. package/src/client/app/components/sandbox/SandboxVue3.vue +70 -2
  53. package/src/client/app/components/story/StoryVariantSinglePreviewRemote.vue +2 -14
  54. package/src/client/app/sandbox.ts +2 -10
  55. package/src/client/app/style/transitions.pcss +12 -0
  56. package/src/client/app/types.ts +22 -7
  57. package/src/client/app/util/state.ts +61 -0
  58. package/src/client/app/util/variant.ts +1 -1
  59. package/src/components.d.ts +135 -0
  60. package/src/node/build.ts +1 -3
  61. package/src/node/collect/index.ts +7 -0
  62. package/src/node/server.ts +20 -5
  63. package/dist/bundled/dark.js +0 -4
  64. package/dist/bundled/reactivity.js +0 -96
  65. package/dist/client/app/util/reactivity.d.ts +0 -1
  66. package/dist/client/app/util/reactivity.js +0 -16
  67. package/src/client/app/util/reactivity.ts +0 -22
@@ -11,7 +11,7 @@ import { PREVIEW_SETTINGS_SYNC, STATE_SYNC, SANDBOX_READY } from './util/const.j
11
11
  import { applyPreviewSettings } from './util/preview-settings.js'
12
12
  import { isDark } from './util/dark.js'
13
13
  import { histoireConfig } from './util/config.js'
14
- import { toRawDeep } from './util/reactivity'
14
+ import { applyStateToVariant, toRawDeep } from './util/state'
15
15
 
16
16
  const query = parseQuery(window.location.search)
17
17
  const file = ref<StoryFile>(mapFile(files.find(f => f.id === query.storyId)))
@@ -30,15 +30,7 @@ const app = createApp({
30
30
  if (event.data?.type === STATE_SYNC) {
31
31
  if (!mounted) return
32
32
  synced = true
33
- if (variant.value.state) {
34
- for (const key in event.data.state) {
35
- if (typeof variant.value.state[key] === 'object') {
36
- Object.assign(variant.value.state[key], event.data.state[key])
37
- } else {
38
- variant.value.state[key] = event.data.state[key]
39
- }
40
- }
41
- }
33
+ applyStateToVariant(variant.value, event.data.state)
42
34
  } else if (event.data?.type === PREVIEW_SETTINGS_SYNC) {
43
35
  applyPreviewSettings(event.data.settings)
44
36
  }
@@ -25,6 +25,18 @@
25
25
  }
26
26
 
27
27
  .__histoire-fade {
28
+ &-enter-active,
29
+ &-leave-active {
30
+ transition: opacity .15s;
31
+ }
32
+
33
+ &-enter-from,
34
+ &-leave-to {
35
+ opacity: 0;
36
+ }
37
+ }
38
+
39
+ .__histoire-fade-bottom {
28
40
  &-enter-active,
29
41
  &-leave-active {
30
42
  transition: transform .15s, opacity .15s;
@@ -9,18 +9,20 @@ export interface StoryFile {
9
9
  path: string[]
10
10
  }
11
11
 
12
+ export type StoryLayout = {
13
+ type: 'single'
14
+ iframe?: boolean
15
+ } | {
16
+ type: 'grid'
17
+ width?: number | string
18
+ }
19
+
12
20
  export interface Story {
13
21
  id: string
14
22
  title: string
15
23
  group?: string
16
24
  variants: Variant[]
17
- layout?: {
18
- type: 'single'
19
- iframe?: boolean
20
- } | {
21
- type: 'grid'
22
- width?: number | string
23
- }
25
+ layout?: StoryLayout
24
26
  icon?: string
25
27
  iconColor?: string
26
28
  docsOnly?: boolean
@@ -81,3 +83,16 @@ export interface PreviewSettings {
81
83
  backgroundColor: string
82
84
  checkerboard: boolean
83
85
  }
86
+
87
+ export interface PropDefinition {
88
+ name: string
89
+ types?: string[]
90
+ required?: boolean
91
+ default?: any
92
+ }
93
+
94
+ export interface AutoPropComponentDefinition {
95
+ name: string
96
+ index: number
97
+ props: PropDefinition[]
98
+ }
@@ -0,0 +1,61 @@
1
+ import { unref, isRef } from 'vue'
2
+ import type { Variant } from '../types'
3
+
4
+ const isObject = (val) => val !== null && typeof val === 'object'
5
+
6
+ export function toRawDeep (val) {
7
+ const unwrappedValue = isRef(val) ? unref(val) : val
8
+
9
+ if (!isObject(unwrappedValue)) {
10
+ return unwrappedValue
11
+ }
12
+
13
+ if (Array.isArray(unwrappedValue)) {
14
+ return unwrappedValue.map(toRawDeep)
15
+ }
16
+
17
+ return toRawObject(unwrappedValue)
18
+ }
19
+
20
+ const toRawObject = (obj: Record<any, any>) => Object.keys(obj).reduce((raw, key) => {
21
+ raw[key] = toRawDeep(obj[key])
22
+ return raw
23
+ }, {})
24
+
25
+ export function clone (data) {
26
+ try {
27
+ return structuredClone(data)
28
+ } catch (e) {
29
+ console.warn(e, `Fallback to JSON cloning`)
30
+ try {
31
+ return JSON.parse(JSON.stringify(data))
32
+ } catch (e) {
33
+ console.error(e)
34
+ }
35
+ return data
36
+ }
37
+ }
38
+
39
+ export function omit (data, keys: string[]) {
40
+ const copy = {}
41
+ for (const key in data) {
42
+ if (!keys.includes(key)) {
43
+ copy[key] = data[key]
44
+ }
45
+ }
46
+ return copy
47
+ }
48
+
49
+ export function applyStateToVariant (variant: Variant, state: any) {
50
+ if (variant.state) {
51
+ for (const key in state) {
52
+ if (variant.state[key] && !key.startsWith('_h') && typeof variant.state[key] === 'object' && !Array.isArray(variant.state[key])) {
53
+ Object.assign(variant.state[key], state[key])
54
+ } else {
55
+ variant.state[key] = state[key]
56
+ }
57
+ }
58
+ } else {
59
+ variant.state = state
60
+ }
61
+ }
@@ -1,6 +1,6 @@
1
1
  import { computed, Ref } from 'vue'
2
2
  import { useRoute } from 'vue-router'
3
- import { Variant } from '../types'
3
+ import type { Variant } from '../types'
4
4
 
5
5
  export function useCurrentVariantRoute (variant: Ref<Variant>) {
6
6
  const route = useRoute()
@@ -0,0 +1,135 @@
1
+ /* eslint-disable @typescript-eslint/ban-types */
2
+
3
+ import type {
4
+ StoryLayout,
5
+ Story,
6
+ Variant,
7
+ } from './dist/client/app/types'
8
+ import type {
9
+ HstCheckbox,
10
+ HstText,
11
+ HstTextarea,
12
+ HstNumber,
13
+ HstTokenGrid,
14
+ HstTokenList,
15
+ HstColorShades,
16
+ } from '@histoire/controls'
17
+
18
+ declare type NonUndefinedable<T> = T extends undefined ? never : T
19
+ declare type TypePropsToRuntimeProps<T> = {
20
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
21
+ type: import('vue').PropType<NonUndefinedable<T[K]>>
22
+ } : {
23
+ type: import('vue').PropType<T[K]>
24
+ required: true
25
+ }
26
+ }
27
+
28
+ interface VueStoryProps {
29
+ /**
30
+ * Title of the story.
31
+ */
32
+ title?: string
33
+ /**
34
+ * Id of the story used in the URL. By default, the id is automatically generated from the file path. Setting an id manually will ensure the URL parameter doesn't change with the order of the variants in the story.
35
+ */
36
+ id?: string
37
+ /**
38
+ * Layout of the story.
39
+ */
40
+ layout?: StoryLayout
41
+ /**
42
+ * Function that returns the intial state. Will be used as default value for variants.
43
+ */
44
+ initState?: () => Record<string, any>
45
+ /**
46
+ * A function to configure the Vue application. This will be the default for the variants in the story.
47
+ */
48
+ setupApp?: (payload: { app: import('vue').App, story: Story, variant: Variant }) => void | Promise<void>
49
+ /**
50
+ * The id of a group to include the story in.
51
+ */
52
+ group?: string
53
+ /**
54
+ * An Iconify id to customize the story icon in the tree.
55
+ * https://icones.js.org/
56
+ */
57
+ icon?: string
58
+ /**
59
+ * The icon color.
60
+ * Example: `#8B5CF6`
61
+ */
62
+ iconColor?: string
63
+ /**
64
+ * This story will only render a documentation page.
65
+ */
66
+ docsOnly?: boolean
67
+ /**
68
+ * The copiable source code of the story.
69
+ */
70
+ source?: string
71
+ /**
72
+ * Disables the responsive menu, preview resize handles and makes the preview laways fit the available space.
73
+ */
74
+ responsiveDisabled?: boolean
75
+ }
76
+
77
+ declare const VueStoryComponent: import('vue').DefineComponent<
78
+ TypePropsToRuntimeProps<VueStoryProps>, {}, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, Readonly<import('vue').ExtractPropTypes<TypePropsToRuntimeProps<VueStoryProps>>> & {}, {}
79
+ >
80
+
81
+ interface VueVariantProps {
82
+ /**
83
+ * Title of the variant.
84
+ */
85
+ title?: string
86
+ /**
87
+ * Id of the variant used in the URL. By default, the id is automatically generated with the index of the variant in the list. Setting an id manually will ensure the URL parameter doesn't change with the order of the variants in the story.
88
+ */
89
+ id?: string
90
+ /**
91
+ * Function that returns the intial state.
92
+ */
93
+ initState?: () => Record<string, any>
94
+ /**
95
+ * A function to configure the Vue application.
96
+ */
97
+ setupApp?: (payload: { app: import('vue').App, story: Story, variant: Variant }) => void | Promise<void>
98
+ /**
99
+ * An Iconify id to customize the variant icon in the UI.
100
+ * https://icones.js.org/
101
+ */
102
+ icon?: string
103
+ /**
104
+ * The icon color.
105
+ * Example: `#8B5CF6`
106
+ */
107
+ iconColor?: string
108
+ /**
109
+ * The copiable source code of the variant.
110
+ */
111
+ source?: string
112
+ /**
113
+ * Disables the responsive menu, preview resize handles and makes the preview laways fit the available space.
114
+ */
115
+ responsiveDisabled?: boolean
116
+ }
117
+
118
+ declare const VueVariantComponent: import('vue').DefineComponent<
119
+ TypePropsToRuntimeProps<VueVariantProps>, {}, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, Readonly<import('vue').ExtractPropTypes<TypePropsToRuntimeProps<VueVariantProps>>> & {}, {}
120
+ >
121
+
122
+ declare module '@vue/runtime-core' {
123
+ export interface GlobalComponents {
124
+ Story: typeof VueStoryComponent
125
+ Variant: typeof VueVariantComponent
126
+ // Controls
127
+ HstCheckbox: typeof HstCheckbox
128
+ HstText: typeof HstText
129
+ HstTextarea: typeof HstTextarea
130
+ HstNumber: typeof HstNumber
131
+ HstTokenGrid: typeof HstTokenGrid
132
+ HstTokenList: typeof HstTokenList
133
+ HstColorShades: typeof HstColorShades
134
+ }
135
+ }
package/src/node/build.ts CHANGED
@@ -53,9 +53,7 @@ export async function build (ctx: Context) {
53
53
  server,
54
54
  throws: true,
55
55
  }, ctx)
56
- for (const storyFile of ctx.storyFiles) {
57
- await executeStoryFile(storyFile)
58
- }
56
+ await Promise.all(ctx.storyFiles.map(storyFile => executeStoryFile(storyFile)))
59
57
  await destroyCollectStories()
60
58
 
61
59
  const storyCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ? 1 : 0), 0)
@@ -6,6 +6,7 @@ import { relative } from 'pathe'
6
6
  import pc from 'picocolors'
7
7
  import Tinypool from 'tinypool'
8
8
  import { createBirpc } from 'birpc'
9
+ import { cpus } from 'os'
9
10
  import type { StoryFile } from '../types.js'
10
11
  import { createPath } from '../tree.js'
11
12
  import type { Context } from '../context.js'
@@ -27,10 +28,16 @@ export function useCollectStories (options: UseCollectStoriesOptions, ctx: Conte
27
28
  },
28
29
  })
29
30
 
31
+ const threadsCount = ctx.mode === 'dev'
32
+ ? Math.max(cpus().length / 2, 1)
33
+ : Math.max(cpus().length - 1, 1)
34
+
30
35
  const threadPool = new Tinypool({
31
36
  filename: new URL('./worker.js', import.meta.url).href,
32
37
  // WebContainer compatibility (Stackblitz)
33
38
  useAtomics: typeof process.versions.webcontainer !== 'string',
39
+ maxThreads: threadsCount,
40
+ minThreads: threadsCount,
34
41
  })
35
42
 
36
43
  function clearCache () {
@@ -110,15 +110,30 @@ export async function createServer (ctx: Context, port: number) {
110
110
  await executeStoryFile(changedFile)
111
111
 
112
112
  // Queued updates
113
- for (const storyFile of queuedFiles) {
114
- await executeStoryFile(storyFile)
115
- }
113
+ await Promise.all(queuedFiles.map(storyFile => executeStoryFile(storyFile)))
116
114
  } else {
117
115
  // Full update
118
- for (const storyFile of ctx.storyFiles) {
119
- await executeStoryFile(storyFile)
116
+
117
+ // Progress tracking
118
+ const fileCount = ctx.storyFiles.length
119
+ let loadedFilesCount = 0
120
+ const sendProgress = () => {
121
+ server.ws.send('histoire:stories-loading-progress', {
122
+ loadedFileCount: loadedFilesCount,
123
+ totalFileCount: fileCount,
124
+ })
120
125
  }
126
+
127
+ sendProgress()
128
+
129
+ await Promise.all(ctx.storyFiles.map(async storyFile => {
130
+ await executeStoryFile(storyFile)
131
+ loadedFilesCount++
132
+ sendProgress()
133
+ }))
134
+
121
135
  didAllStoriesYet = true
136
+ server.ws.send('histoire:all-stories-loaded', {})
122
137
  }
123
138
  console.log('Collect stories end', Date.now() - time, 'ms')
124
139
 
@@ -1,4 +0,0 @@
1
- import { useDark, useToggle } from "@vueuse/core";
2
- const isDark = useDark({ valueDark: "htw-dark" });
3
- const toggleDark = useToggle(isDark);
4
- export { isDark as i, toggleDark as t };
@@ -1,96 +0,0 @@
1
- import { defineComponent, ref, createApp, onMounted, watch, onUnmounted, openBlock, createElementBlock, isRef, unref } from "vue";
2
- import * as setup from "$histoire-setup";
3
- const _sfc_main = /* @__PURE__ */ defineComponent({
4
- props: {
5
- variant: {
6
- type: Object,
7
- required: true
8
- },
9
- story: {
10
- type: Object,
11
- required: true
12
- },
13
- slotName: {
14
- type: String,
15
- default: "default"
16
- }
17
- },
18
- emits: {
19
- ready: () => true
20
- },
21
- setup(__props, { emit }) {
22
- const props = __props;
23
- const sandbox = ref();
24
- let app;
25
- let mounting = false;
26
- async function mountVariant() {
27
- mounting = true;
28
- await props.variant.initState();
29
- app = createApp({
30
- name: "SandboxVue3",
31
- render: () => {
32
- var _a, _b, _c, _d, _e, _f, _g;
33
- return (_g = (_c = (_a = props.variant.slots()) == null ? void 0 : _a[props.slotName]) == null ? void 0 : _c.call(_a, {
34
- state: (_b = props.variant.state) != null ? _b : {}
35
- })) != null ? _g : (_f = (_d = props.story.slots()) == null ? void 0 : _d[props.slotName]) == null ? void 0 : _f.call(_d, {
36
- state: (_e = props.variant.state) != null ? _e : {}
37
- });
38
- }
39
- });
40
- if (typeof (setup == null ? void 0 : setup.setupVue3) === "function") {
41
- await setup.setupVue3({
42
- app,
43
- story: props.story,
44
- variant: props.variant
45
- });
46
- }
47
- if (typeof props.variant.setupApp === "function") {
48
- await props.variant.setupApp({
49
- app,
50
- story: props.story,
51
- variant: props.variant
52
- });
53
- }
54
- const target = document.createElement("div");
55
- sandbox.value.appendChild(target);
56
- app.mount(target);
57
- emit("ready");
58
- }
59
- onMounted(async () => {
60
- if (props.variant.initState) {
61
- await mountVariant();
62
- }
63
- });
64
- watch(() => props.variant.initState, (value) => {
65
- if (value && !mounting) {
66
- mountVariant();
67
- }
68
- });
69
- onUnmounted(() => {
70
- app == null ? void 0 : app.unmount();
71
- });
72
- return (_ctx, _cache) => {
73
- return openBlock(), createElementBlock("div", {
74
- ref_key: "sandbox",
75
- ref: sandbox,
76
- class: "__histoire-sandbox htw-overflow-auto"
77
- }, null, 512);
78
- };
79
- }
80
- });
81
- const isObject = (val) => val !== null && typeof val === "object";
82
- function toRawDeep(val) {
83
- const unwrappedValue = isRef(val) ? unref(val) : val;
84
- if (!isObject(unwrappedValue)) {
85
- return unwrappedValue;
86
- }
87
- if (Array.isArray(unwrappedValue)) {
88
- return unwrappedValue.map(toRawDeep);
89
- }
90
- return toRawObject(unwrappedValue);
91
- }
92
- const toRawObject = (obj) => Object.keys(obj).reduce((raw, key) => {
93
- raw[key] = toRawDeep(obj[key]);
94
- return raw;
95
- }, {});
96
- export { _sfc_main as _, toRawDeep as t };
@@ -1 +0,0 @@
1
- export declare function toRawDeep(val: any): any;
@@ -1,16 +0,0 @@
1
- import { unref, isRef } from 'vue';
2
- const isObject = (val) => val !== null && typeof val === 'object';
3
- export function toRawDeep(val) {
4
- const unwrappedValue = isRef(val) ? unref(val) : val;
5
- if (!isObject(unwrappedValue)) {
6
- return unwrappedValue;
7
- }
8
- if (Array.isArray(unwrappedValue)) {
9
- return unwrappedValue.map(toRawDeep);
10
- }
11
- return toRawObject(unwrappedValue);
12
- }
13
- const toRawObject = (obj) => Object.keys(obj).reduce((raw, key) => {
14
- raw[key] = toRawDeep(obj[key]);
15
- return raw;
16
- }, {});
@@ -1,22 +0,0 @@
1
- import { unref, isRef } from 'vue'
2
-
3
- const isObject = (val) => val !== null && typeof val === 'object'
4
-
5
- export function toRawDeep (val) {
6
- const unwrappedValue = isRef(val) ? unref(val) : val
7
-
8
- if (!isObject(unwrappedValue)) {
9
- return unwrappedValue
10
- }
11
-
12
- if (Array.isArray(unwrappedValue)) {
13
- return unwrappedValue.map(toRawDeep)
14
- }
15
-
16
- return toRawObject(unwrappedValue)
17
- }
18
-
19
- const toRawObject = (obj: Record<any, any>) => Object.keys(obj).reduce((raw, key) => {
20
- raw[key] = toRawDeep(obj[key])
21
- return raw
22
- }, {})