Skip to content

Commit a9d0e7d

Browse files
committed
Store the demo doc as a URL query param
1 parent fbb7e5b commit a9d0e7d

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

examples/demo.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ declare global {
1212
}
1313
}
1414

15+
const url = new URL(window.location.href)
16+
const doc = url.searchParams.get('doc') ?? example
17+
1518
window.ink = ink(document.getElementById('app')!, {
16-
doc: example,
19+
doc,
1720
files: {
1821
clipboard: true,
1922
dragAndDrop: true,
@@ -29,6 +32,13 @@ window.ink = ink(document.getElementById('app')!, {
2932
},
3033
injectMarkup: true,
3134
},
35+
hooks: {
36+
afterUpdate: (text) => {
37+
url.searchParams.set('doc', text)
38+
39+
window.history.replaceState(null, '', url)
40+
},
41+
},
3242
interface: {
3343
images: true,
3444
lists: true,
@@ -55,3 +65,5 @@ const toggleTheme = (theme: Values.Appearance) => {
5565
window.auto = toggleTheme.bind(undefined, 'auto')
5666
window.dark = toggleTheme.bind(undefined, 'dark')
5767
window.light = toggleTheme.bind(undefined, 'light')
68+
69+
toggleTheme('light')

index.html

+9-1
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@
1919

2020
margin: 0;
2121
}
22+
23+
@media (prefers-color-scheme: dark) {
24+
.auto {
25+
background-color: #222;
26+
color: white;
27+
}
28+
}
2229
</style>
2330
</head>
2431
<body>
2532
<div id="app"></div>
26-
<script type="module" src="/examples/web-component.ts"></script>
33+
<script type="module" src="/examples/demo.ts"></script>
34+
<!-- <script type="module" src="/examples/web-component.ts"></script> -->
2735
</body>
2836
</html>

0 commit comments

Comments
 (0)