svelte-spa-history-router 2.1.1 → 2.2.0-next.0

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 (61) hide show
  1. package/README.md +11 -2
  2. package/{example → examples/app-svelte4}/dist/Article.js +11 -11
  3. package/examples/app-svelte4/dist/Article.js.map +1 -0
  4. package/{example → examples/app-svelte4}/dist/Login.js +8 -8
  5. package/examples/app-svelte4/dist/Login.js.map +1 -0
  6. package/{example → examples/app-svelte4}/dist/Query.js +8 -8
  7. package/examples/app-svelte4/dist/Query.js.map +1 -0
  8. package/{example → examples/app-svelte4}/dist/main2.js +148 -116
  9. package/examples/app-svelte4/dist/main2.js.map +1 -0
  10. package/examples/app-svelte4/package-lock.json +776 -0
  11. package/examples/app-svelte4/package.json +23 -0
  12. package/{example → examples/app-svelte4}/rollup.config.js +25 -2
  13. package/examples/app-svelte4/server.js +115 -0
  14. package/{example → examples/app-svelte4/src}/App.svelte +9 -5
  15. package/{example → examples/app-svelte4/src}/Article.svelte +1 -2
  16. package/{example → examples/app-svelte4/src}/Home.svelte +1 -2
  17. package/{example → examples/app-svelte4/src}/Login.svelte +1 -1
  18. package/{example → examples/app-svelte4/src}/Query.svelte +2 -3
  19. package/{example → examples/app-svelte4/src}/data-source.js +7 -0
  20. package/examples/app-svelte4/src/store.js +11 -0
  21. package/examples/app-svelte5/index.html +14 -0
  22. package/examples/app-svelte5/jsconfig.json +17 -0
  23. package/examples/app-svelte5/package-lock.json +1178 -0
  24. package/examples/app-svelte5/package.json +24 -0
  25. package/examples/app-svelte5/playwright.config.js +26 -0
  26. package/examples/app-svelte5/src/App.svelte +66 -0
  27. package/examples/app-svelte5/src/articles.js +43 -0
  28. package/examples/app-svelte5/src/main.js +10 -0
  29. package/examples/app-svelte5/src/pages/Admin.svelte +6 -0
  30. package/examples/app-svelte5/src/pages/Blog.svelte +18 -0
  31. package/examples/app-svelte5/src/pages/Guide.svelte +21 -0
  32. package/examples/app-svelte5/src/pages/Home.svelte +6 -0
  33. package/examples/app-svelte5/src/pages/NotFound.svelte +1 -0
  34. package/examples/app-svelte5/src/pages/Post.svelte +21 -0
  35. package/examples/app-svelte5/src/vite-env.d.ts +2 -0
  36. package/examples/app-svelte5/svelte.config.js +7 -0
  37. package/examples/app-svelte5/tests/e2e.spec.js +69 -0
  38. package/examples/app-svelte5/vite.config.js +7 -0
  39. package/jsconfig.json +1 -1
  40. package/package.json +10 -10
  41. package/src/Router.svelte +52 -12
  42. package/src/index.d.ts +48 -0
  43. package/src/link.js +7 -1
  44. package/src/push.js +6 -0
  45. package/src/scratch.js +12 -0
  46. package/src/stores.js +24 -6
  47. package/src/types.ts +26 -4
  48. package/example/dist/Article.js.map +0 -1
  49. package/example/dist/Login.js.map +0 -1
  50. package/example/dist/Query.js.map +0 -1
  51. package/example/dist/main2.js.map +0 -1
  52. package/example/store.js +0 -3
  53. package/server.js +0 -65
  54. package/src/route_state.js +0 -44
  55. /package/{example → examples/app-svelte4}/dist/index.html +0 -0
  56. /package/{example → examples/app-svelte4}/dist/main.js +0 -0
  57. /package/{example → examples/app-svelte4}/dist/main.js.map +0 -0
  58. /package/{example → examples/app-svelte4/src}/Admin.svelte +0 -0
  59. /package/{example → examples/app-svelte4/src}/NotFound.svelte +0 -0
  60. /package/{example → examples/app-svelte4/src}/main.js +0 -0
  61. /package/{tests → examples/app-svelte4/tests}/e2e.test.js +0 -0
package/README.md CHANGED
@@ -24,7 +24,7 @@ $ yarn add svelte-spa-history-router
24
24
 
25
25
  ## Usage
26
26
 
27
- Import `Route` and put into your main component (typically App.svelte).
27
+ Import `Router` and put into your main component (typically App.svelte).
28
28
 
29
29
  For example:
30
30
 
@@ -184,9 +184,18 @@ store to detect URL changes (including query string or hash)
184
184
 
185
185
  ## ChangeLog
186
186
 
187
+ ### 2.1.0-next.0
188
+
189
+ * [PR12](https://github.com/ykrods/svelte-spa-history-router/pull/12)
190
+ * Refactor (changes: [2.1.2...7b7795b](https://github.com/ykrods/svelte-spa-history-router/compare/2.1.2...7b7795b2675c452a1a189d3931c0c4c9abb04c51) )
191
+
192
+ ### 2.1.2 (2024-04-29)
193
+
194
+ * Support types [PR10](https://github.com/ykrods/svelte-spa-history-router/pull/10)
195
+
187
196
  ### 2.1.1 (2024-01-13)
188
197
 
189
- * Support Types
198
+ * ~~Support Types~~ Add typecheck [PR9](https://github.com/ykrods/svelte-spa-history-router/pull/9)
190
199
 
191
200
  ### 2.1.0 (2021-04-29)
192
201
 
@@ -1,11 +1,11 @@
1
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 v4.2.8 */
3
+ /* src/Article.svelte generated by Svelte v4.2.17 */
4
4
 
5
5
  const { console: console_1 } = globals;
6
- const file = "Article.svelte";
6
+ const file = "src/Article.svelte";
7
7
 
8
- // (19:4) {#if article.previous}
8
+ // (18:4) {#if article.previous}
9
9
  function create_if_block_1(ctx) {
10
10
  let a;
11
11
  let t;
@@ -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, 381);
21
+ add_location(a, file, 17, 26, 354);
22
22
  },
23
23
  m: function mount(target, anchor) {
24
24
  insert_dev(target, a, anchor);
@@ -48,14 +48,14 @@ function create_if_block_1(ctx) {
48
48
  block,
49
49
  id: create_if_block_1.name,
50
50
  type: "if",
51
- source: "(19:4) {#if article.previous}",
51
+ source: "(18:4) {#if article.previous}",
52
52
  ctx
53
53
  });
54
54
 
55
55
  return block;
56
56
  }
57
57
 
58
- // (20:4) {#if article.next}
58
+ // (19:4) {#if article.next}
59
59
  function create_if_block(ctx) {
60
60
  let a;
61
61
  let t;
@@ -68,7 +68,7 @@ function create_if_block(ctx) {
68
68
  a = element("a");
69
69
  t = text("Next");
70
70
  attr_dev(a, "href", a_href_value = `/posts/${/*article*/ ctx[0].next}`);
71
- add_location(a, file, 19, 22, 465);
71
+ add_location(a, file, 18, 22, 438);
72
72
  },
73
73
  m: function mount(target, anchor) {
74
74
  insert_dev(target, a, anchor);
@@ -98,7 +98,7 @@ function create_if_block(ctx) {
98
98
  block,
99
99
  id: create_if_block.name,
100
100
  type: "if",
101
- source: "(20:4) {#if article.next}",
101
+ source: "(19:4) {#if article.next}",
102
102
  ctx
103
103
  });
104
104
 
@@ -135,11 +135,11 @@ function create_fragment(ctx) {
135
135
  if (if_block0) if_block0.c();
136
136
  t4 = space();
137
137
  if (if_block1) if_block1.c();
138
- add_location(h1, file, 15, 2, 299);
138
+ add_location(h1, file, 14, 2, 272);
139
139
  html_tag.a = t3;
140
- add_location(div0, file, 17, 2, 349);
140
+ add_location(div0, file, 16, 2, 322);
141
141
  attr_dev(div1, "class", "article");
142
- add_location(div1, file, 14, 0, 275);
142
+ add_location(div1, file, 13, 0, 248);
143
143
  },
144
144
  l: function claim(nodes) {
145
145
  throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Article.js","sources":["../src/Article.svelte"],"sourcesContent":["<script>\n import { link, routeParams } from 'svelte-spa-history-router';\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":";;;;;;;;;;;;;;;;;;YAiB0E,MAAI,CAAA,CAAA;AAAxB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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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,7 +1,7 @@
1
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
2
 
3
- /* Login.svelte generated by Svelte v4.2.8 */
4
- const file = "Login.svelte";
3
+ /* src/Login.svelte generated by Svelte v4.2.17 */
4
+ const file = "src/Login.svelte";
5
5
 
6
6
  // (18:2) {:else }
7
7
  function create_else_block(ctx) {
@@ -20,7 +20,7 @@ function create_else_block(ctx) {
20
20
  button = element("button");
21
21
  button.textContent = "logout";
22
22
  attr_dev(button, "id", "logout");
23
- add_location(button, file, 18, 26, 341);
23
+ add_location(button, file, 18, 26, 352);
24
24
  },
25
25
  m: function mount(target, anchor) {
26
26
  insert_dev(target, t0, anchor);
@@ -29,7 +29,7 @@ function create_else_block(ctx) {
29
29
  insert_dev(target, button, anchor);
30
30
 
31
31
  if (!mounted) {
32
- dispose = listen_dev(button, "click", /*logout*/ ctx[2], false, false, false, false);
32
+ dispose = listen_dev(button, "click", /*logout*/ ctx[2], false);
33
33
  mounted = true;
34
34
  }
35
35
  },
@@ -71,13 +71,13 @@ function create_if_block(ctx) {
71
71
  button = element("button");
72
72
  button.textContent = "login";
73
73
  attr_dev(button, "id", "login");
74
- add_location(button, file, 16, 2, 253);
74
+ add_location(button, file, 16, 2, 264);
75
75
  },
76
76
  m: function mount(target, anchor) {
77
77
  insert_dev(target, button, anchor);
78
78
 
79
79
  if (!mounted) {
80
- dispose = listen_dev(button, "click", /*login*/ ctx[1], false, false, false, false);
80
+ dispose = listen_dev(button, "click", /*login*/ ctx[1], false);
81
81
  mounted = true;
82
82
  }
83
83
  },
@@ -123,9 +123,9 @@ function create_fragment(ctx) {
123
123
  h1.textContent = "Login";
124
124
  t1 = space();
125
125
  if_block.c();
126
- add_location(h1, file, 14, 2, 212);
126
+ add_location(h1, file, 14, 2, 223);
127
127
  attr_dev(div, "class", "login");
128
- add_location(div, file, 13, 0, 190);
128
+ add_location(div, file, 13, 0, 201);
129
129
  },
130
130
  l: function claim(nodes) {
131
131
  throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Login.js","sources":["../src/Login.svelte"],"sourcesContent":["<script>\n import { push } from 'svelte-spa-history-router';\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,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,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,7 +1,7 @@
1
1
  import { S as SvelteComponentDev, i as init, s as safe_not_equal, d as dispatch_dev, v as validate_store, y as currentURL, c as component_subscribe, a as validate_slots, l as link, b as space, e as element, t as text, h as attr_dev, f as add_location, j as insert_dev, k as append_dev, p as action_destroyer, m as set_data_dev, n as noop, o as detach_dev, z as run_all } from './main2.js';
2
2
 
3
- /* Query.svelte generated by Svelte v4.2.8 */
4
- const file = "Query.svelte";
3
+ /* src/Query.svelte generated by Svelte v4.2.17 */
4
+ const file = "src/Query.svelte";
5
5
 
6
6
  function create_fragment(ctx) {
7
7
  let t0;
@@ -33,14 +33,14 @@ function create_fragment(ctx) {
33
33
  a1.textContent = "bar";
34
34
  document.title = "query";
35
35
  attr_dev(span, "id", "name");
36
- add_location(span, file, 10, 11, 256);
37
- add_location(p, file, 10, 2, 247);
36
+ add_location(span, file, 9, 11, 230);
37
+ add_location(p, file, 9, 2, 221);
38
38
  attr_dev(a0, "href", "/query?name=foo");
39
- add_location(a0, file, 11, 2, 294);
39
+ add_location(a0, file, 10, 2, 268);
40
40
  attr_dev(a1, "href", "/query?name=bar");
41
- add_location(a1, file, 12, 2, 339);
41
+ add_location(a1, file, 11, 2, 313);
42
42
  attr_dev(div, "class", "query");
43
- add_location(div, file, 9, 0, 225);
43
+ add_location(div, file, 8, 0, 199);
44
44
  },
45
45
  l: function claim(nodes) {
46
46
  throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
@@ -118,7 +118,7 @@ function instance($$self, $$props, $$invalidate) {
118
118
 
119
119
  $$self.$$.update = () => {
120
120
  if ($$self.$$.dirty & /*$currentURL*/ 2) {
121
- $$invalidate(0, name = $currentURL.searchParams.get("name") || 'unknown');
121
+ $$invalidate(0, name = $currentURL.searchParams.get("name") ?? 'unknown');
122
122
  }
123
123
  };
124
124
 
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Query.js","sources":["../src/Query.svelte"],"sourcesContent":["<script>\n import { link, currentURL } from \"svelte-spa-history-router\";\n\n $: name = $currentURL.searchParams.get(\"name\") ?? 'unknown';\n</script>\n<svelte:head>\n <title>query</title>\n</svelte:head>\n<div class=\"query\">\n <p>name: <span id=\"name\">{ name }</span></p>\n <a use:link href=\"/query?name=foo\">foo</a>\n <a use:link href=\"/query?name=bar\">bar</a>\n</div>\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;aASK,QAAM,CAAA,CAAA;;sBAAkB,GAAI,CAAA,CAAA,CAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;GADjC,UAIM,CAAA,MAAA,EAAA,GAAA,EAAA,MAAA,CAAA,CAAA;GAHJ,UAA4C,CAAA,GAAA,EAAA,CAAA,CAAA,CAAA;;GAAnC,UAA+B,CAAA,CAAA,EAAA,IAAA,CAAA,CAAA;;;GACxC,UAA0C,CAAA,GAAA,EAAA,EAAA,CAAA,CAAA;;GAC1C,UAA0C,CAAA,GAAA,EAAA,EAAA,CAAA,CAAA;;;;;;;;;;;;qDAFf,GAAI,CAAA,CAAA,CAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAN9B,YAAA,CAAA,CAAA,EAAE,IAAI,GAAG,WAAW,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAA,IAAK,SAAS,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;"}