@pihanga2/core 0.2.0
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/dist/card.d.ts +22 -0
- package/dist/card.d.ts.map +1 -0
- package/dist/card.js +493 -0
- package/dist/card.js.map +1 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +88 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +5 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +12 -0
- package/dist/logger.js.map +1 -0
- package/dist/reducer.d.ts +5 -0
- package/dist/reducer.d.ts.map +1 -0
- package/dist/reducer.js +77 -0
- package/dist/reducer.js.map +1 -0
- package/dist/redux.d.ts +31 -0
- package/dist/redux.d.ts.map +1 -0
- package/dist/redux.js +50 -0
- package/dist/redux.js.map +1 -0
- package/dist/rest/delete.d.ts +4 -0
- package/dist/rest/delete.d.ts.map +1 -0
- package/dist/rest/delete.js +23 -0
- package/dist/rest/delete.js.map +1 -0
- package/dist/rest/enums.d.ts +6 -0
- package/dist/rest/enums.d.ts.map +1 -0
- package/dist/rest/enums.js +9 -0
- package/dist/rest/enums.js.map +1 -0
- package/dist/rest/get.d.ts +10 -0
- package/dist/rest/get.d.ts.map +1 -0
- package/dist/rest/get.js +31 -0
- package/dist/rest/get.js.map +1 -0
- package/dist/rest/index.d.ts +6 -0
- package/dist/rest/index.d.ts.map +1 -0
- package/dist/rest/index.js +6 -0
- package/dist/rest/index.js.map +1 -0
- package/dist/rest/postPutPatch.d.ts +6 -0
- package/dist/rest/postPutPatch.d.ts.map +1 -0
- package/dist/rest/postPutPatch.js +72 -0
- package/dist/rest/postPutPatch.js.map +1 -0
- package/dist/rest/types.d.ts +93 -0
- package/dist/rest/types.d.ts.map +1 -0
- package/dist/rest/types.js +38 -0
- package/dist/rest/types.js.map +1 -0
- package/dist/rest/utils.d.ts +8 -0
- package/dist/rest/utils.d.ts.map +1 -0
- package/dist/rest/utils.js +212 -0
- package/dist/rest/utils.js.map +1 -0
- package/dist/router.d.ts +25 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +136 -0
- package/dist/router.js.map +1 -0
- package/dist/store.d.ts +1 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +18 -0
- package/dist/store.js.map +1 -0
- package/dist/types.d.ts +94 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +71 -0
- package/src/card.tsx +628 -0
- package/src/index.tsx +193 -0
- package/src/logger.ts +13 -0
- package/src/reducer.ts +127 -0
- package/src/redux.ts +64 -0
- package/src/rest/delete.ts +41 -0
- package/src/rest/enums.ts +8 -0
- package/src/rest/get.ts +50 -0
- package/src/rest/index.ts +7 -0
- package/src/rest/postPutPatch.ts +118 -0
- package/src/rest/types.ts +135 -0
- package/src/rest/utils.ts +265 -0
- package/src/router.ts +171 -0
- package/src/store.ts +19 -0
- package/src/types.ts +146 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
export type ReduxState = {
|
|
2
|
+
route: Route
|
|
3
|
+
|
|
4
|
+
pihanga?: { [key: string]: any }
|
|
5
|
+
}
|
|
6
|
+
|
|
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 }
|
|
14
|
+
|
|
15
|
+
export type ReduxAction = {
|
|
16
|
+
type: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type CardAction = ReduxAction & {
|
|
20
|
+
cardID: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type PiRegisterComponent = {
|
|
24
|
+
name: string
|
|
25
|
+
component: any // ReactComponent
|
|
26
|
+
events?: { [key: string]: string }
|
|
27
|
+
// defaults?: { [key: string]: any }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type ReduceF<S extends ReduxState, A extends ReduxAction> = (
|
|
31
|
+
state: S,
|
|
32
|
+
action: A,
|
|
33
|
+
dispatch: DispatchF,
|
|
34
|
+
) => S
|
|
35
|
+
|
|
36
|
+
export type ReduceOnceF<S extends ReduxState, A extends ReduxAction> = (
|
|
37
|
+
state: S,
|
|
38
|
+
action: A,
|
|
39
|
+
dispatch: DispatchF,
|
|
40
|
+
) => [S, boolean]
|
|
41
|
+
|
|
42
|
+
export type DispatchF = <T extends ReduxAction>(a: T) => void
|
|
43
|
+
|
|
44
|
+
export interface PiReducer {
|
|
45
|
+
register: PiRegisterReducerF
|
|
46
|
+
registerOneShot: PiRegisterOneShotReducerF
|
|
47
|
+
dispatch: DispatchF
|
|
48
|
+
dispatchFromReducer: DispatchF
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type PiRegisterReducerF = <S extends ReduxState, A extends ReduxAction>(
|
|
52
|
+
eventType: string,
|
|
53
|
+
mapper: ReduceF<S, A>, // (state: S, action: A, dispatch: DispatchF) => S,
|
|
54
|
+
priority?: number,
|
|
55
|
+
) => void
|
|
56
|
+
|
|
57
|
+
export type PiRegisterOneShotReducerF = <
|
|
58
|
+
S extends ReduxState,
|
|
59
|
+
A extends ReduxAction,
|
|
60
|
+
>(
|
|
61
|
+
eventType: string,
|
|
62
|
+
mapper: ReduceOnceF<S, A>,
|
|
63
|
+
priority?: number,
|
|
64
|
+
) => void
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
// CARDS
|
|
68
|
+
|
|
69
|
+
// context props given to <Card> in parent card
|
|
70
|
+
export type PiDefCtxtProps = { [k: string]: any }
|
|
71
|
+
|
|
72
|
+
// type for <Card .../>
|
|
73
|
+
export type CardProp = {
|
|
74
|
+
cardName: PiCardRef
|
|
75
|
+
cardKey?: string
|
|
76
|
+
parentCard: string
|
|
77
|
+
} & PiDefCtxtProps
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
// type which needs to be implemented by card components
|
|
81
|
+
export type PiCardProps<P, E = {}> = P & {
|
|
82
|
+
cardName: string
|
|
83
|
+
children?: React.ReactNode[]
|
|
84
|
+
_cls: (elName: string | string[], styles?: CSSModuleClasses) => string
|
|
85
|
+
_dispatch: DispatchF
|
|
86
|
+
} & {
|
|
87
|
+
[Key in keyof E]: (ev: E[Key]) => void
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type CSSModuleClasses = { readonly [key: string]: string }
|
|
91
|
+
|
|
92
|
+
export type PiCardRef = string | PiCardDef
|
|
93
|
+
|
|
94
|
+
export type RefF = any
|
|
95
|
+
export type StateMapper<T, S extends ReduxState, C = PiDefCtxtProps> = (
|
|
96
|
+
state: S,
|
|
97
|
+
context: StateMapperContext<C>,
|
|
98
|
+
) => T
|
|
99
|
+
|
|
100
|
+
export type StateMapperContext<C> = {
|
|
101
|
+
cardName: string
|
|
102
|
+
cardKey?: string
|
|
103
|
+
ctxtProps: C
|
|
104
|
+
ref?: RefF
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export type PiMapProps<
|
|
108
|
+
CType,
|
|
109
|
+
S extends ReduxState,
|
|
110
|
+
EType = {},
|
|
111
|
+
C = PiDefCtxtProps,
|
|
112
|
+
> = {
|
|
113
|
+
[Property in keyof CType]:
|
|
114
|
+
| CType[Property]
|
|
115
|
+
| StateMapper<CType[Property], S, C>
|
|
116
|
+
} & EventHandler<EType, S> &
|
|
117
|
+
EventMapper<EType>
|
|
118
|
+
|
|
119
|
+
export type EventHandler<T, S extends ReduxState> = {
|
|
120
|
+
[Key in keyof T]?: ReduceF<S, T[Key] & ReduxAction>
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export type EventMapper<T> = {
|
|
124
|
+
[Key in keyof T as `${Key & string}Mapper`]?: (ev: T[Key]) => ReduxAction | null
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export type GenericCardParameterT =
|
|
128
|
+
| unknown
|
|
129
|
+
| StateMapper<unknown, ReduxState, unknown>
|
|
130
|
+
|
|
131
|
+
export type PiCardDef = {
|
|
132
|
+
cardType: string
|
|
133
|
+
} & {
|
|
134
|
+
[k: string]: GenericCardParameterT
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// METACARD
|
|
138
|
+
|
|
139
|
+
export type PiRegisterMetaCard = {
|
|
140
|
+
type: string,
|
|
141
|
+
mapper: MetaCardMapperF
|
|
142
|
+
events?: { [key: string]: string }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export type RegisterCardF = (name: string, parameters: PiCardDef) => PiCardRef
|
|
146
|
+
export type MetaCardMapperF = (name: string, props: any, registerCard: RegisterCardF) => PiCardDef
|