Skip to content

Commit 55c9ada

Browse files
committed
build code snippets for the Vue playground
1 parent 1f29594 commit 55c9ada

File tree

5 files changed

+123
-0
lines changed

5 files changed

+123
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"babel-jest": "^26.3.0",
3434
"husky": "^4.3.0",
3535
"jest": "^26.4.2",
36+
"prismjs": "^1.21.0",
3637
"tsdx": "^0.13.3",
3738
"tslib": "^2.0.1",
3839
"typescript": "^3.9.7"

packages/@headlessui-vue/examples/src/App.vue

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,34 @@
1414
<main class="flex-1 overflow-auto bg-gray-50">
1515
<router-view />
1616
<KeyCaster />
17+
18+
<!-- TODO: Position this in the correct spot -->
19+
<div
20+
v-if="sourceCode"
21+
class="container fixed bottom-0 left-0 right-0 my-12 overflow-scroll rounded-md max-h-96"
22+
v-html="sourceCode"
23+
/>
1724
</main>
1825
</div>
1926
</template>
2027

2128
<script>
29+
import { computed, watchEffect } from 'vue'
30+
import { useRoute } from 'vue-router'
2231
import KeyCaster from './KeyCaster.vue'
2332
import './.generated/preload.js'
33+
import source from './.generated/source.json'
2434
2535
export default {
2636
name: 'App',
2737
components: {
2838
KeyCaster,
2939
},
40+
setup() {
41+
const route = useRoute()
42+
const sourceCode = computed(() => source[route.path])
43+
44+
return { sourceCode }
45+
},
3046
}
3147
</script>

packages/@headlessui-vue/vite.config.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
const fs = require('fs')
22
const path = require('path')
3+
4+
const prettier = require('prettier')
5+
const Prism = require('prismjs')
6+
require('prismjs/plugins/custom-class/prism-custom-class')
7+
38
const routes = require('./examples/src/routes')
49

510
function flatten(routes, resolver) {
@@ -28,6 +33,59 @@ fs.writeFileSync(
2833
'utf8'
2934
)
3035

36+
// ---
37+
38+
function pipe(...fns) {
39+
return fns.reduceRight((f, g) => (...args) => f(g(...args)), fns.pop())
40+
}
41+
42+
Prism.plugins.customClass.map({
43+
tag: 'text-code-red',
44+
'attr-name': 'text-code-yellow',
45+
'attr-value': 'text-code-green',
46+
deleted: 'text-code-red',
47+
inserted: 'text-code-green',
48+
punctuation: 'text-code-white',
49+
keyword: 'text-code-purple',
50+
string: 'text-code-green',
51+
function: 'text-code-blue',
52+
boolean: 'text-code-red',
53+
comment: 'text-gray-400 italic',
54+
})
55+
56+
const sourcePipeline = pipe(
57+
path => fs.readFileSync(path, 'utf8'),
58+
contents => prettier.format(contents, { parser: 'vue', printWidth: 100 }),
59+
contents => Prism.highlight(contents, Prism.languages.markup),
60+
contents =>
61+
[
62+
'<pre class="language-vue rounded-md bg-gray-800 py-3 px-4 overflow-x-auto">',
63+
'<code class="language-vue text-gray-200">',
64+
contents,
65+
'</code>',
66+
'</pre>',
67+
].join('')
68+
)
69+
70+
const skipRoutes = ['/']
71+
const source = Object.assign(
72+
{},
73+
...flatten(routes, route => ({
74+
urlPath: route.path,
75+
sourcePath: route.component,
76+
}))
77+
.filter(({ urlPath }) => !skipRoutes.includes(urlPath))
78+
.map(({ urlPath, sourcePath }) => ({
79+
[urlPath]: sourcePipeline(path.resolve(__dirname, 'examples', 'src', sourcePath), 'utf8'),
80+
}))
81+
)
82+
fs.writeFileSync(
83+
path.resolve(__dirname, './examples/src/.generated/source.json'),
84+
JSON.stringify(source, null, 2),
85+
'utf8'
86+
)
87+
// ---
88+
3189
const TailwindUIPlugin = ({
3290
root, // project root directory, absolute path
3391
app, // Koa app instance

tailwind.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ module.exports = {
1010
fontFamily: {
1111
sans: ['Inter var', ...defaultTheme.fontFamily.sans],
1212
},
13+
colors: {
14+
code: {
15+
green: '#b5f4a5',
16+
yellow: '#ffe484',
17+
purple: '#d9a9ff',
18+
red: '#ff8383',
19+
blue: '#93ddfd',
20+
white: '#fff',
21+
},
22+
},
1323
},
1424
},
1525
variants: {},

yarn.lock

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3506,6 +3506,15 @@ cli-width@^3.0.0:
35063506
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-3.0.0.tgz#a2f48437a2caa9a22436e794bf071ec9e61cedf6"
35073507
integrity sha512-FxqpkPPwu1HjuN93Omfm4h8uIanXofW0RxVEW3k5RKx+mJJYSthzNhp32Kzxxy3YAEZ/Dc/EWN1vZRY0+kOhbw==
35083508

3509+
clipboard@^2.0.0:
3510+
version "2.0.6"
3511+
resolved "https://registry.yarnpkg.com/clipboard/-/clipboard-2.0.6.tgz#52921296eec0fdf77ead1749421b21c968647376"
3512+
integrity sha512-g5zbiixBRk/wyKakSwCKd7vQXDjFnAMGHoEyBogG/bw9kTD9GvdAvaoRR1ALcEzt3pVKxZR0pViekPMIS0QyGg==
3513+
dependencies:
3514+
good-listener "^1.2.2"
3515+
select "^1.1.2"
3516+
tiny-emitter "^2.0.0"
3517+
35093518
cliui@^5.0.0:
35103519
version "5.0.0"
35113520
resolved "https://registry.yarnpkg.com/cliui/-/cliui-5.0.0.tgz#deefcfdb2e800784aa34f46fa08e06851c7bbbc5"
@@ -4146,6 +4155,11 @@ delayed-stream@~1.0.0:
41464155
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
41474156
integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk=
41484157

4158+
delegate@^3.1.2:
4159+
version "3.2.0"
4160+
resolved "https://registry.yarnpkg.com/delegate/-/delegate-3.2.0.tgz#b66b71c3158522e8ab5744f720d8ca0c2af59166"
4161+
integrity sha512-IofjkYBZaZivn0V8nnsMJGBr4jVLxHDheKSW88PyxS5QC4Vo9ZbZVvhzlSxY87fVq3STR6r+4cGepyHkcWOQSw==
4162+
41494163
delegates@^1.0.0:
41504164
version "1.0.0"
41514165
resolved "https://registry.yarnpkg.com/delegates/-/delegates-1.0.0.tgz#84c6e159b81904fdca59a0ef44cd870d31250f9a"
@@ -5406,6 +5420,13 @@ globrex@^0.1.1:
54065420
resolved "https://registry.yarnpkg.com/globrex/-/globrex-0.1.2.tgz#dd5d9ec826232730cd6793a5e33a9302985e6098"
54075421
integrity sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==
54085422

5423+
good-listener@^1.2.2:
5424+
version "1.2.2"
5425+
resolved "https://registry.yarnpkg.com/good-listener/-/good-listener-1.2.2.tgz#d53b30cdf9313dffb7dc9a0d477096aa6d145c50"
5426+
integrity sha1-1TswzfkxPf+33JoNR3CWqm0UXFA=
5427+
dependencies:
5428+
delegate "^3.1.2"
5429+
54095430
graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.2, graceful-fs@^4.2.4:
54105431
version "4.2.4"
54115432
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb"
@@ -8828,6 +8849,13 @@ pretty@^2.0.0:
88288849
extend-shallow "^2.0.1"
88298850
js-beautify "^1.6.12"
88308851

8852+
prismjs@^1.21.0:
8853+
version "1.21.0"
8854+
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.21.0.tgz#36c086ec36b45319ec4218ee164c110f9fc015a3"
8855+
integrity sha512-uGdSIu1nk3kej2iZsLyDoJ7e9bnPzIgY0naW/HdknGj61zScaprVEVGHrPoXqI+M9sP0NDnTK2jpkvmldpuqDw==
8856+
optionalDependencies:
8857+
clipboard "^2.0.0"
8858+
88318859
process-nextick-args@~2.0.0:
88328860
version "2.0.1"
88338861
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
@@ -9652,6 +9680,11 @@ schema-utils@^2.6.1, schema-utils@^2.6.6:
96529680
ajv "^6.12.4"
96539681
ajv-keywords "^3.5.2"
96549682

9683+
select@^1.1.2:
9684+
version "1.1.2"
9685+
resolved "https://registry.yarnpkg.com/select/-/select-1.1.2.tgz#0e7350acdec80b1108528786ec1d4418d11b396d"
9686+
integrity sha1-DnNQrN7ICxEIUoeG7B1EGNEbOW0=
9687+
96559688
selfsigned@^1.10.7:
96569689
version "1.10.8"
96579690
resolved "https://registry.yarnpkg.com/selfsigned/-/selfsigned-1.10.8.tgz#0d17208b7d12c33f8eac85c41835f27fc3d81a30"
@@ -10450,6 +10483,11 @@ timers-browserify@^2.0.4:
1045010483
dependencies:
1045110484
setimmediate "^1.0.4"
1045210485

10486+
tiny-emitter@^2.0.0:
10487+
version "2.1.0"
10488+
resolved "https://registry.yarnpkg.com/tiny-emitter/-/tiny-emitter-2.1.0.tgz#1d1a56edfc51c43e863cbb5382a72330e3555423"
10489+
integrity sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==
10490+
1045310491
tiny-glob@^0.2.6:
1045410492
version "0.2.6"
1045510493
resolved "https://registry.yarnpkg.com/tiny-glob/-/tiny-glob-0.2.6.tgz#9e056e169d9788fe8a734dfa1ff02e9b92ed7eda"

0 commit comments

Comments
 (0)