histoire 0.0.2 → 0.0.5

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 (119) hide show
  1. package/README.md +11 -0
  2. package/dist/client/app/App.vue +8 -8
  3. package/dist/client/app/codegen/vue3.js +28 -4
  4. package/dist/client/app/codegen/vue3.ts +32 -4
  5. package/dist/client/app/components/app/AppHeader.vue +10 -3
  6. package/dist/client/app/components/base/BaseTab.vue +46 -0
  7. package/dist/client/app/components/exposed/Story.vue +21 -1
  8. package/dist/client/app/components/exposed/Variant.vue +1 -0
  9. package/dist/client/app/components/misc/CheckerboardPattern.vue +32 -0
  10. package/dist/client/app/components/sandbox/SandboxVue3.vue +6 -0
  11. package/dist/client/app/components/search/SearchItem.vue +5 -9
  12. package/dist/client/app/components/{StoryControls.vue → story/StoryControls.vue} +3 -3
  13. package/dist/client/app/components/story/StoryDocs.vue +37 -0
  14. package/dist/client/app/components/{StoryList.vue → story/StoryList.vue} +4 -4
  15. package/{src/client/app/components → dist/client/app/components/story}/StoryListFolder.vue +5 -5
  16. package/{src/client/app/components → dist/client/app/components/story}/StoryListItem.vue +11 -6
  17. package/dist/client/app/components/story/StoryResponsivePreview.vue +214 -0
  18. package/dist/client/app/components/{StorySourceCode.vue → story/StorySourceCode.vue} +4 -8
  19. package/{src/client/app/components → dist/client/app/components/story}/StoryVariantGridItem.vue +14 -6
  20. package/dist/client/app/components/{StoryVariantListItem.vue → story/StoryVariantListItem.vue} +9 -8
  21. package/dist/client/app/components/story/StoryVariantSingleView.vue +182 -0
  22. package/dist/client/app/components/{StoryView.vue → story/StoryView.vue} +37 -10
  23. package/dist/client/app/global-components.js +2 -0
  24. package/dist/client/app/global-components.ts +3 -0
  25. package/dist/client/app/index.js +10 -0
  26. package/dist/client/app/index.ts +10 -0
  27. package/dist/client/app/router.js +1 -1
  28. package/dist/client/app/router.ts +1 -1
  29. package/dist/client/app/sandbox.js +37 -3
  30. package/dist/client/app/sandbox.ts +37 -3
  31. package/dist/client/app/stores/story.d.ts +15 -0
  32. package/dist/client/app/style/floating-vue.css +31 -0
  33. package/dist/client/app/style/main.css +17 -1
  34. package/dist/client/app/style/sandbox.css +5 -0
  35. package/dist/client/app/style/transitions.css +12 -0
  36. package/dist/client/app/types.d.ts +1 -0
  37. package/dist/client/app/types.ts +1 -0
  38. package/dist/client/app/util/const.d.ts +2 -0
  39. package/dist/client/app/util/const.js +2 -0
  40. package/dist/client/app/util/const.ts +2 -0
  41. package/dist/client/app/util/mapping.js +6 -0
  42. package/dist/client/app/util/mapping.ts +5 -0
  43. package/dist/client/app/util/preview-settings.d.ts +16 -0
  44. package/dist/client/app/util/preview-settings.js +15 -0
  45. package/dist/client/app/util/preview-settings.ts +26 -0
  46. package/dist/client/app/util/reactivity.d.ts +1 -0
  47. package/dist/client/app/util/reactivity.js +16 -0
  48. package/dist/client/app/util/reactivity.ts +22 -0
  49. package/dist/client/app/util/scroll.d.ts +2 -0
  50. package/dist/client/app/util/scroll.js +24 -0
  51. package/dist/client/app/util/scroll.ts +27 -0
  52. package/dist/client/app/{composable → util}/variant.d.ts +0 -0
  53. package/dist/client/app/{composable → util}/variant.js +0 -0
  54. package/dist/client/app/{composable → util}/variant.ts +0 -0
  55. package/dist/client/server/Story.server.vue +25 -2
  56. package/dist/client/server/index.js +2 -0
  57. package/dist/client/server/index.ts +3 -0
  58. package/dist/controls.d.ts +1 -0
  59. package/dist/controls.js +1 -0
  60. package/dist/node/build.js +36 -11
  61. package/dist/node/collect.js +12 -3
  62. package/dist/node/commands/dev.js +43 -5
  63. package/dist/node/config.d.ts +35 -0
  64. package/dist/node/config.js +75 -1
  65. package/dist/node/markdown.d.ts +2 -0
  66. package/dist/node/markdown.js +48 -0
  67. package/dist/node/plugin.js +35 -0
  68. package/dist/node/util/slugify.d.ts +1 -0
  69. package/dist/node/util/slugify.js +22 -0
  70. package/dist/style.css +869 -159
  71. package/package.json +15 -6
  72. package/src/client/app/App.vue +8 -8
  73. package/src/client/app/codegen/vue3.ts +32 -4
  74. package/src/client/app/components/app/AppHeader.vue +10 -3
  75. package/src/client/app/components/base/BaseTab.vue +46 -0
  76. package/src/client/app/components/exposed/Story.vue +21 -1
  77. package/src/client/app/components/exposed/Variant.vue +1 -0
  78. package/src/client/app/components/misc/CheckerboardPattern.vue +32 -0
  79. package/src/client/app/components/sandbox/SandboxVue3.vue +6 -0
  80. package/src/client/app/components/search/SearchItem.vue +5 -9
  81. package/src/client/app/components/{StoryControls.vue → story/StoryControls.vue} +3 -3
  82. package/src/client/app/components/story/StoryDocs.vue +37 -0
  83. package/src/client/app/components/{StoryList.vue → story/StoryList.vue} +4 -4
  84. package/{dist/client/app/components → src/client/app/components/story}/StoryListFolder.vue +5 -5
  85. package/{dist/client/app/components → src/client/app/components/story}/StoryListItem.vue +11 -6
  86. package/src/client/app/components/story/StoryResponsivePreview.vue +214 -0
  87. package/src/client/app/components/{StorySourceCode.vue → story/StorySourceCode.vue} +4 -8
  88. package/{dist/client/app/components → src/client/app/components/story}/StoryVariantGridItem.vue +14 -6
  89. package/src/client/app/components/{StoryVariantListItem.vue → story/StoryVariantListItem.vue} +9 -8
  90. package/src/client/app/components/story/StoryVariantSingleView.vue +182 -0
  91. package/src/client/app/components/{StoryView.vue → story/StoryView.vue} +37 -10
  92. package/src/client/app/global-components.ts +3 -0
  93. package/src/client/app/index.ts +10 -0
  94. package/src/client/app/router.ts +1 -1
  95. package/src/client/app/sandbox.ts +37 -3
  96. package/src/client/app/style/floating-vue.css +31 -0
  97. package/src/client/app/style/main.css +17 -1
  98. package/src/client/app/style/sandbox.css +5 -0
  99. package/src/client/app/style/transitions.css +12 -0
  100. package/src/client/app/types.ts +1 -0
  101. package/src/client/app/util/const.ts +2 -0
  102. package/src/client/app/util/mapping.ts +5 -0
  103. package/src/client/app/util/preview-settings.ts +26 -0
  104. package/src/client/app/util/reactivity.ts +22 -0
  105. package/src/client/app/util/scroll.ts +27 -0
  106. package/src/client/app/{composable → util}/variant.ts +0 -0
  107. package/src/client/server/Story.server.vue +25 -2
  108. package/src/client/server/index.ts +3 -0
  109. package/src/controls.ts +1 -0
  110. package/src/node/build.ts +43 -11
  111. package/src/node/collect.ts +12 -3
  112. package/src/node/commands/dev.ts +49 -5
  113. package/src/node/config.ts +112 -2
  114. package/src/node/markdown.ts +56 -0
  115. package/src/node/plugin.ts +38 -0
  116. package/src/node/util/slugify.ts +26 -0
  117. package/tailwind.config.cjs +79 -4
  118. package/dist/client/app/components/StoryVariantSingleView.vue +0 -145
  119. package/src/client/app/components/StoryVariantSingleView.vue +0 -145
@@ -1,17 +1,29 @@
1
1
  import path from 'pathe'
2
2
  import fs from 'fs'
3
3
  import defu from 'defu'
4
- import { createServer, resolveConfig as resolveViteConfig } from 'vite'
4
+ import { createServer, resolveConfig as resolveViteConfig, UserConfig as ViteConfig, ConfigEnv as ViteConfigEnv } from 'vite'
5
5
  import { ViteNodeServer } from 'vite-node/server'
6
6
  import { ViteNodeRunner } from 'vite-node/client'
7
7
  import pc from 'picocolors'
8
8
  import { TreeFile } from './tree.js'
9
9
  import { defaultColors } from './colors.js'
10
+ import type MarkdownIt from 'markdown-it'
10
11
 
11
12
  type CustomizableColors = 'primary' | 'gray'
12
13
  type ColorKeys = '50' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900'
13
14
  type GrayColorKeys = ColorKeys | '750' | '850' | '950'
14
15
 
16
+ interface ResponsivePreset {
17
+ label: string
18
+ width: number
19
+ height: number
20
+ }
21
+
22
+ interface BackgroundPreset {
23
+ label: string
24
+ color: string
25
+ }
26
+
15
27
  export interface HistoireConfig {
16
28
  /**
17
29
  * Output directory.
@@ -84,6 +96,10 @@ export interface HistoireConfig {
84
96
  [key in ColorKeys]?: string
85
97
  }
86
98
  }
99
+ /**
100
+ * Add a link to the main logo
101
+ */
102
+ logoHref?: string
87
103
  }
88
104
  /**
89
105
  * Setup file exposting a default function executed when setting up each story preview.
@@ -93,6 +109,26 @@ export interface HistoireConfig {
93
109
  * Example: `'/src/histoire-setup.ts'`
94
110
  */
95
111
  setupFile?: string
112
+ /**
113
+ * Predefined responsive sizes for story playgrounds.
114
+ */
115
+ responsivePresets?: ResponsivePreset[]
116
+ /**
117
+ * Background color of the story preview.
118
+ */
119
+ backgroundPresets?: BackgroundPreset[]
120
+ /**
121
+ * Class added to the html root of the story preview when dark mode is enabled.
122
+ */
123
+ sandboxDarkClass?: string
124
+ /**
125
+ * Customize the markdown-it renderer
126
+ */
127
+ markdown?: (md: MarkdownIt) => MarkdownIt | Promise<MarkdownIt>
128
+ /**
129
+ * Vite config override
130
+ */
131
+ vite?: ViteConfig | ((config: ViteConfig, env: ViteConfigEnv) => void | ViteConfig | Promise<void | ViteConfig>)
96
132
  }
97
133
 
98
134
  export function getDefaultConfig (): HistoireConfig {
@@ -111,6 +147,71 @@ export function getDefaultConfig (): HistoireConfig {
111
147
  gray: defaultColors.zinc,
112
148
  },
113
149
  },
150
+ responsivePresets: [
151
+ {
152
+ label: 'Mobile (Small)',
153
+ width: 320,
154
+ height: 560,
155
+ },
156
+ {
157
+ label: 'Mobile (Medium)',
158
+ width: 360,
159
+ height: 640,
160
+ },
161
+ {
162
+ label: 'Mobile (Large)',
163
+ width: 414,
164
+ height: 896,
165
+ },
166
+ {
167
+ label: 'Tablet',
168
+ width: 768,
169
+ height: 1024,
170
+ },
171
+ {
172
+ label: 'Laptop (Small)',
173
+ width: 1024,
174
+ height: null,
175
+ },
176
+ {
177
+ label: 'Laptop (Large)',
178
+ width: 1366,
179
+ height: null,
180
+ },
181
+ {
182
+ label: 'Desktop',
183
+ width: 1920,
184
+ height: null,
185
+ },
186
+ {
187
+ label: '4K',
188
+ width: 3840,
189
+ height: null,
190
+ },
191
+ ],
192
+ backgroundPresets: [
193
+ {
194
+ label: 'Transparent',
195
+ color: 'transparent',
196
+ },
197
+ {
198
+ label: 'White',
199
+ color: '#fff',
200
+ },
201
+ {
202
+ label: 'Light gray',
203
+ color: '#aaa',
204
+ },
205
+ {
206
+ label: 'Dark gray',
207
+ color: '#333',
208
+ },
209
+ {
210
+ label: 'Black',
211
+ color: '#000',
212
+ },
213
+ ],
214
+ sandboxDarkClass: 'dark',
114
215
  }
115
216
  }
116
217
 
@@ -147,12 +248,21 @@ export async function loadConfigFile (configFile: string): Promise<Partial<Histo
147
248
  try {
148
249
  const server = await createServer()
149
250
  await server.pluginContainer.buildStart({})
150
- const node = new ViteNodeServer(server)
251
+ const node = new ViteNodeServer(server, {
252
+ deps: {
253
+ inline: [
254
+ /histoire\/dist/,
255
+ ],
256
+ },
257
+ })
151
258
  const runner = new ViteNodeRunner({
152
259
  root: path.dirname(configFile),
153
260
  fetchModule (id) {
154
261
  return node.fetchModule(id)
155
262
  },
263
+ resolveId (id, importer) {
264
+ return node.resolveId(id, importer)
265
+ },
156
266
  })
157
267
  const result: { default: Partial<HistoireConfig> } = await runner.executeFile(configFile)
158
268
  await server.close()
@@ -0,0 +1,56 @@
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
+
8
+ export async function createMarkdownRenderer () {
9
+ const highlighter = await shiki.getHighlighter({
10
+ theme: 'github-dark',
11
+ })
12
+
13
+ const md = new MarkdownIt({
14
+ 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, {
15
+ lang,
16
+ })}</div>`,
17
+ linkify: true,
18
+ html: true,
19
+ breaks: true,
20
+ })
21
+
22
+ md.use(anchor, {
23
+ slugify,
24
+ permalink: anchor.permalink.ariaHidden({}),
25
+ })
26
+ .use(attrs)
27
+ .use(emoji)
28
+
29
+ // External links
30
+ {
31
+ const defaultRender = md.renderer.rules.link_open || function (tokens, idx, options, env, self) {
32
+ return self.renderToken(tokens, idx, options)
33
+ }
34
+
35
+ md.renderer.rules.link_open = function (tokens, idx, options, env, self) {
36
+ const hrefIndex = tokens[idx].attrIndex('href')
37
+ const classIndex = tokens[idx].attrIndex('class')
38
+
39
+ if (hrefIndex >= 0 && !tokens[idx].attrs[hrefIndex][1].startsWith('/') && (classIndex < 0 || !tokens[idx].attrs[classIndex][1].includes('header-anchor'))) {
40
+ // If you are sure other plugins can't add `target` - drop check below
41
+ const aIndex = tokens[idx].attrIndex('target')
42
+
43
+ if (aIndex < 0) {
44
+ tokens[idx].attrPush(['target', '_blank']) // add new attribute
45
+ } else {
46
+ tokens[idx].attrs[aIndex][1] = '_blank' // replace value of existing attr
47
+ }
48
+ }
49
+
50
+ // pass token to default renderer.
51
+ return defaultRender(tokens, idx, options, env, self)
52
+ }
53
+ }
54
+
55
+ return md
56
+ }
@@ -6,6 +6,7 @@ import { Context } from './context.js'
6
6
  import { notifyStoryChange } from './stories.js'
7
7
  import { makeTree } from './tree.js'
8
8
  import { parseColor } from './colors.js'
9
+ import { createMarkdownRenderer } from './markdown.js'
9
10
 
10
11
  export const STORIES_ID = '$histoire-stories'
11
12
  export const RESOLVED_STORIES_ID = `/${STORIES_ID}-resolved`
@@ -26,6 +27,15 @@ export async function createVitePlugins (ctx: Context): Promise<VitePlugin[]> {
26
27
  plugins.push((await import('@vitejs/plugin-vue')).default())
27
28
  }
28
29
 
30
+ if (ctx.config.vite) {
31
+ plugins.push({
32
+ name: 'histoire-vite-config-override',
33
+ config (config, env) {
34
+ return typeof ctx.config.vite === 'function' ? ctx.config.vite(config, env) : ctx.config.vite
35
+ },
36
+ })
37
+ }
38
+
29
39
  plugins.push({
30
40
  name: 'histoire-vite-plugin',
31
41
 
@@ -192,6 +202,9 @@ if (import.meta.hot) {
192
202
  },
193
203
  })
194
204
 
205
+ // Custom blocks
206
+ plugins.push(...await createCustomBlocksPlugins(ctx))
207
+
195
208
  if (ctx.mode === 'build') {
196
209
  // Add file name in build mode to have components names instead of <Anonymous>
197
210
  const include = [/\.vue$/]
@@ -214,3 +227,28 @@ if (import.meta.hot) {
214
227
 
215
228
  return plugins
216
229
  }
230
+
231
+ async function createCustomBlocksPlugins (ctx) {
232
+ const plugins: VitePlugin[] = []
233
+
234
+ let md = await createMarkdownRenderer()
235
+ if (ctx.config.markdown) {
236
+ const result = await ctx.config.markdown(md)
237
+ if (result) {
238
+ md = result
239
+ }
240
+ }
241
+ plugins.push({
242
+ name: 'histoire-vue-docs-block',
243
+ transform (code, id) {
244
+ if (!id.includes('?vue&type=docs')) return
245
+ if (!id.includes('lang.md')) return
246
+ const html = md.render(code)
247
+ return `export default Comp => {
248
+ Comp.doc = ${JSON.stringify(html)}
249
+ }`
250
+ },
251
+ })
252
+
253
+ return plugins
254
+ }
@@ -0,0 +1,26 @@
1
+ // From vitepress
2
+
3
+ // string.js slugify drops non ascii chars so we have to
4
+ // use a custom implementation here
5
+ import { remove as removeDiacritics } from 'diacritics'
6
+ // eslint-disable-next-line no-control-regex
7
+ const rControl = /[\u0000-\u001f]/g
8
+ const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.?/]+/g
9
+
10
+ export const slugify = (str: string): string => {
11
+ return (
12
+ removeDiacritics(str)
13
+ // Remove control characters
14
+ .replace(rControl, '')
15
+ // Replace special characters
16
+ .replace(rSpecial, '-')
17
+ // Remove continuous separators
18
+ .replace(/-{2,}/g, '-')
19
+ // Remove prefixing and trailing separators
20
+ .replace(/^-+|-+$/g, '')
21
+ // ensure it doesn't start with a number (#121)
22
+ .replace(/^(\d)/, '_$1')
23
+ // lowercase
24
+ .toLowerCase()
25
+ )
26
+ }
@@ -1,6 +1,7 @@
1
1
 
2
2
  const inheritedConfig = require('../../tailwind.config.cjs')
3
3
  const defaultColors = require('tailwindcss/colors')
4
+ const path = require('pathe')
4
5
 
5
6
  // Colors
6
7
 
@@ -23,11 +24,30 @@ const themedColors = ['primary', 'gray'].reduce((acc, color) => {
23
24
  return acc
24
25
  }, {})
25
26
 
27
+ const excludedDefaultColors = [
28
+ // Grays
29
+ 'slate',
30
+ 'gray',
31
+ 'zinc',
32
+ 'neutral',
33
+ 'stone',
34
+ // Deprecated colors
35
+ 'lightBlue',
36
+ 'warmGray',
37
+ 'trueGray',
38
+ 'coolGray',
39
+ 'blueGray',
40
+ ]
41
+
42
+ const includedDefaultColors = {}
43
+ for (const key in defaultColors) {
44
+ if (!excludedDefaultColors.includes(key)) {
45
+ includedDefaultColors[key] = defaultColors[key]
46
+ }
47
+ }
48
+
26
49
  const colors = {
27
- ...{
28
- ...defaultColors,
29
- gray: undefined,
30
- },
50
+ ...includedDefaultColors,
31
51
  white: '#fff',
32
52
  black: '#000',
33
53
  transparent: 'transparent',
@@ -38,6 +58,8 @@ module.exports = {
38
58
  ...inheritedConfig,
39
59
  content: [
40
60
  './src/**/*.{vue,js,ts,jsx,tsx,md}',
61
+ // Include controls CSS directly
62
+ path.resolve(__dirname, '../histoire-controls/src/**/*.{vue,js,ts,jsx,tsx,md}'),
41
63
  ],
42
64
  corePlugins: {
43
65
  preflight: false,
@@ -47,3 +69,56 @@ module.exports = {
47
69
  delete module.exports.theme.extend.colors.primary
48
70
  delete module.exports.theme.extend.colors.gray
49
71
  module.exports.theme.colors = colors
72
+
73
+ module.exports.plugins.push(require('@tailwindcss/typography'))
74
+ // prose-a:htw-text-primary-500 prose-headings:htw-mb-2 prose-headings:htw-mt-4 first:prose-headings:htw-mt-0 prose-blockquote:htw-ml-0
75
+ module.exports.theme.extend.typography = (theme) => ({
76
+ DEFAULT: {
77
+ css: {
78
+ a: {
79
+ color: theme('colors.primary-500'),
80
+ textDecoration: 'none',
81
+
82
+ '&:hover': {
83
+ textDecoration: 'underline',
84
+ },
85
+ },
86
+
87
+ 'h1, h2, h3, h4, th': {
88
+ marginBottom: '0.75rem',
89
+
90
+ '&:not(:first-child)': {
91
+ marginTop: '1.25rem',
92
+ },
93
+ },
94
+
95
+ '--tw-prose-invert-quote-borders': theme('colors.gray-800'),
96
+
97
+ blockquote: {
98
+ marginLeft: 0,
99
+ marginRight: 0,
100
+ backgroundColor: theme('colors.gray-100'),
101
+ padding: '4px 6px',
102
+
103
+ '& p:first-child': {
104
+ marginTop: 0,
105
+ },
106
+
107
+ '& p:last-child': {
108
+ marginBottom: 0,
109
+ },
110
+
111
+ '.dark &': {
112
+ backgroundColor: theme('colors.gray-750'),
113
+ },
114
+ },
115
+
116
+ '--tw-prose-invert-bullets': theme('colors.gray-500'),
117
+
118
+ li: {
119
+ marginTop: '0.1rem',
120
+ marginBottom: '0.1rem',
121
+ },
122
+ },
123
+ },
124
+ })
@@ -1,145 +0,0 @@
1
- <script lang="ts" setup>
2
- import { useEventListener } from '@vueuse/core'
3
- import { PropType, ref, watch, toRaw, computed } from 'vue'
4
- import { Icon } from '@iconify/vue'
5
- import { Story, Variant } from '../types'
6
- import { STATE_SYNC } from '../util/const.js'
7
- import BaseSplitPane from './base/BaseSplitPane.vue'
8
- import HatchedPattern from './misc/HatchedPattern.vue'
9
-
10
- const props = defineProps({
11
- variant: {
12
- type: Object as PropType<Variant>,
13
- required: true,
14
- },
15
-
16
- story: {
17
- type: Object as PropType<Story>,
18
- required: true,
19
- },
20
- })
21
-
22
- // Iframe
23
-
24
- const iframe = ref<HTMLIFrameElement>()
25
-
26
- function syncState () {
27
- if (iframe.value) {
28
- iframe.value.contentWindow.postMessage({
29
- type: STATE_SYNC,
30
- state: toRaw(props.variant.state),
31
- })
32
- }
33
- }
34
-
35
- watch(() => props.variant.state, () => {
36
- syncState()
37
- }, {
38
- deep: true,
39
- immediate: true,
40
- })
41
-
42
- useEventListener(window, 'message', (event) => {
43
- if (event.data.type === STATE_SYNC) {
44
- Object.assign(props.variant.state, event.data.state)
45
- }
46
- })
47
-
48
- const sandboxUrl = computed(() => {
49
- const url = new URLSearchParams()
50
- url.append('storyId', props.story.id)
51
- url.append('variantId', props.variant.id)
52
- return '/__sandbox?' + url.toString()
53
- })
54
-
55
- const isIframeLoaded = ref(false)
56
-
57
- watch(sandboxUrl, () => {
58
- isIframeLoaded.value = false
59
- })
60
-
61
- function onIframeLoad () {
62
- isIframeLoaded.value = true
63
- syncState()
64
- }
65
-
66
- // Responsive
67
-
68
- const responsiveWidth = ref<number>(undefined)
69
- </script>
70
-
71
- <template>
72
- <div class="htw-h-full htw-flex htw-flex-col htw-gap-2">
73
- <div class="htw-flex-none htw-flex htw-items-center htw-gap-2">
74
- <!-- Variant title -->
75
- <div class="htw-flex htw-items-center htw-gap-1 htw-text-gray-500 htw-flex-1 htw-truncate htw-min-w-0">
76
- <Icon
77
- :icon="variant.icon ?? 'carbon:cube'"
78
- class="base-list-item-link-icon htw-w-4 htw-h-4 htw-opacity-50"
79
- :class="[
80
- variant.iconColor ? 'bind-icon-color' : 'htw-text-gray-500',
81
- ]"
82
- />
83
- <span>{{ variant.title }}</span>
84
- </div>
85
-
86
- <!-- Responsive size -->
87
- <div class="htw-flex-none htw-flex htw-gap-1 htw-items-center">
88
- <Icon
89
- icon="ic:baseline-phone-android"
90
- class="htw-w-4 htw-h-4 htw-opacity-50"
91
- />
92
-
93
- <input
94
- v-model.number="responsiveWidth"
95
- v-tooltip="'Responsive width (px)'"
96
- type="number"
97
- class="htw-bg-transparent htw-border htw-border-gray-200 dark:htw-border-gray-850 htw-rounded htw-w-16 htw-opacity-50 focus:htw-opacity-100"
98
- step="16"
99
- >
100
- </div>
101
- </div>
102
-
103
- <BaseSplitPane
104
- v-model:split="responsiveWidth"
105
- save-id="story-single-responsive"
106
- :min="30"
107
- :max="6000"
108
- :default-split="720"
109
- fixed
110
- class="htw-w-full htw-h-full htw-flex-1 htw-border htw-border-gray-100 dark:htw-border-gray-800 htw-rounded-lg"
111
- >
112
- <template #first>
113
- <div class="htw-p-4 htw-h-full htw-overflow-hidden htw-bg-white dark:htw-bg-gray-700 htw-rounded-l-lg htw-relative">
114
- <div class="htw-w-full htw-h-full htw-border htw-border-gray-100 dark:htw-border-gray-800 htw-bg-white htw-rounded-sm">
115
- <iframe
116
- ref="iframe"
117
- :src="sandboxUrl"
118
- class="htw-w-full htw-h-full"
119
- :class="{'htw-invisible': !isIframeLoaded}"
120
- @load="onIframeLoad()"
121
- />
122
- </div>
123
- <!-- Markers -->
124
- <div class="htw-absolute htw-top-1 htw-left-4 htw-h-2 htw-w-px htw-bg-gray-200 dark:htw-bg-gray-800" />
125
- <div class="htw-absolute htw-top-1 htw-right-4 htw-h-2 htw-w-px htw-bg-gray-200 dark:htw-bg-gray-800" />
126
- <div class="htw-absolute htw-bottom-1 htw-left-4 htw-h-2 htw-w-px htw-bg-gray-200 dark:htw-bg-gray-800" />
127
- <div class="htw-absolute htw-bottom-1 htw-right-4 htw-h-2 htw-w-px htw-bg-gray-200 dark:htw-bg-gray-800" />
128
- <div class="htw-absolute htw-left-1 htw-top-4 htw-w-2 htw-h-px htw-bg-gray-200 dark:htw-bg-gray-800" />
129
- <div class="htw-absolute htw-left-1 htw-bottom-4 htw-w-2 htw-h-px htw-bg-gray-200 dark:htw-bg-gray-800" />
130
- <div class="htw-absolute htw-right-1 htw-top-4 htw-w-2 htw-h-px htw-bg-gray-200 dark:htw-bg-gray-800" />
131
- <div class="htw-absolute htw-right-1 htw-bottom-4 htw-w-2 htw-h-px htw-bg-gray-200 dark:htw-bg-gray-800" />
132
- </div>
133
- </template>
134
- <template #last>
135
- <div
136
- class="htw-w-full htw-h-full htw-bg-gray-200 dark:htw-bg-gray-850 htw-rounded-r-lg htw-border-l-2 htw-border-gray-500/10 dark:htw-border-gray-700/30"
137
- >
138
- <HatchedPattern
139
- class="htw-w-full htw-h-full htw-text-black/[2%] dark:htw-text-white/[2%]"
140
- />
141
- </div>
142
- </template>
143
- </BaseSplitPane>
144
- </div>
145
- </template>
@@ -1,145 +0,0 @@
1
- <script lang="ts" setup>
2
- import { useEventListener } from '@vueuse/core'
3
- import { PropType, ref, watch, toRaw, computed } from 'vue'
4
- import { Icon } from '@iconify/vue'
5
- import { Story, Variant } from '../types'
6
- import { STATE_SYNC } from '../util/const.js'
7
- import BaseSplitPane from './base/BaseSplitPane.vue'
8
- import HatchedPattern from './misc/HatchedPattern.vue'
9
-
10
- const props = defineProps({
11
- variant: {
12
- type: Object as PropType<Variant>,
13
- required: true,
14
- },
15
-
16
- story: {
17
- type: Object as PropType<Story>,
18
- required: true,
19
- },
20
- })
21
-
22
- // Iframe
23
-
24
- const iframe = ref<HTMLIFrameElement>()
25
-
26
- function syncState () {
27
- if (iframe.value) {
28
- iframe.value.contentWindow.postMessage({
29
- type: STATE_SYNC,
30
- state: toRaw(props.variant.state),
31
- })
32
- }
33
- }
34
-
35
- watch(() => props.variant.state, () => {
36
- syncState()
37
- }, {
38
- deep: true,
39
- immediate: true,
40
- })
41
-
42
- useEventListener(window, 'message', (event) => {
43
- if (event.data.type === STATE_SYNC) {
44
- Object.assign(props.variant.state, event.data.state)
45
- }
46
- })
47
-
48
- const sandboxUrl = computed(() => {
49
- const url = new URLSearchParams()
50
- url.append('storyId', props.story.id)
51
- url.append('variantId', props.variant.id)
52
- return '/__sandbox?' + url.toString()
53
- })
54
-
55
- const isIframeLoaded = ref(false)
56
-
57
- watch(sandboxUrl, () => {
58
- isIframeLoaded.value = false
59
- })
60
-
61
- function onIframeLoad () {
62
- isIframeLoaded.value = true
63
- syncState()
64
- }
65
-
66
- // Responsive
67
-
68
- const responsiveWidth = ref<number>(undefined)
69
- </script>
70
-
71
- <template>
72
- <div class="htw-h-full htw-flex htw-flex-col htw-gap-2">
73
- <div class="htw-flex-none htw-flex htw-items-center htw-gap-2">
74
- <!-- Variant title -->
75
- <div class="htw-flex htw-items-center htw-gap-1 htw-text-gray-500 htw-flex-1 htw-truncate htw-min-w-0">
76
- <Icon
77
- :icon="variant.icon ?? 'carbon:cube'"
78
- class="base-list-item-link-icon htw-w-4 htw-h-4 htw-opacity-50"
79
- :class="[
80
- variant.iconColor ? 'bind-icon-color' : 'htw-text-gray-500',
81
- ]"
82
- />
83
- <span>{{ variant.title }}</span>
84
- </div>
85
-
86
- <!-- Responsive size -->
87
- <div class="htw-flex-none htw-flex htw-gap-1 htw-items-center">
88
- <Icon
89
- icon="ic:baseline-phone-android"
90
- class="htw-w-4 htw-h-4 htw-opacity-50"
91
- />
92
-
93
- <input
94
- v-model.number="responsiveWidth"
95
- v-tooltip="'Responsive width (px)'"
96
- type="number"
97
- class="htw-bg-transparent htw-border htw-border-gray-200 dark:htw-border-gray-850 htw-rounded htw-w-16 htw-opacity-50 focus:htw-opacity-100"
98
- step="16"
99
- >
100
- </div>
101
- </div>
102
-
103
- <BaseSplitPane
104
- v-model:split="responsiveWidth"
105
- save-id="story-single-responsive"
106
- :min="30"
107
- :max="6000"
108
- :default-split="720"
109
- fixed
110
- class="htw-w-full htw-h-full htw-flex-1 htw-border htw-border-gray-100 dark:htw-border-gray-800 htw-rounded-lg"
111
- >
112
- <template #first>
113
- <div class="htw-p-4 htw-h-full htw-overflow-hidden htw-bg-white dark:htw-bg-gray-700 htw-rounded-l-lg htw-relative">
114
- <div class="htw-w-full htw-h-full htw-border htw-border-gray-100 dark:htw-border-gray-800 htw-bg-white htw-rounded-sm">
115
- <iframe
116
- ref="iframe"
117
- :src="sandboxUrl"
118
- class="htw-w-full htw-h-full"
119
- :class="{'htw-invisible': !isIframeLoaded}"
120
- @load="onIframeLoad()"
121
- />
122
- </div>
123
- <!-- Markers -->
124
- <div class="htw-absolute htw-top-1 htw-left-4 htw-h-2 htw-w-px htw-bg-gray-200 dark:htw-bg-gray-800" />
125
- <div class="htw-absolute htw-top-1 htw-right-4 htw-h-2 htw-w-px htw-bg-gray-200 dark:htw-bg-gray-800" />
126
- <div class="htw-absolute htw-bottom-1 htw-left-4 htw-h-2 htw-w-px htw-bg-gray-200 dark:htw-bg-gray-800" />
127
- <div class="htw-absolute htw-bottom-1 htw-right-4 htw-h-2 htw-w-px htw-bg-gray-200 dark:htw-bg-gray-800" />
128
- <div class="htw-absolute htw-left-1 htw-top-4 htw-w-2 htw-h-px htw-bg-gray-200 dark:htw-bg-gray-800" />
129
- <div class="htw-absolute htw-left-1 htw-bottom-4 htw-w-2 htw-h-px htw-bg-gray-200 dark:htw-bg-gray-800" />
130
- <div class="htw-absolute htw-right-1 htw-top-4 htw-w-2 htw-h-px htw-bg-gray-200 dark:htw-bg-gray-800" />
131
- <div class="htw-absolute htw-right-1 htw-bottom-4 htw-w-2 htw-h-px htw-bg-gray-200 dark:htw-bg-gray-800" />
132
- </div>
133
- </template>
134
- <template #last>
135
- <div
136
- class="htw-w-full htw-h-full htw-bg-gray-200 dark:htw-bg-gray-850 htw-rounded-r-lg htw-border-l-2 htw-border-gray-500/10 dark:htw-border-gray-700/30"
137
- >
138
- <HatchedPattern
139
- class="htw-w-full htw-h-full htw-text-black/[2%] dark:htw-text-white/[2%]"
140
- />
141
- </div>
142
- </template>
143
- </BaseSplitPane>
144
- </div>
145
- </template>