@@ -11,8 +11,6 @@ import { Debouncer } from '@polymer/polymer/lib/utils/debounce';
11
11
import { animationFrame } from '@polymer/polymer/lib/utils/async' ;
12
12
import { flush } from '@polymer/polymer/lib/utils/flush' ;
13
13
14
- import '@neovici/cosmoz-page-router/cosmoz-page-location' ;
15
-
16
14
import { hauntedPolymer } from '@neovici/cosmoz-utils' ;
17
15
18
16
import { useDataNav } from './lib/use-data-nav.js' ;
@@ -21,6 +19,20 @@ const _async = window.requestIdleCallback || window.requestAnimationFrame || win
21
19
_hasDeadline = 'IdleDeadline' in window ,
22
20
_asyncPeriod = ( cb , timeout = 1500 ) => {
23
21
_async ( ( ) => cb ( ) , _hasDeadline && { timeout } ) ;
22
+ } ,
23
+
24
+ hashUrl = ( ) => new URL ( location . hash . replace ( / ^ # ! ? / iu, '' ) . replace ( '%23' , '#' ) , location . origin ) ,
25
+ getHashParam = param => new URLSearchParams ( hashUrl ( ) . hash . replace ( '#' , '' ) ) . get ( param ) ,
26
+ setHashParam = ( param , value ) => {
27
+ const
28
+ url = hashUrl ( ) ,
29
+ searchParams = new URLSearchParams ( url . hash . replace ( '#' , '' ) ) ;
30
+
31
+ searchParams . set ( param , value ) ;
32
+
33
+ const newUrl = '#!' + Object . assign ( url , { hash : searchParams } ) . href . replace ( location . origin , '' ) ;
34
+
35
+ history . replaceState ( null , '' , newUrl ) ;
24
36
} ;
25
37
26
38
class CosmozDataNav extends hauntedPolymer ( 'haunted' , useDataNav ) ( PolymerElement ) {
@@ -64,7 +76,6 @@ class CosmozDataNav extends hauntedPolymer('haunted', useDataNav)(PolymerElement
64
76
display : none;
65
77
}
66
78
</ style >
67
- < cosmoz-page-location id ="location " route-hash ="{{ _routeHashParams }} "> </ cosmoz-page-location >
68
79
< div id ="items ">
69
80
< slot name ="items "> </ slot >
70
81
</ div >
@@ -250,14 +261,6 @@ class CosmozDataNav extends hauntedPolymer('haunted', useDataNav)(PolymerElement
250
261
type : String
251
262
} ,
252
263
253
- /**
254
- * The route hash parameters extracted by the `cosmoz-page-location`
255
- * element.
256
- */
257
- _routeHashParams : {
258
- type : Object
259
- } ,
260
-
261
264
/**
262
265
*
263
266
*/
@@ -941,7 +944,7 @@ class CosmozDataNav extends hauntedPolymer('haunted', useDataNav)(PolymerElement
941
944
const hashParam = this . hashParam ,
942
945
idPath = this . idPath ;
943
946
944
- if ( ! hashParam || ! idPath || ! this . _routeHashParams || ! this . items . length ) {
947
+ if ( ! hashParam || ! idPath || ! this . items . length ) {
945
948
return ;
946
949
}
947
950
@@ -950,30 +953,28 @@ class CosmozDataNav extends hauntedPolymer('haunted', useDataNav)(PolymerElement
950
953
return ;
951
954
}
952
955
const itemId = this . _getItemId ( item ) ,
953
- path = [ '_routeHashParams' , hashParam ] ,
954
- hashValue = this . get ( path ) ;
956
+ hashValue = getHashParam ( hashParam ) ;
955
957
956
958
if ( itemId === hashValue ) {
957
959
return ;
958
960
}
959
961
960
- this . set ( path , itemId ) ;
962
+ setHashParam ( hashParam , itemId ) ;
961
963
}
962
964
963
965
_updateSelectedFromHash ( ) {
964
966
const hashParam = this . hashParam ,
965
967
idPath = this . idPath ;
966
968
967
- if ( ! ( hashParam && idPath && this . _routeHashParams ) ) {
969
+ if ( ! ( hashParam && idPath ) ) {
968
970
return ;
969
971
}
970
972
971
973
if ( this . _readFromHashOnce && ! this . maintainSelection ) {
972
974
return ;
973
975
}
974
976
975
- const path = [ '_routeHashParams' , hashParam ] ,
976
- hashValue = this . get ( path ) ;
977
+ const hashValue = getHashParam ( hashParam ) ;
977
978
978
979
if ( ! hashValue ) {
979
980
this . _readFromHashOnce = true ;
0 commit comments