@thepassle/app-tools 0.9.9 → 0.9.11

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,5 +1,5 @@
1
1
  /**
2
- * @returns {import('../index').Plugin}
2
+ * @returns {import('../index.js').Plugin}
3
3
  */
4
4
  export function abortPlugin() {
5
5
  let requestId;
@@ -2,7 +2,7 @@ const TEN_MINUTES = 1000 * 60 * 10;
2
2
 
3
3
  /**
4
4
  * @param {{maxAge?: number}} options
5
- * @returns {import('../index').Plugin}
5
+ * @returns {import('../index.js').Plugin}
6
6
  */
7
7
  export function cachePlugin({maxAge = TEN_MINUTES} = {}) {
8
8
  let requestId;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @param {number} ms
3
- * @returns {import('../index').Plugin}
3
+ * @returns {import('../index.js').Plugin}
4
4
  */
5
5
  export const delayPlugin = (ms) => ({
6
6
  name: 'delay',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @param {string} jsonPrefix
3
- * @returns {import('../index').Plugin}
3
+ * @returns {import('../index.js').Plugin}
4
4
  */
5
5
  export function jsonPrefixPlugin(jsonPrefix) {
6
6
  let responseType;
@@ -2,7 +2,7 @@
2
2
  * @param {{
3
3
  * collapsed?: boolean
4
4
  * }} options
5
- * @returns {import('../index').Plugin}
5
+ * @returns {import('../index.js').Plugin}
6
6
  */
7
7
  export function loggerPlugin({collapsed = true} = {}) {
8
8
  let m;
@@ -2,7 +2,7 @@ import { setAbortableTimeout } from '../../utils/async.js';
2
2
 
3
3
  /**
4
4
  * @param {Response | (() => Response) | (() => Promise<Response>)} response
5
- * @returns {import('../index').Plugin}
5
+ * @returns {import('../index.js').Plugin}
6
6
  */
7
7
  export function mock(response) {
8
8
  return {
@@ -8,7 +8,7 @@ function getCookie(name, _document = document) {
8
8
  * xsrfCookieName?: string,
9
9
  * xsrfHeaderName?: string,
10
10
  * }} options
11
- * @returns {import('../index').Plugin}
11
+ * @returns {import('../index.js').Plugin}
12
12
  */
13
13
  export function xsrfPlugin({
14
14
  xsrfCookieName = 'XSRF-TOKEN',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thepassle/app-tools",
3
- "version": "0.9.9",
3
+ "version": "0.9.11",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "scripts": {
package/router/index.js CHANGED
@@ -51,7 +51,7 @@ export class Router extends EventTarget {
51
51
  log('Initialized routes', this.routes);
52
52
 
53
53
  queueMicrotask(() => {
54
- this.navigate(new URL(window.location.href));
54
+ this.navigate(new URL(window.location.href), { replace: true });
55
55
  });
56
56
  window.addEventListener('popstate', this._onPopState);
57
57
  window.addEventListener('click', this._onAnchorClick);
@@ -167,7 +167,8 @@ export class Router extends EventTarget {
167
167
  /**
168
168
  * @param {string | URL} url The URL to navigate to.
169
169
  * @param {{
170
- * backNav?: boolean
170
+ * backNav?: boolean,
171
+ * replace?: boolean,
171
172
  * }} options options An options object to configure the navigation. The backNav property specifies whether the navigation is a backward navigation, which doesn't push the navigation into browser nav history.
172
173
  */
173
174
  async navigate(url, options = {}) {
@@ -214,9 +215,12 @@ export class Router extends EventTarget {
214
215
  }
215
216
  }
216
217
 
217
- if (!options.backNav) {
218
+ if (options?.replace) {
219
+ window.history.replaceState(null, '', `${url.pathname}${url.search}${url.hash}`);
220
+ } else if (!options.backNav) {
218
221
  window.history.pushState(null, '', `${url.pathname}${url.search}${url.hash}`);
219
222
  }
223
+
220
224
  document.title = this.context.title;
221
225
  this._notifyUrlChanged();
222
226
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @returns {import('../index').Plugin}
2
+ * @returns {import('../index.js').Plugin}
3
3
  */
4
- export function abortPlugin(): import('../index').Plugin;
5
- export const abort: import("../types").Plugin;
4
+ export function abortPlugin(): import('../index.js').Plugin;
5
+ export const abort: import("../types.js").Plugin;
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @param {{maxAge?: number}} options
3
- * @returns {import('../index').Plugin}
3
+ * @returns {import('../index.js').Plugin}
4
4
  */
5
5
  export function cachePlugin({ maxAge }?: {
6
6
  maxAge?: number;
7
- }): import('../index').Plugin;
8
- export const cache: import("../types").Plugin;
7
+ }): import('../index.js').Plugin;
8
+ export const cache: import("../types.js").Plugin;
@@ -1,2 +1,2 @@
1
- export function delayPlugin(ms: number): import('../index').Plugin;
2
- export const delay: import("../types").Plugin;
1
+ export function delayPlugin(ms: number): import('../index.js').Plugin;
2
+ export const delay: import("../types.js").Plugin;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @param {string} jsonPrefix
3
- * @returns {import('../index').Plugin}
3
+ * @returns {import('../index.js').Plugin}
4
4
  */
5
- export function jsonPrefixPlugin(jsonPrefix: string): import('../index').Plugin;
6
- export const jsonPrefix: import("../types").Plugin;
5
+ export function jsonPrefixPlugin(jsonPrefix: string): import('../index.js').Plugin;
6
+ export const jsonPrefix: import("../types.js").Plugin;
@@ -2,9 +2,9 @@
2
2
  * @param {{
3
3
  * collapsed?: boolean
4
4
  * }} options
5
- * @returns {import('../index').Plugin}
5
+ * @returns {import('../index.js').Plugin}
6
6
  */
7
7
  export function loggerPlugin({ collapsed }?: {
8
8
  collapsed?: boolean;
9
- }): import('../index').Plugin;
10
- export const logger: import("../types").Plugin;
9
+ }): import('../index.js').Plugin;
10
+ export const logger: import("../types.js").Plugin;
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * @param {Response | (() => Response) | (() => Promise<Response>)} response
3
- * @returns {import('../index').Plugin}
3
+ * @returns {import('../index.js').Plugin}
4
4
  */
5
- export function mock(response: Response | (() => Response) | (() => Promise<Response>)): import('../index').Plugin;
5
+ export function mock(response: Response | (() => Response) | (() => Promise<Response>)): import('../index.js').Plugin;
@@ -3,10 +3,10 @@
3
3
  * xsrfCookieName?: string,
4
4
  * xsrfHeaderName?: string,
5
5
  * }} options
6
- * @returns {import('../index').Plugin}
6
+ * @returns {import('../index.js').Plugin}
7
7
  */
8
8
  export function xsrfPlugin({ xsrfCookieName, xsrfHeaderName }?: {
9
9
  xsrfCookieName?: string;
10
10
  xsrfHeaderName?: string;
11
- }): import('../index').Plugin;
12
- export const xsrf: import("../types").Plugin;
11
+ }): import('../index.js').Plugin;
12
+ export const xsrf: import("../types.js").Plugin;