@pihanga2/core 0.3.0 → 0.3.2

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,153 +1,160 @@
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
- ) => void
55
+ key?: string
56
+ ) => PiReducerCancelF;
57
+
58
+ export type PiReducerCancelF = () => void;
57
59
 
58
60
  export type PiRegisterOneShotReducerF = <
59
61
  S extends ReduxState,
60
- A extends ReduxAction,
62
+ A extends ReduxAction
61
63
  >(
62
64
  eventType: string,
63
65
  mapper: ReduceOnceF<S, A>,
64
- priority?: number,
65
- ) => void
66
-
66
+ priority?: number
67
+ ) => void;
67
68
 
68
69
  // CARDS
69
70
 
70
71
  // context props given to <Card> in parent card
71
- export type PiDefCtxtProps = { [k: string]: any }
72
+ export type PiDefCtxtProps = { [k: string]: any };
72
73
 
73
74
  // type for <Card .../>
74
75
  export type CardProp = {
75
- cardName: PiCardRef
76
- cardKey?: string
77
- parentCard: string
78
- } & PiDefCtxtProps
76
+ cardName: PiCardRef;
77
+ cardKey?: string;
78
+ parentCard: string;
79
+ } & PiDefCtxtProps;
79
80
 
80
81
  // props for the 'root' of all cards
81
82
  export type WindowProps = {
82
- page: PiCardRef
83
- framework?: string // select framework to render window
84
- theme?: any // depends on framework
85
- }
83
+ page: PiCardRef;
84
+ framework?: string; // select framework to render window
85
+ theme?: any; // depends on framework
86
+ };
86
87
 
87
88
  // type which needs to be implemented by card components
88
89
  export type PiCardProps<P, E = {}> = P & {
89
- cardName: string
90
- children?: React.ReactNode[]
91
- _cls: (elName: string | string[], styles?: CSSModuleClasses) => string
92
- _dispatch: DispatchF
90
+ cardName: string;
91
+ children?: React.ReactNode[];
92
+ _cls: (elName: string | string[], className?: string) => string;
93
+ _dispatch: DispatchF;
93
94
  } & {
94
- [Key in keyof E]: (ev: E[Key]) => void
95
- }
95
+ [Key in keyof E]: (ev: E[Key]) => void;
96
+ };
96
97
 
97
- export type CSSModuleClasses = { readonly [key: string]: string }
98
+ export type CSSModuleClasses = { readonly [key: string]: string };
98
99
 
99
- export type PiCardRef = string | PiCardDef
100
+ export type PiCardRef = string | PiCardDef;
100
101
 
101
- export type RefF = any
102
+ export type RefF = any;
102
103
  export type StateMapper<T, S extends ReduxState, C = PiDefCtxtProps> = (
103
104
  state: S,
104
- context: StateMapperContext<C>,
105
- ) => T
105
+ context: StateMapperContext<C>
106
+ ) => T;
106
107
 
107
108
  export type StateMapperContext<C> = {
108
- cardName: string
109
- cardKey?: string
110
- ctxtProps: C
111
- ref?: RefF
112
- }
109
+ cardName: string;
110
+ cardKey?: string;
111
+ ctxtProps: C;
112
+ ref?: RefF;
113
+ };
113
114
 
114
115
  export type PiMapProps<
115
116
  CType,
116
117
  S extends ReduxState,
117
118
  EType = {},
118
- C = PiDefCtxtProps,
119
+ C = PiDefCtxtProps
119
120
  > = {
120
121
  [Property in keyof CType]:
121
- | CType[Property]
122
- | StateMapper<CType[Property], S, C>
122
+ | CType[Property]
123
+ | StateMapper<CType[Property], S, C>;
123
124
  } & EventHandler<EType, S> &
124
- EventMapper<EType>
125
+ EventMapper<EType>;
125
126
 
126
127
  export type EventHandler<T, S extends ReduxState> = {
127
- [Key in keyof T]?: ReduceF<S, T[Key] & ReduxAction>
128
- }
128
+ [Key in keyof T]?: ReduceF<S, T[Key] & ReduxAction>;
129
+ };
129
130
 
130
131
  export type EventMapper<T> = {
131
- [Key in keyof T as `${Key & string}Mapper`]?: (ev: T[Key]) => ReduxAction | null
132
- }
132
+ [Key in keyof T as `${Key & string}Mapper`]?: (
133
+ ev: T[Key]
134
+ ) => ReduxAction | null;
135
+ };
133
136
 
134
137
  export type GenericCardParameterT =
135
138
  | unknown
136
- | StateMapper<unknown, ReduxState, unknown>
139
+ | StateMapper<unknown, ReduxState, unknown>;
137
140
 
138
141
  export type PiCardDef = {
139
- cardType: string
142
+ cardType: string;
140
143
  } & {
141
- [k: string]: GenericCardParameterT
142
- }
144
+ [k: string]: GenericCardParameterT;
145
+ };
143
146
 
144
147
  // METACARD
145
148
 
146
149
  export type PiRegisterMetaCard = {
147
- type: string,
148
- mapper: MetaCardMapperF
149
- events?: { [key: string]: string }
150
- }
151
-
152
- export type RegisterCardF = (name: string, parameters: PiCardDef) => PiCardRef
153
- export type MetaCardMapperF = (name: string, props: any, registerCard: RegisterCardF) => PiCardDef
150
+ type: string;
151
+ mapper: MetaCardMapperF;
152
+ events?: { [key: string]: string };
153
+ };
154
+
155
+ export type RegisterCardF = (name: string, parameters: PiCardDef) => PiCardRef;
156
+ export type MetaCardMapperF = (
157
+ name: string,
158
+ props: any,
159
+ registerCard: RegisterCardF
160
+ ) => PiCardDef;