tungsten 0.6.2 → 0.6.3

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
- 1789702483581
1
+ 1789711902548
@@ -14,6 +14,7 @@ type DisposableComponent = {
14
14
  __delete: () => void;
15
15
  __deleted: () => void;
16
16
  };
17
+ export type NavigationCause = 'navigate' | 'history';
17
18
  export declare class Instance {
18
19
  location: string;
19
20
  reqRes: ReqRes | null;
@@ -40,14 +41,18 @@ export declare class Instance {
40
41
  } | undefined;
41
42
  constructor(location: string, instanceConfig: InstanceConfig, reqRes: ReqRes | null, appRoutes: AppRoutes, routes: Routes, internalStore: InternalStore, stores: TrueStore<any>[], storeSubscriptions: StoreSubscriptionsMap, globalData: GlobalData, matchedRouteInfo: MatchedRouteInfo, runtimeContext?: ClientRuntimeContext);
42
43
  routeKeyToUrl: (routeKey: RouteKey) => string;
43
- urlToRouteKey: (pathname: string) => RouteKey;
44
+ urlToLocation: (url: {
45
+ pathname: string;
46
+ search: string;
47
+ }) => RouteKey;
44
48
  getRoutes: () => Routes;
45
49
  updateLocation: (location: string) => void;
46
- goto: (path: RouteKey, { pushHistory }?: {
47
- pushHistory?: boolean;
50
+ goto: (path: RouteKey, { cause }?: {
51
+ cause?: NavigationCause;
48
52
  }) => Promise<void>;
49
53
  redirect: (url: string, code?: RedirectCode) => void;
50
54
  httpTo: (url: string) => void;
55
+ httpReload: () => void;
51
56
  setDefaultTitle: (defaultTitle: string) => void;
52
57
  setTitle: (title: string) => void;
53
58
  setTitleToDefault: () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"Instance.d.ts","sourceRoot":"","sources":["../../src/Instance/Instance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4CAA4C,CAAA;AAEvF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cA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Q,CAC9B;IACD,SAAS,eAER;IACD,cAAc,GAAI,UAAU,MAAM,UAMjC;IAED,IAAI,GAAU,MAAM,QAAQ,EAAE,YAAwB;QAAE,KAAK,CAAC,EAAE,eAAe,CAAA;KAAO,mBAsGrF;IASD,QAAQ,GAAI,KAAK,MAAM,EAAE,OAAM,YAAkB,UAahD;IACD,MAAM,GAAI,KAAK,MAAM,UAMpB;IACD,UAAU,aAMT;IACD,eAAe,GAAI,cAAc,MAAM,UAEtC;IACD,QAAQ,GAAI,OAAO,MAAM,UAIxB;IACD,iBAAiB,aAEhB;IAKD,WAAW,GAAI,WAAW,MAAM,GAAG;QAC/B,QAAQ,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;QAChC,gBAAgB,CAAC,EAAE,OAAO,CAAA;KAC7B,aAYA;IAED,SAAS,GAAI,MAAM,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAAE,aAAa,MAAM,aAKjE;IAED,SAAS,GAAI,MAAM,MAAM,OAAO,EAAE,aAAa,MAAM,UAIpD;IAED,iBAAiB,GAAI,WAAW,mBAAmB,UAElD;IAED,mBAAmB,GAAI,WAAW,mBAAmB,UAGpD;IAED,2BAA2B,aAM1B;CACJ;AAID,wBAAgB,cAAc,CAC1B,IAAI,EAAE,MAAM,OAAO,EACnB,WAAW,EAAE,MAAM,EACnB,MAAM,GAAE,CAAC,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,KAAK,IAA6B,QAejF"}
@@ -4,7 +4,7 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
4
4
  import { isClient } from '../isClient.js';
5
5
  import { routing } from "../Servers/routing.js";
6
6
  import { RoutingRedirect } from '../routing/RoutingRedirect.js';
7
- import { routeKeyToUrl, urlToRouteKey } from '../routing/routeUrl.js';
7
+ import { routeKeyToUrl, urlToLocation } from '../routing/routeUrl.js';
8
8
  import { isProd } from '../isProd.js';
9
9
  import { WebRedirect } from '../routing/WebRedirect.js';
10
10
  import { RouteRedirectComponent } from "../components/RouteRedirectComponent.js";
@@ -52,9 +52,9 @@ export class Instance {
52
52
  return routeKeyToUrl(routeKey, this.config.siteBasePath, isProd && this.config.staticSite);
53
53
  });
54
54
  // unchecked: goto's routing() does the pattern matching and 404 fallback
55
- _defineProperty(this, "urlToRouteKey", pathname => {
56
- const routeKey = urlToRouteKey(pathname, this.config.siteBasePath, isProd && this.config.staticSite);
57
- return routeKey; // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion
55
+ _defineProperty(this, "urlToLocation", url => {
56
+ const location = urlToLocation(url, this.config.siteBasePath, isProd && this.config.staticSite);
57
+ return location; // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion
58
58
  });
59
59
  _defineProperty(this, "getRoutes", () => {
60
60
  return typeof this.appRoutes === 'function' ? this.appRoutes(this.reqRes) : this.appRoutes;
@@ -66,18 +66,19 @@ export class Instance {
66
66
  this.location = location;
67
67
  this.internalStore.location.set(location);
68
68
  });
69
+ // 'history': the browser has already moved to path (back/forward)
69
70
  _defineProperty(this, "goto", async (path, {
70
- pushHistory = true
71
+ cause = 'navigate'
71
72
  } = {}) => {
72
73
  if (isServer) {
73
74
  this.redirect(this.routeKeyToUrl(path));
74
75
  return;
75
76
  }
76
- // immediate redirect
77
- //
77
+ // a history move within the page (a #fragment): the browser has already scrolled
78
+ if (cause === 'history' && path === this.location) return;
78
79
  if (!this.config.clientSideNav) {
79
80
  // if clientSideNav is off, these navs should turn into requests to the server
80
- this.httpTo(this.routeKeyToUrl(path));
81
+ if (cause === 'history') this.httpReload();else this.httpTo(this.routeKeyToUrl(path));
81
82
  return;
82
83
  }
83
84
  // the store types these two readonly for everyone else; goto() is what owns them
@@ -132,7 +133,7 @@ export class Instance {
132
133
  this.goto(matchedRouteInfo.content[$props].to);
133
134
  return;
134
135
  } else if (matchedRouteInfo.content[$type] === WebRedirectComponent || matchedRouteInfo.content[$type].prototype instanceof WebRedirectComponent) {
135
- console.log('Content is a WebRedirectComponent - perform a hard redirect');
136
+ //console.log('Content is a WebRedirectComponent - perform a hard redirect')
136
137
  this.redirect(matchedRouteInfo.content[$props].to);
137
138
  return;
138
139
  }
@@ -143,7 +144,7 @@ export class Instance {
143
144
  //console.log('location', location)
144
145
  //console.log('final dest', this.config.siteBasePath + location)
145
146
  this.matchedRouteInfo = matchedRouteInfo;
146
- if (isClient && pushHistory) {
147
+ if (isClient && cause === 'navigate') {
147
148
  const runtimeWindow = this.runtimeContext?.window ?? window;
148
149
  runtimeWindow.history.pushState(null, '', this.routeKeyToUrl(path));
149
150
  }
@@ -186,6 +187,13 @@ export class Instance {
186
187
  const runtimeWindow = this.runtimeContext?.window ?? window;
187
188
  runtimeWindow.location.assign(url);
188
189
  });
190
+ _defineProperty(this, "httpReload", () => {
191
+ if (!isClient) {
192
+ throwError('httpReload', 'Cannot modify window location on the server');
193
+ }
194
+ const runtimeWindow = this.runtimeContext?.window ?? window;
195
+ runtimeWindow.location.reload();
196
+ });
189
197
  _defineProperty(this, "setDefaultTitle", defaultTitle => {
190
198
  this.defaultTitle = defaultTitle;
191
199
  });
@@ -256,9 +264,8 @@ export class Instance {
256
264
  runtimeWindow.addEventListener('popstate', event => {
257
265
  //console.log('popstate', window.location.pathname)
258
266
  //this.updateLocation(window.location.pathname)
259
- const newLocation = this.urlToRouteKey(runtimeWindow.location.pathname);
260
- void this.goto(newLocation, {
261
- pushHistory: false
267
+ void this.goto(this.urlToLocation(runtimeWindow.location), {
268
+ cause: 'history'
262
269
  });
263
270
  });
264
271
  }
@@ -28,7 +28,7 @@ import { Default404 } from "../routing/Default404.js";
28
28
  import { MatchedRoute } from '../routing/MatchedRoute.js';
29
29
  import { isDev } from '../isDev.js';
30
30
  import { isProd } from '../isProd.js';
31
- import { urlToRouteKey } from '../routing/routeUrl.js';
31
+ import { urlToLocation } from '../routing/routeUrl.js';
32
32
  import { warn } from '../appOutput.js';
33
33
  import { reconcileHydratedAttributes } from './reconcileHydratedAttributes.js';
34
34
  import { markOptionSelected } from '../markOptionSelected.js';
@@ -60,7 +60,7 @@ export async function hydrate(appRoutes, RootComponent, instanceConfig) {
60
60
  // happens next (a read of its value throws below). Rendered again at the end, for the count.
61
61
  if (isDev) renderDocInitErrorBanner();
62
62
  //console.log('hydration global data ', __tungsten_global_data__)
63
- const location = urlToRouteKey(window.location.pathname, instanceConfig.siteBasePath, isProd && instanceConfig.staticSite);
63
+ const location = urlToLocation(window.location, instanceConfig.siteBasePath, isProd && instanceConfig.staticSite);
64
64
  const routes = typeof appRoutes === 'function' ? appRoutes(null) : appRoutes;
65
65
  const matchedRouteInfo = hydrationRouting(__tungsten_matched_route_info__, routes);
66
66
  const globalData = __tungsten_global_data__;
@@ -1,4 +1,8 @@
1
1
  import type { SiteBasePath } from '../render/HeadData.js';
2
2
  export declare function routeKeyToUrl(routeKey: string, siteBasePath: SiteBasePath, staticFiles: boolean): string;
3
3
  export declare function urlToRouteKey(pathname: string, siteBasePath: SiteBasePath, staticFiles: boolean): string;
4
+ export declare function urlToLocation(url: {
5
+ pathname: string;
6
+ search: string;
7
+ }, siteBasePath: SiteBasePath, staticFiles: boolean): string;
4
8
  //# sourceMappingURL=routeUrl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"routeUrl.d.ts","sourceRoot":"","sources":["../../src/routing/routeUrl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAOzD,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,GAAG,MAAM,CASxG;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,GAAG,MAAM,CAWxG"}
1
+ {"version":3,"file":"routeUrl.d.ts","sourceRoot":"","sources":["../../src/routing/routeUrl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAOzD,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,GAAG,MAAM,CASxG;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,GAAG,MAAM,CAWxG;AAGD,wBAAgB,aAAa,CACzB,GAAG,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,GAC5F,MAAM,CAER"}
@@ -20,4 +20,8 @@ export function urlToRouteKey(pathname, siteBasePath, staticFiles) {
20
20
  if (path.endsWith('/index.html')) path = path.slice(0, -'index.html'.length);else if (path.endsWith('.html')) path = path.slice(0, -'.html'.length);
21
21
  }
22
22
  return path;
23
+ }
24
+ // the app's location for a browser URL: route path plus query, as the server sees it (no fragment)
25
+ export function urlToLocation(url, siteBasePath, staticFiles) {
26
+ return urlToRouteKey(url.pathname, siteBasePath, staticFiles) + url.search;
23
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tungsten",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "bin": {