crelte 0.4.0 → 0.4.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"InnerRouter.d.ts","sourceRoot":"","sources":["../../src/routing/InnerRouter.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,OAAO,EAAE,EAAa,cAAc,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,MAAM,MAAM,eAAe,GAAG;IAC7B,kBAAkB,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,WAAW;IAC/B,KAAK,EAAE,IAAI,EAAE,CAAC;IACd;;;;;OAKG;IACH,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,kBAAkB,EAAE,OAAO,CAAC;IAC5B;;;OAGG;IACH,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;IAC7D,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAEpC,OAAO,CAAC,qBAAqB,CAAa;IAE1C;;;;;OAKG;gBACS,KAAK,EAAE,eAAe,EAAE,EAAE,IAAI,EAAE,eAAe;IAkB3D;;OAEG;IACH,UAAU;IAgBV;;OAEG;IACH,UAAU;IAEV;;;;OAIG;IACH,gBAAgB,CAAC,UAAU,GAAE,MAAM,GAAG,IAAW,GAAG,IAAI;IAsCxD;;OAEG;IACH,WAAW,IAAI,IAAI;IAInB;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAKjC;;;;;;OAMG;IACH,eAAe,CACd,MAAM,EA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AE1C;;;;;OAKG;gBACS,KAAK,EAAE,eAAe,EAAE,EAAE,IAAI,EAAE,eAAe;IAkB3D;;OAEG;IACH,UAAU;IAgBV;;OAEG;IACH,UAAU;IAEV;;;;OAIG;IACH,gBAAgB,CAAC,UAAU,GAAE,MAAM,GAAG,IAAW,GAAG,IAAI;IAsCxD;;OAEG;IACH,WAAW,IAAI,IAAI;IAInB;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAKjC;;;;;;OAMG;IACH,eAAe,CACd,MAAM,EAAE,MAAM,GAAG,GAAG,GAAG,KAAK,GAAG,OAAO,EACtC,IAAI,GAAE,cAAmB,GACvB,OAAO;IA0BV;;;;;OAKG;IACH,YAAY,CAAC,OAAO,EAAE,GAAG,GAAG,KAAK;IAcjC,MAAM;IAiGN;;;;;;;;;OASG;IACH,IAAI,CAAC,GAAG,EAAE,OAAO;IA6CjB;;;;;;;OAOG;IACH,IAAI,CAAC,GAAG,EAAE,OAAO;IAuBjB;;;;;;;OAOG;IACH,OAAO,CAAC,GAAG,EAAE,OAAO;IAuBpB;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,GAAG,KAAK,GAAG,OAAO;IAW9C,QAAQ,CAAC,GAAG,EAAE,OAAO;CAsErB"}
@@ -1,4 +1,4 @@
1
- import Site from './Site.js';
1
+ import Site, { siteFromUrl } from './Site.js';
2
2
  import { ClientHistory, ServerHistory } from './History.js';
3
3
  import Request, { isRequest } from './Request.js';
4
4
  import Route from './Route.js';
@@ -155,23 +155,7 @@ export default class InnerRouter {
155
155
  // strip stuff we dont need from url
156
156
  const route = new Route(fullUrl, null);
157
157
  const url = route.url;
158
- let site = null;
159
- // get the site which matches the url the most
160
- for (const s of this.sites) {
161
- const siteUri = s.uri;
162
- // make sure the start of the url matches
163
- if (url.host !== s.url.host || !url.pathname.startsWith(siteUri)) {
164
- continue;
165
- }
166
- // make sure that after the base url a slash follows or nothing
167
- const uri = url.pathname.substring(siteUri.length);
168
- if (uri.length > 0 && !uri.startsWith('/'))
169
- continue;
170
- /// make sure we get the most matched site
171
- if (site && site.uri.length > siteUri.length)
172
- continue;
173
- site = s;
174
- }
158
+ const site = siteFromUrl(url, this.sites);
175
159
  // todo should we throw if we can't find a site
176
160
  // or use the site which matches the language
177
161
  route.site = site ?? this.defaultSite();
@@ -192,12 +176,8 @@ export default class InnerRouter {
192
176
  e.preventDefault();
193
177
  const req = this.targetToRequest(link.href, { origin: 'click' });
194
178
  const routeEq = this.route && this.route.eqUrl(req) && this.route.eqSearch(req);
195
- // the route is the same don't do anything
196
- // or maybe scroll the page to the hash? todo
197
- if (routeEq && this.route?.eqHash(req))
198
- return;
199
- // this means the hash did not match, so we wan't to just scroll but not load
200
- // data
179
+ // this means the route is the same maybe with a different hash
180
+ // so it is not necessary to load the data again
201
181
  if (routeEq) {
202
182
  req.disableLoadData = true;
203
183
  }
@@ -278,6 +258,7 @@ export default class InnerRouter {
278
258
  throw new Error('Do not use open with push or replace');
279
259
  }
280
260
  const current = this.route;
261
+ // store scrollY
281
262
  if (current) {
282
263
  // if the scrollY would still be updated we clear the timeout
283
264
  // since we should have the latest scrollY
@@ -44,4 +44,5 @@ export default class Site {
44
44
  */
45
45
  get uri(): string;
46
46
  }
47
+ export declare function siteFromUrl(url: URL, sites: Site[]): Site | null;
47
48
  //# sourceMappingURL=Site.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Site.d.ts","sourceRoot":"","sources":["../../src/routing/Site.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,eAAe,GAAG;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,IAAI;IACxB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,GAAG,EAAE,GAAG,CAAC;IAET;;;;OAIG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAEpB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;gBAEL,GAAG,EAAE,eAAe;IAShC;;;;OAIG;IACH,IAAI,GAAG,IAAI,MAAM,CAEhB;CACD"}
1
+ {"version":3,"file":"Site.d.ts","sourceRoot":"","sources":["../../src/routing/Site.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,eAAe,GAAG;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,IAAI;IACxB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,GAAG,EAAE,GAAG,CAAC;IAET;;;;OAIG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAEpB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;gBAEL,GAAG,EAAE,eAAe;IAShC;;;;OAIG;IACH,IAAI,GAAG,IAAI,MAAM,CAEhB;CACD;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,GAAG,IAAI,CAsBhE"}
@@ -46,3 +46,23 @@ export default class Site {
46
46
  return trimSlashEnd(this.url.pathname);
47
47
  }
48
48
  }
49
+ export function siteFromUrl(url, sites) {
50
+ let site = null;
51
+ // get the site which matches the url the most
52
+ for (const s of sites) {
53
+ const siteUri = s.uri;
54
+ // make sure the start of the url matches
55
+ if (url.host !== s.url.host || !url.pathname.startsWith(siteUri)) {
56
+ continue;
57
+ }
58
+ // make sure that after the base url a slash follows or nothing
59
+ const uri = url.pathname.substring(siteUri.length);
60
+ if (uri.length > 0 && !uri.startsWith('/'))
61
+ continue;
62
+ /// make sure we get the most matched site
63
+ if (site && site.uri.length > siteUri.length)
64
+ continue;
65
+ site = s;
66
+ }
67
+ return site;
68
+ }
@@ -0,0 +1,3 @@
1
+ import { siteFromUrl } from './Site.js';
2
+ export { siteFromUrl };
3
+ //# sourceMappingURL=internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/routing/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { siteFromUrl } from './Site.js';
2
+ export { siteFromUrl };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crelte",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "author": "Crelte <support@crelte.com>",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -44,6 +44,10 @@
44
44
  "types": "./dist/routing/index.d.ts",
45
45
  "default": "./dist/routing/index.js"
46
46
  },
47
+ "./routing/internal": {
48
+ "types": "./dist/routing/internal.d.ts",
49
+ "default": "./dist/routing/internal.js"
50
+ },
47
51
  "./entry": {
48
52
  "types": "./dist/entry/index.d.ts",
49
53
  "default": "./dist/entry/index.js"
@@ -1,4 +1,4 @@
1
- import Site, { SiteFromGraphQl } from './Site.js';
1
+ import Site, { SiteFromGraphQl, siteFromUrl } from './Site.js';
2
2
  import History from './History.js';
3
3
  import { ClientHistory, ServerHistory } from './History.js';
4
4
  import Request, { isRequest, RequestOptions } from './Request.js';
@@ -184,25 +184,7 @@ export default class InnerRouter {
184
184
  const route = new Route(fullUrl, null!);
185
185
  const url = route.url;
186
186
 
187
- let site: Site | null = null;
188
- // get the site which matches the url the most
189
- for (const s of this.sites) {
190
- const siteUri = s.uri;
191
-
192
- // make sure the start of the url matches
193
- if (url.host !== s.url.host || !url.pathname.startsWith(siteUri)) {
194
- continue;
195
- }
196
-
197
- // make sure that after the base url a slash follows or nothing
198
- const uri = url.pathname.substring(siteUri.length);
199
- if (uri.length > 0 && !uri.startsWith('/')) continue;
200
-
201
- /// make sure we get the most matched site
202
- if (site && site.uri.length > siteUri.length) continue;
203
-
204
- site = s;
205
- }
187
+ const site = siteFromUrl(url, this.sites);
206
188
 
207
189
  // todo should we throw if we can't find a site
208
190
  // or use the site which matches the language
@@ -226,12 +208,9 @@ export default class InnerRouter {
226
208
  const req = this.targetToRequest(link.href, { origin: 'click' });
227
209
  const routeEq =
228
210
  this.route && this.route.eqUrl(req) && this.route.eqSearch(req);
229
- // the route is the same don't do anything
230
- // or maybe scroll the page to the hash? todo
231
- if (routeEq && this.route?.eqHash(req)) return;
232
211
 
233
- // this means the hash did not match, so we wan't to just scroll but not load
234
- // data
212
+ // this means the route is the same maybe with a different hash
213
+ // so it is not necessary to load the data again
235
214
  if (routeEq) {
236
215
  req.disableLoadData = true;
237
216
  }
@@ -327,6 +306,7 @@ export default class InnerRouter {
327
306
  }
328
307
 
329
308
  const current = this.route;
309
+ // store scrollY
330
310
  if (current) {
331
311
  // if the scrollY would still be updated we clear the timeout
332
312
  // since we should have the latest scrollY
@@ -63,3 +63,27 @@ export default class Site {
63
63
  return trimSlashEnd(this.url.pathname);
64
64
  }
65
65
  }
66
+
67
+ export function siteFromUrl(url: URL, sites: Site[]): Site | null {
68
+ let site: Site | null = null;
69
+ // get the site which matches the url the most
70
+ for (const s of sites) {
71
+ const siteUri = s.uri;
72
+
73
+ // make sure the start of the url matches
74
+ if (url.host !== s.url.host || !url.pathname.startsWith(siteUri)) {
75
+ continue;
76
+ }
77
+
78
+ // make sure that after the base url a slash follows or nothing
79
+ const uri = url.pathname.substring(siteUri.length);
80
+ if (uri.length > 0 && !uri.startsWith('/')) continue;
81
+
82
+ /// make sure we get the most matched site
83
+ if (site && site.uri.length > siteUri.length) continue;
84
+
85
+ site = s;
86
+ }
87
+
88
+ return site;
89
+ }
@@ -0,0 +1,3 @@
1
+ import { siteFromUrl } from './Site.js';
2
+
3
+ export { siteFromUrl };