svelte-spa-history-router 2.0.0 → 2.1.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.
- package/README.md +92 -6
- package/example/App.svelte +10 -6
- package/example/Article.svelte +2 -2
- package/example/Home.svelte +2 -2
- package/example/Login.svelte +2 -2
- package/example/Query.svelte +14 -0
- package/example/data-source.js +3 -7
- package/example/dist/Article.js +36 -27
- package/example/dist/Article.js.map +1 -1
- package/example/dist/Login.js +214 -0
- package/example/dist/Login.js.map +1 -0
- package/example/dist/Query.js +143 -0
- package/example/dist/Query.js.map +1 -0
- package/example/dist/main.js +1 -1
- package/example/dist/main2.js +1505 -919
- package/example/dist/main2.js.map +1 -1
- package/jsconfig.json +17 -0
- package/package.json +15 -16
- package/server.js +4 -0
- package/src/Router.svelte +31 -31
- package/src/index.js +14 -5
- package/src/link.js +11 -2
- package/src/push.js +5 -1
- package/src/route_state.js +44 -0
- package/src/stores.js +43 -6
- package/src/types.ts +28 -0
- package/tests/e2e.test.js +129 -0
- package/example/dist/NotFound.js +0 -73
- package/example/dist/NotFound.js.map +0 -1
- package/scratch.js +0 -7
- package/tests/test_e2e.js +0 -105
package/README.md
CHANGED
|
@@ -5,8 +5,8 @@ History base router for Svelte 3 SPA (Single Page Application).
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- History-base routing
|
|
8
|
-
-
|
|
9
|
-
- resolver (for dynamic routing, code-splitting, preloading
|
|
8
|
+
- path matching and path variable capturing by regular expression
|
|
9
|
+
- resolver (for dynamic routing, code-splitting, data preloading, etc...)
|
|
10
10
|
|
|
11
11
|
## *Not* supported features
|
|
12
12
|
|
|
@@ -74,7 +74,7 @@ For example:
|
|
|
74
74
|
</div>
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
###
|
|
77
|
+
### Navigation methods
|
|
78
78
|
|
|
79
79
|
To navigate another page, `link` and `push` are available.
|
|
80
80
|
|
|
@@ -96,9 +96,87 @@ import { push } from 'svelte-spa-history-router';
|
|
|
96
96
|
|
|
97
97
|
### resolver
|
|
98
98
|
|
|
99
|
+
Resolver is a mechanism to dynamically determine component and can be used in multiple use cases.
|
|
100
|
+
|
|
101
|
+
Example: code spliting (dynamic import)
|
|
102
|
+
|
|
103
|
+
```html
|
|
104
|
+
<script>
|
|
105
|
+
import { Router } from 'svelte-spa-history-router';
|
|
106
|
+
|
|
107
|
+
const routes = [
|
|
108
|
+
{ path: '/', resolver: _ => import("Home.svelte") },
|
|
109
|
+
];
|
|
110
|
+
</script>
|
|
111
|
+
<Router {routes}/>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Example: dynamic routing and pass value to component props.
|
|
115
|
+
|
|
116
|
+
```html
|
|
117
|
+
<script>
|
|
118
|
+
import { Router } from 'svelte-spa-history-router';
|
|
119
|
+
|
|
120
|
+
import Article from "./Article.svelte";
|
|
121
|
+
import NotFound from "./NotFound.svelte";
|
|
122
|
+
|
|
123
|
+
async function prefetchArticle(route) {
|
|
124
|
+
const article = await getArticle(route.params.postId);
|
|
125
|
+
if (article) {
|
|
126
|
+
// pass value to component props
|
|
127
|
+
route.props.article = article;
|
|
128
|
+
return Article;
|
|
129
|
+
} else {
|
|
130
|
+
return NotFound;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const routes = [
|
|
135
|
+
{ path: '/posts/(?<postId>.*)', resolver: prefetchArticle },
|
|
136
|
+
];
|
|
137
|
+
</script>
|
|
138
|
+
<Router {routes}/>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Example: guard
|
|
142
|
+
|
|
143
|
+
```html
|
|
144
|
+
<script>
|
|
145
|
+
import { Router, redirect } from 'svelte-spa-history-router';
|
|
146
|
+
|
|
147
|
+
import Admin from "./Admin.svelte";
|
|
148
|
+
|
|
149
|
+
function adminGuard(route) {
|
|
150
|
+
if (!isAdmin($user)) {
|
|
151
|
+
return redirect("/");
|
|
152
|
+
}
|
|
153
|
+
return Admin;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const routes = [
|
|
157
|
+
{ path: '/', component: Home },
|
|
158
|
+
{ path: '/admin', resolver: adminGuard },
|
|
159
|
+
];
|
|
160
|
+
</script>
|
|
161
|
+
<Router {routes}/>
|
|
162
|
+
```
|
|
163
|
+
|
|
99
164
|
(Added in v2.0.0)
|
|
100
165
|
|
|
101
|
-
|
|
166
|
+
### currentURL
|
|
167
|
+
|
|
168
|
+
store to detect URL changes (including query string or hash)
|
|
169
|
+
|
|
170
|
+
```html
|
|
171
|
+
<script>
|
|
172
|
+
import { currentURL } from "svelte-spa-history-router";
|
|
173
|
+
|
|
174
|
+
$: name = $currentURL.searchParams.get("name") || 'unknown';
|
|
175
|
+
</script>
|
|
176
|
+
<div>{ name }</div>
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
(Added in 2.1.0)
|
|
102
180
|
|
|
103
181
|
### Full example:
|
|
104
182
|
|
|
@@ -106,10 +184,18 @@ see [example](https://github.com/ykrods/svelte-spa-history-router/blob/main/exam
|
|
|
106
184
|
|
|
107
185
|
## ChangeLog
|
|
108
186
|
|
|
187
|
+
### 2.1.1 (2024-01-13)
|
|
188
|
+
|
|
189
|
+
* Support Types
|
|
190
|
+
|
|
191
|
+
### 2.1.0 (2021-04-29)
|
|
192
|
+
|
|
193
|
+
* Add `currentURL` store to detect URL changes [PR6](https://github.com/ykrods/svelte-spa-history-router/pull/6)
|
|
194
|
+
|
|
109
195
|
### 2.0.0 (2021-04-15)
|
|
110
196
|
|
|
111
|
-
* [Added]
|
|
112
|
-
* [Removed]
|
|
197
|
+
* [Added] resolver
|
|
198
|
+
* [Removed] guard
|
|
113
199
|
|
|
114
200
|
### 1.1.1 (2021-04-12)
|
|
115
201
|
|
package/example/App.svelte
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { Router, link, redirect } from '../src/index';
|
|
2
|
+
import { Router, link, redirect } from '../src/index.js';
|
|
3
3
|
|
|
4
|
-
import { user } from './store';
|
|
5
|
-
import { getArticle } from './data-source';
|
|
4
|
+
import { user } from './store.js';
|
|
5
|
+
import { getArticle } from './data-source.js';
|
|
6
6
|
|
|
7
7
|
// static routes
|
|
8
8
|
import Home from './Home.svelte';
|
|
9
9
|
import Admin from './Admin.svelte';
|
|
10
|
-
import Login from './Login.svelte';
|
|
11
10
|
import NotFound from "./NotFound.svelte";
|
|
12
11
|
|
|
13
|
-
function adminGuard(
|
|
12
|
+
function adminGuard() {
|
|
14
13
|
if ($user === null) {
|
|
15
14
|
return redirect("/login");
|
|
16
15
|
} else {
|
|
@@ -18,6 +17,9 @@
|
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
|
|
20
|
+
/**
|
|
21
|
+
* @param {import("../src/types").RouteState} route
|
|
22
|
+
*/
|
|
21
23
|
async function prefetchArticle(route) {
|
|
22
24
|
const article = await getArticle(route.params.postId);
|
|
23
25
|
if (article) {
|
|
@@ -33,7 +35,8 @@
|
|
|
33
35
|
{ path: '/', component: Home},
|
|
34
36
|
{ path: '/posts/(?<postId>.*)', resolver: prefetchArticle },
|
|
35
37
|
{ path: '/admin', resolver: adminGuard },
|
|
36
|
-
{ path: '/login',
|
|
38
|
+
{ path: '/login', resolver: () => import("./Login.svelte") },
|
|
39
|
+
{ path: '/query', resolver: () => import("./Query.svelte") },
|
|
37
40
|
];
|
|
38
41
|
</script>
|
|
39
42
|
|
|
@@ -42,6 +45,7 @@
|
|
|
42
45
|
<li><a use:link href="/">Home</a></li>
|
|
43
46
|
<li><a use:link href="/admin">Admin</a></li>
|
|
44
47
|
<li><a use:link href="/login">Login</a></li>
|
|
48
|
+
<li><a use:link href="/query">Query</a></li>
|
|
45
49
|
</ul>
|
|
46
50
|
</div>
|
|
47
51
|
|
package/example/Article.svelte
CHANGED
package/example/Home.svelte
CHANGED
package/example/Login.svelte
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { link } from "../src/link.js";
|
|
3
|
+
import { currentURL } from "../src/stores.js";
|
|
4
|
+
|
|
5
|
+
$: name = $currentURL.searchParams.get("name") || 'unknown';
|
|
6
|
+
</script>
|
|
7
|
+
<svelte:head>
|
|
8
|
+
<title>query</title>
|
|
9
|
+
</svelte:head>
|
|
10
|
+
<div class="query">
|
|
11
|
+
<p>name: <span id="name">{ name }</span></p>
|
|
12
|
+
<a use:link href="/query?name=foo">foo</a>
|
|
13
|
+
<a use:link href="/query?name=bar">bar</a>
|
|
14
|
+
</div>
|
package/example/data-source.js
CHANGED
|
@@ -4,12 +4,8 @@
|
|
|
4
4
|
* Dummy APIs for fetch data
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
return new Promise((resolve,
|
|
9
|
-
setTimeout(() => {
|
|
10
|
-
resolve();
|
|
11
|
-
}, s * 1000);
|
|
12
|
-
});
|
|
7
|
+
function sleep(time) {
|
|
8
|
+
return new Promise(resolve => setTimeout(resolve, time));
|
|
13
9
|
};
|
|
14
10
|
|
|
15
11
|
const articles = [
|
|
@@ -37,7 +33,7 @@ const articles = [
|
|
|
37
33
|
];
|
|
38
34
|
|
|
39
35
|
export async function getArticles() {
|
|
40
|
-
await sleep(
|
|
36
|
+
await sleep(100);
|
|
41
37
|
return articles;
|
|
42
38
|
}
|
|
43
39
|
|
package/example/dist/Article.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { S as SvelteComponentDev, i as init, s as safe_not_equal, d as dispatch_dev,
|
|
1
|
+
import { S as SvelteComponentDev, i as init, s as safe_not_equal, d as dispatch_dev, v as validate_store, r as routeParams, c as component_subscribe, a as validate_slots, l as link, g as globals, b as space, e as element, t as text, f as add_location, h as attr_dev, j as insert_dev, k as append_dev, m as set_data_dev, n as noop, o as detach_dev, p as action_destroyer, H as HtmlTag } from './main2.js';
|
|
2
2
|
|
|
3
|
-
/* Article.svelte generated by Svelte
|
|
3
|
+
/* Article.svelte generated by Svelte v4.2.8 */
|
|
4
4
|
|
|
5
5
|
const { console: console_1 } = globals;
|
|
6
6
|
const file = "Article.svelte";
|
|
@@ -18,7 +18,7 @@ function create_if_block_1(ctx) {
|
|
|
18
18
|
a = element("a");
|
|
19
19
|
t = text("Prev");
|
|
20
20
|
attr_dev(a, "href", a_href_value = `/posts/${/*article*/ ctx[0].previous}`);
|
|
21
|
-
add_location(a, file, 18, 26,
|
|
21
|
+
add_location(a, file, 18, 26, 381);
|
|
22
22
|
},
|
|
23
23
|
m: function mount(target, anchor) {
|
|
24
24
|
insert_dev(target, a, anchor);
|
|
@@ -35,7 +35,10 @@ function create_if_block_1(ctx) {
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
d: function destroy(detaching) {
|
|
38
|
-
if (detaching)
|
|
38
|
+
if (detaching) {
|
|
39
|
+
detach_dev(a);
|
|
40
|
+
}
|
|
41
|
+
|
|
39
42
|
mounted = false;
|
|
40
43
|
dispose();
|
|
41
44
|
}
|
|
@@ -65,7 +68,7 @@ function create_if_block(ctx) {
|
|
|
65
68
|
a = element("a");
|
|
66
69
|
t = text("Next");
|
|
67
70
|
attr_dev(a, "href", a_href_value = `/posts/${/*article*/ ctx[0].next}`);
|
|
68
|
-
add_location(a, file, 19, 22,
|
|
71
|
+
add_location(a, file, 19, 22, 465);
|
|
69
72
|
},
|
|
70
73
|
m: function mount(target, anchor) {
|
|
71
74
|
insert_dev(target, a, anchor);
|
|
@@ -82,7 +85,10 @@ function create_if_block(ctx) {
|
|
|
82
85
|
}
|
|
83
86
|
},
|
|
84
87
|
d: function destroy(detaching) {
|
|
85
|
-
if (detaching)
|
|
88
|
+
if (detaching) {
|
|
89
|
+
detach_dev(a);
|
|
90
|
+
}
|
|
91
|
+
|
|
86
92
|
mounted = false;
|
|
87
93
|
dispose();
|
|
88
94
|
}
|
|
@@ -123,16 +129,17 @@ function create_fragment(ctx) {
|
|
|
123
129
|
h1 = element("h1");
|
|
124
130
|
t1 = text(t1_value);
|
|
125
131
|
t2 = space();
|
|
132
|
+
html_tag = new HtmlTag(false);
|
|
126
133
|
t3 = space();
|
|
127
134
|
div0 = element("div");
|
|
128
135
|
if (if_block0) if_block0.c();
|
|
129
136
|
t4 = space();
|
|
130
137
|
if (if_block1) if_block1.c();
|
|
131
|
-
add_location(h1, file, 15, 2,
|
|
132
|
-
html_tag =
|
|
133
|
-
add_location(div0, file, 17, 2,
|
|
138
|
+
add_location(h1, file, 15, 2, 299);
|
|
139
|
+
html_tag.a = t3;
|
|
140
|
+
add_location(div0, file, 17, 2, 349);
|
|
134
141
|
attr_dev(div1, "class", "article");
|
|
135
|
-
add_location(div1, file, 14, 0,
|
|
142
|
+
add_location(div1, file, 14, 0, 275);
|
|
136
143
|
},
|
|
137
144
|
l: function claim(nodes) {
|
|
138
145
|
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
|
|
@@ -187,8 +194,11 @@ function create_fragment(ctx) {
|
|
|
187
194
|
i: noop,
|
|
188
195
|
o: noop,
|
|
189
196
|
d: function destroy(detaching) {
|
|
190
|
-
if (detaching)
|
|
191
|
-
|
|
197
|
+
if (detaching) {
|
|
198
|
+
detach_dev(t0);
|
|
199
|
+
detach_dev(div1);
|
|
200
|
+
}
|
|
201
|
+
|
|
192
202
|
if (if_block0) if_block0.d();
|
|
193
203
|
if (if_block1) if_block1.d();
|
|
194
204
|
}
|
|
@@ -207,26 +217,32 @@ function create_fragment(ctx) {
|
|
|
207
217
|
|
|
208
218
|
function instance($$self, $$props, $$invalidate) {
|
|
209
219
|
let $routeParams;
|
|
210
|
-
validate_store(routeParams,
|
|
220
|
+
validate_store(routeParams, 'routeParams');
|
|
211
221
|
component_subscribe($$self, routeParams, $$value => $$invalidate(1, $routeParams = $$value));
|
|
212
222
|
let { $$slots: slots = {}, $$scope } = $$props;
|
|
213
|
-
validate_slots(
|
|
223
|
+
validate_slots('Article', slots, []);
|
|
214
224
|
let { article } = $$props;
|
|
215
|
-
|
|
216
|
-
|
|
225
|
+
|
|
226
|
+
$$self.$$.on_mount.push(function () {
|
|
227
|
+
if (article === undefined && !('article' in $$props || $$self.$$.bound[$$self.$$.props['article']])) {
|
|
228
|
+
console_1.warn("<Article> was created without expected prop 'article'");
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const writable_props = ['article'];
|
|
217
233
|
|
|
218
234
|
Object.keys($$props).forEach(key => {
|
|
219
|
-
if (!~writable_props.indexOf(key) && key.slice(0, 2) !==
|
|
235
|
+
if (!~writable_props.indexOf(key) && key.slice(0, 2) !== '$$' && key !== 'slot') console_1.warn(`<Article> was created with unknown prop '${key}'`);
|
|
220
236
|
});
|
|
221
237
|
|
|
222
238
|
$$self.$$set = $$props => {
|
|
223
|
-
if (
|
|
239
|
+
if ('article' in $$props) $$invalidate(0, article = $$props.article);
|
|
224
240
|
};
|
|
225
241
|
|
|
226
242
|
$$self.$capture_state = () => ({ link, routeParams, article, $routeParams });
|
|
227
243
|
|
|
228
244
|
$$self.$inject_state = $$props => {
|
|
229
|
-
if (
|
|
245
|
+
if ('article' in $$props) $$invalidate(0, article = $$props.article);
|
|
230
246
|
};
|
|
231
247
|
|
|
232
248
|
if ($$props && "$$inject" in $$props) {
|
|
@@ -255,13 +271,6 @@ class Article extends SvelteComponentDev {
|
|
|
255
271
|
options,
|
|
256
272
|
id: create_fragment.name
|
|
257
273
|
});
|
|
258
|
-
|
|
259
|
-
const { ctx } = this.$$;
|
|
260
|
-
const props = options.props || {};
|
|
261
|
-
|
|
262
|
-
if (/*article*/ ctx[0] === undefined && !("article" in props)) {
|
|
263
|
-
console_1.warn("<Article> was created without expected prop 'article'");
|
|
264
|
-
}
|
|
265
274
|
}
|
|
266
275
|
|
|
267
276
|
get article() {
|
|
@@ -273,5 +282,5 @@ class Article extends SvelteComponentDev {
|
|
|
273
282
|
}
|
|
274
283
|
}
|
|
275
284
|
|
|
276
|
-
export default
|
|
285
|
+
export { Article as default };
|
|
277
286
|
//# sourceMappingURL=Article.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Article.js","sources":["../Article.svelte"],"sourcesContent":["<script>\n import { link } from '../src/index';\n import { routeParams } from '../src/stores';\n\n export let article;\n\n $: if ($routeParams.postId) {\n console.log($routeParams.postId);\n };\n</script>\n\n<svelte:head>\n <title>{ article.title }</title>\n</svelte:head>\n<div class=\"article\">\n <h1>{article.title}</h1>\n {@html article.html}\n <div>\n {#if article.previous}<a use:link href={`/posts/${article.previous}`}>Prev</a>{/if}\n {#if article.next}<a use:link href={`/posts/${article.next}`}>Next</a>{/if}\n </div>\n</div>\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Article.js","sources":["../Article.svelte"],"sourcesContent":["<script>\n import { link } from '../src/index.js';\n import { routeParams } from '../src/stores.js';\n\n export let article;\n\n $: if ($routeParams.postId) {\n console.log($routeParams.postId);\n };\n</script>\n\n<svelte:head>\n <title>{ article.title }</title>\n</svelte:head>\n<div class=\"article\">\n <h1>{article.title}</h1>\n {@html article.html}\n <div>\n {#if article.previous}<a use:link href={`/posts/${article.previous}`}>Prev</a>{/if}\n {#if article.next}<a use:link href={`/posts/${article.next}`}>Next</a>{/if}\n </div>\n</div>\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;YAkB0E,MAAI,CAAA,CAAA;AAAxB,GAAA,QAAA,CAAA,CAAA,EAAA,MAAA,EAAA,YAAA,GAAA,CAAA,OAAA,cAAA,GAAO,IAAC,QAAQ,CAAA,CAAA,CAAA,CAAA;;;;GAA5C,UAAwD,CAAA,MAAA,EAAA,CAAA,EAAA,MAAA,CAAA,CAAA;;;;;;;;;AAA5B,GAAA,IAAA,KAAA,eAAA,CAAA,IAAA,YAAA,MAAA,YAAA,GAAA,CAAA,OAAA,cAAA,GAAO,IAAC,QAAQ,CAAA,CAAA,CAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YACJ,MAAI,CAAA,CAAA;AAApB,GAAA,QAAA,CAAA,CAAA,EAAA,MAAA,EAAA,YAAA,GAAA,CAAA,OAAA,cAAA,GAAO,IAAC,IAAI,CAAA,CAAA,CAAA,CAAA;;;;GAAxC,UAAoD,CAAA,MAAA,EAAA,CAAA,EAAA,MAAA,CAAA,CAAA;;;;;;;;;AAAxB,GAAA,IAAA,KAAA,eAAA,CAAA,IAAA,YAAA,MAAA,YAAA,GAAA,CAAA,OAAA,cAAA,GAAO,IAAC,IAAI,CAAA,CAAA,CAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAJvD,CAAA,IAAA,QAAA,eAAA,GAAO,IAAC,KAAK,GAAA,EAAA,CAAA;;;;AACX,CAAA,IAAA,SAAA,eAAA,GAAO,IAAC,IAAI,GAAA,EAAA,CAAA;;;;AAJV,CAAA,QAAA,CAAA,KAAA,GAAA,WAAA,eAAA,GAAO,IAAC,KAAK,CAAA;AAMf,CAAA,IAAA,SAAA,eAAA,GAAO,IAAC,QAAQ,IAAA,iBAAA,CAAA,GAAA,CAAA,CAAA;AAChB,CAAA,IAAA,SAAA,eAAA,GAAO,IAAC,IAAI,IAAA,eAAA,CAAA,GAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GALrB,UAOM,CAAA,MAAA,EAAA,IAAA,EAAA,MAAA,CAAA,CAAA;GANJ,UAAwB,CAAA,IAAA,EAAA,EAAA,CAAA,CAAA;;;;;GAExB,UAGM,CAAA,IAAA,EAAA,IAAA,CAAA,CAAA;;;;;;AARG,GAAA,IAAA,KAAA,eAAA,CAAA,IAAA,WAAA,MAAA,WAAA,eAAA,GAAO,IAAC,KAAK,CAAA,EAAA;;;;AAGjB,GAAA,IAAA,KAAA,eAAA,CAAA,IAAA,QAAA,MAAA,QAAA,eAAA,GAAO,IAAC,KAAK,GAAA,EAAA,CAAA,EAAA,YAAA,CAAA,EAAA,EAAA,QAAA,CAAA,CAAA;AACX,GAAA,IAAA,KAAA,eAAA,CAAA,IAAA,SAAA,MAAA,SAAA,eAAA,GAAO,IAAC,IAAI,GAAA,EAAA,CAAA,EAAA,QAAA,CAAA,CAAA,CAAA,SAAA,CAAA,CAAA;;AAEZ,GAAA,gBAAA,GAAO,IAAC,QAAQ,EAAA;;;;;;;;;;;;;AAChB,GAAA,gBAAA,GAAO,IAAC,IAAI,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAfR,OAAO,EAAA,GAAA,OAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAEjB,IAAM,YAAY,CAAC,MAAM,EAAA;AACxB,IAAA,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { S as SvelteComponentDev, i as init, s as safe_not_equal, d as dispatch_dev, v as validate_store, u as user, c as component_subscribe, a as validate_slots, q as push, e as element, b as space, f as add_location, h as attr_dev, j as insert_dev, k as append_dev, n as noop, o as detach_dev, w as set_store_value, t as text, x as listen_dev, m as set_data_dev } from './main2.js';
|
|
2
|
+
|
|
3
|
+
/* Login.svelte generated by Svelte v4.2.8 */
|
|
4
|
+
const file = "Login.svelte";
|
|
5
|
+
|
|
6
|
+
// (18:2) {:else }
|
|
7
|
+
function create_else_block(ctx) {
|
|
8
|
+
let t0;
|
|
9
|
+
let t1;
|
|
10
|
+
let t2;
|
|
11
|
+
let button;
|
|
12
|
+
let mounted;
|
|
13
|
+
let dispose;
|
|
14
|
+
|
|
15
|
+
const block = {
|
|
16
|
+
c: function create() {
|
|
17
|
+
t0 = text("current user: ");
|
|
18
|
+
t1 = text(/*$user*/ ctx[0]);
|
|
19
|
+
t2 = space();
|
|
20
|
+
button = element("button");
|
|
21
|
+
button.textContent = "logout";
|
|
22
|
+
attr_dev(button, "id", "logout");
|
|
23
|
+
add_location(button, file, 18, 26, 341);
|
|
24
|
+
},
|
|
25
|
+
m: function mount(target, anchor) {
|
|
26
|
+
insert_dev(target, t0, anchor);
|
|
27
|
+
insert_dev(target, t1, anchor);
|
|
28
|
+
insert_dev(target, t2, anchor);
|
|
29
|
+
insert_dev(target, button, anchor);
|
|
30
|
+
|
|
31
|
+
if (!mounted) {
|
|
32
|
+
dispose = listen_dev(button, "click", /*logout*/ ctx[2], false, false, false, false);
|
|
33
|
+
mounted = true;
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
p: function update(ctx, dirty) {
|
|
37
|
+
if (dirty & /*$user*/ 1) set_data_dev(t1, /*$user*/ ctx[0]);
|
|
38
|
+
},
|
|
39
|
+
d: function destroy(detaching) {
|
|
40
|
+
if (detaching) {
|
|
41
|
+
detach_dev(t0);
|
|
42
|
+
detach_dev(t1);
|
|
43
|
+
detach_dev(t2);
|
|
44
|
+
detach_dev(button);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
mounted = false;
|
|
48
|
+
dispose();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
dispatch_dev("SvelteRegisterBlock", {
|
|
53
|
+
block,
|
|
54
|
+
id: create_else_block.name,
|
|
55
|
+
type: "else",
|
|
56
|
+
source: "(18:2) {:else }",
|
|
57
|
+
ctx
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return block;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// (16:2) {#if $user === null }
|
|
64
|
+
function create_if_block(ctx) {
|
|
65
|
+
let button;
|
|
66
|
+
let mounted;
|
|
67
|
+
let dispose;
|
|
68
|
+
|
|
69
|
+
const block = {
|
|
70
|
+
c: function create() {
|
|
71
|
+
button = element("button");
|
|
72
|
+
button.textContent = "login";
|
|
73
|
+
attr_dev(button, "id", "login");
|
|
74
|
+
add_location(button, file, 16, 2, 253);
|
|
75
|
+
},
|
|
76
|
+
m: function mount(target, anchor) {
|
|
77
|
+
insert_dev(target, button, anchor);
|
|
78
|
+
|
|
79
|
+
if (!mounted) {
|
|
80
|
+
dispose = listen_dev(button, "click", /*login*/ ctx[1], false, false, false, false);
|
|
81
|
+
mounted = true;
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
p: noop,
|
|
85
|
+
d: function destroy(detaching) {
|
|
86
|
+
if (detaching) {
|
|
87
|
+
detach_dev(button);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
mounted = false;
|
|
91
|
+
dispose();
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
dispatch_dev("SvelteRegisterBlock", {
|
|
96
|
+
block,
|
|
97
|
+
id: create_if_block.name,
|
|
98
|
+
type: "if",
|
|
99
|
+
source: "(16:2) {#if $user === null }",
|
|
100
|
+
ctx
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
return block;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function create_fragment(ctx) {
|
|
107
|
+
let div;
|
|
108
|
+
let h1;
|
|
109
|
+
let t1;
|
|
110
|
+
|
|
111
|
+
function select_block_type(ctx, dirty) {
|
|
112
|
+
if (/*$user*/ ctx[0] === null) return create_if_block;
|
|
113
|
+
return create_else_block;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let current_block_type = select_block_type(ctx);
|
|
117
|
+
let if_block = current_block_type(ctx);
|
|
118
|
+
|
|
119
|
+
const block = {
|
|
120
|
+
c: function create() {
|
|
121
|
+
div = element("div");
|
|
122
|
+
h1 = element("h1");
|
|
123
|
+
h1.textContent = "Login";
|
|
124
|
+
t1 = space();
|
|
125
|
+
if_block.c();
|
|
126
|
+
add_location(h1, file, 14, 2, 212);
|
|
127
|
+
attr_dev(div, "class", "login");
|
|
128
|
+
add_location(div, file, 13, 0, 190);
|
|
129
|
+
},
|
|
130
|
+
l: function claim(nodes) {
|
|
131
|
+
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
|
|
132
|
+
},
|
|
133
|
+
m: function mount(target, anchor) {
|
|
134
|
+
insert_dev(target, div, anchor);
|
|
135
|
+
append_dev(div, h1);
|
|
136
|
+
append_dev(div, t1);
|
|
137
|
+
if_block.m(div, null);
|
|
138
|
+
},
|
|
139
|
+
p: function update(ctx, [dirty]) {
|
|
140
|
+
if (current_block_type === (current_block_type = select_block_type(ctx)) && if_block) {
|
|
141
|
+
if_block.p(ctx, dirty);
|
|
142
|
+
} else {
|
|
143
|
+
if_block.d(1);
|
|
144
|
+
if_block = current_block_type(ctx);
|
|
145
|
+
|
|
146
|
+
if (if_block) {
|
|
147
|
+
if_block.c();
|
|
148
|
+
if_block.m(div, null);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
i: noop,
|
|
153
|
+
o: noop,
|
|
154
|
+
d: function destroy(detaching) {
|
|
155
|
+
if (detaching) {
|
|
156
|
+
detach_dev(div);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if_block.d();
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
dispatch_dev("SvelteRegisterBlock", {
|
|
164
|
+
block,
|
|
165
|
+
id: create_fragment.name,
|
|
166
|
+
type: "component",
|
|
167
|
+
source: "",
|
|
168
|
+
ctx
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
return block;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function instance($$self, $$props, $$invalidate) {
|
|
175
|
+
let $user;
|
|
176
|
+
validate_store(user, 'user');
|
|
177
|
+
component_subscribe($$self, user, $$value => $$invalidate(0, $user = $$value));
|
|
178
|
+
let { $$slots: slots = {}, $$scope } = $$props;
|
|
179
|
+
validate_slots('Login', slots, []);
|
|
180
|
+
|
|
181
|
+
function login() {
|
|
182
|
+
set_store_value(user, $user = "admin", $user);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function logout() {
|
|
186
|
+
set_store_value(user, $user = null, $user);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const writable_props = [];
|
|
190
|
+
|
|
191
|
+
Object.keys($$props).forEach(key => {
|
|
192
|
+
if (!~writable_props.indexOf(key) && key.slice(0, 2) !== '$$' && key !== 'slot') console.warn(`<Login> was created with unknown prop '${key}'`);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
$$self.$capture_state = () => ({ push, user, login, logout, $user });
|
|
196
|
+
return [$user, login, logout];
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
class Login extends SvelteComponentDev {
|
|
200
|
+
constructor(options) {
|
|
201
|
+
super(options);
|
|
202
|
+
init(this, options, instance, create_fragment, safe_not_equal, {});
|
|
203
|
+
|
|
204
|
+
dispatch_dev("SvelteRegisterComponent", {
|
|
205
|
+
component: this,
|
|
206
|
+
tagName: "Login",
|
|
207
|
+
options,
|
|
208
|
+
id: create_fragment.name
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export { Login as default };
|
|
214
|
+
//# sourceMappingURL=Login.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Login.js","sources":["../Login.svelte"],"sourcesContent":["<script>\n import { push } from '../src/push.js';\n\n import { user } from './store.js';\n\n function login() {\n $user = \"admin\";\n }\n function logout() {\n $user = null;\n }\n</script>\n\n<div class=\"login\">\n <h1>Login</h1>\n {#if $user === null }\n <button id=\"login\" on:click={login}>login</button>\n {:else }\n current user: { $user } <button id=\"logout\" on:click={logout}>logout</button>\n {/if }\n</div>\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;aAiBU,gBACM,CAAA,CAAA;uBAAE,GAAK,CAAA,CAAA,CAAA,CAAA,CAAA;;;;;;;;;;;GAAG,UAAqD,CAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,CAAA;;;qDAAvB,GAAM,CAAA,CAAA,CAAA,EAAA,KAAA,EAAA,KAAA,EAAA,KAAA,EAAA,KAAA,CAAA,CAAA;;;;;uDAA5C,GAAK,CAAA,CAAA,CAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAFrB,UAAkD,CAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,CAAA;;;oDAArB,GAAK,CAAA,CAAA,CAAA,EAAA,KAAA,EAAA,KAAA,EAAA,KAAA,EAAA,KAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAD7B,EAAA,cAAA,GAAK,QAAK,IAAI,EAAA,OAAA,eAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;GAFrB,UAOM,CAAA,MAAA,EAAA,GAAA,EAAA,MAAA,CAAA,CAAA;GANJ,UAAc,CAAA,GAAA,EAAA,EAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UATL,KAAK,GAAA;AACZ,EAAA,eAAA,CAAA,IAAA,EAAA,KAAK,GAAG,OAAO,EAAA,KAAA,CAAA,CAAA;;;UAER,MAAM,GAAA;AACb,EAAA,eAAA,CAAA,IAAA,EAAA,KAAK,GAAG,IAAI,EAAA,KAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|