exta2 0.0.1-beta.29 → 0.0.1-beta.31

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.
@@ -55,12 +55,12 @@ function Link({ href, onClick, prefetch, preload, ...props }) {
55
55
  if (e.defaultPrevented || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || props.target === "_blank")
56
56
  return;
57
57
  let current = window.location, target = new URL(href, current.href), isHashOnly = href.startsWith("#"), isSamePath = target.pathname === current.pathname, isHashChange = target.hash && target.hash !== current.hash;
58
- if (!(isHashOnly || isSamePath && isHashChange) && (e.preventDefault(), e.stopPropagation(), !(onClick && (await onClick(e), e.defaultPrevented)))) {
58
+ if (!(isHashOnly || isSamePath && isHashChange) && !(onClick && (await onClick(e), e.defaultPrevented))) {
59
59
  if (isExternal(href)) {
60
60
  window.location.href = href;
61
61
  return;
62
62
  }
63
- await extaRouter.goto(target.pathname), router.push(target.pathname + target.search + target.hash);
63
+ e.preventDefault(), e.stopPropagation(), await extaRouter.goto(target.pathname), router.push(target.pathname + target.search + target.hash);
64
64
  }
65
65
  } }, props.children);
66
66
  }
@@ -19,12 +19,12 @@ function Link({ href, onClick, prefetch, preload, ...props }) {
19
19
  if (e.defaultPrevented || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || props.target === "_blank")
20
20
  return;
21
21
  let current = window.location, target = new URL(href, current.href), isHashOnly = href.startsWith("#"), isSamePath = target.pathname === current.pathname, isHashChange = target.hash && target.hash !== current.hash;
22
- if (!(isHashOnly || isSamePath && isHashChange) && (e.preventDefault(), e.stopPropagation(), !(onClick && (await onClick(e), e.defaultPrevented)))) {
22
+ if (!(isHashOnly || isSamePath && isHashChange) && !(onClick && (await onClick(e), e.defaultPrevented))) {
23
23
  if (isExternal(href)) {
24
24
  window.location.href = href;
25
25
  return;
26
26
  }
27
- await extaRouter.goto(target.pathname), router.push(target.pathname + target.search + target.hash);
27
+ e.preventDefault(), e.stopPropagation(), await extaRouter.goto(target.pathname), router.push(target.pathname + target.search + target.hash);
28
28
  }
29
29
  } }, props.children);
30
30
  }
package/dist/router.d.ts CHANGED
@@ -25,6 +25,7 @@ declare class Router {
25
25
  modules: Record<string, any>;
26
26
  data: Map<string, any>;
27
27
  loadedModules: Map<string, any>;
28
+ hook: EventTarget;
28
29
  constructor(routes: PageManifest[]);
29
30
  prefetch(url: string): Promise<void>;
30
31
  getHref(page: PageManifest): string;
package/dist/router.js CHANGED
@@ -217,8 +217,9 @@ var Router = class {
217
217
  modules = {};
218
218
  data = /* @__PURE__ */ new Map();
219
219
  loadedModules = /* @__PURE__ */ new Map();
220
+ hook;
220
221
  constructor(routes) {
221
- this.routes = routes;
222
+ this.hook = new EventTarget(), this.routes = routes;
222
223
  }
223
224
  async prefetch(url) {
224
225
  let _url = prettyURL(url);
@@ -257,13 +258,16 @@ var Router = class {
257
258
  return url = url.toLowerCase(), findPage(url, this.routes);
258
259
  }
259
260
  async goto(href) {
261
+ this.hook.dispatchEvent(new Event("load:start"));
260
262
  let url = decodeURIComponent(
261
263
  new URL(href, window.location.origin).pathname
262
264
  ).toLowerCase(), page = this.findPage(url);
263
- if (await this.loadLayout(), await this.loadError(), !page)
265
+ if (await this.loadLayout(), await this.loadError(), !page) {
266
+ this.hook.dispatchEvent(new Event("load:end"));
264
267
  return;
268
+ }
265
269
  let pageModule = this.loadedModules.has(page.path) ? this.loadedModules.get(page.path) : this.loadedModules.set(page.path, await import_exta_pages.default[page.path]()).get(page.path), _url = prettyURL(url), data = this.data.has(_url) ? this.data.get(_url) : this.data.set(_url, await loadPageData(url)).get(_url);
266
- if (this.modules[page.path] = pageModule, data?.status !== 404)
270
+ if (this.modules[page.path] = pageModule, this.hook.dispatchEvent(new Event("load:end")), data?.status !== 404)
267
271
  return { module: this.modules, data };
268
272
  }
269
273
  }, router = new Router(import_exta_manifest.PAGES_MANIFEST);
package/dist/router.mjs CHANGED
@@ -188,8 +188,9 @@ var Router = class {
188
188
  modules = {};
189
189
  data = /* @__PURE__ */ new Map();
190
190
  loadedModules = /* @__PURE__ */ new Map();
191
+ hook;
191
192
  constructor(routes) {
192
- this.routes = routes;
193
+ this.hook = new EventTarget(), this.routes = routes;
193
194
  }
194
195
  async prefetch(url) {
195
196
  let _url = prettyURL(url);
@@ -228,13 +229,16 @@ var Router = class {
228
229
  return url = url.toLowerCase(), findPage(url, this.routes);
229
230
  }
230
231
  async goto(href) {
232
+ this.hook.dispatchEvent(new Event("load:start"));
231
233
  let url = decodeURIComponent(
232
234
  new URL(href, window.location.origin).pathname
233
235
  ).toLowerCase(), page = this.findPage(url);
234
- if (await this.loadLayout(), await this.loadError(), !page)
236
+ if (await this.loadLayout(), await this.loadError(), !page) {
237
+ this.hook.dispatchEvent(new Event("load:end"));
235
238
  return;
239
+ }
236
240
  let pageModule = this.loadedModules.has(page.path) ? this.loadedModules.get(page.path) : this.loadedModules.set(page.path, await pages[page.path]()).get(page.path), _url = prettyURL(url), data = this.data.has(_url) ? this.data.get(_url) : this.data.set(_url, await loadPageData(url)).get(_url);
237
- if (this.modules[page.path] = pageModule, data?.status !== 404)
241
+ if (this.modules[page.path] = pageModule, this.hook.dispatchEvent(new Event("load:end")), data?.status !== 404)
238
242
  return { module: this.modules, data };
239
243
  }
240
244
  }, router = new Router(manifest);
package/env.d.ts CHANGED
@@ -31,6 +31,25 @@ declare module '$exta-router' {
31
31
  params: string[];
32
32
  }
33
33
 
34
+ interface LoaderEventMap {
35
+ 'load:start': void;
36
+ 'load:end': void;
37
+ }
38
+
39
+ declare class LoaderHook extends EventTarget {
40
+ addEventListener<K extends keyof LoaderEventMap>(
41
+ type: K,
42
+ listener: (ev: CustomEvent<void>) => void,
43
+ options?: boolean | AddEventListenerOptions,
44
+ ): void;
45
+
46
+ removeEventListener<K extends keyof LoaderEventMap>(
47
+ type: K,
48
+ listener: (ev: CustomEvent<void>) => void,
49
+ options?: boolean | EventListenerOptions,
50
+ ): void;
51
+ }
52
+
34
53
  /**
35
54
  * Return `url.location`.
36
55
  */
@@ -81,6 +100,8 @@ declare module '$exta-router' {
81
100
  */
82
101
  data: Map<string, any>;
83
102
 
103
+ hook: LoaderHook;
104
+
84
105
  constructor(routes: PageManifest[]);
85
106
 
86
107
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exta2",
3
- "version": "0.0.1-beta.29",
3
+ "version": "0.0.1-beta.31",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",