solid-navigator 0.3.6 → 0.3.8
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 +30 -5
- package/dist/dev.jsx +25 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.js +30 -5
- package/dist/index.jsx +25 -4
- package/package.json +1 -1
package/dist/dev.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext, children, createMemo, createSignal, onCleanup, batch, mergeProps, createEffect, on, useContext } from 'solid-js';
|
|
2
|
-
import { delegateEvents, createComponent, spread, template } from 'solid-js/web';
|
|
2
|
+
import { delegateEvents, createComponent, spread, mergeProps as mergeProps$1, template } from 'solid-js/web';
|
|
3
3
|
import { createStore, reconcile } from 'solid-js/store';
|
|
4
4
|
|
|
5
5
|
// src/navigator.ts
|
|
@@ -74,6 +74,7 @@ var createLocation = (path, query, setQuery) => {
|
|
|
74
74
|
const search = createMemo(() => url().search);
|
|
75
75
|
const pathname = createMemo(() => url().pathname);
|
|
76
76
|
const hash = createMemo(() => url().hash);
|
|
77
|
+
const state = createMemo(on([hash, pathname, search], () => history.state));
|
|
77
78
|
return {
|
|
78
79
|
query,
|
|
79
80
|
get search() {
|
|
@@ -84,6 +85,9 @@ var createLocation = (path, query, setQuery) => {
|
|
|
84
85
|
},
|
|
85
86
|
get hash() {
|
|
86
87
|
return hash();
|
|
88
|
+
},
|
|
89
|
+
get state() {
|
|
90
|
+
return state();
|
|
87
91
|
}
|
|
88
92
|
};
|
|
89
93
|
};
|
|
@@ -281,9 +285,9 @@ var createNavigate = (routes, pathname, setPathname, setHashAndSearch) => {
|
|
|
281
285
|
newPath = currentPathname + "/" + newPath.slice(2);
|
|
282
286
|
}
|
|
283
287
|
if (options?.replace) {
|
|
284
|
-
history.replaceState(
|
|
288
|
+
history.replaceState(options.data || null, "", newPath);
|
|
285
289
|
} else {
|
|
286
|
-
history.pushState(
|
|
290
|
+
history.pushState(options?.data || null, "", newPath);
|
|
287
291
|
}
|
|
288
292
|
if (!isValidPath(routes, location.pathname)) {
|
|
289
293
|
console.warn("Invalid path: " + path);
|
|
@@ -313,7 +317,10 @@ function useSearchParams() {
|
|
|
313
317
|
url.search = newSearch.toString();
|
|
314
318
|
navigate(url.pathname + url.search + url.hash, options);
|
|
315
319
|
};
|
|
316
|
-
return [
|
|
320
|
+
return [
|
|
321
|
+
context.location.query,
|
|
322
|
+
updateQuery
|
|
323
|
+
];
|
|
317
324
|
}
|
|
318
325
|
var Fragment = () => [];
|
|
319
326
|
var Outlet = (props) => {
|
|
@@ -364,9 +371,27 @@ var matchComponent = (name) => {
|
|
|
364
371
|
};
|
|
365
372
|
var _tmpl$ = /* @__PURE__ */ template(`<a sn-link>`);
|
|
366
373
|
var A = (props) => {
|
|
374
|
+
const location2 = useLocation();
|
|
375
|
+
const resolvedHref = () => {
|
|
376
|
+
if (!props.href)
|
|
377
|
+
return props.href;
|
|
378
|
+
let newPath = props.href;
|
|
379
|
+
let currentPathname = location2.pathname;
|
|
380
|
+
if (currentPathname.endsWith("/")) {
|
|
381
|
+
currentPathname = currentPathname.slice(0, -1);
|
|
382
|
+
}
|
|
383
|
+
if (newPath.startsWith("./")) {
|
|
384
|
+
newPath = currentPathname + "/" + newPath.slice(2);
|
|
385
|
+
}
|
|
386
|
+
return newPath;
|
|
387
|
+
};
|
|
367
388
|
return (() => {
|
|
368
389
|
var _el$ = _tmpl$();
|
|
369
|
-
spread(_el$, props,
|
|
390
|
+
spread(_el$, mergeProps$1(props, {
|
|
391
|
+
get href() {
|
|
392
|
+
return resolvedHref();
|
|
393
|
+
}
|
|
394
|
+
}), false, false);
|
|
370
395
|
return _el$;
|
|
371
396
|
})();
|
|
372
397
|
};
|
package/dist/dev.jsx
CHANGED
|
@@ -88,6 +88,7 @@ var createLocation = (path, query, setQuery) => {
|
|
|
88
88
|
const search = createMemo(() => url().search);
|
|
89
89
|
const pathname = createMemo(() => url().pathname);
|
|
90
90
|
const hash = createMemo(() => url().hash);
|
|
91
|
+
const state = createMemo(on([hash, pathname, search], () => history.state));
|
|
91
92
|
return {
|
|
92
93
|
query,
|
|
93
94
|
get search() {
|
|
@@ -98,6 +99,9 @@ var createLocation = (path, query, setQuery) => {
|
|
|
98
99
|
},
|
|
99
100
|
get hash() {
|
|
100
101
|
return hash();
|
|
102
|
+
},
|
|
103
|
+
get state() {
|
|
104
|
+
return state();
|
|
101
105
|
}
|
|
102
106
|
};
|
|
103
107
|
};
|
|
@@ -287,9 +291,9 @@ var createNavigate = (routes, pathname, setPathname, setHashAndSearch) => {
|
|
|
287
291
|
newPath = currentPathname + "/" + newPath.slice(2);
|
|
288
292
|
}
|
|
289
293
|
if (options?.replace) {
|
|
290
|
-
history.replaceState(
|
|
294
|
+
history.replaceState(options.data || null, "", newPath);
|
|
291
295
|
} else {
|
|
292
|
-
history.pushState(
|
|
296
|
+
history.pushState(options?.data || null, "", newPath);
|
|
293
297
|
}
|
|
294
298
|
if (!isValidPath(routes, location.pathname)) {
|
|
295
299
|
console.warn("Invalid path: " + path);
|
|
@@ -319,7 +323,10 @@ function useSearchParams() {
|
|
|
319
323
|
url.search = newSearch.toString();
|
|
320
324
|
navigate(url.pathname + url.search + url.hash, options);
|
|
321
325
|
};
|
|
322
|
-
return [
|
|
326
|
+
return [
|
|
327
|
+
context.location.query,
|
|
328
|
+
updateQuery
|
|
329
|
+
];
|
|
323
330
|
}
|
|
324
331
|
|
|
325
332
|
// src/Outlet.tsx
|
|
@@ -378,7 +385,21 @@ var matchComponent = (name) => {
|
|
|
378
385
|
// src/Link.tsx
|
|
379
386
|
import { createMemo as createMemo5 } from "solid-js";
|
|
380
387
|
var A = (props) => {
|
|
381
|
-
|
|
388
|
+
const location2 = useLocation();
|
|
389
|
+
const resolvedHref = () => {
|
|
390
|
+
if (!props.href)
|
|
391
|
+
return props.href;
|
|
392
|
+
let newPath = props.href;
|
|
393
|
+
let currentPathname = location2.pathname;
|
|
394
|
+
if (currentPathname.endsWith("/")) {
|
|
395
|
+
currentPathname = currentPathname.slice(0, -1);
|
|
396
|
+
}
|
|
397
|
+
if (newPath.startsWith("./")) {
|
|
398
|
+
newPath = currentPathname + "/" + newPath.slice(2);
|
|
399
|
+
}
|
|
400
|
+
return newPath;
|
|
401
|
+
};
|
|
402
|
+
return <a sn-link {...props} href={resolvedHref()} />;
|
|
382
403
|
};
|
|
383
404
|
var useMatch = (path) => {
|
|
384
405
|
const location2 = useLocation();
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ declare const matchComponent: (name: () => string) => () => Component;
|
|
|
14
14
|
|
|
15
15
|
interface NavigateOptions {
|
|
16
16
|
replace?: boolean;
|
|
17
|
+
data?: any;
|
|
17
18
|
}
|
|
18
19
|
declare const useNavigate: () => (path: string, options?: NavigateOptions | undefined) => void;
|
|
19
20
|
declare const Navigate: (props: {
|
|
@@ -43,6 +44,7 @@ declare const useLocation: () => {
|
|
|
43
44
|
readonly search: string;
|
|
44
45
|
readonly pathname: string;
|
|
45
46
|
readonly hash: string;
|
|
47
|
+
readonly state: any;
|
|
46
48
|
};
|
|
47
49
|
|
|
48
50
|
type LinkProps = {
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext, children, createMemo, createSignal, onCleanup, batch, mergeProps, createEffect, on, useContext } from 'solid-js';
|
|
2
|
-
import { delegateEvents, createComponent, spread, template } from 'solid-js/web';
|
|
2
|
+
import { delegateEvents, createComponent, spread, mergeProps as mergeProps$1, template } from 'solid-js/web';
|
|
3
3
|
import { createStore, reconcile } from 'solid-js/store';
|
|
4
4
|
|
|
5
5
|
// src/navigator.ts
|
|
@@ -74,6 +74,7 @@ var createLocation = (path, query, setQuery) => {
|
|
|
74
74
|
const search = createMemo(() => url().search);
|
|
75
75
|
const pathname = createMemo(() => url().pathname);
|
|
76
76
|
const hash = createMemo(() => url().hash);
|
|
77
|
+
const state = createMemo(on([hash, pathname, search], () => history.state));
|
|
77
78
|
return {
|
|
78
79
|
query,
|
|
79
80
|
get search() {
|
|
@@ -84,6 +85,9 @@ var createLocation = (path, query, setQuery) => {
|
|
|
84
85
|
},
|
|
85
86
|
get hash() {
|
|
86
87
|
return hash();
|
|
88
|
+
},
|
|
89
|
+
get state() {
|
|
90
|
+
return state();
|
|
87
91
|
}
|
|
88
92
|
};
|
|
89
93
|
};
|
|
@@ -281,9 +285,9 @@ var createNavigate = (routes, pathname, setPathname, setHashAndSearch) => {
|
|
|
281
285
|
newPath = currentPathname + "/" + newPath.slice(2);
|
|
282
286
|
}
|
|
283
287
|
if (options?.replace) {
|
|
284
|
-
history.replaceState(
|
|
288
|
+
history.replaceState(options.data || null, "", newPath);
|
|
285
289
|
} else {
|
|
286
|
-
history.pushState(
|
|
290
|
+
history.pushState(options?.data || null, "", newPath);
|
|
287
291
|
}
|
|
288
292
|
if (!isValidPath(routes, location.pathname)) ;
|
|
289
293
|
batch(() => {
|
|
@@ -311,7 +315,10 @@ function useSearchParams() {
|
|
|
311
315
|
url.search = newSearch.toString();
|
|
312
316
|
navigate(url.pathname + url.search + url.hash, options);
|
|
313
317
|
};
|
|
314
|
-
return [
|
|
318
|
+
return [
|
|
319
|
+
context.location.query,
|
|
320
|
+
updateQuery
|
|
321
|
+
];
|
|
315
322
|
}
|
|
316
323
|
var Fragment = () => [];
|
|
317
324
|
var Outlet = (props) => {
|
|
@@ -360,9 +367,27 @@ var matchComponent = (name) => {
|
|
|
360
367
|
};
|
|
361
368
|
var _tmpl$ = /* @__PURE__ */ template(`<a sn-link>`);
|
|
362
369
|
var A = (props) => {
|
|
370
|
+
const location2 = useLocation();
|
|
371
|
+
const resolvedHref = () => {
|
|
372
|
+
if (!props.href)
|
|
373
|
+
return props.href;
|
|
374
|
+
let newPath = props.href;
|
|
375
|
+
let currentPathname = location2.pathname;
|
|
376
|
+
if (currentPathname.endsWith("/")) {
|
|
377
|
+
currentPathname = currentPathname.slice(0, -1);
|
|
378
|
+
}
|
|
379
|
+
if (newPath.startsWith("./")) {
|
|
380
|
+
newPath = currentPathname + "/" + newPath.slice(2);
|
|
381
|
+
}
|
|
382
|
+
return newPath;
|
|
383
|
+
};
|
|
363
384
|
return (() => {
|
|
364
385
|
var _el$ = _tmpl$();
|
|
365
|
-
spread(_el$, props,
|
|
386
|
+
spread(_el$, mergeProps$1(props, {
|
|
387
|
+
get href() {
|
|
388
|
+
return resolvedHref();
|
|
389
|
+
}
|
|
390
|
+
}), false, false);
|
|
366
391
|
return _el$;
|
|
367
392
|
})();
|
|
368
393
|
};
|
package/dist/index.jsx
CHANGED
|
@@ -88,6 +88,7 @@ var createLocation = (path, query, setQuery) => {
|
|
|
88
88
|
const search = createMemo(() => url().search);
|
|
89
89
|
const pathname = createMemo(() => url().pathname);
|
|
90
90
|
const hash = createMemo(() => url().hash);
|
|
91
|
+
const state = createMemo(on([hash, pathname, search], () => history.state));
|
|
91
92
|
return {
|
|
92
93
|
query,
|
|
93
94
|
get search() {
|
|
@@ -98,6 +99,9 @@ var createLocation = (path, query, setQuery) => {
|
|
|
98
99
|
},
|
|
99
100
|
get hash() {
|
|
100
101
|
return hash();
|
|
102
|
+
},
|
|
103
|
+
get state() {
|
|
104
|
+
return state();
|
|
101
105
|
}
|
|
102
106
|
};
|
|
103
107
|
};
|
|
@@ -287,9 +291,9 @@ var createNavigate = (routes, pathname, setPathname, setHashAndSearch) => {
|
|
|
287
291
|
newPath = currentPathname + "/" + newPath.slice(2);
|
|
288
292
|
}
|
|
289
293
|
if (options?.replace) {
|
|
290
|
-
history.replaceState(
|
|
294
|
+
history.replaceState(options.data || null, "", newPath);
|
|
291
295
|
} else {
|
|
292
|
-
history.pushState(
|
|
296
|
+
history.pushState(options?.data || null, "", newPath);
|
|
293
297
|
}
|
|
294
298
|
if (!isValidPath(routes, location.pathname)) {
|
|
295
299
|
}
|
|
@@ -318,7 +322,10 @@ function useSearchParams() {
|
|
|
318
322
|
url.search = newSearch.toString();
|
|
319
323
|
navigate(url.pathname + url.search + url.hash, options);
|
|
320
324
|
};
|
|
321
|
-
return [
|
|
325
|
+
return [
|
|
326
|
+
context.location.query,
|
|
327
|
+
updateQuery
|
|
328
|
+
];
|
|
322
329
|
}
|
|
323
330
|
|
|
324
331
|
// src/Outlet.tsx
|
|
@@ -375,7 +382,21 @@ var matchComponent = (name) => {
|
|
|
375
382
|
// src/Link.tsx
|
|
376
383
|
import { createMemo as createMemo5 } from "solid-js";
|
|
377
384
|
var A = (props) => {
|
|
378
|
-
|
|
385
|
+
const location2 = useLocation();
|
|
386
|
+
const resolvedHref = () => {
|
|
387
|
+
if (!props.href)
|
|
388
|
+
return props.href;
|
|
389
|
+
let newPath = props.href;
|
|
390
|
+
let currentPathname = location2.pathname;
|
|
391
|
+
if (currentPathname.endsWith("/")) {
|
|
392
|
+
currentPathname = currentPathname.slice(0, -1);
|
|
393
|
+
}
|
|
394
|
+
if (newPath.startsWith("./")) {
|
|
395
|
+
newPath = currentPathname + "/" + newPath.slice(2);
|
|
396
|
+
}
|
|
397
|
+
return newPath;
|
|
398
|
+
};
|
|
399
|
+
return <a sn-link {...props} href={resolvedHref()} />;
|
|
379
400
|
};
|
|
380
401
|
var useMatch = (path) => {
|
|
381
402
|
const location2 = useLocation();
|