piral-core 0.15.0-beta.4670 → 0.15.0-beta.4672

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/app.codegen CHANGED
@@ -65,146 +65,20 @@ function createDefaultState(imports, exports) {
65
65
  imports.push(
66
66
  `import { DefaultRouter } from 'piral-core/${cat}/defaults/DefaultRouter_v5';`,
67
67
  `import { DefaultRouteSwitch } from 'piral-core/${cat}/defaults/DefaultRouteSwitch_v5';`,
68
- `import { __RouterContext as RouterContext } from 'react-router'`,
68
+ `import { createRedirect, createNavigation, useCurrentNavigation, useRouterContext } from 'piral-core/${cat}/defaults/navigator_v5'`,
69
69
  );
70
- exports.push(`
71
- function useCurrentNavigation() {
72
- const ctx = useRouterContext();
73
-
74
- useEffect(() => {
75
- _nav = ctx.history;
76
- return () => {
77
- _nav = undefined;
78
- };
79
- }, []);
80
- }
81
- `);
82
-
83
- exports.push(`
84
- export function createNavigation() {
85
- const enhance = info => ({
86
- ...info,
87
- location: {
88
- get href() {
89
- return _nav.createHref(info.location);
90
- },
91
- ...info.location,
92
- },
93
- });
94
-
95
- return {
96
- get path() {
97
- if (_nav) {
98
- return _nav.location.pathname;
99
- }
100
-
101
- return location.pathname;
102
- },
103
- push(target, state) {
104
- if (_nav) {
105
- _nav.push(target, state);
106
- }
107
- },
108
- replace(target, state) {
109
- if (_nav) {
110
- _nav.replace(target, state);
111
- }
112
- },
113
- go(n) {
114
- if (_nav) {
115
- _nav.go(n);
116
- }
117
- },
118
- block(blocker) {
119
- if (!_nav) {
120
- return _noop;
121
- }
122
- return _nav.block((location, action) => blocker(enhance({ location, action })));
123
- },
124
- listen(listener) {
125
- if (!_nav) {
126
- return _noop;
127
- }
128
- return _nav.listen((location, action) => listener(enhance({ location, action })));
129
- },
130
- router: {
131
- history: _nav,
132
- },
133
- };
134
- }
135
- `);
136
70
  } else {
137
71
  imports.push(
138
72
  `import { DefaultRouter } from 'piral-core/${cat}/defaults/DefaultRouter_v6';`,
139
73
  `import { DefaultRouteSwitch } from 'piral-core/${cat}/defaults/DefaultRouteSwitch_v6';`,
140
- `import { UNSAFE_NavigationContext as RouterContext } from 'react-router'`,
74
+ `import { createRedirect, createNavigation, useCurrentNavigation, useRouterContext } from 'piral-core/${cat}/defaults/navigator_v6'`,
141
75
  );
142
- exports.push(`
143
- function useCurrentNavigation() {
144
- const ctx = useRouterContext();
145
-
146
- useEffect(() => {
147
- _nav = ctx.navigator;
148
- return () => {
149
- _nav = undefined;
150
- };
151
- }, []);
152
- }
153
- `);
154
-
155
- exports.push(`
156
- export function createNavigation() {
157
- const enhance = info => ({
158
- ...info,
159
- location: {
160
- get href() {
161
- return _nav.createHref(info.location);
162
- },
163
- ...info.location,
164
- },
165
- });
166
-
167
- return {
168
- get path() {
169
- if (_nav) {
170
- return _nav.location.pathname;
171
- }
172
-
173
- return location.pathname;
174
- },
175
- push(target, state) {
176
- if (_nav) {
177
- _nav.push(target, state);
178
- }
179
- },
180
- replace(target, state) {
181
- if (_nav) {
182
- _nav.replace(target, state);
183
- }
184
- },
185
- go(n) {
186
- if (_nav) {
187
- _nav.go(n);
188
- }
189
- },
190
- block(blocker) {
191
- if (!_nav) {
192
- return _noop;
193
- }
194
- return _nav.block(transition => blocker(enhance(transition)));
195
- },
196
- listen(listener) {
197
- if (!_nav) {
198
- return _noop;
199
- }
200
- return _nav.listen(update => listener(enhance(update)));
201
- },
202
- router: _nav,
203
- };
204
- }
205
- `);
206
76
  }
207
77
 
78
+ exports.push(`
79
+ export { createRedirect, createNavigation, useRouterContext };
80
+ `);
81
+
208
82
  exports.push(`
209
83
  export const publicPath = ${JSON.stringify(publicPath)};
210
84
  `);
@@ -260,8 +134,6 @@ function createRouteHandler(imports, exports) {
260
134
  const assignments = [];
261
135
 
262
136
  imports.push(
263
- `import { useContext, useEffect, createElement } from 'react';`,
264
- `import { Redirect } from 'react-router';`,
265
137
  `import { useGlobalStateContext } from 'piral-core/${cat}/hooks/globalState';`,
266
138
  );
267
139
 
@@ -276,18 +148,6 @@ function createRouteHandler(imports, exports) {
276
148
  assignments.push('return paths;');
277
149
  }
278
150
 
279
- exports.push(`
280
- export function createRedirect(to) {
281
- return () => createElement(Redirect, { to });
282
- }
283
- `);
284
-
285
- exports.push(`
286
- export function useRouterContext() {
287
- return useContext(RouterContext);
288
- }
289
- `);
290
-
291
151
  exports.push(`
292
152
  export function useRouteFilter(paths) {
293
153
  ${assignments.join('\n')}
@@ -307,9 +167,6 @@ module.exports = function () {
307
167
  return `
308
168
  ${imports.join('\n')}
309
169
 
310
- let _nav;
311
- const _noop = () => {};
312
-
313
170
  ${exports.join('\n')}
314
171
  `;
315
172
  };
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { NavigationApi } from '../types';
3
+ export declare function useRouterContext(): import("react-router").RouteComponentProps<{}, import("react-router").StaticContext, unknown>;
4
+ export declare function useCurrentNavigation(): void;
5
+ export declare function createRedirect(to: string): () => JSX.Element;
6
+ export declare function createNavigation(): NavigationApi;
@@ -0,0 +1,77 @@
1
+ import * as React from 'react';
2
+ import { __RouterContext as RouterContext, Redirect, useLocation } from 'react-router';
3
+ let _nav;
4
+ const _noop = () => { };
5
+ export function useRouterContext() {
6
+ return React.useContext(RouterContext);
7
+ }
8
+ export function useCurrentNavigation() {
9
+ const ctx = useRouterContext();
10
+ const location = useLocation();
11
+ React.useEffect(() => {
12
+ if (_nav) {
13
+ window.dispatchEvent(new CustomEvent('piral-navigate', {
14
+ detail: {
15
+ location,
16
+ },
17
+ }));
18
+ }
19
+ }, [location]);
20
+ React.useEffect(() => {
21
+ _nav = ctx.history;
22
+ return () => {
23
+ _nav = undefined;
24
+ };
25
+ }, []);
26
+ }
27
+ export function createRedirect(to) {
28
+ return () => React.createElement(Redirect, { to: to });
29
+ }
30
+ export function createNavigation() {
31
+ const enhance = (location, action) => ({
32
+ action,
33
+ location: Object.assign({ get href() {
34
+ return _nav.createHref(location);
35
+ } }, location),
36
+ });
37
+ return {
38
+ get path() {
39
+ if (_nav) {
40
+ return _nav.location.pathname;
41
+ }
42
+ return location.pathname;
43
+ },
44
+ push(target, state) {
45
+ if (_nav) {
46
+ _nav.push(target, state);
47
+ }
48
+ },
49
+ replace(target, state) {
50
+ if (_nav) {
51
+ _nav.replace(target, state);
52
+ }
53
+ },
54
+ go(n) {
55
+ if (_nav) {
56
+ _nav.go(n);
57
+ }
58
+ },
59
+ block(blocker) {
60
+ if (!_nav) {
61
+ return _noop;
62
+ }
63
+ return _nav.block((location, action) => blocker(enhance(location, action)));
64
+ },
65
+ listen(listener) {
66
+ const handler = (e) => listener(enhance(e.detail, _nav.action));
67
+ window.addEventListener('piral-navigate', handler);
68
+ return () => {
69
+ window.removeEventListener('piral-navigate', handler);
70
+ };
71
+ },
72
+ router: {
73
+ history: _nav,
74
+ },
75
+ };
76
+ }
77
+ //# sourceMappingURL=navigator_v5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigator_v5.js","sourceRoot":"","sources":["../../src/defaults/navigator_v5.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,eAAe,IAAI,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGvF,IAAI,IAAa,CAAC;AAClB,MAAM,KAAK,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAEvB,MAAM,UAAU,gBAAgB;IAC9B,OAAO,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,oBAAoB;IAClC,MAAM,GAAG,GAAG,gBAAgB,EAAE,CAAC;IAC/B,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAE/B,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,IAAI,EAAE;YACR,MAAM,CAAC,aAAa,CAClB,IAAI,WAAW,CAAC,gBAAgB,EAAE;gBAChC,MAAM,EAAE;oBACN,QAAQ;iB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CAAC,IAAI,EAAE;gBACT,OAAO,KAAK,CAAC;aACd;YAED,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;QAC9E,CAAC;QACD,MAAM,CAAC,QAAQ;YACb,MAAM,OAAO,GAAG,CAAC,CAAc,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;YAE7E,MAAM,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;YAEnD,OAAO,GAAG,EAAE;gBACV,MAAM,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;YACxD,CAAC,CAAC;QACJ,CAAC;QACD,MAAM,EAAE;YACN,OAAO,EAAE,IAAI;SACd;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { NavigationApi } from '../types';
3
+ export declare function useRouterContext(): unknown;
4
+ export declare function useCurrentNavigation(): void;
5
+ export declare function createRedirect(to: string): () => JSX.Element;
6
+ export declare function createNavigation(): NavigationApi;
@@ -0,0 +1,73 @@
1
+ import * as React from 'react';
2
+ //@ts-ignore
3
+ import { UNSAFE_NavigationContext as RouterContext, Navigate, useLocation } from 'react-router';
4
+ let _nav;
5
+ const _noop = () => { };
6
+ export function useRouterContext() {
7
+ return React.useContext(RouterContext);
8
+ }
9
+ export function useCurrentNavigation() {
10
+ const ctx = useRouterContext();
11
+ const location = useLocation();
12
+ React.useEffect(() => {
13
+ if (_nav) {
14
+ window.dispatchEvent(new CustomEvent('piral-navigate', {
15
+ detail: {
16
+ location,
17
+ },
18
+ }));
19
+ }
20
+ }, [location]);
21
+ React.useEffect(() => {
22
+ _nav = ctx.navigator;
23
+ return () => {
24
+ _nav = undefined;
25
+ };
26
+ }, []);
27
+ }
28
+ export function createRedirect(to) {
29
+ return () => React.createElement(Navigate, { to: to });
30
+ }
31
+ export function createNavigation() {
32
+ const enhance = (info) => (Object.assign(Object.assign({}, info), { location: Object.assign({ get href() {
33
+ return _nav.createHref(info.location);
34
+ } }, info.location) }));
35
+ return {
36
+ get path() {
37
+ if (_nav) {
38
+ return _nav.location.pathname;
39
+ }
40
+ return location.pathname;
41
+ },
42
+ push(target, state) {
43
+ if (_nav) {
44
+ _nav.push(target, state);
45
+ }
46
+ },
47
+ replace(target, state) {
48
+ if (_nav) {
49
+ _nav.replace(target, state);
50
+ }
51
+ },
52
+ go(n) {
53
+ if (_nav) {
54
+ _nav.go(n);
55
+ }
56
+ },
57
+ block(blocker) {
58
+ if (!_nav) {
59
+ return _noop;
60
+ }
61
+ return _nav.block((transition) => blocker(enhance(transition)));
62
+ },
63
+ listen(listener) {
64
+ const handler = (e) => listener(enhance(e.detail));
65
+ window.addEventListener('piral-navigate', handler);
66
+ return () => {
67
+ window.removeEventListener('piral-navigate', handler);
68
+ };
69
+ },
70
+ router: _nav,
71
+ };
72
+ }
73
+ //# sourceMappingURL=navigator_v6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigator_v6.js","sourceRoot":"","sources":["../../src/defaults/navigator_v6.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,YAAY;AACZ,OAAO,EAAE,wBAAwB,IAAI,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhG,IAAI,IAAS,CAAC;AACd,MAAM,KAAK,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAEvB,MAAM,UAAU,gBAAgB;IAC9B,OAAO,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,oBAAoB;IAClC,MAAM,GAAG,GAAQ,gBAAgB,EAAE,CAAC;IACpC,MAAM,QAAQ,GAAG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K,CAAC,CAAC;aAC7B;QACH,CAAC;QACD,EAAE,CAAC,CAAC;YACF,IAAI,IAAI,EAAE;gBACR,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;aACZ;QACH,CAAC;QACD,KAAK,CAAC,OAAO;YACX,IAAI,CAAC,IAAI,EAAE;gBACT,OAAO,KAAK,CAAC;aACd;YACD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAClE,CAAC;QACD,MAAM,CAAC,QAAQ;YACb,MAAM,OAAO,GAAG,CAAC,CAAc,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;YAEhE,MAAM,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;YAEnD,OAAO,GAAG,EAAE;gBACV,MAAM,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;YACxD,CAAC,CAAC;QACJ,CAAC;QACD,MAAM,EAAE,IAAI;KACb,CAAC;AACJ,CAAC"}
@@ -34,7 +34,7 @@ export interface NavigationLocation {
34
34
  * On the initial location, this will be the string default. On all subsequent
35
35
  * locations, this string will be a unique identifier.
36
36
  */
37
- key: string;
37
+ key?: string;
38
38
  }
39
39
  export interface NavigationListener {
40
40
  (update: NavigationUpdate): void;
@@ -47,7 +47,7 @@ export interface NavigationUpdate {
47
47
  location: NavigationLocation;
48
48
  }
49
49
  export interface NavigationTransition extends NavigationUpdate {
50
- retry(): void;
50
+ retry?(): void;
51
51
  }
52
52
  export interface NavigationApi {
53
53
  /**
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { NavigationApi } from '../types';
3
+ export declare function useRouterContext(): import("react-router").RouteComponentProps<{}, import("react-router").StaticContext, unknown>;
4
+ export declare function useCurrentNavigation(): void;
5
+ export declare function createRedirect(to: string): () => JSX.Element;
6
+ export declare function createNavigation(): NavigationApi;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNavigation = exports.createRedirect = exports.useCurrentNavigation = exports.useRouterContext = void 0;
4
+ const React = require("react");
5
+ const react_router_1 = require("react-router");
6
+ let _nav;
7
+ const _noop = () => { };
8
+ function useRouterContext() {
9
+ return React.useContext(react_router_1.__RouterContext);
10
+ }
11
+ exports.useRouterContext = useRouterContext;
12
+ function useCurrentNavigation() {
13
+ const ctx = useRouterContext();
14
+ const location = (0, react_router_1.useLocation)();
15
+ React.useEffect(() => {
16
+ if (_nav) {
17
+ window.dispatchEvent(new CustomEvent('piral-navigate', {
18
+ detail: {
19
+ location,
20
+ },
21
+ }));
22
+ }
23
+ }, [location]);
24
+ React.useEffect(() => {
25
+ _nav = ctx.history;
26
+ return () => {
27
+ _nav = undefined;
28
+ };
29
+ }, []);
30
+ }
31
+ exports.useCurrentNavigation = useCurrentNavigation;
32
+ function createRedirect(to) {
33
+ return () => React.createElement(react_router_1.Redirect, { to: to });
34
+ }
35
+ exports.createRedirect = createRedirect;
36
+ function createNavigation() {
37
+ const enhance = (location, action) => ({
38
+ action,
39
+ location: Object.assign({ get href() {
40
+ return _nav.createHref(location);
41
+ } }, location),
42
+ });
43
+ return {
44
+ get path() {
45
+ if (_nav) {
46
+ return _nav.location.pathname;
47
+ }
48
+ return location.pathname;
49
+ },
50
+ push(target, state) {
51
+ if (_nav) {
52
+ _nav.push(target, state);
53
+ }
54
+ },
55
+ replace(target, state) {
56
+ if (_nav) {
57
+ _nav.replace(target, state);
58
+ }
59
+ },
60
+ go(n) {
61
+ if (_nav) {
62
+ _nav.go(n);
63
+ }
64
+ },
65
+ block(blocker) {
66
+ if (!_nav) {
67
+ return _noop;
68
+ }
69
+ return _nav.block((location, action) => blocker(enhance(location, action)));
70
+ },
71
+ listen(listener) {
72
+ const handler = (e) => listener(enhance(e.detail, _nav.action));
73
+ window.addEventListener('piral-navigate', handler);
74
+ return () => {
75
+ window.removeEventListener('piral-navigate', handler);
76
+ };
77
+ },
78
+ router: {
79
+ history: _nav,
80
+ },
81
+ };
82
+ }
83
+ exports.createNavigation = createNavigation;
84
+ //# sourceMappingURL=navigator_v5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigator_v5.js","sourceRoot":"","sources":["../../src/defaults/navigator_v5.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAE/B,+CAAuF;AAGvF,IAAI,IAAa,CAAC;AAClB,MAAM,KAAK,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAEvB,SAAgB,gBAAgB;IAC9B,OAAO,KAAK,CAAC,UAAU,CAAC,8BAAa,CAAC,CAAC;AACzC,CAAC;AAFD,4CAEC;AAED,SAAgB,oBAAoB;IAClC,MAAM,GAAG,GAAG,gBAAgB,EAAE,CAAC;IAC/B,MAAM,QAAQ,GAAG,IAAA,0BAAW,GAAE,CAAC;IAE/B,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,IAAI,EAAE;YACR,MAAM,CAAC,aAAa,CAClB,IAAI,WAAW,CAAC,gBAAgB,EAAE;gBAChC,MAAM,EAAE;oBACN,QAAQ;iBACT;aACF,CAAC,CACH,CAAC;SACH;IACH,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC;QAEnB,OAAO,GAAG,EAAE;YACV,IAAI,GAAG,SAAS,CAAC;QACnB,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AAvBD,oDAuBC;AAED,SAAgB,cAAc,CAAC,EAAU;IACvC,OAAO,GAAG,EAAE,CAAC,oBAAC,uBAAQ,IAAC,EAAE,EAAE,EAAE,GAAI,CAAC;AACpC,CAAC;AAFD,wCAEC;AAED,SAAgB,gBAAgB;IAC9B,MA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AO,GAAG,EAAE;gBACV,MAAM,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;YACxD,CAAC,CAAC;QACJ,CAAC;QACD,MAAM,EAAE;YACN,OAAO,EAAE,IAAI;SACd;KACF,CAAC;AACJ,CAAC;AAtDD,4CAsDC"}
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { NavigationApi } from '../types';
3
+ export declare function useRouterContext(): unknown;
4
+ export declare function useCurrentNavigation(): void;
5
+ export declare function createRedirect(to: string): () => JSX.Element;
6
+ export declare function createNavigation(): NavigationApi;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNavigation = exports.createRedirect = exports.useCurrentNavigation = exports.useRouterContext = void 0;
4
+ const React = require("react");
5
+ //@ts-ignore
6
+ const react_router_1 = require("react-router");
7
+ let _nav;
8
+ const _noop = () => { };
9
+ function useRouterContext() {
10
+ return React.useContext(react_router_1.UNSAFE_NavigationContext);
11
+ }
12
+ exports.useRouterContext = useRouterContext;
13
+ function useCurrentNavigation() {
14
+ const ctx = useRouterContext();
15
+ const location = (0, react_router_1.useLocation)();
16
+ React.useEffect(() => {
17
+ if (_nav) {
18
+ window.dispatchEvent(new CustomEvent('piral-navigate', {
19
+ detail: {
20
+ location,
21
+ },
22
+ }));
23
+ }
24
+ }, [location]);
25
+ React.useEffect(() => {
26
+ _nav = ctx.navigator;
27
+ return () => {
28
+ _nav = undefined;
29
+ };
30
+ }, []);
31
+ }
32
+ exports.useCurrentNavigation = useCurrentNavigation;
33
+ function createRedirect(to) {
34
+ return () => React.createElement(react_router_1.Navigate, { to: to });
35
+ }
36
+ exports.createRedirect = createRedirect;
37
+ function createNavigation() {
38
+ const enhance = (info) => (Object.assign(Object.assign({}, info), { location: Object.assign({ get href() {
39
+ return _nav.createHref(info.location);
40
+ } }, info.location) }));
41
+ return {
42
+ get path() {
43
+ if (_nav) {
44
+ return _nav.location.pathname;
45
+ }
46
+ return location.pathname;
47
+ },
48
+ push(target, state) {
49
+ if (_nav) {
50
+ _nav.push(target, state);
51
+ }
52
+ },
53
+ replace(target, state) {
54
+ if (_nav) {
55
+ _nav.replace(target, state);
56
+ }
57
+ },
58
+ go(n) {
59
+ if (_nav) {
60
+ _nav.go(n);
61
+ }
62
+ },
63
+ block(blocker) {
64
+ if (!_nav) {
65
+ return _noop;
66
+ }
67
+ return _nav.block((transition) => blocker(enhance(transition)));
68
+ },
69
+ listen(listener) {
70
+ const handler = (e) => listener(enhance(e.detail));
71
+ window.addEventListener('piral-navigate', handler);
72
+ return () => {
73
+ window.removeEventListener('piral-navigate', handler);
74
+ };
75
+ },
76
+ router: _nav,
77
+ };
78
+ }
79
+ exports.createNavigation = createNavigation;
80
+ //# sourceMappingURL=navigator_v6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigator_v6.js","sourceRoot":"","sources":["../../src/defaults/navigator_v6.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,YAAY;AACZ,+CAAgG;AAGhG,IAAI,IAAS,CAAC;AACd,MAAM,KAAK,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAEvB,SAAgB,gBAAgB;IAC9B,OAAO,KAAK,CAAC,UAAU,CAAC,uCAAa,CAAC,CAAC;AACzC,CAAC;AAFD,4CAEC;AAED,SAAgB,oBAAoB;IAClC,MAAM,GAAG,GAAQ,gBAAgB,EAAE,CAAC;IACpC,MAAM,QAAQ,GAAG,IAAA,0BAAW,GAAE,CAAC;IAE/B,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,IAAI,EAAE;YACR,MAAM,CAAC,aAAa,CAClB,IAAI,WAAW,CAAC,gBAAgB,EAAE;gBAChC,MAAM,EAAE;oBACN,QAAQ;iBACT;aACF,CAAC,CACH,CAAC;SACH;IACH,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE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,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAClE,CAAC;QACD,MAAM,CAAC,QAAQ;YACb,MAAM,OAAO,GAAG,CAAC,CAAc,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;YAEhE,MAAM,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;YAEnD,OAAO,GAAG,EAAE;gBACV,MAAM,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;YACxD,CAAC,CAAC;QACJ,CAAC;QACD,MAAM,EAAE,IAAI;KACb,CAAC;AACJ,CAAC;AAnDD,4CAmDC"}
@@ -34,7 +34,7 @@ export interface NavigationLocation {
34
34
  * On the initial location, this will be the string default. On all subsequent
35
35
  * locations, this string will be a unique identifier.
36
36
  */
37
- key: string;
37
+ key?: string;
38
38
  }
39
39
  export interface NavigationListener {
40
40
  (update: NavigationUpdate): void;
@@ -47,7 +47,7 @@ export interface NavigationUpdate {
47
47
  location: NavigationLocation;
48
48
  }
49
49
  export interface NavigationTransition extends NavigationUpdate {
50
- retry(): void;
50
+ retry?(): void;
51
51
  }
52
52
  export interface NavigationApi {
53
53
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-core",
3
- "version": "0.15.0-beta.4670",
3
+ "version": "0.15.0-beta.4672",
4
4
  "description": "The core library for creating a Piral instance.",
5
5
  "keywords": [
6
6
  "portal",
@@ -71,8 +71,8 @@
71
71
  },
72
72
  "dependencies": {
73
73
  "enhanced-resolve": "^5.10.0",
74
- "piral-base": "0.15.0-beta.4670",
75
- "piral-debug-utils": "0.15.0-beta.4670",
74
+ "piral-base": "0.15.0-beta.4672",
75
+ "piral-debug-utils": "0.15.0-beta.4672",
76
76
  "zustand": "^3.0.0"
77
77
  },
78
78
  "peerDependencies": {
@@ -98,5 +98,5 @@
98
98
  "react-router-dom",
99
99
  "tslib"
100
100
  ],
101
- "gitHead": "ffd8707600e028a55258028d394b76fe3a0cd175"
101
+ "gitHead": "cd1026b70c90290fa5ba3f9b86c038eb852595be"
102
102
  }
@@ -0,0 +1,96 @@
1
+ import * as React from 'react';
2
+ import type { History, Location, Action } from 'history';
3
+ import { __RouterContext as RouterContext, Redirect, useLocation } from 'react-router';
4
+ import { NavigationApi } from '../types';
5
+
6
+ let _nav: History;
7
+ const _noop = () => {};
8
+
9
+ export function useRouterContext() {
10
+ return React.useContext(RouterContext);
11
+ }
12
+
13
+ export function useCurrentNavigation() {
14
+ const ctx = useRouterContext();
15
+ const location = useLocation();
16
+
17
+ React.useEffect(() => {
18
+ if (_nav) {
19
+ window.dispatchEvent(
20
+ new CustomEvent('piral-navigate', {
21
+ detail: {
22
+ location,
23
+ },
24
+ }),
25
+ );
26
+ }
27
+ }, [location]);
28
+
29
+ React.useEffect(() => {
30
+ _nav = ctx.history;
31
+
32
+ return () => {
33
+ _nav = undefined;
34
+ };
35
+ }, []);
36
+ }
37
+
38
+ export function createRedirect(to: string) {
39
+ return () => <Redirect to={to} />;
40
+ }
41
+
42
+ export function createNavigation(): NavigationApi {
43
+ const enhance = (location: Location, action: Action) => ({
44
+ action,
45
+ location: {
46
+ get href() {
47
+ return _nav.createHref(location);
48
+ },
49
+ ...location,
50
+ },
51
+ });
52
+
53
+ return {
54
+ get path() {
55
+ if (_nav) {
56
+ return _nav.location.pathname;
57
+ }
58
+
59
+ return location.pathname;
60
+ },
61
+ push(target, state) {
62
+ if (_nav) {
63
+ _nav.push(target, state);
64
+ }
65
+ },
66
+ replace(target, state) {
67
+ if (_nav) {
68
+ _nav.replace(target, state);
69
+ }
70
+ },
71
+ go(n) {
72
+ if (_nav) {
73
+ _nav.go(n);
74
+ }
75
+ },
76
+ block(blocker) {
77
+ if (!_nav) {
78
+ return _noop;
79
+ }
80
+
81
+ return _nav.block((location, action) => blocker(enhance(location, action)));
82
+ },
83
+ listen(listener) {
84
+ const handler = (e: CustomEvent) => listener(enhance(e.detail, _nav.action));
85
+
86
+ window.addEventListener('piral-navigate', handler);
87
+
88
+ return () => {
89
+ window.removeEventListener('piral-navigate', handler);
90
+ };
91
+ },
92
+ router: {
93
+ history: _nav,
94
+ },
95
+ };
96
+ }
@@ -0,0 +1,93 @@
1
+ import * as React from 'react';
2
+ //@ts-ignore
3
+ import { UNSAFE_NavigationContext as RouterContext, Navigate, useLocation } from 'react-router';
4
+ import { NavigationApi } from '../types';
5
+
6
+ let _nav: any;
7
+ const _noop = () => {};
8
+
9
+ export function useRouterContext() {
10
+ return React.useContext(RouterContext);
11
+ }
12
+
13
+ export function useCurrentNavigation() {
14
+ const ctx: any = useRouterContext();
15
+ const location = useLocation();
16
+
17
+ React.useEffect(() => {
18
+ if (_nav) {
19
+ window.dispatchEvent(
20
+ new CustomEvent('piral-navigate', {
21
+ detail: {
22
+ location,
23
+ },
24
+ }),
25
+ );
26
+ }
27
+ }, [location]);
28
+
29
+ React.useEffect(() => {
30
+ _nav = ctx.navigator;
31
+
32
+ return () => {
33
+ _nav = undefined;
34
+ };
35
+ }, []);
36
+ }
37
+
38
+ export function createRedirect(to: string) {
39
+ return () => <Navigate to={to} />;
40
+ }
41
+
42
+ export function createNavigation(): NavigationApi {
43
+ const enhance = (info) => ({
44
+ ...info,
45
+ location: {
46
+ get href() {
47
+ return _nav.createHref(info.location);
48
+ },
49
+ ...info.location,
50
+ },
51
+ });
52
+
53
+ return {
54
+ get path() {
55
+ if (_nav) {
56
+ return _nav.location.pathname;
57
+ }
58
+
59
+ return location.pathname;
60
+ },
61
+ push(target, state) {
62
+ if (_nav) {
63
+ _nav.push(target, state);
64
+ }
65
+ },
66
+ replace(target, state) {
67
+ if (_nav) {
68
+ _nav.replace(target, state);
69
+ }
70
+ },
71
+ go(n) {
72
+ if (_nav) {
73
+ _nav.go(n);
74
+ }
75
+ },
76
+ block(blocker) {
77
+ if (!_nav) {
78
+ return _noop;
79
+ }
80
+ return _nav.block((transition) => blocker(enhance(transition)));
81
+ },
82
+ listen(listener) {
83
+ const handler = (e: CustomEvent) => listener(enhance(e.detail));
84
+
85
+ window.addEventListener('piral-navigate', handler);
86
+
87
+ return () => {
88
+ window.removeEventListener('piral-navigate', handler);
89
+ };
90
+ },
91
+ router: _nav,
92
+ };
93
+ }
@@ -36,7 +36,7 @@ export interface NavigationLocation {
36
36
  * On the initial location, this will be the string default. On all subsequent
37
37
  * locations, this string will be a unique identifier.
38
38
  */
39
- key: string;
39
+ key?: string;
40
40
  }
41
41
 
42
42
  export interface NavigationListener {
@@ -53,7 +53,7 @@ export interface NavigationUpdate {
53
53
  }
54
54
 
55
55
  export interface NavigationTransition extends NavigationUpdate {
56
- retry(): void;
56
+ retry?(): void;
57
57
  }
58
58
 
59
59
  export interface NavigationApi {