@domql/router 2.3.65 → 2.3.71

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.
package/dist/cjs/index.js CHANGED
@@ -33,7 +33,8 @@ const defaultOptions = {
33
33
  scrollToTop: true,
34
34
  scrollToNode: false,
35
35
  useFragment: false,
36
- updateState: true
36
+ updateState: true,
37
+ stateContentUpdate: false
37
38
  };
38
39
  const router = (element, path, state = {}, options = defaultOptions) => {
39
40
  (0, import_utils.merge)(options, defaultOptions);
@@ -46,7 +47,7 @@ const router = (element, path, state = {}, options = defaultOptions) => {
46
47
  import_globals.window.history.pushState(state, null, pathname + (hash ? `#${hash}` : ""));
47
48
  element.set({ tag: options.useFragment && "fragment", extend: content });
48
49
  if (options.updateState)
49
- element.state.update({ route, hash });
50
+ element.state.update({ route, hash }, { preventContentUpdate: !options.stateContentUpdate });
50
51
  const rootNode = element.node;
51
52
  if (options.scrollToTop)
52
53
  rootNode.scrollTo({ behavior: "smooth", top: 0, left: 0 });
package/index.js CHANGED
@@ -15,7 +15,8 @@ const defaultOptions = {
15
15
  scrollToTop: true,
16
16
  scrollToNode: false,
17
17
  useFragment: false,
18
- updateState: true
18
+ updateState: true,
19
+ stateContentUpdate: false
19
20
  }
20
21
 
21
22
  export const router = (
@@ -36,7 +37,7 @@ export const router = (
36
37
  if (options.pushState) window.history.pushState(state, null, pathname + (hash ? `#${hash}` : ''))
37
38
 
38
39
  element.set({ tag: options.useFragment && 'fragment', extend: content })
39
- if (options.updateState) element.state.update({ route, hash })
40
+ if (options.updateState) element.state.update({ route, hash }, { preventContentUpdate: !options.stateContentUpdate })
40
41
 
41
42
  const rootNode = element.node
42
43
  if (options.scrollToTop) rootNode.scrollTo({ behavior: 'smooth', top: 0, left: 0 })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/router",
3
- "version": "2.3.65",
3
+ "version": "2.3.71",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "dist/esm/index.js",
@@ -18,11 +18,12 @@
18
18
  "build:esm": "npx esbuild *.js --target=es2020 --format=esm --outdir=dist/esm",
19
19
  "build:cjs": "npx esbuild *.js --target=node16 --format=cjs --outdir=dist/cjs",
20
20
  "build:iife": "npx esbuild *.js --target=node16 --format=iife --outdir=dist/iife",
21
- "build": "yarn build:esm && yarn build:cjs",
21
+ "build": "yarn build:cjs",
22
22
  "prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
23
23
  },
24
24
  "dependencies": {
25
+ "@domql/globals": "latest",
25
26
  "@domql/utils": "latest"
26
27
  },
27
- "gitHead": "d6740b17c388380f26aaaa962a1e518324a90a66"
28
+ "gitHead": "dca5db039e858002d2d7b2d6e827d0cef26faa98"
28
29
  }
package/dist/esm/index.js DELETED
@@ -1,43 +0,0 @@
1
- import { window } from "@domql/globals";
2
- import { merge } from "@domql/utils";
3
- const getActiveRoute = (route = window.location.pathname, level) => `/${route.split("/")[level + 1]}`;
4
- let lastLevel = 0;
5
- const defaultOptions = {
6
- level: lastLevel,
7
- pushState: true,
8
- scrollToTop: true,
9
- scrollToNode: false,
10
- useFragment: false,
11
- updateState: true
12
- };
13
- const router = (element, path, state = {}, options = defaultOptions) => {
14
- merge(options, defaultOptions);
15
- lastLevel = options.lastLevel;
16
- const [pathname, hash] = path.split("#");
17
- const route = getActiveRoute(pathname, options.level);
18
- const content = element.routes[route] || element.routes["/*"];
19
- if (content) {
20
- if (options.pushState)
21
- window.history.pushState(state, null, pathname + (hash ? `#${hash}` : ""));
22
- element.set({ tag: options.useFragment && "fragment", extend: content });
23
- if (options.updateState)
24
- element.state.update({ route, hash });
25
- const rootNode = element.node;
26
- if (options.scrollToTop)
27
- rootNode.scrollTo({ behavior: "smooth", top: 0, left: 0 });
28
- if (options.scrollToNode)
29
- content.content.node.scrollTo({ behavior: "smooth", top: 0, left: 0 });
30
- if (hash) {
31
- const activeNode = document.getElementById(hash);
32
- if (activeNode) {
33
- const top = activeNode.getBoundingClientRect().top + rootNode.scrollToTopp - 140;
34
- rootNode.scrollTo({ behavior: "smooth", top, left: 0 });
35
- }
36
- }
37
- }
38
- };
39
- export {
40
- getActiveRoute,
41
- lastLevel,
42
- router
43
- };