@@ -33,7 +33,7 @@ class RequestBuilder {
33
33
fetchOptions . headers = {
34
34
Accept : 'application/vnd.live-component+html' ,
35
35
'X-Requested-With' : 'XMLHttpRequest' ,
36
- 'X-Live-Url' : window . location . pathname + window . location . search
36
+ 'X-Live-Url' : window . location . pathname + window . location . search ,
37
37
} ;
38
38
const totalFiles = Object . entries ( files ) . reduce ( ( total , current ) => total + current . length , 0 ) ;
39
39
const hasFingerprints = Object . keys ( children ) . length > 0 ;
@@ -1805,7 +1805,109 @@ class ExternalMutationTracker {
1805
1805
return element . tagName === 'FONT' && element . getAttribute ( 'style' ) === 'vertical-align: inherit;' ;
1806
1806
}
1807
1807
}
1808
-
1808
+ function isValueEmpty ( value ) {
1809
+ if ( null === value || value === '' || undefined === value || ( Array . isArray ( value ) && value . length === 0 ) ) {
1810
+ return true ;
1811
+ }
1812
+ if ( typeof value !== 'object' ) {
1813
+ return false ;
1814
+ }
1815
+ for ( const key of Object . keys ( value ) ) {
1816
+ if ( ! isValueEmpty ( value [ key ] ) ) {
1817
+ return false ;
1818
+ }
1819
+ }
1820
+ return true ;
1821
+ }
1822
+ function toQueryString ( data ) {
1823
+ const buildQueryStringEntries = ( data , entries = { } , baseKey = '' ) => {
1824
+ Object . entries ( data ) . forEach ( ( [ iKey , iValue ] ) => {
1825
+ const key = baseKey === '' ? iKey : `${ baseKey } [${ iKey } ]` ;
1826
+ if ( '' === baseKey && isValueEmpty ( iValue ) ) {
1827
+ entries [ key ] = '' ;
1828
+ }
1829
+ else if ( null !== iValue ) {
1830
+ if ( typeof iValue === 'object' ) {
1831
+ entries = { ...entries , ...buildQueryStringEntries ( iValue , entries , key ) } ;
1832
+ }
1833
+ else {
1834
+ entries [ key ] = encodeURIComponent ( iValue )
1835
+ . replace ( / % 2 0 / g, '+' )
1836
+ . replace ( / % 2 C / g, ',' ) ;
1837
+ }
1838
+ }
1839
+ } ) ;
1840
+ return entries ;
1841
+ } ;
1842
+ const entries = buildQueryStringEntries ( data ) ;
1843
+ return Object . entries ( entries )
1844
+ . map ( ( [ key , value ] ) => `${ key } =${ value } ` )
1845
+ . join ( '&' ) ;
1846
+ }
1847
+ function fromQueryString ( search ) {
1848
+ search = search . replace ( '?' , '' ) ;
1849
+ if ( search === '' )
1850
+ return { } ;
1851
+ const insertDotNotatedValueIntoData = ( key , value , data ) => {
1852
+ const [ first , second , ...rest ] = key . split ( '.' ) ;
1853
+ if ( ! second ) {
1854
+ data [ key ] = value ;
1855
+ return value ;
1856
+ }
1857
+ if ( data [ first ] === undefined ) {
1858
+ data [ first ] = Number . isNaN ( Number . parseInt ( second ) ) ? { } : [ ] ;
1859
+ }
1860
+ insertDotNotatedValueIntoData ( [ second , ...rest ] . join ( '.' ) , value , data [ first ] ) ;
1861
+ } ;
1862
+ const entries = search . split ( '&' ) . map ( ( i ) => i . split ( '=' ) ) ;
1863
+ const data = { } ;
1864
+ entries . forEach ( ( [ key , value ] ) => {
1865
+ value = decodeURIComponent ( String ( value || '' ) . replace ( / \+ / g, '%20' ) ) ;
1866
+ if ( ! key . includes ( '[' ) ) {
1867
+ data [ key ] = value ;
1868
+ }
1869
+ else {
1870
+ if ( '' === value )
1871
+ return ;
1872
+ const dotNotatedKey = key . replace ( / \[ / g, '.' ) . replace ( / ] / g, '' ) ;
1873
+ insertDotNotatedValueIntoData ( dotNotatedKey , value , data ) ;
1874
+ }
1875
+ } ) ;
1876
+ return data ;
1877
+ }
1878
+ class UrlUtils extends URL {
1879
+ has ( key ) {
1880
+ const data = this . getData ( ) ;
1881
+ return Object . keys ( data ) . includes ( key ) ;
1882
+ }
1883
+ set ( key , value ) {
1884
+ const data = this . getData ( ) ;
1885
+ data [ key ] = value ;
1886
+ this . setData ( data ) ;
1887
+ }
1888
+ get ( key ) {
1889
+ return this . getData ( ) [ key ] ;
1890
+ }
1891
+ remove ( key ) {
1892
+ const data = this . getData ( ) ;
1893
+ delete data [ key ] ;
1894
+ this . setData ( data ) ;
1895
+ }
1896
+ getData ( ) {
1897
+ if ( ! this . search ) {
1898
+ return { } ;
1899
+ }
1900
+ return fromQueryString ( this . search ) ;
1901
+ }
1902
+ setData ( data ) {
1903
+ this . search = toQueryString ( data ) ;
1904
+ }
1905
+ }
1906
+ class HistoryStrategy {
1907
+ static replace ( url ) {
1908
+ history . replaceState ( history . state , '' , url ) ;
1909
+ }
1910
+ }
1809
1911
class UnsyncedInputsTracker {
1810
1912
constructor ( component , modelElementResolver ) {
1811
1913
this . elementEventListeners = [
@@ -1984,110 +2086,6 @@ class ValueStore {
1984
2086
}
1985
2087
}
1986
2088
1987
- function isValueEmpty ( value ) {
1988
- if ( null === value || value === '' || undefined === value || ( Array . isArray ( value ) && value . length === 0 ) ) {
1989
- return true ;
1990
- }
1991
- if ( typeof value !== 'object' ) {
1992
- return false ;
1993
- }
1994
- for ( const key of Object . keys ( value ) ) {
1995
- if ( ! isValueEmpty ( value [ key ] ) ) {
1996
- return false ;
1997
- }
1998
- }
1999
- return true ;
2000
- }
2001
- function toQueryString ( data ) {
2002
- const buildQueryStringEntries = ( data , entries = { } , baseKey = '' ) => {
2003
- Object . entries ( data ) . forEach ( ( [ iKey , iValue ] ) => {
2004
- const key = baseKey === '' ? iKey : `${ baseKey } [${ iKey } ]` ;
2005
- if ( '' === baseKey && isValueEmpty ( iValue ) ) {
2006
- entries [ key ] = '' ;
2007
- }
2008
- else if ( null !== iValue ) {
2009
- if ( typeof iValue === 'object' ) {
2010
- entries = { ...entries , ...buildQueryStringEntries ( iValue , entries , key ) } ;
2011
- }
2012
- else {
2013
- entries [ key ] = encodeURIComponent ( iValue )
2014
- . replace ( / % 2 0 / g, '+' )
2015
- . replace ( / % 2 C / g, ',' ) ;
2016
- }
2017
- }
2018
- } ) ;
2019
- return entries ;
2020
- } ;
2021
- const entries = buildQueryStringEntries ( data ) ;
2022
- return Object . entries ( entries )
2023
- . map ( ( [ key , value ] ) => `${ key } =${ value } ` )
2024
- . join ( '&' ) ;
2025
- }
2026
- function fromQueryString ( search ) {
2027
- search = search . replace ( '?' , '' ) ;
2028
- if ( search === '' )
2029
- return { } ;
2030
- const insertDotNotatedValueIntoData = ( key , value , data ) => {
2031
- const [ first , second , ...rest ] = key . split ( '.' ) ;
2032
- if ( ! second ) {
2033
- data [ key ] = value ;
2034
- return value ;
2035
- }
2036
- if ( data [ first ] === undefined ) {
2037
- data [ first ] = Number . isNaN ( Number . parseInt ( second ) ) ? { } : [ ] ;
2038
- }
2039
- insertDotNotatedValueIntoData ( [ second , ...rest ] . join ( '.' ) , value , data [ first ] ) ;
2040
- } ;
2041
- const entries = search . split ( '&' ) . map ( ( i ) => i . split ( '=' ) ) ;
2042
- const data = { } ;
2043
- entries . forEach ( ( [ key , value ] ) => {
2044
- value = decodeURIComponent ( String ( value || '' ) . replace ( / \+ / g, '%20' ) ) ;
2045
- if ( ! key . includes ( '[' ) ) {
2046
- data [ key ] = value ;
2047
- }
2048
- else {
2049
- if ( '' === value )
2050
- return ;
2051
- const dotNotatedKey = key . replace ( / \[ / g, '.' ) . replace ( / ] / g, '' ) ;
2052
- insertDotNotatedValueIntoData ( dotNotatedKey , value , data ) ;
2053
- }
2054
- } ) ;
2055
- return data ;
2056
- }
2057
- class UrlUtils extends URL {
2058
- has ( key ) {
2059
- const data = this . getData ( ) ;
2060
- return Object . keys ( data ) . includes ( key ) ;
2061
- }
2062
- set ( key , value ) {
2063
- const data = this . getData ( ) ;
2064
- data [ key ] = value ;
2065
- this . setData ( data ) ;
2066
- }
2067
- get ( key ) {
2068
- return this . getData ( ) [ key ] ;
2069
- }
2070
- remove ( key ) {
2071
- const data = this . getData ( ) ;
2072
- delete data [ key ] ;
2073
- this . setData ( data ) ;
2074
- }
2075
- getData ( ) {
2076
- if ( ! this . search ) {
2077
- return { } ;
2078
- }
2079
- return fromQueryString ( this . search ) ;
2080
- }
2081
- setData ( data ) {
2082
- this . search = toQueryString ( data ) ;
2083
- }
2084
- }
2085
- class HistoryStrategy {
2086
- static replace ( url ) {
2087
- history . replaceState ( history . state , '' , url ) ;
2088
- }
2089
- }
2090
-
2091
2089
class Component {
2092
2090
constructor ( element , name , props , listeners , id , backend , elementDriver ) {
2093
2091
this . fingerprint = '' ;
@@ -2885,25 +2883,6 @@ class PollingPlugin {
2885
2883
}
2886
2884
}
2887
2885
2888
- class QueryStringPlugin {
2889
- constructor ( mapping ) {
2890
- this . mapping = mapping ;
2891
- }
2892
- attachToComponent ( component ) {
2893
- component . on ( 'render:finished' , ( component ) => {
2894
- const urlUtils = new UrlUtils ( window . location . href ) ;
2895
- const currentUrl = urlUtils . toString ( ) ;
2896
- Object . entries ( this . mapping ) . forEach ( ( [ prop , mapping ] ) => {
2897
- const value = component . valueStore . get ( prop ) ;
2898
- urlUtils . set ( mapping . name , value ) ;
2899
- } ) ;
2900
- if ( currentUrl !== urlUtils . toString ( ) ) {
2901
- HistoryStrategy . replace ( urlUtils ) ;
2902
- }
2903
- } ) ;
2904
- }
2905
- }
2906
-
2907
2886
class SetValueOntoModelFieldsPlugin {
2908
2887
attachToComponent ( component ) {
2909
2888
this . synchronizeValueOfModelFields ( component ) ;
@@ -3113,7 +3092,6 @@ class LiveControllerDefault extends Controller {
3113
3092
new PageUnloadingPlugin ( ) ,
3114
3093
new PollingPlugin ( ) ,
3115
3094
new SetValueOntoModelFieldsPlugin ( ) ,
3116
- new QueryStringPlugin ( this . queryMappingValue ) ,
3117
3095
new ChildComponentPlugin ( this . component ) ,
3118
3096
] ;
3119
3097
plugins . forEach ( ( plugin ) => {
@@ -3244,7 +3222,6 @@ LiveControllerDefault.values = {
3244
3222
debounce : { type : Number , default : 150 } ,
3245
3223
fingerprint : { type : String , default : '' } ,
3246
3224
requestMethod : { type : String , default : 'post' } ,
3247
- queryMapping : { type : Object , default : { } } ,
3248
3225
} ;
3249
3226
LiveControllerDefault . backendFactory = ( controller ) => new Backend ( controller . urlValue , controller . requestMethodValue ) ;
3250
3227
0 commit comments