-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
377 lines (341 loc) · 14.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Native SPA Route Demo</title>
<!-- <link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.0.0-beta.83/dist/themes/light.css"
/> -->
<!-- <script type="module" src="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.0.0-beta.83/dist/shoelace.js"></script> -->
</head>
<body class="sl-theme-light">
<script type="module" async>
import { preload } from /*IMPORTSOURCESTART*/'/src/main.ts'/*IMPORTSOURCEEND*/;
preload();
</script>
<style>
:root {
--font-family-base: -apple-system, BlinkMacSystemFont, 'Segoe UI',
Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans',
'Helvetica Neue', sans-serif;
--font-family-mono: source-code-pro, Menlo, Monaco, Consolas,
'Courier New', monospace;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 5px;
min-width: 100vw;
min-height: 100vh;
line-height: 1.4;
font-family: var(--font-family-base);
font-size: 16px;
font-weight: 400;
direction: ltr;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
background-color: #61dafb;
}
native-route {
visibility: hidden;
}
native-route:defined {
/* display: block; */
visibility: visible;
}
native-route-container {
visibility: hidden;
}
native-route-container:defined {
visibility: visible;
}
.route-content {
border: 1px solid #d5d5d5;
border-radius: 3px;
box-shadow: 0 0 5px 0px #d5d5d5d9;
margin: 15px;
min-height: 100px;
}
</style>
<main>
<p>
provide SPA route's experience with native web component
<div>
<a href="https://github.com/Yiniau/native-spa-route">Github Repo</a>
</div>
</p>
<p>NOTICE! this demo use `<code>:defined</code>` pseudo-class to avoid undefined element's inner content leak</p>
<p>BTW. you can use `<code>disable-shadow</code>` to disable shadowDOM</p>
<ul>
<li><a href="/common">common</a></li>
<li><a href="/root">nest path: root</a></li>
<li><a href="/root/all">nest path: root/all</a></li>
<div style="height: 16px"></div>
<li>
<a href="/cache-and-drop">cache and drop</a>
</li>
<native-route path="/cache-and-drop">
<ul>
<li>
<a href="/cache-and-drop/cache/input1">cache input 1</a>
</li>
<li>
<a href="/cache-and-drop/cache/input2">cache input 2</a>
</li>
<li>
<a href="/cache-and-drop/drop/input1">drop input 1 (will drop input value after switch route)</a>
</li>
<li>
<a href="/cache-and-drop/drop/input2">drop input 2 (will drop input value after switch route)</a>
</li>
</ul>
</native-route>
<div style="height: 16px"></div>
<li>
<a href="/lazy">lazy demo</a>
<native-route path="/lazy">
<ul>
<li>
<a href="/lazy/sl/button">@shoelace-style/shoelace Button</a>
</li>
<li>
<a href="/lazy/sl/ready_button"
>render shoelace Button after module ready, disable cache to
get clear effect</a
>
</li>
</ul>
</native-route>
</li>
<div style="height: 16px"></div>
<li>
<a href="/custom-render"
>custom render demo, this could be use to render react/vue/other
render lib content<br/>
<strong>If you are in a local environment, you need to additionally run the <code>pnpm run dev:demo</code> command</strong>
</a>
<native-route path="/custom-render">
<ul>
<li>
<a href="/custom-render/react/17/basic">react 17 demo</a>
</li>
<li>
<a href="/custom-render/react/17/custom-render-name">react 17 custom render name</a>
</li>
<li>
<a href="/custom-render/react/17/with-css">react 17 with css</a>
</li>
<li>
<a href="/custom-render/vue/3/basic">vue 3 demo (enable drop)</a>
</li>
</ul>
</native-route>
</li>
<div style="height: 16px"></div>
<li>
<a href="/append-direction/before">append before</a>
</li>
<li>
<a href="/append-direction/after">append after</a>
</li>
<div style="height: 16px"></div>
<li><a href="/loading">loading status</a></li>
</ul>
<h3>common demo area</h3>
<div class="route-content">
<native-route path="/common" element="common"></native-route>
<!-- basic useage -->
<native-route path="/">
<!-- exact case, only active while pathname full match /root -->
<native-route
path="root"
exact
element="exact /root path route here"
></native-route>
<native-route path="root" element="<div>ROOT HERE</div>">
<native-route path="all" element="<div>ALL HERE</div>">
</native-route>
</native-route>
</native-route>
<native-route path="/cache-and-drop">
<native-route path="cache">
<native-route path="input1" element="<input>"></native-route>
<native-route path="input2" element="<input>"></native-route>
</native-route>
<native-route path="drop">
<native-route path="input1" drop element="<input>"></native-route>
<native-route path="input2" drop element="<input>"></native-route>
</native-route>
</native-route>
<!-- lazy useage -->
<native-route path="/lazy/sl">
<native-route
path="button"
url="//cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.0.0-beta.83/dist/components/button/button.js"
css-url='["https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.0.0-beta.83/dist/themes/light.css"]'
element='<sl-button>Button</sl-button><sl-button variant="primary">Primary</sl-button><sl-button variant="neutral" loading>Neutral</sl-button>'
lazy
>
</native-route>
<native-route
path="ready_button"
url="//cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.0.0-beta.83/dist/components/button/button.js"
css-url='["//cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.0.0-beta.83/dist/themes/light.css"]'
element='<sl-button>Render After Ready Button</sl-button><sl-button variant="primary">Primary</sl-button><sl-button variant="neutral" loading>Neutral</sl-button>'
render-after-ready
lazy
>
</native-route>
</native-route>
<!-- custom render useage -->
<native-route path="/custom-render">
<native-route path="react">
<native-route path="17/basic" lazy url="@PUBLICK_PATH/react17.js" custom-render></native-route>
<native-route path="17/custom-render-name" lazy url="@PUBLICK_PATH/react17.js" custom-render="customRenderFunction"></native-route>
<native-route path="17/with-css" lazy url="@PUBLICK_PATH/react17.js" custom-render="withCss" shadowCSSUrl="@PUBLICK_PATH/react17.css"></native-route>
</native-route>
<native-route path="vue">
<native-route drop path="3/basic" lazy url="@PUBLICK_PATH/vue3.js" shadowCSSUrl="@PUBLICK_PATH/vue3.css" custom-render></native-route>
</native-route>
</native-route>
<!-- append direction -->
<native-route path="/append-direction">
<native-route path="before" element="<strong>CENTER</strong>" append-direction="before">
<div slot>child before after</div>
</native-route>
<native-route path="after" element="<strong>CENTER</strong>">
<div slot>child append after</div>
</native-route>
</native-route>
<native-route
path="/loading"
lazy
url="//cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.0.0-beta.83/dist/components/button/button.js"
css-url="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.0.0-beta.83/dist/themes/light.css"
render-after-ready
loadingElement="<span>will show loading... 50000ms</span>"
lockLoadingTime="50000"
></native-route>
</div>
<h3>common route container demo area</h3>
<ul>
<li><a href="/route-container">container (virtualNode, this route's active status will be ignored by container)</a></li>
<li><a href="/route-container/not-match-any-route-asd123t9q3gjh34g1">unvalid route</a></li>
<li><a href="/route-container/not-404">valid route</a></li>
</ul>
<div class="route-content">
<native-route-container root-path="/route-container">
<div slot="404" style="width: 100px; height: 50px; display: flex; align-items: center; justify-content: space-around;">
<strong>404</strong>
</div>
<div>
<native-route
path="/route-container"
lazy
url="//cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.0.0-beta.83/dist/components/button/button.js"
css-url="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.0.0-beta.83/dist/themes/light.css"
render-after-ready
loadingElement="<span>will show loading as last 96ms</span>"
lockLoadingTime="96"
element="<div><code>route container demo</code></div>"
virtualNode
>
<native-route path="not-match-path_1jj41gn5og159" element="not match route, this content should not appear"></native-route>
<native-route path="not-404" element="common content here"></native-route>
</native-route>
</div>
</native-route-container>
</div>
<h3>no shadow dom route container demo area</h3>
<ul>
<li><a href="/light-dom-route-container">container</a></li>
<li><a href="/light-dom-route-container/light-dom-not-match-any-route-asd123t9q3gjh34g1">unvalid route</a></li>
<li><a href="/light-dom-route-container/not-404">valid route</a></li>
</ul>
<div class="route-content">
<native-route-container root-path="/light-dom-route-container" disableShadow>
<native-route
path="/light-dom-route-container"
lazy
url="//cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.0.0-beta.83/dist/components/button/button.js"
css-url="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.0.0-beta.83/dist/themes/light.css"
render-after-ready
loadingElement="<span>will show loading as last 96ms</span>"
lockLoadingTime="96"
element="<div><code>no shadow dom route container demo<br/>this line always visiable while location.href starts with `/light-dom-route-container`</code></div>"
virtualNode
>
<native-route path="not-match-path_1jj41gn5og159" element="not match route, this content should not appear"></native-route>
<native-route path="not-404" element="<span>common content here</span>"></native-route>
</native-route>
</native-route-container>
</div>
<h3>dynamic route path</h3>
<ul>
<li><a href="/dynamic-route">dynamic route</a></li>
<li><a href="/dynamic-route/matched_1">matched value 1</a></li>
<li><a href="/dynamic-route/matched_2">matched value 2</a></li>
<li><a href="/dynamic-route/matched_3">matched value 3</a></li>
<li><a href="/dynamic-route/matched_4">matched value 4</a></li>
<li><a href="/dynamic-route/not-matched">not matched</a></li>
</ul>
<div class="route-content">
<native-route-container
disableShadow
root-path="/dynamic-route"
element="<div><code>dynamic route</code></div>"
>
<native-route path="/dynamic-route">
<native-route path=":matched_[0-9]" element="matched"></native-route>
<native-route path=":DEFAULT" element="not match"></native-route>
</native-route>
</native-route-container>
</div>
<h3>group route match mode</h3>
<p>
<section>group match mode will split path to <code style="background-color: #9e9e9e25; border-radius: 4px;">['before self route', 'self route', 'after self route']</code></section>
<section>
common match mode will split path to
<code style="background-color: #9e9e9e25; border-radius: 4px;">
fullpath.split('/')
</code>
</section>
</p>
<ul>
<li><a href="/group-match-route">group-match-route</a></li>
<li><a href="/group-match-route/matched_1">matched value 1</a></li>
<li><a href="/group-match-route/nest/route">nest route</a></li>
<li><a href="/group-match-route/not-matched">not matched</a></li>
</ul>
<div class="route-content">
<native-route-container root-path="/group-match-route" disableShadow>
<native-route path="/group-match-route" element="<div><code>group match mode</code></div>">
<native-route path="matched_1" element="matched value 1" groupMatchMode></native-route>
<native-route path=":(?:^$)|(?:nest)|(?:nest/route)" element="nest route" groupMatchMode></native-route>
<native-route path=":DEFAULT" element="not match" groupMatchMode></native-route>></native-route>
</native-route>
</native-route-container>
</div>
</main>
<script type="module">
document.querySelectorAll('native-route-container').forEach(t => {
console.log(t);
t.set404Content(/* html */`
<div style="width: 100px; height: 50px; display: flex; align-items: center; justify-content: space-around;">
<strong>404</strong>
</div>
`);
})
history.pushState(history.state, '', location.pathname);
</script>
</body>
</html>