piral-core 0.15.0-alpha.4311 → 0.15.0-alpha.4345
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 +191 -0
- package/{debug.codegen.d.ts → app.codegen.d.ts} +10 -1
- package/esm/actions/app.d.ts +1 -0
- package/esm/actions/app.js +3 -0
- package/esm/actions/app.js.map +1 -1
- package/esm/actions/state.js +6 -7
- package/esm/actions/state.js.map +1 -1
- package/esm/components/PiralRoutes.js +2 -6
- package/esm/components/PiralRoutes.js.map +1 -1
- package/esm/components/wrapComponent.js +2 -2
- package/esm/components/wrapComponent.js.map +1 -1
- package/esm/createInstance.js +1 -1
- package/esm/createInstance.js.map +1 -1
- package/esm/debugger.js +4 -2
- package/esm/debugger.js.map +1 -1
- package/esm/defaults/{DefaultRouteSwitch.d.ts → DefaultRouteSwitch_v5.d.ts} +0 -0
- package/esm/defaults/{DefaultRouteSwitch.js → DefaultRouteSwitch_v5.js} +2 -1
- package/esm/defaults/DefaultRouteSwitch_v5.js.map +1 -0
- package/{lib/defaults/DefaultRouteSwitch.d.ts → esm/defaults/DefaultRouteSwitch_v6.d.ts} +0 -0
- package/esm/defaults/DefaultRouteSwitch_v6.js +15 -0
- package/esm/defaults/DefaultRouteSwitch_v6.js.map +1 -0
- package/esm/defaults/{DefaultRouter.d.ts → DefaultRouter_v5.d.ts} +0 -0
- package/esm/defaults/{DefaultRouter.js → DefaultRouter_v5.js} +2 -1
- package/esm/defaults/DefaultRouter_v5.js.map +1 -0
- package/{lib/defaults/DefaultRouter.d.ts → esm/defaults/DefaultRouter_v6.d.ts} +0 -0
- package/esm/defaults/DefaultRouter_v6.js +9 -0
- package/esm/defaults/DefaultRouter_v6.js.map +1 -0
- package/esm/emulator.js +2 -3
- package/esm/emulator.js.map +1 -1
- package/esm/helpers.js +1 -1
- package/esm/helpers.js.map +1 -1
- package/esm/hooks/globalState.js +2 -9
- package/esm/hooks/globalState.js.map +1 -1
- package/esm/hooks/index.d.ts +1 -0
- package/esm/hooks/index.js +1 -0
- package/esm/hooks/index.js.map +1 -1
- package/esm/hooks/routes.d.ts +2 -0
- package/esm/hooks/routes.js +11 -0
- package/esm/hooks/routes.js.map +1 -0
- package/esm/modules/dependencies.js +1 -1
- package/esm/modules/dependencies.js.map +1 -1
- package/esm/state/createActions.d.ts +2 -2
- package/esm/state/createActions.js.map +1 -1
- package/esm/state/createGlobalState.d.ts +1 -2
- package/esm/state/createGlobalState.js +4 -27
- package/esm/state/createGlobalState.js.map +1 -1
- package/esm/types/components.d.ts +14 -10
- package/esm/types/state.d.ts +8 -3
- package/lib/actions/app.d.ts +1 -0
- package/lib/actions/app.js +5 -1
- package/lib/actions/app.js.map +1 -1
- package/lib/actions/state.js +6 -7
- package/lib/actions/state.js.map +1 -1
- package/lib/components/PiralRoutes.js +1 -5
- package/lib/components/PiralRoutes.js.map +1 -1
- package/lib/components/wrapComponent.js +2 -2
- package/lib/components/wrapComponent.js.map +1 -1
- package/lib/createInstance.js +1 -1
- package/lib/createInstance.js.map +1 -1
- package/lib/debugger.js +4 -2
- package/lib/debugger.js.map +1 -1
- package/lib/defaults/DefaultRouteSwitch_v5.d.ts +3 -0
- package/lib/defaults/{DefaultRouteSwitch.js → DefaultRouteSwitch_v5.js} +2 -1
- package/lib/defaults/DefaultRouteSwitch_v5.js.map +1 -0
- package/lib/defaults/DefaultRouteSwitch_v6.d.ts +3 -0
- package/lib/defaults/DefaultRouteSwitch_v6.js +19 -0
- package/lib/defaults/DefaultRouteSwitch_v6.js.map +1 -0
- package/lib/defaults/DefaultRouter_v5.d.ts +3 -0
- package/lib/defaults/{DefaultRouter.js → DefaultRouter_v5.js} +2 -1
- package/lib/defaults/DefaultRouter_v5.js.map +1 -0
- package/lib/defaults/DefaultRouter_v6.d.ts +3 -0
- package/lib/defaults/DefaultRouter_v6.js +13 -0
- package/lib/defaults/DefaultRouter_v6.js.map +1 -0
- package/lib/emulator.js +2 -3
- package/lib/emulator.js.map +1 -1
- package/lib/helpers.js +3 -3
- package/lib/helpers.js.map +1 -1
- package/lib/hooks/globalState.js +2 -9
- package/lib/hooks/globalState.js.map +1 -1
- package/lib/hooks/index.d.ts +1 -0
- package/lib/hooks/index.js +1 -0
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/routes.d.ts +2 -0
- package/lib/hooks/routes.js +15 -0
- package/lib/hooks/routes.js.map +1 -0
- package/lib/modules/dependencies.js +3 -3
- package/lib/modules/dependencies.js.map +1 -1
- package/lib/state/createActions.d.ts +2 -2
- package/lib/state/createActions.js.map +1 -1
- package/lib/state/createGlobalState.d.ts +1 -2
- package/lib/state/createGlobalState.js +4 -27
- package/lib/state/createGlobalState.js.map +1 -1
- package/lib/types/components.d.ts +14 -10
- package/lib/types/state.d.ts +8 -3
- package/package.json +13 -17
- package/src/Piral.test.tsx +7 -5
- package/src/RootListener.test.tsx +8 -4
- package/src/actions/app.test.ts +32 -32
- package/src/actions/app.ts +4 -0
- package/src/actions/components.test.ts +10 -10
- package/src/actions/data.test.ts +49 -49
- package/src/actions/define.test.ts +2 -2
- package/src/actions/portal.test.ts +17 -17
- package/src/actions/state.test.ts +3 -3
- package/src/actions/state.ts +7 -8
- package/src/components/ForeignComponentContainer.test.tsx +9 -5
- package/src/components/Mediator.test.tsx +11 -10
- package/src/components/PiralRoutes.test.tsx +23 -16
- package/src/components/PiralRoutes.tsx +2 -8
- package/src/components/wrapComponent.tsx +2 -2
- package/src/createInstance.tsx +1 -1
- package/src/debugger.ts +4 -2
- package/src/defaults/{DefaultRouteSwitch.tsx → DefaultRouteSwitch_v5.tsx} +1 -0
- package/src/defaults/DefaultRouteSwitch_v6.tsx +20 -0
- package/src/defaults/{DefaultRouter.tsx → DefaultRouter_v5.tsx} +1 -0
- package/src/defaults/DefaultRouter_v6.tsx +10 -0
- package/src/emulator.ts +2 -10
- package/src/helpers.test.tsx +9 -8
- package/src/helpers.tsx +1 -1
- package/src/hooks/globalState.ts +2 -11
- package/src/hooks/index.ts +1 -0
- package/src/hooks/routes.ts +14 -0
- package/src/hooks/setter.test.ts +1 -1
- package/src/modules/dependencies.ts +1 -1
- package/src/modules/element-server.test.ts +4 -4
- package/src/modules/element.test.ts +6 -6
- package/src/setters/SetComponent.test.tsx +7 -6
- package/src/setters/SetError.test.tsx +7 -6
- package/src/setters/SetErrors.test.tsx +7 -6
- package/src/setters/SetLayout.test.tsx +7 -6
- package/src/setters/SetProvider.test.tsx +7 -6
- package/src/setters/SetRedirect.test.tsx +7 -6
- package/src/setters/SetRoute.test.tsx +7 -6
- package/src/state/createActions.ts +3 -3
- package/src/state/createGlobalState.test.ts +53 -58
- package/src/state/createGlobalState.ts +4 -34
- package/src/state/withApi.test.tsx +5 -5
- package/src/types/components.ts +15 -10
- package/src/types/state.ts +8 -3
- package/src/utils/foreign.test.ts +1 -1
- package/debug.codegen +0 -24
- package/dependencies.codegen +0 -37
- package/dependencies.codegen.d.ts +0 -1
- package/dependencies.codegen.native.js +0 -2
- package/esm/defaults/DefaultRouteSwitch.js.map +0 -1
- package/esm/defaults/DefaultRouter.js.map +0 -1
- package/esm/defaults/index.d.ts +0 -5
- package/esm/defaults/index.js +0 -6
- package/esm/defaults/index.js.map +0 -1
- package/lib/defaults/DefaultRouteSwitch.js.map +0 -1
- package/lib/defaults/DefaultRouter.js.map +0 -1
- package/lib/defaults/index.d.ts +0 -5
- package/lib/defaults/index.js +0 -9
- package/lib/defaults/index.js.map +0 -1
- package/src/defaults/index.ts +0 -5
- package/src/hooks/globalState-server.test.ts +0 -41
- package/src/hooks/globalState.test.ts +0 -47
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import { deref } from '@dbeining/react-atom';
|
|
2
1
|
import { createGlobalState } from './createGlobalState';
|
|
3
|
-
import {
|
|
4
|
-
DefaultErrorInfo,
|
|
5
|
-
DefaultLoadingIndicator,
|
|
6
|
-
DefaultLayout,
|
|
7
|
-
DefaultRouter,
|
|
8
|
-
DefaultRouteSwitch,
|
|
9
|
-
} from '../defaults';
|
|
10
2
|
|
|
11
3
|
process.env.PIRAL_PUBLIC_PATH = '/';
|
|
12
4
|
|
|
@@ -15,7 +7,11 @@ describe('Create Global State Module', () => {
|
|
|
15
7
|
|
|
16
8
|
it('global state works with language as empty string', () => {
|
|
17
9
|
const globalState = createGlobalState({});
|
|
18
|
-
|
|
10
|
+
const tmp = globalState.getState();
|
|
11
|
+
|
|
12
|
+
console.log(tmp);
|
|
13
|
+
|
|
14
|
+
expect(tmp).toEqual({
|
|
19
15
|
app: {
|
|
20
16
|
loading: true,
|
|
21
17
|
error: undefined,
|
|
@@ -23,11 +19,11 @@ describe('Create Global State Module', () => {
|
|
|
23
19
|
},
|
|
24
20
|
errorComponents: {},
|
|
25
21
|
components: {
|
|
26
|
-
ErrorInfo:
|
|
27
|
-
LoadingIndicator:
|
|
28
|
-
Router:
|
|
29
|
-
Layout:
|
|
30
|
-
RouteSwitch:
|
|
22
|
+
ErrorInfo: expect.anything(),
|
|
23
|
+
LoadingIndicator: expect.anything(),
|
|
24
|
+
Router: expect.anything(),
|
|
25
|
+
Layout: expect.anything(),
|
|
26
|
+
RouteSwitch: expect.anything(),
|
|
31
27
|
},
|
|
32
28
|
routes: {},
|
|
33
29
|
registry: {
|
|
@@ -43,7 +39,7 @@ describe('Create Global State Module', () => {
|
|
|
43
39
|
|
|
44
40
|
it('global state with custom language and translations', () => {
|
|
45
41
|
const globalState = createGlobalState({});
|
|
46
|
-
expect(
|
|
42
|
+
expect(globalState.getState()).toEqual({
|
|
47
43
|
app: {
|
|
48
44
|
loading: true,
|
|
49
45
|
error: undefined,
|
|
@@ -51,11 +47,11 @@ describe('Create Global State Module', () => {
|
|
|
51
47
|
},
|
|
52
48
|
errorComponents: {},
|
|
53
49
|
components: {
|
|
54
|
-
ErrorInfo:
|
|
55
|
-
LoadingIndicator:
|
|
56
|
-
Router:
|
|
57
|
-
Layout:
|
|
58
|
-
RouteSwitch:
|
|
50
|
+
ErrorInfo: expect.anything(),
|
|
51
|
+
LoadingIndicator: expect.anything(),
|
|
52
|
+
Router: expect.anything(),
|
|
53
|
+
Layout: expect.anything(),
|
|
54
|
+
RouteSwitch: expect.anything(),
|
|
59
55
|
},
|
|
60
56
|
routes: {},
|
|
61
57
|
registry: {
|
|
@@ -75,7 +71,7 @@ describe('Create Global State Module', () => {
|
|
|
75
71
|
'/foo': '...' as any,
|
|
76
72
|
};
|
|
77
73
|
const globalState = createGlobalState({ routes });
|
|
78
|
-
expect(
|
|
74
|
+
expect(globalState.getState()).toEqual({
|
|
79
75
|
app: {
|
|
80
76
|
error: undefined,
|
|
81
77
|
loading: true,
|
|
@@ -83,11 +79,11 @@ describe('Create Global State Module', () => {
|
|
|
83
79
|
},
|
|
84
80
|
errorComponents: {},
|
|
85
81
|
components: {
|
|
86
|
-
ErrorInfo:
|
|
87
|
-
LoadingIndicator:
|
|
88
|
-
Router:
|
|
89
|
-
Layout:
|
|
90
|
-
RouteSwitch:
|
|
82
|
+
ErrorInfo: expect.anything(),
|
|
83
|
+
LoadingIndicator: expect.anything(),
|
|
84
|
+
Router: expect.anything(),
|
|
85
|
+
Layout: expect.anything(),
|
|
86
|
+
RouteSwitch: expect.anything(),
|
|
91
87
|
},
|
|
92
88
|
routes,
|
|
93
89
|
registry: {
|
|
@@ -103,7 +99,7 @@ describe('Create Global State Module', () => {
|
|
|
103
99
|
|
|
104
100
|
it('global state can be created without arguments', () => {
|
|
105
101
|
const globalState = createGlobalState();
|
|
106
|
-
expect(
|
|
102
|
+
expect(globalState.getState()).toEqual({
|
|
107
103
|
app: {
|
|
108
104
|
loading: true,
|
|
109
105
|
error: undefined,
|
|
@@ -111,11 +107,11 @@ describe('Create Global State Module', () => {
|
|
|
111
107
|
},
|
|
112
108
|
errorComponents: {},
|
|
113
109
|
components: {
|
|
114
|
-
ErrorInfo:
|
|
115
|
-
LoadingIndicator:
|
|
116
|
-
Router:
|
|
117
|
-
Layout:
|
|
118
|
-
RouteSwitch:
|
|
110
|
+
ErrorInfo: expect.anything(),
|
|
111
|
+
LoadingIndicator: expect.anything(),
|
|
112
|
+
Router: expect.anything(),
|
|
113
|
+
Layout: expect.anything(),
|
|
114
|
+
RouteSwitch: expect.anything(),
|
|
119
115
|
},
|
|
120
116
|
registry: {
|
|
121
117
|
extensions: {},
|
|
@@ -133,7 +129,7 @@ describe('Create Global State Module', () => {
|
|
|
133
129
|
const globalState = createGlobalState({
|
|
134
130
|
app: {},
|
|
135
131
|
});
|
|
136
|
-
expect(
|
|
132
|
+
expect(globalState.getState()).toEqual({
|
|
137
133
|
app: {
|
|
138
134
|
loading: true,
|
|
139
135
|
error: undefined,
|
|
@@ -141,11 +137,11 @@ describe('Create Global State Module', () => {
|
|
|
141
137
|
},
|
|
142
138
|
errorComponents: {},
|
|
143
139
|
components: {
|
|
144
|
-
ErrorInfo:
|
|
145
|
-
LoadingIndicator:
|
|
146
|
-
Router:
|
|
147
|
-
Layout:
|
|
148
|
-
RouteSwitch:
|
|
140
|
+
ErrorInfo: expect.anything(),
|
|
141
|
+
LoadingIndicator: expect.anything(),
|
|
142
|
+
Router: expect.anything(),
|
|
143
|
+
Layout: expect.anything(),
|
|
144
|
+
RouteSwitch: expect.anything(),
|
|
149
145
|
},
|
|
150
146
|
registry: {
|
|
151
147
|
extensions: {},
|
|
@@ -163,7 +159,7 @@ describe('Create Global State Module', () => {
|
|
|
163
159
|
const globalState = createGlobalState({
|
|
164
160
|
app: {},
|
|
165
161
|
});
|
|
166
|
-
expect(
|
|
162
|
+
expect(globalState.getState()).toEqual({
|
|
167
163
|
app: {
|
|
168
164
|
loading: true,
|
|
169
165
|
error: undefined,
|
|
@@ -171,11 +167,11 @@ describe('Create Global State Module', () => {
|
|
|
171
167
|
},
|
|
172
168
|
errorComponents: {},
|
|
173
169
|
components: {
|
|
174
|
-
ErrorInfo:
|
|
175
|
-
LoadingIndicator:
|
|
176
|
-
Router:
|
|
177
|
-
Layout:
|
|
178
|
-
RouteSwitch:
|
|
170
|
+
ErrorInfo: expect.anything(),
|
|
171
|
+
LoadingIndicator: expect.anything(),
|
|
172
|
+
Router: expect.anything(),
|
|
173
|
+
Layout: expect.anything(),
|
|
174
|
+
RouteSwitch: expect.anything(),
|
|
179
175
|
},
|
|
180
176
|
registry: {
|
|
181
177
|
extensions: {},
|
|
@@ -191,14 +187,13 @@ describe('Create Global State Module', () => {
|
|
|
191
187
|
|
|
192
188
|
it('global state with non-default breakpoints and more routes', () => {
|
|
193
189
|
const globalState = createGlobalState({
|
|
194
|
-
app: {
|
|
195
|
-
},
|
|
190
|
+
app: {},
|
|
196
191
|
routes: {
|
|
197
192
|
'/': '...' as any,
|
|
198
193
|
'/foo': '...' as any,
|
|
199
194
|
},
|
|
200
195
|
});
|
|
201
|
-
expect(
|
|
196
|
+
expect(globalState.getState()).toEqual({
|
|
202
197
|
app: {
|
|
203
198
|
loading: true,
|
|
204
199
|
error: undefined,
|
|
@@ -206,11 +201,11 @@ describe('Create Global State Module', () => {
|
|
|
206
201
|
},
|
|
207
202
|
errorComponents: {},
|
|
208
203
|
components: {
|
|
209
|
-
ErrorInfo:
|
|
210
|
-
LoadingIndicator:
|
|
211
|
-
Router:
|
|
212
|
-
Layout:
|
|
213
|
-
RouteSwitch:
|
|
204
|
+
ErrorInfo: expect.anything(),
|
|
205
|
+
LoadingIndicator: expect.anything(),
|
|
206
|
+
Router: expect.anything(),
|
|
207
|
+
Layout: expect.anything(),
|
|
208
|
+
RouteSwitch: expect.anything(),
|
|
214
209
|
},
|
|
215
210
|
registry: {
|
|
216
211
|
extensions: {},
|
|
@@ -233,7 +228,7 @@ describe('Create Global State Module', () => {
|
|
|
233
228
|
loading: false,
|
|
234
229
|
},
|
|
235
230
|
});
|
|
236
|
-
expect(
|
|
231
|
+
expect(globalState.getState()).toEqual({
|
|
237
232
|
app: {
|
|
238
233
|
loading: false,
|
|
239
234
|
error: undefined,
|
|
@@ -241,11 +236,11 @@ describe('Create Global State Module', () => {
|
|
|
241
236
|
},
|
|
242
237
|
errorComponents: {},
|
|
243
238
|
components: {
|
|
244
|
-
ErrorInfo:
|
|
245
|
-
LoadingIndicator:
|
|
246
|
-
Router:
|
|
247
|
-
Layout:
|
|
248
|
-
RouteSwitch:
|
|
239
|
+
ErrorInfo: expect.anything(),
|
|
240
|
+
LoadingIndicator: expect.anything(),
|
|
241
|
+
Router: expect.anything(),
|
|
242
|
+
Layout: expect.anything(),
|
|
243
|
+
RouteSwitch: expect.anything(),
|
|
249
244
|
},
|
|
250
245
|
registry: {
|
|
251
246
|
extensions: {},
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import create from 'zustand';
|
|
2
|
+
import { createDefaultState } from '../../app.codegen';
|
|
2
3
|
import { GlobalState, NestedPartial } from '../types';
|
|
3
|
-
import {
|
|
4
|
-
DefaultErrorInfo,
|
|
5
|
-
DefaultLoadingIndicator,
|
|
6
|
-
DefaultLayout,
|
|
7
|
-
DefaultRouter,
|
|
8
|
-
DefaultRouteSwitch,
|
|
9
|
-
} from '../defaults';
|
|
10
4
|
|
|
11
5
|
function extend<T>(defaultState: T, customState: NestedPartial<T>) {
|
|
12
6
|
for (const key of Object.keys(customState)) {
|
|
@@ -24,30 +18,6 @@ function extend<T>(defaultState: T, customState: NestedPartial<T>) {
|
|
|
24
18
|
}
|
|
25
19
|
|
|
26
20
|
export function createGlobalState(customState: NestedPartial<GlobalState> = {}) {
|
|
27
|
-
const defaultState: GlobalState =
|
|
28
|
-
|
|
29
|
-
error: undefined,
|
|
30
|
-
loading: typeof window !== 'undefined',
|
|
31
|
-
publicPath: process.env.PIRAL_PUBLIC_PATH || '/',
|
|
32
|
-
},
|
|
33
|
-
components: {
|
|
34
|
-
ErrorInfo: DefaultErrorInfo,
|
|
35
|
-
LoadingIndicator: DefaultLoadingIndicator,
|
|
36
|
-
Router: DefaultRouter,
|
|
37
|
-
RouteSwitch: DefaultRouteSwitch,
|
|
38
|
-
Layout: DefaultLayout,
|
|
39
|
-
},
|
|
40
|
-
errorComponents: {},
|
|
41
|
-
registry: {
|
|
42
|
-
extensions: {},
|
|
43
|
-
pages: {},
|
|
44
|
-
wrappers: {},
|
|
45
|
-
},
|
|
46
|
-
routes: {},
|
|
47
|
-
data: {},
|
|
48
|
-
portals: {},
|
|
49
|
-
modules: [],
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
return Atom.of(extend(defaultState, customState));
|
|
21
|
+
const defaultState: GlobalState = createDefaultState();
|
|
22
|
+
return create(() => extend(defaultState, customState));
|
|
53
23
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import * as hooks from '../hooks';
|
|
3
|
+
import create from 'zustand';
|
|
3
4
|
import { mount } from 'enzyme';
|
|
4
|
-
import { Atom } from '@dbeining/react-atom';
|
|
5
5
|
import { withApi } from './withApi';
|
|
6
6
|
import { StateContext } from '../state';
|
|
7
7
|
|
|
8
8
|
function createMockContainer() {
|
|
9
|
-
const state =
|
|
9
|
+
const state = create(() => ({
|
|
10
10
|
portals: {},
|
|
11
|
-
});
|
|
11
|
+
}));
|
|
12
12
|
return {
|
|
13
13
|
context: {
|
|
14
14
|
converters: {},
|
|
@@ -29,9 +29,9 @@ function createMockContainer() {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
function createMockContainerWithNoWrappers() {
|
|
32
|
-
const state =
|
|
32
|
+
const state = create(() => ({
|
|
33
33
|
portals: {},
|
|
34
|
-
});
|
|
34
|
+
}));
|
|
35
35
|
return {
|
|
36
36
|
context: {
|
|
37
37
|
converters: {},
|
package/src/types/components.ts
CHANGED
|
@@ -207,6 +207,20 @@ export interface RouterProps {
|
|
|
207
207
|
children?: ReactNode;
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
+
/**
|
|
211
|
+
* Represents a path in the app registration.
|
|
212
|
+
*/
|
|
213
|
+
export interface AppPath {
|
|
214
|
+
/**
|
|
215
|
+
* The exact path to use.
|
|
216
|
+
*/
|
|
217
|
+
path: string;
|
|
218
|
+
/**
|
|
219
|
+
* The component to register for this path.
|
|
220
|
+
*/
|
|
221
|
+
Component: ComponentType<RouteComponentProps>;
|
|
222
|
+
}
|
|
223
|
+
|
|
210
224
|
/**
|
|
211
225
|
* The props of the RouteSwitch component.
|
|
212
226
|
*/
|
|
@@ -218,14 +232,5 @@ export interface RouteSwitchProps extends SwitchProps {
|
|
|
218
232
|
/**
|
|
219
233
|
* The component to register for the different paths.
|
|
220
234
|
*/
|
|
221
|
-
paths: Array<
|
|
222
|
-
/**
|
|
223
|
-
* The exact path to use.
|
|
224
|
-
*/
|
|
225
|
-
path: string;
|
|
226
|
-
/**
|
|
227
|
-
* The component to register for this path.
|
|
228
|
-
*/
|
|
229
|
-
Component: ComponentType<RouteComponentProps>;
|
|
230
|
-
}>;
|
|
235
|
+
paths: Array<AppPath>;
|
|
231
236
|
}
|
package/src/types/state.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ComponentType, ReactPortal, PropsWithChildren } from 'react';
|
|
2
2
|
import type { RouteComponentProps } from 'react-router';
|
|
3
|
-
import type { Atom } from '@dbeining/react-atom';
|
|
4
3
|
import type { LoadPiletsOptions } from 'piral-base';
|
|
4
|
+
import type { StoreApi, UseBoundStore } from 'zustand';
|
|
5
5
|
import type { Dict, Without } from './common';
|
|
6
6
|
import type { SharedDataItem, DataStoreTarget } from './data';
|
|
7
7
|
import type {
|
|
@@ -36,7 +36,6 @@ export interface StateDispatcher<TState> {
|
|
|
36
36
|
|
|
37
37
|
declare module './components' {
|
|
38
38
|
interface ComponentContext {
|
|
39
|
-
state: Atom<GlobalState>;
|
|
40
39
|
readState: PiralActions['readState'];
|
|
41
40
|
}
|
|
42
41
|
}
|
|
@@ -348,6 +347,12 @@ export interface PiralActions extends PiralCustomActions {
|
|
|
348
347
|
* @returns The desired part.
|
|
349
348
|
*/
|
|
350
349
|
readState<S>(select: (state: GlobalState) => S): S;
|
|
350
|
+
/**
|
|
351
|
+
* Performs a navigation.
|
|
352
|
+
* @param path The path to navigate to.
|
|
353
|
+
* @param state The optional state for the navigation.
|
|
354
|
+
*/
|
|
355
|
+
navigate(path: string, state?: any): void;
|
|
351
356
|
}
|
|
352
357
|
|
|
353
358
|
/**
|
|
@@ -358,7 +363,7 @@ export interface GlobalStateContext extends PiralActions, EventEmitter {
|
|
|
358
363
|
* The global state context atom.
|
|
359
364
|
* Changes to the state should always be dispatched via the `dispatch` action.
|
|
360
365
|
*/
|
|
361
|
-
state:
|
|
366
|
+
state: UseBoundStore<GlobalState>;
|
|
362
367
|
/**
|
|
363
368
|
* The API objects created for the loaded pilets.
|
|
364
369
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { changeDomPortal, convertComponent, renderInDom } from './foreign';
|
|
3
|
-
import { DefaultLoadingIndicator } from '../defaults';
|
|
3
|
+
import { DefaultLoadingIndicator } from '../defaults/DefaultLoadingIndicator';
|
|
4
4
|
import { ForeignComponent } from '../types';
|
|
5
5
|
|
|
6
6
|
// const StubComponent: React.FC = (props) => <div />;
|
package/debug.codegen
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
module.exports = function () {
|
|
2
|
-
const imports = [];
|
|
3
|
-
const exports = [];
|
|
4
|
-
|
|
5
|
-
// if we build the debug version of piral (debug and emulator build)
|
|
6
|
-
if (process.env.DEBUG_PIRAL) {
|
|
7
|
-
imports.push('import { integrateDebugger } from "./esm/debugger"');
|
|
8
|
-
exports.push(`export { integrateDebugger }`);
|
|
9
|
-
} else {
|
|
10
|
-
exports.push(`export function integrateDebugger() {}`);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// if we build the emulator version of piral (shipped to pilets)
|
|
14
|
-
if (process.env.DEBUG_PILET) {
|
|
15
|
-
imports.push('import { integrateEmulator } from "./esm/emulator"');
|
|
16
|
-
exports.push(`export { integrateEmulator }`);
|
|
17
|
-
} else {
|
|
18
|
-
exports.push(`export function integrateEmulator() {}`);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return `${imports.join(';\n')}
|
|
22
|
-
${exports.join('\n')}
|
|
23
|
-
`;
|
|
24
|
-
};
|
package/dependencies.codegen
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
function getIdentifiers(packageName) {
|
|
2
|
-
const packageJson = `${packageName}/package.json`;
|
|
3
|
-
|
|
4
|
-
try {
|
|
5
|
-
const details = require(packageJson);
|
|
6
|
-
|
|
7
|
-
if (details.version) {
|
|
8
|
-
return [packageName, `${packageName}@${details.version}`];
|
|
9
|
-
}
|
|
10
|
-
} catch {}
|
|
11
|
-
|
|
12
|
-
return [packageName];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
module.exports = function () {
|
|
16
|
-
const appName = process.env.BUILD_PCKG_NAME || '';
|
|
17
|
-
const externals = (process.env.SHARED_DEPENDENCIES || '').split(',').filter(Boolean);
|
|
18
|
-
const assignments = [];
|
|
19
|
-
const imports = [];
|
|
20
|
-
|
|
21
|
-
if (appName) {
|
|
22
|
-
assignments.push(`deps['${appName}']={}`);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
for (const name of externals) {
|
|
26
|
-
const identifiers = getIdentifiers(name);
|
|
27
|
-
const ref = `_${imports.length}`;
|
|
28
|
-
imports.push(`import * as ${ref} from ${JSON.stringify(name)}`);
|
|
29
|
-
|
|
30
|
-
for (const id of identifiers) {
|
|
31
|
-
assignments.push(`deps[${JSON.stringify(id)}]=${ref}`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return `${imports.join(';\n')}
|
|
36
|
-
export default function(deps) {${assignments.join(';')}}`;
|
|
37
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function (deps: Record<string, any>): void;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultRouteSwitch.js","sourceRoot":"","sources":["../../src/defaults/DefaultRouteSwitch.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAG7C,MAAM,CAAC,MAAM,kBAAkB,GAA+B,CAAC,EAA6B,EAAE,EAAE;QAAjC,EAAE,KAAK,EAAE,QAAQ,OAAY,EAAP,KAAK,cAA3B,qBAA6B,CAAF;IACxF,OAAO,CACL,oBAAC,MAAM,oBAAK,KAAK;QACd,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAClC,oBAAC,KAAK,IAAC,KAAK,QAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,GAAI,CAC7D,CAAC;QACF,oBAAC,KAAK,IAAC,SAAS,EAAE,QAAQ,GAAI,CACvB,CACV,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultRouter.js","sourceRoot":"","sources":["../../src/defaults/DefaultRouter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG1C,MAAM,CAAC,MAAM,aAAa,GAA0B,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;IACnE,MAAM,UAAU,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC3D,OAAO,oBAAC,aAAa,IAAC,QAAQ,EAAE,UAAU,IAAG,QAAQ,CAAiB,CAAC;AACzE,CAAC,CAAC"}
|
package/esm/defaults/index.d.ts
DELETED
package/esm/defaults/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/defaults/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultRouteSwitch.js","sourceRoot":"","sources":["../../src/defaults/DefaultRouteSwitch.tsx"],"names":[],"mappings":";;;;AAAA,+BAA+B;AAC/B,+CAA6C;AAGtC,MAAM,kBAAkB,GAA+B,CAAC,EAA6B,EAAE,EAAE;QAAjC,EAAE,KAAK,EAAE,QAAQ,OAAY,EAAP,KAAK,sBAA3B,qBAA6B,CAAF;IACxF,OAAO,CACL,oBAAC,qBAAM,oBAAK,KAAK;QACd,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAClC,oBAAC,oBAAK,IAAC,KAAK,QAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,GAAI,CAC7D,CAAC;QACF,oBAAC,oBAAK,IAAC,SAAS,EAAE,QAAQ,GAAI,CACvB,CACV,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,kBAAkB,sBAS7B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultRouter.js","sourceRoot":"","sources":["../../src/defaults/DefaultRouter.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,uDAAiD;AACjD,oCAA0C;AAGnC,MAAM,aAAa,GAA0B,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;IACnE,MAAM,UAAU,GAAG,IAAA,sBAAc,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC3D,OAAO,oBAAC,gCAAa,IAAC,QAAQ,EAAE,UAAU,IAAG,QAAQ,CAAiB,CAAC;AACzE,CAAC,CAAC;AAHW,QAAA,aAAa,iBAGxB"}
|
package/lib/defaults/index.d.ts
DELETED
package/lib/defaults/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./DefaultErrorInfo"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./DefaultLayout"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./DefaultLoadingIndicator"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./DefaultRouter"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./DefaultRouteSwitch"), exports);
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/defaults/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,0DAAgC;AAChC,oEAA0C;AAC1C,0DAAgC;AAChC,+DAAqC"}
|
package/src/defaults/index.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jest-environment node
|
|
3
|
-
*/
|
|
4
|
-
import { useGlobalState } from './globalState';
|
|
5
|
-
|
|
6
|
-
jest.mock('react', () => {
|
|
7
|
-
const { Atom } = require('@libre/atom');
|
|
8
|
-
const state = Atom.of({
|
|
9
|
-
foo: 5,
|
|
10
|
-
bar: {
|
|
11
|
-
qxz: 'hello',
|
|
12
|
-
},
|
|
13
|
-
list: [1, 2, 3],
|
|
14
|
-
});
|
|
15
|
-
return {
|
|
16
|
-
createContext: jest.fn(),
|
|
17
|
-
useContext: () => ({ state }),
|
|
18
|
-
useState: (v) => [v, jest.fn()],
|
|
19
|
-
useMemo: (f) => f(),
|
|
20
|
-
useLayoutEffect: (f) => f(),
|
|
21
|
-
};
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe('Media Module', () => {
|
|
25
|
-
it('in here window should be undefined', () => {
|
|
26
|
-
expect(typeof window).toBe('undefined');
|
|
27
|
-
const result = useGlobalState((m) => (m as any).foo);
|
|
28
|
-
expect(result).toBe(5);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('gets full state object', () => {
|
|
32
|
-
const result = useGlobalState();
|
|
33
|
-
expect(result).toEqual({
|
|
34
|
-
foo: 5,
|
|
35
|
-
bar: {
|
|
36
|
-
qxz: 'hello',
|
|
37
|
-
},
|
|
38
|
-
list: [1, 2, 3],
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { useGlobalState } from './globalState';
|
|
2
|
-
|
|
3
|
-
jest.mock('react', () => {
|
|
4
|
-
const { Atom } = require('@libre/atom');
|
|
5
|
-
const state = Atom.of({
|
|
6
|
-
foo: 5,
|
|
7
|
-
bar: {
|
|
8
|
-
qxz: 'hello',
|
|
9
|
-
},
|
|
10
|
-
list: [1, 2, 3],
|
|
11
|
-
});
|
|
12
|
-
return {
|
|
13
|
-
createContext: jest.fn(),
|
|
14
|
-
useContext: () => ({ state }),
|
|
15
|
-
useState: (v) => [v, jest.fn()],
|
|
16
|
-
useMemo: (f) => f(),
|
|
17
|
-
useLayoutEffect: (f) => f(),
|
|
18
|
-
};
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe('GlobalState Hook Module', () => {
|
|
22
|
-
it('selects key from state', () => {
|
|
23
|
-
const result = useGlobalState((m) => (m as any).foo);
|
|
24
|
-
expect(result).toBe(5);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('gets full state object', () => {
|
|
28
|
-
const result = useGlobalState();
|
|
29
|
-
expect(result).toEqual({
|
|
30
|
-
foo: 5,
|
|
31
|
-
bar: {
|
|
32
|
-
qxz: 'hello',
|
|
33
|
-
},
|
|
34
|
-
list: [1, 2, 3],
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('selects nested values', () => {
|
|
39
|
-
const result = useGlobalState((m) => (m as any).bar.qxz);
|
|
40
|
-
expect(result).toBe('hello');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('selection works against array members', () => {
|
|
44
|
-
const result = useGlobalState((m) => (m as any).list[2]);
|
|
45
|
-
expect(result).toBe(3);
|
|
46
|
-
});
|
|
47
|
-
});
|