@cascateer/core 2.4.7 → 2.4.9
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/package.json +1 -1
- package/src/component.ts +42 -26
- package/src/slice.ts +151 -79
package/package.json
CHANGED
package/src/component.ts
CHANGED
|
@@ -10,8 +10,8 @@ import { asStoreEffects, StoreAdapter, StoreEffects } from "./store";
|
|
|
10
10
|
import { TerminalAdapter, TerminalEffect } from "./terminal";
|
|
11
11
|
import { Action, Effect } from "./types";
|
|
12
12
|
|
|
13
|
-
export
|
|
14
|
-
|
|
13
|
+
export interface ComponentConstructor<Props extends JSX.Props> {
|
|
14
|
+
(key: string): JSX.Component<Props>;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export function createComponent(customElement?: string) {
|
|
@@ -23,33 +23,49 @@ export function createComponent(customElement?: string) {
|
|
|
23
23
|
>(
|
|
24
24
|
constructor: (
|
|
25
25
|
ctx: Context,
|
|
26
|
-
...
|
|
26
|
+
...cn: { -readonly [K in keyof Styles]: Awaited<Styles[K]> }
|
|
27
27
|
) => JSX.Component<Props>,
|
|
28
28
|
) =>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const element = constructor(ctx, ...cssModules)(props);
|
|
29
|
+
(ctx: Context): ComponentConstructor<Props> =>
|
|
30
|
+
(key) =>
|
|
31
|
+
(props) =>
|
|
32
|
+
createFragment({
|
|
33
|
+
children: defer(() =>
|
|
34
|
+
Promise.all(styles).then((cssModules) =>
|
|
35
|
+
cssStyleSheets(cssModules).then((cssStyleSheets) => {
|
|
36
|
+
const element = constructor(ctx, ...cssModules)(props);
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
38
|
+
return customElement != null
|
|
39
|
+
? new (defineCustomElement(
|
|
40
|
+
`${key}-${kebabCase(customElement)}`,
|
|
41
|
+
))(element, cssStyleSheets)
|
|
42
|
+
: createFragment({
|
|
43
|
+
children: element,
|
|
44
|
+
}); /* TODO omit cssModules (whole workflow) */
|
|
45
|
+
}),
|
|
46
|
+
),
|
|
47
|
+
).pipe(share()),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
withStyles: <Styles extends Promise<unknown>[]>(...styles: Styles) => ({
|
|
52
|
+
withTemplate: withTemplate(...styles),
|
|
53
|
+
}),
|
|
54
|
+
withTemplate: withTemplate(),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function createStandaloneComponent(customElement?: string) {
|
|
59
|
+
const withTemplate =
|
|
60
|
+
<Styles extends Promise<unknown>[]>(...styles: Styles) =>
|
|
61
|
+
<Props extends JSX.Props>(
|
|
62
|
+
constructor: (
|
|
63
|
+
...cn: { -readonly [K in keyof Styles]: Awaited<Styles[K]> }
|
|
64
|
+
) => JSX.Component<Props>,
|
|
65
|
+
): ComponentConstructor<Props> =>
|
|
66
|
+
createComponent(customElement)
|
|
67
|
+
.withStyles(...styles)
|
|
68
|
+
.withTemplate<{}, Props>((_, ...cn) => constructor(...cn))({});
|
|
53
69
|
|
|
54
70
|
return {
|
|
55
71
|
withStyles: <Styles extends Promise<unknown>[]>(...styles: Styles) => ({
|
package/src/slice.ts
CHANGED
|
@@ -15,94 +15,106 @@ import { StoreAdapter, StoreProvider } from "./store";
|
|
|
15
15
|
import { TerminalAdapter, TerminalEffect, TerminalProvider } from "./terminal";
|
|
16
16
|
import { Action } from "./types";
|
|
17
17
|
|
|
18
|
-
interface
|
|
18
|
+
interface SliceConfigStore<
|
|
19
19
|
Data,
|
|
20
20
|
StoreSignals extends Dictionary<ComputedSignal<any>>,
|
|
21
21
|
StoreActions extends Dictionary<Action<any, any>>,
|
|
22
|
+
> extends UnaryFunction<
|
|
23
|
+
{
|
|
24
|
+
StoreProvider: {
|
|
25
|
+
new (): StoreProvider<Data>;
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
StoreAdapter<StoreSignals, StoreActions>
|
|
29
|
+
> {}
|
|
30
|
+
|
|
31
|
+
interface SliceConfigApi<
|
|
32
|
+
ApiEffects extends Dictionary<ApiEffect<any, any>>,
|
|
33
|
+
ApiActions extends Dictionary<Action<any, any>>,
|
|
34
|
+
> extends ApiAdapter<ApiEffects, ApiActions> {}
|
|
35
|
+
|
|
36
|
+
interface SliceConfigTerminal<
|
|
37
|
+
StoreSignals extends Dictionary<ComputedSignal<any>>,
|
|
38
|
+
StoreActions extends Dictionary<Action<any, any>>,
|
|
22
39
|
ApiEffects extends Dictionary<ApiEffect<any, any>>,
|
|
23
40
|
ApiActions extends Dictionary<Action<any, any>>,
|
|
24
41
|
TerminalEffects extends Dictionary<TerminalEffect<any, any>>,
|
|
25
42
|
TerminalActions extends Dictionary<Action<any, any>>,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
StoreAdapter<StoreSignals, StoreActions>
|
|
36
|
-
>;
|
|
37
|
-
api: ApiAdapter<ApiEffects, ApiActions>;
|
|
38
|
-
terminal: UnaryFunction<
|
|
39
|
-
{
|
|
40
|
-
TerminalProvider: {
|
|
41
|
-
new (): TerminalProvider<
|
|
42
|
-
StoreSignals,
|
|
43
|
-
StoreActions,
|
|
44
|
-
ApiEffects,
|
|
45
|
-
ApiActions
|
|
46
|
-
>;
|
|
47
|
-
};
|
|
48
|
-
},
|
|
49
|
-
TerminalAdapter<TerminalEffects, TerminalActions>
|
|
50
|
-
>;
|
|
51
|
-
components: UnaryFunction<
|
|
52
|
-
{
|
|
53
|
-
ComponentsProvider: {
|
|
54
|
-
new (): ComponentsProvider<
|
|
55
|
-
StoreSignals,
|
|
56
|
-
StoreActions,
|
|
57
|
-
ApiEffects,
|
|
58
|
-
ApiActions,
|
|
59
|
-
TerminalEffects,
|
|
60
|
-
TerminalActions
|
|
61
|
-
>;
|
|
62
|
-
};
|
|
63
|
-
},
|
|
64
|
-
ComponentsAdapter<Components>
|
|
65
|
-
>;
|
|
66
|
-
render: UnaryFunction<
|
|
67
|
-
{
|
|
68
|
-
[K in keyof Components]: ReturnType<
|
|
69
|
-
<
|
|
70
|
-
Props extends Components[K] extends ComponentConstructor<infer Props>
|
|
71
|
-
? Props
|
|
72
|
-
: never,
|
|
73
|
-
>() => JSX.Component<Props>
|
|
43
|
+
> extends UnaryFunction<
|
|
44
|
+
{
|
|
45
|
+
TerminalProvider: {
|
|
46
|
+
new (): TerminalProvider<
|
|
47
|
+
StoreSignals,
|
|
48
|
+
StoreActions,
|
|
49
|
+
ApiEffects,
|
|
50
|
+
ApiActions
|
|
74
51
|
>;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
TerminalAdapter<TerminalEffects, TerminalActions>
|
|
55
|
+
> {}
|
|
79
56
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
<
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
SliceConfig<
|
|
93
|
-
Data,
|
|
57
|
+
interface SliceConfigComponents<
|
|
58
|
+
StoreSignals extends Dictionary<ComputedSignal<any>>,
|
|
59
|
+
StoreActions extends Dictionary<Action<any, any>>,
|
|
60
|
+
ApiEffects extends Dictionary<ApiEffect<any, any>>,
|
|
61
|
+
ApiActions extends Dictionary<Action<any, any>>,
|
|
62
|
+
TerminalEffects extends Dictionary<TerminalEffect<any, any>>,
|
|
63
|
+
TerminalActions extends Dictionary<Action<any, any>>,
|
|
64
|
+
Components extends Dictionary<ComponentConstructor<any>>,
|
|
65
|
+
> extends UnaryFunction<
|
|
66
|
+
{
|
|
67
|
+
ComponentsProvider: {
|
|
68
|
+
new (): ComponentsProvider<
|
|
94
69
|
StoreSignals,
|
|
95
70
|
StoreActions,
|
|
96
71
|
ApiEffects,
|
|
97
72
|
ApiActions,
|
|
98
73
|
TerminalEffects,
|
|
99
|
-
TerminalActions
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
74
|
+
TerminalActions
|
|
75
|
+
>;
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
ComponentsAdapter<Components>
|
|
79
|
+
> {}
|
|
80
|
+
|
|
81
|
+
interface SliceConfigTemplate<
|
|
82
|
+
Components extends Dictionary<ComponentConstructor<any>>,
|
|
83
|
+
> extends UnaryFunction<
|
|
84
|
+
{
|
|
85
|
+
[K in keyof Components]: ReturnType<
|
|
86
|
+
<
|
|
87
|
+
Props extends Components[K] extends ComponentConstructor<infer Props>
|
|
88
|
+
? Props
|
|
89
|
+
: never,
|
|
90
|
+
>() => JSX.Component<Props>
|
|
91
|
+
>;
|
|
92
|
+
},
|
|
93
|
+
JSX.Element
|
|
94
|
+
> {}
|
|
95
|
+
|
|
96
|
+
interface SliceConfig<
|
|
97
|
+
Data,
|
|
98
|
+
StoreSignals extends Dictionary<ComputedSignal<any>>,
|
|
99
|
+
StoreActions extends Dictionary<Action<any, any>>,
|
|
100
|
+
ApiEffects extends Dictionary<ApiEffect<any, any>>,
|
|
101
|
+
ApiActions extends Dictionary<Action<any, any>>,
|
|
102
|
+
TerminalEffects extends Dictionary<TerminalEffect<any, any>>,
|
|
103
|
+
TerminalActions extends Dictionary<Action<any, any>>,
|
|
104
|
+
Components extends Dictionary<ComponentConstructor<any>>,
|
|
105
|
+
> {
|
|
106
|
+
data: Data;
|
|
107
|
+
store: SliceConfigStore<Data, StoreSignals, StoreActions>;
|
|
108
|
+
api: SliceConfigApi<ApiEffects, ApiActions>;
|
|
109
|
+
terminal: SliceConfigTerminal<
|
|
110
|
+
StoreSignals,
|
|
111
|
+
StoreActions,
|
|
112
|
+
ApiEffects,
|
|
113
|
+
ApiActions,
|
|
114
|
+
TerminalEffects,
|
|
115
|
+
TerminalActions
|
|
116
|
+
>;
|
|
117
|
+
components: SliceConfigComponents<
|
|
106
118
|
StoreSignals,
|
|
107
119
|
StoreActions,
|
|
108
120
|
ApiEffects,
|
|
@@ -110,7 +122,68 @@ export const createSlice =
|
|
|
110
122
|
TerminalEffects,
|
|
111
123
|
TerminalActions,
|
|
112
124
|
Components
|
|
113
|
-
|
|
125
|
+
>;
|
|
126
|
+
template: SliceConfigTemplate<Components>;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export const createSlice = () => ({
|
|
130
|
+
withData: <Data>(data: Data) => ({
|
|
131
|
+
withStore: <
|
|
132
|
+
StoreSignals extends Dictionary<ComputedSignal<any>>,
|
|
133
|
+
StoreActions extends Dictionary<Action<any, any>>,
|
|
134
|
+
>(
|
|
135
|
+
store: SliceConfigStore<Data, StoreSignals, StoreActions>,
|
|
136
|
+
) => ({
|
|
137
|
+
withApi: <
|
|
138
|
+
ApiEffects extends Dictionary<ApiEffect<any, any>>,
|
|
139
|
+
ApiActions extends Dictionary<Action<any, any>>,
|
|
140
|
+
>(
|
|
141
|
+
api: SliceConfigApi<ApiEffects, ApiActions>,
|
|
142
|
+
) => ({
|
|
143
|
+
withTerminal: <
|
|
144
|
+
TerminalEffects extends Dictionary<TerminalEffect<any, any>>,
|
|
145
|
+
TerminalActions extends Dictionary<Action<any, any>>,
|
|
146
|
+
>(
|
|
147
|
+
terminal: SliceConfigTerminal<
|
|
148
|
+
StoreSignals,
|
|
149
|
+
StoreActions,
|
|
150
|
+
ApiEffects,
|
|
151
|
+
ApiActions,
|
|
152
|
+
TerminalEffects,
|
|
153
|
+
TerminalActions
|
|
154
|
+
>,
|
|
155
|
+
) => ({
|
|
156
|
+
withComponents: <
|
|
157
|
+
Components extends Dictionary<ComponentConstructor<any>>,
|
|
158
|
+
>(
|
|
159
|
+
components: SliceConfigComponents<
|
|
160
|
+
StoreSignals,
|
|
161
|
+
StoreActions,
|
|
162
|
+
ApiEffects,
|
|
163
|
+
ApiActions,
|
|
164
|
+
TerminalEffects,
|
|
165
|
+
TerminalActions,
|
|
166
|
+
Components
|
|
167
|
+
>,
|
|
168
|
+
) => ({
|
|
169
|
+
withTemplate: (
|
|
170
|
+
template: SliceConfigTemplate<Components>,
|
|
171
|
+
): SliceConfig<
|
|
172
|
+
Data,
|
|
173
|
+
StoreSignals,
|
|
174
|
+
StoreActions,
|
|
175
|
+
ApiEffects,
|
|
176
|
+
ApiActions,
|
|
177
|
+
TerminalEffects,
|
|
178
|
+
TerminalActions,
|
|
179
|
+
Components
|
|
180
|
+
> => ({ data, store, api, terminal, components, template }),
|
|
181
|
+
}),
|
|
182
|
+
}),
|
|
183
|
+
}),
|
|
184
|
+
}),
|
|
185
|
+
}),
|
|
186
|
+
});
|
|
114
187
|
|
|
115
188
|
export class Slice<
|
|
116
189
|
Data,
|
|
@@ -136,7 +209,7 @@ export class Slice<
|
|
|
136
209
|
api,
|
|
137
210
|
terminal,
|
|
138
211
|
components,
|
|
139
|
-
|
|
212
|
+
template,
|
|
140
213
|
}: SliceConfig<
|
|
141
214
|
Data,
|
|
142
215
|
StoreSignals,
|
|
@@ -179,7 +252,7 @@ export class Slice<
|
|
|
179
252
|
map(
|
|
180
253
|
(key) =>
|
|
181
254
|
new (defineCustomElement(`${key}-slice`))(
|
|
182
|
-
|
|
255
|
+
template(
|
|
183
256
|
mapValues(
|
|
184
257
|
components({
|
|
185
258
|
ComponentsProvider: ((context) =>
|
|
@@ -196,8 +269,7 @@ export class Slice<
|
|
|
196
269
|
}
|
|
197
270
|
})({ store: this.store, api, terminal: this.terminal }),
|
|
198
271
|
}).components,
|
|
199
|
-
(componentConstructor) =>
|
|
200
|
-
componentConstructor.predicate(key),
|
|
272
|
+
(componentConstructor) => componentConstructor(key),
|
|
201
273
|
),
|
|
202
274
|
),
|
|
203
275
|
),
|