@akc42/app-utils 5.0.6 → 5.0.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/location.js +0 -6
- package/package.json +1 -1
- package/pdf.js +1 -1
- package/route.js +0 -10
package/location.js
CHANGED
|
@@ -18,19 +18,16 @@
|
|
|
18
18
|
along with Distributed Router. If not, see <http://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
import Debug from './debug.js';
|
|
22
21
|
let routeCallback = null;
|
|
23
22
|
let lastChangedAt;
|
|
24
23
|
let route = null;
|
|
25
24
|
|
|
26
|
-
const debug = Debug('router');
|
|
27
25
|
|
|
28
26
|
const dwellTime = () => {
|
|
29
27
|
return parseInt(localStorage.getItem('dwellTime') || 2000, 10); //dwell time might not be set initially, so keep retrying.
|
|
30
28
|
}
|
|
31
29
|
|
|
32
30
|
export function connectUrl(callback) {
|
|
33
|
-
debug('connectUrl called')
|
|
34
31
|
if (routeCallback === null) {
|
|
35
32
|
window.addEventListener('hashchange', urlChanged);
|
|
36
33
|
window.addEventListener('popstate', urlChanged);
|
|
@@ -46,7 +43,6 @@ export function connectUrl(callback) {
|
|
|
46
43
|
|
|
47
44
|
}
|
|
48
45
|
export function disconnectUrl() {
|
|
49
|
-
debug('disconnectUrl called')
|
|
50
46
|
routeCallback = null;
|
|
51
47
|
window.removeEventListener('hashchange',urlChanged);
|
|
52
48
|
window.removeEventListener('popstate', urlChanged);
|
|
@@ -63,7 +59,6 @@ function urlChanged() {
|
|
|
63
59
|
}
|
|
64
60
|
const query = decodeParams(window.location.search.substring(1));
|
|
65
61
|
if (route && route.path === path && JSON.stringify(route.query) === JSON.stringify(query)) return;
|
|
66
|
-
debug('url change route to path',path, 'has query', Object.keys(query).length > 0 )
|
|
67
62
|
lastChangedAt = window.performance.now();
|
|
68
63
|
route = {
|
|
69
64
|
path: path ,
|
|
@@ -79,7 +74,6 @@ function routeChanged(e) {
|
|
|
79
74
|
let newPath = route.path;
|
|
80
75
|
if(e.detail.path !== undefined) {
|
|
81
76
|
if (Number.isInteger(e.detail.segment)) {
|
|
82
|
-
debug('route change called path', e.detail.path, 'segments', e.detail.segment, 'current path', route.path )
|
|
83
77
|
let segments = route.path.split('/');
|
|
84
78
|
if (segments[0] === '') segments.shift(); //loose leeding
|
|
85
79
|
if(segments.length < e.detail.segment) {
|
package/package.json
CHANGED
package/pdf.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
You should have received a copy of the GNU General Public License
|
|
18
18
|
along with @akc42/app-utils. If not, see <http://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
|
-
import api from './api.js';
|
|
20
|
+
import {api} from './api.js';
|
|
21
21
|
export default (url,params) => {
|
|
22
22
|
api(`pdf/${url}`,params,true);
|
|
23
23
|
}
|
package/route.js
CHANGED
|
@@ -17,9 +17,6 @@
|
|
|
17
17
|
You should have received a copy of the GNU General Public License
|
|
18
18
|
along with Distributed Router. If not, see <http://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
|
-
import Debug from './debug.js';
|
|
21
|
-
|
|
22
|
-
const debug = Debug('router');
|
|
23
20
|
|
|
24
21
|
export default class Route {
|
|
25
22
|
constructor(match = '', ifmatched = '') {
|
|
@@ -35,11 +32,9 @@ export default class Route {
|
|
|
35
32
|
//this is our output
|
|
36
33
|
this._route = {active: false, segment: 0, path: '', params: {}, query: {}};
|
|
37
34
|
this.sentRouteChanged = false;
|
|
38
|
-
debug('new route made with match', match, 'ifmatched', ifmatched)
|
|
39
35
|
}
|
|
40
36
|
|
|
41
37
|
routeChange(preroute) {
|
|
42
|
-
debug('routeChanged called with preroute of', JSON.stringify(preroute));
|
|
43
38
|
this.preroute = preroute; //remember it
|
|
44
39
|
if (preroute !== undefined && preroute.active && preroute.path.length > 0 &&
|
|
45
40
|
this._ifMatches(preroute.params) ) {
|
|
@@ -107,7 +102,6 @@ export default class Route {
|
|
|
107
102
|
this._route = newRoute;
|
|
108
103
|
this.sentRouteChanged = true;
|
|
109
104
|
}
|
|
110
|
-
debug('Route Change returning (no clear active)', JSON.stringify(this._route));
|
|
111
105
|
} else {
|
|
112
106
|
throw new Error('Route: Match String Required');
|
|
113
107
|
}
|
|
@@ -166,7 +160,6 @@ export default class Route {
|
|
|
166
160
|
}
|
|
167
161
|
if (changeMade) {
|
|
168
162
|
const path = '/' + urlPieces.join('/');
|
|
169
|
-
debug('params set, about to set path',path,'segment', this.preroute.segment );
|
|
170
163
|
window.dispatchEvent(new CustomEvent ('route-changed',{bubbles: true, composed: true, detail:{
|
|
171
164
|
segment: this.preroute.segment,
|
|
172
165
|
path: path
|
|
@@ -179,7 +172,6 @@ export default class Route {
|
|
|
179
172
|
*/
|
|
180
173
|
set query(value) {
|
|
181
174
|
const jsv = JSON.stringify(value)
|
|
182
|
-
debug('set query to value', jsv)
|
|
183
175
|
if (this._route.active && JSON.stringify(this._route.query) !== jsv) {
|
|
184
176
|
window.dispatchEvent(new CustomEvent('route-changed',{bubbles: true, composed: true, detail:{query: value}}));
|
|
185
177
|
}
|
|
@@ -188,7 +180,6 @@ export default class Route {
|
|
|
188
180
|
* We can set or break the connection between a pre-route and its route
|
|
189
181
|
*/
|
|
190
182
|
set connection(value) {
|
|
191
|
-
debug('set connection called with value', value);
|
|
192
183
|
if (this.preroute.active) {
|
|
193
184
|
if (this._route.active) {
|
|
194
185
|
if (value) return; //can't set a matched route active
|
|
@@ -226,7 +217,6 @@ export default class Route {
|
|
|
226
217
|
this._route = Object.assign({}, this._route, {active:false});
|
|
227
218
|
this.sentRouteChanged = true;
|
|
228
219
|
}
|
|
229
|
-
debug('clearOutActive returning route', JSON.stringify(this._route));
|
|
230
220
|
return this._route;
|
|
231
221
|
}
|
|
232
222
|
}
|