PluginProbe ʕ •ᴥ•ʔ
Presto Player / 4.3.2
Presto Player v4.3.2
4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.4 4.2.3 4.2.2 4.2.0 4.2.1 trunk 1.10.0 1.10.1 1.10.2 1.11.0 1.12.0 1.13.0 1.14.0 1.14.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.13 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.3-beta1 2.3.0 2.3.1 2.3.2 2.3.3 3.0.0 3.0.0-beta1 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.1.0 3.1.1 3.1.2 3.1.3 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4
presto-player / src / admin / dashboard / router / history.js
presto-player / src / admin / dashboard / router Last commit date
history.js 3 months ago router.js 3 months ago
history.js
79 lines
1 /**
2 * External dependencies
3 */
4 import { createBrowserHistory } from 'history';
5
6 /**
7 * WordPress dependencies
8 */
9 import { buildQueryString } from '@wordpress/url';
10
11 const history = createBrowserHistory();
12
13 const originalHistoryPush = history.push;
14 const originalHistoryReplace = history.replace;
15
16 /**
17 * Custom push/replace wrappers that accept a plain params object instead of
18 * a full location descriptor.
19 *
20 * Navigation contract: params you don't pass are dropped, except for the
21 * WordPress-admin routing params in PRESERVED_PARAM_KEYS. Those must survive
22 * every navigation — otherwise admin.php loses the query args it needs to
23 * route back to this page on reload (`?page=presto-dashboard&post_type=…`).
24 *
25 * Any app-level param the caller wants to keep must be passed explicitly.
26 */
27 const PRESERVED_PARAM_KEYS = [ 'page', 'post_type' ];
28
29 function mergeParams( incoming ) {
30 const currentAll = Object.fromEntries(
31 new URLSearchParams( history.location.search )
32 );
33 const preserved = {};
34 for ( const key of PRESERVED_PARAM_KEYS ) {
35 if ( currentAll[ key ] !== undefined ) {
36 preserved[ key ] = currentAll[ key ];
37 }
38 }
39 const merged = { ...preserved, ...incoming };
40 // Remove keys explicitly set to null or undefined (allows param deletion)
41 Object.keys( merged ).forEach( ( key ) => {
42 if ( merged[ key ] == null ) {
43 delete merged[ key ];
44 }
45 } );
46 return merged;
47 }
48
49 function push( params, state ) {
50 const search = buildQueryString( mergeParams( params ) );
51 return originalHistoryPush.call( history, { search }, state );
52 }
53
54 function replace( params, state ) {
55 const search = buildQueryString( mergeParams( params ) );
56 return originalHistoryReplace.call( history, { search }, state );
57 }
58
59 const locationMemo = new WeakMap();
60 function getLocationWithParams() {
61 const location = history.location;
62 let locationWithParams = locationMemo.get( location );
63 if ( ! locationWithParams ) {
64 locationWithParams = {
65 ...location,
66 params: Object.fromEntries(
67 new URLSearchParams( location.search )
68 ),
69 };
70 locationMemo.set( location, locationWithParams );
71 }
72 return locationWithParams;
73 }
74
75 history.push = push;
76 history.replace = replace;
77 history.getLocationWithParams = getLocationWithParams;
78
79 export default history;