@pihanga2/core 0.3.1 → 0.3.3

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/src/types.ts CHANGED
@@ -1,155 +1,161 @@
1
1
  export type ReduxState = {
2
- route: Route
2
+ route: Route;
3
3
 
4
- pihanga?: { [key: string]: any }
5
- }
4
+ pihanga?: { [key: string]: any };
5
+ };
6
6
 
7
7
  export type Route = {
8
- path: string[]
9
- query: PathQuery
10
- url: string
11
- fromBrowser?: boolean
12
- }
13
- export type PathQuery = { [k: string]: string | number | boolean }
8
+ path: string[];
9
+ query: PathQuery;
10
+ url: string;
11
+ fromBrowser?: boolean;
12
+ };
13
+ export type PathQuery = { [k: string]: string | number | boolean };
14
14
 
15
15
  export type ReduxAction = {
16
- type: string
17
- }
16
+ type: string;
17
+ };
18
18
 
19
19
  export type CardAction = ReduxAction & {
20
- cardID: string
21
- }
20
+ cardID: string;
21
+ };
22
22
 
23
23
  export type PiRegisterComponent = {
24
- name: string
25
- component: any // ReactComponent
26
- events?: { [key: string]: string }
24
+ name: string;
25
+ component: any; // ReactComponent
26
+ events?: { [key: string]: string };
27
27
  // defaults?: { [key: string]: any }
28
- }
28
+ };
29
29
 
30
30
  export type ReduceF<S extends ReduxState, A extends ReduxAction> = (
31
31
  state: S,
32
32
  action: A,
33
- dispatch: DispatchF,
34
- ) => void // S
33
+ dispatch: DispatchF
34
+ ) => void; // S
35
35
 
36
36
  export type ReduceOnceF<S extends ReduxState, A extends ReduxAction> = (
37
37
  state: S,
38
38
  action: A,
39
- dispatch: DispatchF,
40
- ) => boolean // [S, boolean]
39
+ dispatch: DispatchF
40
+ ) => boolean; // [S, boolean]
41
41
 
42
- export type DispatchF = <T extends ReduxAction>(a: T) => void
42
+ export type DispatchF = <T extends ReduxAction>(a: T) => void;
43
43
 
44
44
  export interface PiReducer {
45
- register: PiRegisterReducerF
46
- registerOneShot: PiRegisterOneShotReducerF
47
- dispatch: DispatchF
48
- dispatchFromReducer: DispatchF
45
+ register: PiRegisterReducerF;
46
+ registerOneShot: PiRegisterOneShotReducerF;
47
+ dispatch: DispatchF;
48
+ dispatchFromReducer: DispatchF;
49
49
  }
50
50
 
51
51
  export type PiRegisterReducerF = <S extends ReduxState, A extends ReduxAction>(
52
52
  eventType: string,
53
53
  mapper: ReduceF<S, A>, // (state: S, action: A, dispatch: DispatchF) => S,
54
54
  priority?: number,
55
- key?: string,
56
- ) => PiReducerCancelF
55
+ key?: string
56
+ ) => PiReducerCancelF;
57
57
 
58
- export type PiReducerCancelF = () => void
58
+ export type PiReducerCancelF = () => void;
59
59
 
60
60
  export type PiRegisterOneShotReducerF = <
61
61
  S extends ReduxState,
62
- A extends ReduxAction,
62
+ A extends ReduxAction
63
63
  >(
64
64
  eventType: string,
65
65
  mapper: ReduceOnceF<S, A>,
66
- priority?: number,
67
- ) => void
68
-
66
+ priority?: number
67
+ ) => void;
69
68
 
70
69
  // CARDS
71
70
 
72
71
  // context props given to <Card> in parent card
73
- export type PiDefCtxtProps = { [k: string]: any }
72
+ export type PiDefCtxtProps = { [k: string]: any };
74
73
 
75
74
  // type for <Card .../>
76
75
  export type CardProp = {
77
- cardName: PiCardRef
78
- cardKey?: string
79
- parentCard: string
80
- } & PiDefCtxtProps
76
+ cardName: PiCardRef;
77
+ cardKey?: string;
78
+ parentCard: string;
79
+ } & PiDefCtxtProps;
81
80
 
82
81
  // props for the 'root' of all cards
83
82
  export type WindowProps = {
84
- page: PiCardRef
85
- framework?: string // select framework to render window
86
- theme?: any // depends on framework
87
- }
83
+ page: PiCardRef;
84
+ framework?: string; // select framework to render window
85
+ theme?: any; // depends on framework
86
+ };
88
87
 
89
88
  // type which needs to be implemented by card components
90
89
  export type PiCardProps<P, E = {}> = P & {
91
- cardName: string
92
- children?: React.ReactNode[]
93
- _cls: (elName: string | string[], styles?: CSSModuleClasses) => string
94
- _dispatch: DispatchF
90
+ cardName: string;
91
+ children?: React.ReactNode[];
92
+ _cls: (elName: string | string[], className?: string) => string;
93
+ _dispatch: DispatchF;
95
94
  } & {
96
- [Key in keyof E]: (ev: E[Key]) => void
97
- }
95
+ [Key in keyof E]: (ev: E[Key]) => void;
96
+ };
98
97
 
99
- export type CSSModuleClasses = { readonly [key: string]: string }
98
+ export type CSSModuleClasses = { readonly [key: string]: string };
100
99
 
101
- export type PiCardRef = string | PiCardDef
100
+ export type PiCardRef = string | PiCardDef;
102
101
 
103
- export type RefF = any
102
+ export type RefF = any;
104
103
  export type StateMapper<T, S extends ReduxState, C = PiDefCtxtProps> = (
105
104
  state: S,
106
- context: StateMapperContext<C>,
107
- ) => T
105
+ context: StateMapperContext<C>
106
+ ) => T;
108
107
 
109
108
  export type StateMapperContext<C> = {
110
- cardName: string
111
- cardKey?: string
112
- ctxtProps: C
113
- ref?: RefF
114
- }
109
+ cardName: string;
110
+ cardKey?: string;
111
+ ctxtProps: C;
112
+ ref?: RefF;
113
+ };
115
114
 
116
115
  export type PiMapProps<
117
116
  CType,
118
117
  S extends ReduxState,
119
118
  EType = {},
120
- C = PiDefCtxtProps,
119
+ C = PiDefCtxtProps
121
120
  > = {
122
121
  [Property in keyof CType]:
123
- | CType[Property]
124
- | StateMapper<CType[Property], S, C>
122
+ | CType[Property]
123
+ | StateMapper<CType[Property], S, C>;
125
124
  } & EventHandler<EType, S> &
126
- EventMapper<EType>
125
+ EventMapper<EType, C>;
127
126
 
128
127
  export type EventHandler<T, S extends ReduxState> = {
129
- [Key in keyof T]?: ReduceF<S, T[Key] & ReduxAction>
130
- }
128
+ [Key in keyof T]?: ReduceF<S, T[Key] & ReduxAction>;
129
+ };
131
130
 
132
- export type EventMapper<T> = {
133
- [Key in keyof T as `${Key & string}Mapper`]?: (ev: T[Key]) => ReduxAction | null
134
- }
131
+ export type EventMapper<T, C = PiDefCtxtProps> = {
132
+ [Key in keyof T as `${Key & string}Mapper`]?: (
133
+ ev: T[Key],
134
+ ctxt: C
135
+ ) => ReduxAction | null;
136
+ };
135
137
 
136
138
  export type GenericCardParameterT =
137
139
  | unknown
138
- | StateMapper<unknown, ReduxState, unknown>
140
+ | StateMapper<unknown, ReduxState, unknown>;
139
141
 
140
142
  export type PiCardDef = {
141
- cardType: string
143
+ cardType: string;
142
144
  } & {
143
- [k: string]: GenericCardParameterT
144
- }
145
+ [k: string]: GenericCardParameterT;
146
+ };
145
147
 
146
148
  // METACARD
147
149
 
148
150
  export type PiRegisterMetaCard = {
149
- type: string,
150
- mapper: MetaCardMapperF
151
- events?: { [key: string]: string }
152
- }
153
-
154
- export type RegisterCardF = (name: string, parameters: PiCardDef) => PiCardRef
155
- export type MetaCardMapperF = (name: string, props: any, registerCard: RegisterCardF) => PiCardDef
151
+ type: string;
152
+ mapper: MetaCardMapperF;
153
+ events?: { [key: string]: string };
154
+ };
155
+
156
+ export type RegisterCardF = (name: string, parameters: PiCardDef) => PiCardRef;
157
+ export type MetaCardMapperF = (
158
+ name: string,
159
+ props: any,
160
+ registerCard: RegisterCardF
161
+ ) => PiCardDef;