solid-navigator 0.3.14 → 0.4.1

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/dev.js CHANGED
@@ -1,5 +1,5 @@
1
- import { createContext, children, createMemo, createSignal, onCleanup, batch, mergeProps, splitProps, createEffect, on, useContext } from 'solid-js';
2
- import { delegateEvents, createComponent, spread, mergeProps as mergeProps$1, template } from 'solid-js/web';
1
+ import { createContext, children, createMemo, createSignal, onCleanup, useContext, batch, mergeProps, splitProps, createEffect, on } from 'solid-js';
2
+ import { delegateEvents, createComponent, template, spread, mergeProps as mergeProps$1 } from 'solid-js/web';
3
3
  import { createStore, reconcile } from 'solid-js/store';
4
4
 
5
5
  // src/navigator.ts
@@ -12,20 +12,20 @@ function createMatcher(path, partial, matchFilters) {
12
12
  return (location2) => {
13
13
  const locSegments = location2.split("/").filter(Boolean);
14
14
  const lenDiff = locSegments.length - len;
15
- if (lenDiff < 0 || lenDiff > 0 && splat === void 0 && !partial) {
15
+ if (lenDiff < 0 || lenDiff > 0 && splat === void 0 && true) {
16
16
  return null;
17
17
  }
18
18
  const match = {
19
19
  path: len ? "" : "/",
20
20
  params: {}
21
21
  };
22
- const matchFilter = (s) => matchFilters === void 0 ? void 0 : matchFilters[s];
22
+ const matchFilter = (s) => void 0 ;
23
23
  for (let i = 0; i < len; i++) {
24
24
  const segment = segments[i];
25
25
  const locSegment = locSegments[i];
26
26
  const dynamic = segment[0] === ":";
27
27
  const key = dynamic ? segment.slice(1) : segment;
28
- if (dynamic && matchSegment(locSegment, matchFilter(key))) {
28
+ if (dynamic && matchSegment(locSegment, matchFilter())) {
29
29
  match.params[key] = locSegment;
30
30
  } else if (dynamic || !matchSegment(locSegment, segment)) {
31
31
  return null;
@@ -34,7 +34,7 @@ function createMatcher(path, partial, matchFilters) {
34
34
  }
35
35
  if (splat) {
36
36
  const remainder = lenDiff ? locSegments.slice(-lenDiff).join("/") : "";
37
- if (matchSegment(remainder, matchFilter(splat))) {
37
+ if (matchSegment(remainder, matchFilter())) {
38
38
  match.params[splat] = remainder;
39
39
  } else {
40
40
  return null;
@@ -219,7 +219,9 @@ var flattenedRoutes = (routes) => {
219
219
  };
220
220
  var flattenedRoute = (route) => {
221
221
  const routes = [];
222
- const components = route.components || {};
222
+ let components = {
223
+ ...route.components || {}
224
+ };
223
225
  let lastComponent = void 0;
224
226
  if (route.component) {
225
227
  lastComponent = route.component;
@@ -229,7 +231,9 @@ var flattenedRoute = (route) => {
229
231
  components: {
230
232
  ...components
231
233
  },
232
- mergedComponents: components,
234
+ mergedComponents: {
235
+ ...components
236
+ },
233
237
  component: route.component || lastComponent
234
238
  });
235
239
  if (!route.children)
@@ -238,8 +242,11 @@ var flattenedRoute = (route) => {
238
242
  const child = route.children[i];
239
243
  if (!child)
240
244
  continue;
245
+ let childComponents = {
246
+ ...components
247
+ };
241
248
  if (child.components) {
242
- Object.assign(components, child.components);
249
+ Object.assign(childComponents, child.components);
243
250
  }
244
251
  if (child.component) {
245
252
  lastComponent = child.component;
@@ -248,16 +255,21 @@ var flattenedRoute = (route) => {
248
255
  if (!child.component) {
249
256
  throw new Error("Route: No component for " + child.path);
250
257
  }
251
- components[child.path] = child.component;
258
+ childComponents[child.path] = child.component;
259
+ components = {
260
+ ...childComponents
261
+ };
252
262
  continue;
253
263
  }
254
264
  routes.push(...flattenedRoute({
255
265
  ...child,
256
266
  path: route.path + child.path,
257
267
  components: {
258
- ...components
268
+ ...childComponents
269
+ },
270
+ mergedComponents: {
271
+ ...childComponents
259
272
  },
260
- mergedComponents: components,
261
273
  component: child.component || lastComponent
262
274
  }));
263
275
  }
@@ -279,6 +291,7 @@ var createNavigate = (routes, pathname, setPathname, setSearchAndHash) => {
279
291
  return (path, options) => {
280
292
  let newPath = path;
281
293
  let currentPathname = pathname();
294
+ const currentSearchAndHash = getSearchAndHash();
282
295
  if (currentPathname.endsWith("/")) {
283
296
  currentPathname = currentPathname.slice(0, -1);
284
297
  }
@@ -288,6 +301,9 @@ var createNavigate = (routes, pathname, setPathname, setSearchAndHash) => {
288
301
  if (newPath.startsWith("../")) {
289
302
  newPath = currentPathname + "/" + newPath;
290
303
  }
304
+ const pathAndSearch = currentPathname + currentSearchAndHash;
305
+ if (pathAndSearch === newPath)
306
+ return;
291
307
  if (options?.replace) {
292
308
  history.replaceState(options.state || null, "", newPath);
293
309
  } else {
package/dist/dev.jsx CHANGED
@@ -227,7 +227,9 @@ var flattenedRoutes = (routes) => {
227
227
  };
228
228
  var flattenedRoute = (route) => {
229
229
  const routes = [];
230
- const components = route.components || {};
230
+ let components = {
231
+ ...route.components || {}
232
+ };
231
233
  let lastComponent = void 0;
232
234
  if (route.component) {
233
235
  lastComponent = route.component;
@@ -235,7 +237,7 @@ var flattenedRoute = (route) => {
235
237
  routes.push({
236
238
  ...route,
237
239
  components: { ...components },
238
- mergedComponents: components,
240
+ mergedComponents: { ...components },
239
241
  component: route.component || lastComponent
240
242
  });
241
243
  if (!route.children)
@@ -244,8 +246,9 @@ var flattenedRoute = (route) => {
244
246
  const child = route.children[i];
245
247
  if (!child)
246
248
  continue;
249
+ let childComponents = { ...components };
247
250
  if (child.components) {
248
- Object.assign(components, child.components);
251
+ Object.assign(childComponents, child.components);
249
252
  }
250
253
  if (child.component) {
251
254
  lastComponent = child.component;
@@ -254,15 +257,16 @@ var flattenedRoute = (route) => {
254
257
  if (!child.component) {
255
258
  throw new Error("Route: No component for " + child.path);
256
259
  }
257
- components[child.path] = child.component;
260
+ childComponents[child.path] = child.component;
261
+ components = { ...childComponents };
258
262
  continue;
259
263
  }
260
264
  routes.push(
261
265
  ...flattenedRoute({
262
266
  ...child,
263
267
  path: route.path + child.path,
264
- components: { ...components },
265
- mergedComponents: components,
268
+ components: { ...childComponents },
269
+ mergedComponents: { ...childComponents },
266
270
  component: child.component || lastComponent
267
271
  })
268
272
  );
@@ -285,6 +289,7 @@ var createNavigate = (routes, pathname, setPathname, setSearchAndHash) => {
285
289
  return (path, options) => {
286
290
  let newPath = path;
287
291
  let currentPathname = pathname();
292
+ const currentSearchAndHash = getSearchAndHash();
288
293
  if (currentPathname.endsWith("/")) {
289
294
  currentPathname = currentPathname.slice(0, -1);
290
295
  }
@@ -294,6 +299,9 @@ var createNavigate = (routes, pathname, setPathname, setSearchAndHash) => {
294
299
  if (newPath.startsWith("../")) {
295
300
  newPath = currentPathname + "/" + newPath;
296
301
  }
302
+ const pathAndSearch = currentPathname + currentSearchAndHash;
303
+ if (pathAndSearch === newPath)
304
+ return;
297
305
  if (options?.replace) {
298
306
  history.replaceState(options.state || null, "", newPath);
299
307
  } else {
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { createContext, children, createMemo, createSignal, onCleanup, batch, mergeProps, splitProps, createEffect, on, useContext } from 'solid-js';
2
- import { delegateEvents, createComponent, spread, mergeProps as mergeProps$1, template } from 'solid-js/web';
1
+ import { createContext, children, createMemo, createSignal, onCleanup, useContext, batch, mergeProps, splitProps, createEffect, on } from 'solid-js';
2
+ import { delegateEvents, createComponent, template, spread, mergeProps as mergeProps$1 } from 'solid-js/web';
3
3
  import { createStore, reconcile } from 'solid-js/store';
4
4
 
5
5
  // src/navigator.ts
@@ -12,20 +12,20 @@ function createMatcher(path, partial, matchFilters) {
12
12
  return (location2) => {
13
13
  const locSegments = location2.split("/").filter(Boolean);
14
14
  const lenDiff = locSegments.length - len;
15
- if (lenDiff < 0 || lenDiff > 0 && splat === void 0 && !partial) {
15
+ if (lenDiff < 0 || lenDiff > 0 && splat === void 0 && true) {
16
16
  return null;
17
17
  }
18
18
  const match = {
19
19
  path: len ? "" : "/",
20
20
  params: {}
21
21
  };
22
- const matchFilter = (s) => matchFilters === void 0 ? void 0 : matchFilters[s];
22
+ const matchFilter = (s) => void 0 ;
23
23
  for (let i = 0; i < len; i++) {
24
24
  const segment = segments[i];
25
25
  const locSegment = locSegments[i];
26
26
  const dynamic = segment[0] === ":";
27
27
  const key = dynamic ? segment.slice(1) : segment;
28
- if (dynamic && matchSegment(locSegment, matchFilter(key))) {
28
+ if (dynamic && matchSegment(locSegment, matchFilter())) {
29
29
  match.params[key] = locSegment;
30
30
  } else if (dynamic || !matchSegment(locSegment, segment)) {
31
31
  return null;
@@ -34,7 +34,7 @@ function createMatcher(path, partial, matchFilters) {
34
34
  }
35
35
  if (splat) {
36
36
  const remainder = lenDiff ? locSegments.slice(-lenDiff).join("/") : "";
37
- if (matchSegment(remainder, matchFilter(splat))) {
37
+ if (matchSegment(remainder, matchFilter())) {
38
38
  match.params[splat] = remainder;
39
39
  } else {
40
40
  return null;
@@ -219,7 +219,9 @@ var flattenedRoutes = (routes) => {
219
219
  };
220
220
  var flattenedRoute = (route) => {
221
221
  const routes = [];
222
- const components = route.components || {};
222
+ let components = {
223
+ ...route.components || {}
224
+ };
223
225
  let lastComponent = void 0;
224
226
  if (route.component) {
225
227
  lastComponent = route.component;
@@ -229,7 +231,9 @@ var flattenedRoute = (route) => {
229
231
  components: {
230
232
  ...components
231
233
  },
232
- mergedComponents: components,
234
+ mergedComponents: {
235
+ ...components
236
+ },
233
237
  component: route.component || lastComponent
234
238
  });
235
239
  if (!route.children)
@@ -238,8 +242,11 @@ var flattenedRoute = (route) => {
238
242
  const child = route.children[i];
239
243
  if (!child)
240
244
  continue;
245
+ let childComponents = {
246
+ ...components
247
+ };
241
248
  if (child.components) {
242
- Object.assign(components, child.components);
249
+ Object.assign(childComponents, child.components);
243
250
  }
244
251
  if (child.component) {
245
252
  lastComponent = child.component;
@@ -248,16 +255,21 @@ var flattenedRoute = (route) => {
248
255
  if (!child.component) {
249
256
  throw new Error("Route: No component for " + child.path);
250
257
  }
251
- components[child.path] = child.component;
258
+ childComponents[child.path] = child.component;
259
+ components = {
260
+ ...childComponents
261
+ };
252
262
  continue;
253
263
  }
254
264
  routes.push(...flattenedRoute({
255
265
  ...child,
256
266
  path: route.path + child.path,
257
267
  components: {
258
- ...components
268
+ ...childComponents
269
+ },
270
+ mergedComponents: {
271
+ ...childComponents
259
272
  },
260
- mergedComponents: components,
261
273
  component: child.component || lastComponent
262
274
  }));
263
275
  }
@@ -279,6 +291,7 @@ var createNavigate = (routes, pathname, setPathname, setSearchAndHash) => {
279
291
  return (path, options) => {
280
292
  let newPath = path;
281
293
  let currentPathname = pathname();
294
+ const currentSearchAndHash = getSearchAndHash();
282
295
  if (currentPathname.endsWith("/")) {
283
296
  currentPathname = currentPathname.slice(0, -1);
284
297
  }
@@ -288,6 +301,9 @@ var createNavigate = (routes, pathname, setPathname, setSearchAndHash) => {
288
301
  if (newPath.startsWith("../")) {
289
302
  newPath = currentPathname + "/" + newPath;
290
303
  }
304
+ const pathAndSearch = currentPathname + currentSearchAndHash;
305
+ if (pathAndSearch === newPath)
306
+ return;
291
307
  if (options?.replace) {
292
308
  history.replaceState(options.state || null, "", newPath);
293
309
  } else {
package/dist/index.jsx CHANGED
@@ -227,7 +227,9 @@ var flattenedRoutes = (routes) => {
227
227
  };
228
228
  var flattenedRoute = (route) => {
229
229
  const routes = [];
230
- const components = route.components || {};
230
+ let components = {
231
+ ...route.components || {}
232
+ };
231
233
  let lastComponent = void 0;
232
234
  if (route.component) {
233
235
  lastComponent = route.component;
@@ -235,7 +237,7 @@ var flattenedRoute = (route) => {
235
237
  routes.push({
236
238
  ...route,
237
239
  components: { ...components },
238
- mergedComponents: components,
240
+ mergedComponents: { ...components },
239
241
  component: route.component || lastComponent
240
242
  });
241
243
  if (!route.children)
@@ -244,8 +246,9 @@ var flattenedRoute = (route) => {
244
246
  const child = route.children[i];
245
247
  if (!child)
246
248
  continue;
249
+ let childComponents = { ...components };
247
250
  if (child.components) {
248
- Object.assign(components, child.components);
251
+ Object.assign(childComponents, child.components);
249
252
  }
250
253
  if (child.component) {
251
254
  lastComponent = child.component;
@@ -254,15 +257,16 @@ var flattenedRoute = (route) => {
254
257
  if (!child.component) {
255
258
  throw new Error("Route: No component for " + child.path);
256
259
  }
257
- components[child.path] = child.component;
260
+ childComponents[child.path] = child.component;
261
+ components = { ...childComponents };
258
262
  continue;
259
263
  }
260
264
  routes.push(
261
265
  ...flattenedRoute({
262
266
  ...child,
263
267
  path: route.path + child.path,
264
- components: { ...components },
265
- mergedComponents: components,
268
+ components: { ...childComponents },
269
+ mergedComponents: { ...childComponents },
266
270
  component: child.component || lastComponent
267
271
  })
268
272
  );
@@ -285,6 +289,7 @@ var createNavigate = (routes, pathname, setPathname, setSearchAndHash) => {
285
289
  return (path, options) => {
286
290
  let newPath = path;
287
291
  let currentPathname = pathname();
292
+ const currentSearchAndHash = getSearchAndHash();
288
293
  if (currentPathname.endsWith("/")) {
289
294
  currentPathname = currentPathname.slice(0, -1);
290
295
  }
@@ -294,6 +299,9 @@ var createNavigate = (routes, pathname, setPathname, setSearchAndHash) => {
294
299
  if (newPath.startsWith("../")) {
295
300
  newPath = currentPathname + "/" + newPath;
296
301
  }
302
+ const pathAndSearch = currentPathname + currentSearchAndHash;
303
+ if (pathAndSearch === newPath)
304
+ return;
297
305
  if (options?.replace) {
298
306
  history.replaceState(options.state || null, "", newPath);
299
307
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-navigator",
3
- "version": "0.3.14",
3
+ "version": "0.4.1",
4
4
  "description": "Solid Navigator is a library that is inspired by vue router and solid router.",
5
5
  "license": "MIT",
6
6
  "author": "SupertigerDev",
@@ -40,6 +40,16 @@
40
40
  }
41
41
  },
42
42
  "typesVersions": {},
43
+ "scripts": {
44
+ "dev": "vite serve dev",
45
+ "build": "tsup",
46
+ "prepublishOnly": "pnpm build",
47
+ "format": "prettier --ignore-path .gitignore -w \"src/**/*.{js,ts,json,css,tsx,jsx}\" \"dev/**/*.{js,ts,json,css,tsx,jsx}\"",
48
+ "lint": "concurrently pnpm:lint:*",
49
+ "lint:code": "eslint --ignore-path .gitignore --max-warnings 0 src/**/*.{js,ts,tsx,jsx}",
50
+ "lint:types": "tsc --noEmit",
51
+ "update-deps": "pnpm up -Li"
52
+ },
43
53
  "peerDependencies": {
44
54
  "solid-js": "^1.6.0"
45
55
  },
@@ -65,17 +75,9 @@
65
75
  "keywords": [
66
76
  "solid"
67
77
  ],
78
+ "packageManager": "pnpm@8.6.0",
68
79
  "engines": {
69
80
  "node": ">=18",
70
81
  "pnpm": ">=8.6.0"
71
- },
72
- "scripts": {
73
- "dev": "vite serve dev",
74
- "build": "tsup",
75
- "format": "prettier --ignore-path .gitignore -w \"src/**/*.{js,ts,json,css,tsx,jsx}\" \"dev/**/*.{js,ts,json,css,tsx,jsx}\"",
76
- "lint": "concurrently pnpm:lint:*",
77
- "lint:code": "eslint --ignore-path .gitignore --max-warnings 0 src/**/*.{js,ts,tsx,jsx}",
78
- "lint:types": "tsc --noEmit",
79
- "update-deps": "pnpm up -Li"
80
82
  }
81
- }
83
+ }