@modular-component/core 0.1.6 → 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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +31 -354
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +53 -145
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +155 -223
- package/dist/types/arguments.d.ts +0 -33
- package/dist/types/arguments.d.ts.map +0 -1
- package/dist/types/arguments.js +0 -6
- package/dist/types/arguments.js.map +0 -1
- package/dist/types/methods/add.d.ts +0 -23
- package/dist/types/methods/add.d.ts.map +0 -1
- package/dist/types/methods/add.js +0 -8
- package/dist/types/methods/add.js.map +0 -1
- package/dist/types/methods/at.d.ts +0 -22
- package/dist/types/methods/at.d.ts.map +0 -1
- package/dist/types/methods/at.js +0 -7
- package/dist/types/methods/at.js.map +0 -1
- package/dist/types/methods/hook.d.ts +0 -14
- package/dist/types/methods/hook.d.ts.map +0 -1
- package/dist/types/methods/hook.js +0 -7
- package/dist/types/methods/hook.js.map +0 -1
- package/dist/types/methods/mock.d.ts +0 -26
- package/dist/types/methods/mock.d.ts.map +0 -1
- package/dist/types/methods/mock.js +0 -6
- package/dist/types/methods/mock.js.map +0 -1
- package/dist/types/methods/with.d.ts +0 -52
- package/dist/types/methods/with.d.ts.map +0 -1
- package/dist/types/methods/with.js +0 -8
- package/dist/types/methods/with.js.map +0 -1
- package/dist/types/methods.d.ts +0 -10
- package/dist/types/methods.d.ts.map +0 -1
- package/dist/types/methods.js +0 -5
- package/dist/types/methods.js.map +0 -1
- package/dist/types/modular-component.d.ts +0 -15
- package/dist/types/modular-component.d.ts.map +0 -1
- package/dist/types/modular-component.js +0 -5
- package/dist/types/modular-component.js.map +0 -1
- package/dist/types/stage.d.ts +0 -41
- package/dist/types/stage.d.ts.map +0 -1
- package/dist/types/stage.js +0 -5
- package/dist/types/stage.js.map +0 -1
- package/dist/types/utils.d.ts +0 -24
- package/dist/types/utils.d.ts.map +0 -1
- package/dist/types/utils.js +0 -5
- package/dist/types/utils.js.map +0 -1
- package/dist/types/validation.d.ts +0 -4
- package/dist/types/validation.d.ts.map +0 -1
- package/dist/types/validation.js +0 -2
- package/dist/types/validation.js.map +0 -1
- package/src/types/arguments.ts +0 -57
- package/src/types/methods/add.ts +0 -52
- package/src/types/methods/at.ts +0 -64
- package/src/types/methods/hook.ts +0 -27
- package/src/types/methods/mock.ts +0 -90
- package/src/types/methods/with.ts +0 -173
- package/src/types/methods.ts +0 -11
- package/src/types/modular-component.ts +0 -25
- package/src/types/stage.ts +0 -91
- package/src/types/utils.ts +0 -63
- package/src/types/validation.ts +0 -13
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAyEA,SAAS,eAAe,CAKtB,MAGG;IAEH,MAAM,YAAY,GAAG,UAAU,KAAY,EAAE,GAA4B;QACvE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,QAAQ,CAAC,EAAE;YACrD,MAAM,GAAG,CAAC,GAAG,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;SACzC;QACD,OAAO,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;IAC/C,CAAC,CAAA;IAED,YAAY,CAAC,IAAI,GAAG,CAAC,KAAgD,EAAE,EAAE;QACvE,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK,CAAC,CAAA;QAE9D,IAAI,KAAK,KAAK,CAAC,CAA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;aACtD;YACD,OAAO,WAAW,EAAE,QAAQ,CAAC,IAAY,EAAE,GAAG,CAAC,IAAI,IAAI,CAAA;QACzD,CAAC,CAAA;IAEH,YAAY,CAAC,KAAK,GAAG,CAAC,KAAiB,EAAE,EAAE;QACzC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,KAAK,CAAC,CAAA;QAC3D,OAAO,KAAK,EAAE,QAAQ,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAA;IACxC,CAAC,CAAA;IAED,YAAY,CAAC,cAAc,GAAG,CAAC,WAAmB,EAAE,EAAE;QACpD,CAAC;QAAC,YAAoB,CAAC,WAAW,GAAG,WAAW,CAAA;IAClD,CAAC,CAAA;IAED,OAAO,YAA6D,CAAA;AACtE,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,WAAoB;IAMpB,MAAM,YAAY,GAAG,eAAe,CAIlC,EAAE,CAAC,CAAA;IACL,YAAY,CAAC,WAAW,GAAG,WAAW,CAAA;IACtC,OAAO,YAAY,CAAA;AACrB,CAAC;AAED,MAAM,UAAU,MAAM,CACpB,MAGwC;IAQxC,OAAO;QACL,KAAK,EAAE,QAAQ;QACf,QAAQ,EAAE,MAAM;KACjB,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"Factory",
|
|
8
8
|
"Test"
|
|
9
9
|
],
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.2.0",
|
|
11
11
|
"type": "module",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"publishConfig": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/react": "^18.0.17",
|
|
31
|
-
"typescript": "^
|
|
31
|
+
"typescript": "^5.2.2"
|
|
32
32
|
},
|
|
33
33
|
"main": "dist/index.js",
|
|
34
34
|
"types": "dist/index.d.ts"
|
package/src/index.ts
CHANGED
|
@@ -1,239 +1,171 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
: never
|
|
15
|
-
|
|
16
|
-
return {
|
|
17
|
-
build: <Stages extends StageTuple = []>(stages: StageTuple = []) => {
|
|
18
|
-
const factory = <Props extends {} = {}, Ref = FunctionComponent<Props>>(
|
|
19
|
-
displayName?: string,
|
|
20
|
-
options?: { memo: boolean },
|
|
21
|
-
) => {
|
|
22
|
-
const generateAsHook =
|
|
23
|
-
(ref?: ForwardedRef<Ref>, field?: string) =>
|
|
24
|
-
() =>
|
|
25
|
-
(props: Props = {} as Props) => {
|
|
26
|
-
// Prepare the shared arguments object, prefilling it with the props
|
|
27
|
-
// and an empty render result
|
|
28
|
-
let args = {
|
|
29
|
-
props,
|
|
30
|
-
children: (props as { children?: unknown })?.children,
|
|
31
|
-
render: null,
|
|
32
|
-
ref,
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const methodsArray = Object.values(methods)
|
|
36
|
-
|
|
37
|
-
// Run each stage in order, replacing the arguments by the response
|
|
38
|
-
// from the last stage
|
|
39
|
-
for (const stage of stages) {
|
|
40
|
-
const method = methodsArray.find(
|
|
41
|
-
(method) => method.symbol === stage.stage,
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
let useTransform =
|
|
45
|
-
// Never transform mocked stages
|
|
46
|
-
((stage as any).mocked ? undefined : method?.transform) ??
|
|
47
|
-
(() => stage.value)
|
|
48
|
-
|
|
49
|
-
args = {
|
|
50
|
-
...args,
|
|
51
|
-
[method?.field as keyof typeof args]: useTransform(
|
|
52
|
-
args,
|
|
53
|
-
stage.value,
|
|
54
|
-
),
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Finally, return the args
|
|
59
|
-
return field ? args[field as keyof typeof args] : args
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Create the actual Component. This is a simple React Functional Component
|
|
63
|
-
// that will call the hooks for each registered stages in order.
|
|
64
|
-
const Component = forwardRef<Ref, Props>((props, ref) => {
|
|
65
|
-
// Prepare the shared arguments object, prefilling it with the props
|
|
66
|
-
// and an empty render result
|
|
67
|
-
const useComponent = generateAsHook(ref)()
|
|
68
|
-
const args = useComponent(props)
|
|
69
|
-
|
|
70
|
-
return (args as unknown as { render: null }).render ?? null
|
|
71
|
-
}) as unknown as ModularComponent<Props, Ref, CleanMethods, Stages>
|
|
72
|
-
|
|
73
|
-
// Set the debug display name if provided
|
|
74
|
-
Component.displayName = displayName
|
|
75
|
-
|
|
76
|
-
// Add an asHook system to get the components args as a reusable hook
|
|
77
|
-
Component.asHook = generateAsHook() as ModularComponent<
|
|
78
|
-
Props,
|
|
79
|
-
Ref,
|
|
80
|
-
CleanMethods,
|
|
81
|
-
Stages
|
|
82
|
-
>['asHook']
|
|
83
|
-
|
|
84
|
-
// Add each configured stage methods to the component
|
|
85
|
-
Object.keys(methods).forEach((method) => {
|
|
86
|
-
// Check if a stage of the same key already exists
|
|
87
|
-
const stageIndices = stages
|
|
88
|
-
// Map all stages to an [index, stage] tuple
|
|
89
|
-
.map((record, index) => [index, record] as const)
|
|
90
|
-
// Remove all tuples not matching our stage
|
|
91
|
-
.filter(([, record]) => record.stage === methods[method].symbol)
|
|
92
|
-
// Get the index
|
|
93
|
-
.map(([index]) => index)
|
|
94
|
-
const lastIndex = [...stageIndices].pop() as number
|
|
95
|
-
|
|
96
|
-
// @ts-ignore
|
|
97
|
-
Component[`with${method}`] = (
|
|
98
|
-
value: unknown,
|
|
99
|
-
forceIndex?: number,
|
|
100
|
-
) => {
|
|
101
|
-
// Prepare the new stage
|
|
102
|
-
const stage = { stage: methods[method].symbol, value } as const
|
|
103
|
-
|
|
104
|
-
// Check if a stage of the same key already exists
|
|
105
|
-
const stageIndex =
|
|
106
|
-
(forceIndex !== undefined
|
|
107
|
-
? stageIndices[forceIndex]
|
|
108
|
-
: lastIndex) ?? -1
|
|
109
|
-
|
|
110
|
-
// If so, copy the stages and replace the previous record
|
|
111
|
-
if (stageIndex > -1) {
|
|
112
|
-
const nextStages = [...stages]
|
|
113
|
-
nextStages[stageIndex] = stage
|
|
114
|
-
return ModularFactory(methods).build(nextStages)<Props>(
|
|
115
|
-
displayName,
|
|
116
|
-
)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Otherwise, append the stage
|
|
120
|
-
return ModularFactory(methods).build([...stages, stage])<Props>(
|
|
121
|
-
displayName,
|
|
122
|
-
)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// @ts-ignore
|
|
126
|
-
Component[`add${method}`] =
|
|
127
|
-
stageIndices.length < 1
|
|
128
|
-
? undefined
|
|
129
|
-
: (value: unknown) => {
|
|
130
|
-
// Prepare the new stage
|
|
131
|
-
const stage = {
|
|
132
|
-
stage: methods[method].symbol,
|
|
133
|
-
value,
|
|
134
|
-
} as const
|
|
135
|
-
|
|
136
|
-
// Append the stage as in multiple mode
|
|
137
|
-
return ModularFactory(methods).build([
|
|
138
|
-
...stages,
|
|
139
|
-
stage,
|
|
140
|
-
])<Props>(displayName)
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// @ts-ignore
|
|
144
|
-
Component[`at${method}`] =
|
|
145
|
-
stageIndices.length < 1
|
|
146
|
-
? undefined
|
|
147
|
-
: (forceIndex?: number) => {
|
|
148
|
-
// Find the needed stage
|
|
149
|
-
const stageIndex =
|
|
150
|
-
(forceIndex !== undefined
|
|
151
|
-
? stageIndices[forceIndex]
|
|
152
|
-
: lastIndex) ?? lastIndex
|
|
153
|
-
|
|
154
|
-
// Otherwise, keep all stages up to and including the found stage
|
|
155
|
-
return ModularFactory<Methods>(methods).build(
|
|
156
|
-
stages.slice(0, stageIndex + 1),
|
|
157
|
-
)<Props>(displayName)
|
|
158
|
-
}
|
|
1
|
+
import React, {
|
|
2
|
+
ForwardRefRenderFunction,
|
|
3
|
+
FunctionComponent,
|
|
4
|
+
PropsWithChildren,
|
|
5
|
+
} from 'react'
|
|
6
|
+
|
|
7
|
+
export interface ModularStage<
|
|
8
|
+
Field extends string,
|
|
9
|
+
Stage extends (args: any, ref?: any) => any,
|
|
10
|
+
> {
|
|
11
|
+
field: Field
|
|
12
|
+
useStage: Stage
|
|
13
|
+
}
|
|
159
14
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
15
|
+
export type FunctionComponentOrRefRenderFunction<Props, Ref> = [Ref] extends [
|
|
16
|
+
never,
|
|
17
|
+
]
|
|
18
|
+
? FunctionComponent<PropsWithChildren<Props>>
|
|
19
|
+
: ForwardRefRenderFunction<Ref, Props>
|
|
20
|
+
|
|
21
|
+
export type ModularComponent<
|
|
22
|
+
Props extends {},
|
|
23
|
+
Ref,
|
|
24
|
+
Args extends { render: ReturnType<FunctionComponent> },
|
|
25
|
+
> = FunctionComponentOrRefRenderFunction<Props, Ref> & {
|
|
26
|
+
with<Field extends string, Type>(stage: {
|
|
27
|
+
field: Field
|
|
28
|
+
useStage: (
|
|
29
|
+
args: Args,
|
|
30
|
+
ref: React.ForwardedRef<Ref>,
|
|
31
|
+
) => Field extends keyof Args ? Args[Field] : Type
|
|
32
|
+
}): ModularComponent<
|
|
33
|
+
Props,
|
|
34
|
+
Ref,
|
|
35
|
+
{
|
|
36
|
+
[key in keyof Args | Field]: key extends 'render'
|
|
37
|
+
? ReturnType<FunctionComponent>
|
|
38
|
+
: key extends Field
|
|
39
|
+
? Type
|
|
40
|
+
: key extends keyof Args
|
|
41
|
+
? Args[key]
|
|
42
|
+
: never
|
|
43
|
+
}
|
|
44
|
+
>
|
|
45
|
+
force<Field extends string, Type>(stage: {
|
|
46
|
+
field: Field
|
|
47
|
+
useStage: (
|
|
48
|
+
args: Args,
|
|
49
|
+
ref: React.ForwardedRef<Ref>,
|
|
50
|
+
) => Field extends 'render' ? Args['render'] : Type
|
|
51
|
+
}): ModularComponent<
|
|
52
|
+
Props,
|
|
53
|
+
Ref,
|
|
54
|
+
{
|
|
55
|
+
[key in keyof Args | Field]: key extends 'render'
|
|
56
|
+
? ReturnType<FunctionComponent>
|
|
57
|
+
: key extends Field
|
|
58
|
+
? Type
|
|
59
|
+
: key extends keyof Args
|
|
60
|
+
? Args[key]
|
|
61
|
+
: never
|
|
62
|
+
}
|
|
63
|
+
>
|
|
64
|
+
use<Field extends keyof Args>(
|
|
65
|
+
key: Field,
|
|
66
|
+
): {} extends Props ? () => Args[Field] : (props: PropsWithChildren<Props>) => Args[Field]
|
|
67
|
+
use(): {} extends Props ? () => Args : (props: PropsWithChildren<Props>) => Args
|
|
68
|
+
stage<Field extends keyof Args>(
|
|
69
|
+
key: Field,
|
|
70
|
+
): (args: Partial<Args>) => Args[Field]
|
|
71
|
+
setDisplayName(displayName: string): ModularComponent<Props, Ref, Args>
|
|
72
|
+
}
|
|
171
73
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
74
|
+
function InternalFactory<
|
|
75
|
+
Props extends {},
|
|
76
|
+
Ref,
|
|
77
|
+
Args extends { render: ReturnType<FunctionComponent> },
|
|
78
|
+
>(
|
|
79
|
+
stages: ModularStage<
|
|
80
|
+
string,
|
|
81
|
+
(args: Args, ref: React.ForwardedRef<Ref>) => any
|
|
82
|
+
>[],
|
|
83
|
+
): ModularComponent<Props, Ref, Args> {
|
|
84
|
+
const useComponent = function (props: Props, ref: React.ForwardedRef<Ref>) {
|
|
85
|
+
if (!stages.some((stage) => stage.field === 'render')) {
|
|
86
|
+
stages = [...stages, render(() => null)]
|
|
87
|
+
}
|
|
88
|
+
return useComponent.use('render')(props, ref)
|
|
89
|
+
}
|
|
177
90
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
nextStages[stageIndex] = stage
|
|
181
|
-
return ModularFactory(methods).build(nextStages)<Props>(
|
|
182
|
-
displayName,
|
|
183
|
-
)
|
|
184
|
-
}
|
|
91
|
+
useComponent.with = (stage: ModularStage<string, (args: Args) => any>) => {
|
|
92
|
+
const index = stages.findIndex((s) => s.field === stage.field)
|
|
185
93
|
|
|
186
|
-
|
|
187
|
-
|
|
94
|
+
if (index !== -1) {
|
|
95
|
+
const next = [...stages]
|
|
96
|
+
next[index] = stage
|
|
97
|
+
return InternalFactory<Props, Ref, Args>(next)
|
|
98
|
+
}
|
|
188
99
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
100
|
+
return InternalFactory<Props, Ref, Args>([...stages, stage])
|
|
101
|
+
}
|
|
102
|
+
useComponent.force = useComponent.with
|
|
103
|
+
|
|
104
|
+
useComponent.use =
|
|
105
|
+
(field: keyof Args) => (props: Props, ref: React.ForwardedRef<Ref>) => {
|
|
106
|
+
const args: Record<string, any> = { props }
|
|
107
|
+
const index = field
|
|
108
|
+
? stages.findIndex((stage) => stage.field === field)
|
|
109
|
+
: false
|
|
110
|
+
|
|
111
|
+
if (index === false) {
|
|
112
|
+
for (let stage of stages) {
|
|
113
|
+
args[stage.field] = stage.useStage(args as Args, ref)
|
|
114
|
+
}
|
|
115
|
+
return args
|
|
116
|
+
}
|
|
193
117
|
|
|
194
|
-
|
|
118
|
+
const argStages =
|
|
119
|
+
index === -1 ? stages.slice(0) : stages.slice(0, index + 1)
|
|
120
|
+
const returnStage = argStages.pop()
|
|
121
|
+
for (let stage of argStages) {
|
|
122
|
+
args[stage.field] = stage.useStage(args as Args, ref)
|
|
195
123
|
}
|
|
124
|
+
return returnStage?.useStage(args as Args, ref) ?? null
|
|
125
|
+
}
|
|
196
126
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
127
|
+
useComponent.stage = (field: keyof Args) => {
|
|
128
|
+
const stage = stages.find((stage) => stage.field === field)
|
|
129
|
+
return stage?.useStage ?? (() => null)
|
|
130
|
+
}
|
|
200
131
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
extend: <_Methods extends Record<string, MethodRecord>>(
|
|
204
|
-
_methods: _Methods,
|
|
205
|
-
) => {
|
|
206
|
-
return ModularFactory<Methods & _Methods>({
|
|
207
|
-
...methods,
|
|
208
|
-
..._methods,
|
|
209
|
-
})
|
|
210
|
-
},
|
|
132
|
+
useComponent.setDisplayName = (displayName: string) => {
|
|
133
|
+
;(useComponent as any).displayName = displayName
|
|
211
134
|
}
|
|
212
|
-
}
|
|
213
135
|
|
|
214
|
-
|
|
136
|
+
return useComponent as unknown as ModularComponent<Props, Ref, Args>
|
|
137
|
+
}
|
|
215
138
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
139
|
+
export function ModularComponent<Props extends {} = {}, Ref = never>(
|
|
140
|
+
displayName?: string,
|
|
141
|
+
): ModularComponent<
|
|
142
|
+
Props,
|
|
143
|
+
Ref,
|
|
144
|
+
{ props: Props; render: ReturnType<FunctionComponent> }
|
|
145
|
+
> {
|
|
146
|
+
const useComponent = InternalFactory<
|
|
147
|
+
Props,
|
|
148
|
+
Ref,
|
|
149
|
+
{ props: Props; render: ReturnType<FunctionComponent> }
|
|
150
|
+
>([])
|
|
151
|
+
useComponent.displayName = displayName
|
|
152
|
+
return useComponent
|
|
225
153
|
}
|
|
226
154
|
|
|
227
|
-
export
|
|
228
|
-
|
|
229
|
-
|
|
155
|
+
export function render<Args extends {}, Ref>(
|
|
156
|
+
render: (
|
|
157
|
+
args: Args,
|
|
158
|
+
ref: React.ForwardedRef<Ref>,
|
|
159
|
+
) => React.ReactElement<any, any> | null,
|
|
160
|
+
): ModularStage<
|
|
161
|
+
'render',
|
|
162
|
+
(
|
|
163
|
+
args: Args,
|
|
164
|
+
ref: React.ForwardedRef<Ref>,
|
|
165
|
+
) => React.ReactElement<any, any> | null
|
|
166
|
+
> {
|
|
167
|
+
return {
|
|
230
168
|
field: 'render',
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
} as const)
|
|
234
|
-
|
|
235
|
-
export function createMethodRecord<R extends Record<string, MethodRecord>>(
|
|
236
|
-
record: R,
|
|
237
|
-
): R {
|
|
238
|
-
return record
|
|
169
|
+
useStage: render,
|
|
170
|
+
}
|
|
239
171
|
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helpers for computing the arguments map generated by a given
|
|
3
|
-
* set of stages
|
|
4
|
-
*/
|
|
5
|
-
import { PropsWithChildren } from 'react';
|
|
6
|
-
import { StageTuple, ModularStages, BeforeStage, CleanUpStages } from './stage';
|
|
7
|
-
import { UnionToIntersection } from './utils';
|
|
8
|
-
export declare type ComputeArguments<Props extends {}, Ref, Methods extends Record<string, {
|
|
9
|
-
symbol: keyof ModularStages;
|
|
10
|
-
field: string;
|
|
11
|
-
}>, Stages extends StageTuple, CleanedStages extends StageTuple = CleanUpStages<Stages>, MethodList = Methods[keyof Methods]> = {
|
|
12
|
-
props: Props extends {
|
|
13
|
-
children: unknown;
|
|
14
|
-
} ? Props : PropsWithChildren<Props>;
|
|
15
|
-
ref: Ref;
|
|
16
|
-
children: Props extends {
|
|
17
|
-
children: infer C;
|
|
18
|
-
} ? C : PropsWithChildren['children'];
|
|
19
|
-
} & (Stages['length'] extends 0 ? {} : UnionToIntersection<{
|
|
20
|
-
[key in keyof CleanedStages]: MethodList extends {
|
|
21
|
-
symbol: CleanedStages[key]['stage'];
|
|
22
|
-
field: infer F;
|
|
23
|
-
} ? {
|
|
24
|
-
[k in F extends string ? F : never]: ModularStages<ComputeArguments<Props, Ref, Methods, BeforeStage<CleanedStages, key>>, CleanedStages[key]['value']>[CleanedStages[key]['stage']] extends {
|
|
25
|
-
transform: infer T;
|
|
26
|
-
} ? T : CleanedStages[key]['value'];
|
|
27
|
-
} : never;
|
|
28
|
-
}[number]>) extends infer U ? {
|
|
29
|
-
[key in keyof U]: U[key] extends Record<string, unknown> ? U[key] extends infer V ? {
|
|
30
|
-
[key in keyof V]: V[key];
|
|
31
|
-
} : never : U[key];
|
|
32
|
-
} : never;
|
|
33
|
-
//# sourceMappingURL=arguments.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"arguments.d.ts","sourceRoot":"","sources":["../../src/types/arguments.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAE7C,oBAAY,gBAAgB,CAC1B,KAAK,SAAS,EAAE,EAChB,GAAG,EACH,OAAO,SAAS,MAAM,CACpB,MAAM,EACN;IAAE,MAAM,EAAE,MAAM,aAAa,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAC/C,EACD,MAAM,SAAS,UAAU,EACzB,aAAa,SAAS,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,EACxD,UAAU,GAAG,OAAO,CAAC,MAAM,OAAO,CAAC,IACjC;IACF,KAAK,EAAE,KAAK,SAAS;QAAE,QAAQ,EAAE,OAAO,CAAA;KAAE,GAAG,KAAK,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAA;IAC7E,GAAG,EAAE,GAAG,CAAA;IACR,QAAQ,EAAE,KAAK,SAAS;QAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;KAAE,GACzC,CAAC,GACD,iBAAiB,CAAC,UAAU,CAAC,CAAA;CAClC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,GAC3B,EAAE,GACF,mBAAmB,CACjB;KACG,GAAG,IAAI,MAAM,aAAa,GAAG,UAAU,SAAS;QAC/C,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAA;QACnC,KAAK,EAAE,MAAM,CAAC,CAAA;KACf,GACG;SACG,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG,CAAC,GAAG,KAAK,GAAG,aAAa,CAChD,gBAAgB,CACd,KAAK,EACL,GAAG,EACH,OAAO,EACP,WAAW,CAAC,aAAa,EAAE,GAAG,CAAC,CAChC,EACD,aAAa,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAC5B,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS;YAAE,SAAS,EAAE,MAAM,CAAC,CAAA;SAAE,GACzD,CAAC,GACD,aAAa,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;KAChC,GACD,KAAK;CACV,CAAC,MAAM,CAAC,CACV,CAAC,SAAS,MAAM,CAAC,GAClB;KACG,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACpD,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,GACpB;SAAG,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC;KAAE,GAC5B,KAAK,GACP,CAAC,CAAC,GAAG,CAAC;CACX,GACD,KAAK,CAAA"}
|
package/dist/types/arguments.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"arguments.js","sourceRoot":"","sources":["../../src/types/arguments.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Methods for adding a new entry for a previous stage, rather
|
|
3
|
-
* than reusing the previous one.
|
|
4
|
-
* One two entries for the same stage have been added, `with`, `at` and
|
|
5
|
-
* `mock` methods can take an optional index to select the entry to target
|
|
6
|
-
*/
|
|
7
|
-
import { ModularComponent } from '../modular-component';
|
|
8
|
-
import { AddStage, ModularStages, StageIndices, StageTuple } from '../stage';
|
|
9
|
-
import { ComputeArguments } from '../arguments';
|
|
10
|
-
import { RestrictValue } from '../validation';
|
|
11
|
-
import { MethodRecord } from '../methods';
|
|
12
|
-
import { FilterNever } from '../utils';
|
|
13
|
-
interface ModularAddMethod<Props extends {}, Ref, Methods extends Record<string, MethodRecord>, Stages extends StageTuple, Method extends keyof Methods, Symbol extends keyof ModularStages = Methods[Method]['symbol']> {
|
|
14
|
-
<Value extends RestrictValue<Arguments, Symbol>, Arguments extends ComputeArguments<Props, Ref, Methods, Stages>>(...args: undefined extends RestrictValue<Arguments, Symbol> ? [value?: Value] : [value: Value]): ModularComponent<Props, Ref, Methods, AddStage<Stages, {
|
|
15
|
-
stage: Symbol;
|
|
16
|
-
value: Value;
|
|
17
|
-
}>>;
|
|
18
|
-
}
|
|
19
|
-
export declare type ModularAddMethods<Props extends {}, Ref, Methods extends Record<string, MethodRecord>, Stages extends StageTuple> = FilterNever<{
|
|
20
|
-
[Method in keyof Methods as `add${Method extends string ? Method : never}`]: StageIndices<Stages, Methods[Method]['symbol']>['length'] extends 0 ? never : ModularAddMethod<Props, Ref, Methods, Stages, Method>;
|
|
21
|
-
}>;
|
|
22
|
-
export {};
|
|
23
|
-
//# sourceMappingURL=add.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"add.d.ts","sourceRoot":"","sources":["../../../src/types/methods/add.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,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AA"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Methods for adding a new entry for a previous stage, rather
|
|
3
|
-
* than reusing the previous one.
|
|
4
|
-
* One two entries for the same stage have been added, `with`, `at` and
|
|
5
|
-
* `mock` methods can take an optional index to select the entry to target
|
|
6
|
-
*/
|
|
7
|
-
export {};
|
|
8
|
-
//# sourceMappingURL=add.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"add.js","sourceRoot":"","sources":["../../../src/types/methods/add.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Methods for rewinding a modular component up to a given stage.
|
|
3
|
-
* If multiple entries of the same stage were previously added,
|
|
4
|
-
* it's possible to pass the index for the entry to rewind to.
|
|
5
|
-
*/
|
|
6
|
-
import { ModularComponent } from '../modular-component';
|
|
7
|
-
import { AtStage, StageIndices, StageTuple } from '../stage';
|
|
8
|
-
import { FilterNever, Last, ToIndices } from '../utils';
|
|
9
|
-
import { ValidateIndex } from '../validation';
|
|
10
|
-
import { MethodRecord } from '../methods';
|
|
11
|
-
interface ModularAtMethodIndices<Props extends {}, Ref, Methods extends Record<string, MethodRecord>, Stages extends StageTuple, Method extends keyof Methods, Indices extends number[]> {
|
|
12
|
-
<StageIndex extends Index extends number ? Indices[Index] : Last<Indices>, ValidIndex extends ValidateIndex<Index, ToIndices<Indices>>, Index extends number>(index: ValidIndex extends true ? Index : ToIndices<Indices>): ModularComponent<Props, Ref, Methods, AtStage<Stages, StageIndex>>;
|
|
13
|
-
}
|
|
14
|
-
interface ModularAtMethodLast<Props extends {}, Ref, Methods extends Record<string, MethodRecord>, Stages extends StageTuple, Method extends keyof Methods, Index extends number> {
|
|
15
|
-
(): ModularComponent<Props, Ref, Methods, AtStage<Stages, Index>>;
|
|
16
|
-
}
|
|
17
|
-
declare type ModularAtMethod<Props extends {}, Ref, Methods extends Record<string, MethodRecord>, Stages extends StageTuple, Method extends keyof Methods, Symbol extends symbol = Methods[Method]['symbol'], Indices extends StageIndices<Stages, Symbol> = StageIndices<Stages, Symbol>> = Indices['length'] extends 0 ? never : ModularAtMethodIndices<Props, Ref, Methods, Stages, Method, Indices> & ModularAtMethodLast<Props, Ref, Methods, Stages, Method, Last<Indices>>;
|
|
18
|
-
export declare type ModularAtMethods<Props extends {}, Ref, Methods extends Record<string, MethodRecord>, Stages extends StageTuple> = FilterNever<{
|
|
19
|
-
[Method in keyof Methods as `at${Method extends string ? Method : never}`]: ModularAtMethod<Props, Ref, Methods, Stages, Method>;
|
|
20
|
-
}>;
|
|
21
|
-
export {};
|
|
22
|
-
//# sourceMappingURL=at.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"at.d.ts","sourceRoot":"","sources":["../../../src/types/methods/at.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEzC,UAAU,sBAAsB,CAC9B,KAAK,SAAS,EAAE,EAChB,GAAG,EACH,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,EAC5C,MAAM,SAAS,UAAU,EACzB,MAAM,SAAS,MAAM,OAAO,EAC5B,OAAO,SAAS,MAAM,EAAE;IAExB,CAEE,UAAU,SAAS,KAAK,SAAS,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,EACxE,UAAU,SAAS,aAAa,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,CA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YAAY,CAAC,EAC5C,MAAM,SAAS,UAAU,IACvB,WAAW,CAAC;KACb,MAAM,IAAI,MAAM,OAAO,IAAI,KAAK,MAAM,SAAS,MAAM,GAClD,MAAM,GACN,KAAK,EAAE,GAAG,eAAe,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC;CACnE,CAAC,CAAA"}
|
package/dist/types/methods/at.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"at.js","sourceRoot":"","sources":["../../../src/types/methods/at.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Methods for converting a modular component to hooks, either
|
|
3
|
-
* a generic hook returning all the arguments, or a specific hook
|
|
4
|
-
* returning one given argument.
|
|
5
|
-
*/
|
|
6
|
-
import { StageTuple } from '../stage';
|
|
7
|
-
import { MethodRecord } from '../methods';
|
|
8
|
-
import { ComputeArguments } from '../arguments';
|
|
9
|
-
export declare type ModularHookMethods<Props extends {}, Ref, Methods extends Record<string, MethodRecord>, Stages extends StageTuple, Arguments extends {} = ComputeArguments<Props, Ref, Methods, Stages>> = {
|
|
10
|
-
asHook(): keyof Props extends never ? () => Arguments : (props: Props) => Arguments;
|
|
11
|
-
} & {
|
|
12
|
-
[Arg in keyof Arguments as `asUse${Capitalize<Arg extends string ? Arg : never>}`]: keyof Props extends never ? () => () => Arguments[Arg] : () => (props: Props) => Arguments[Arg];
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=hook.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../../../src/types/methods/hook.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAE/C,oBAAY,kBAAkB,CAC5B,KAAK,SAAS,EAAE,EAChB,GAAG,EACH,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,EAC5C,MAAM,SAAS,UAAU,EACzB,SAAS,SAAS,EAAE,GAAG,gBAAgB,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,IAClE;IACF,MAAM,IAAI,MAAM,KAAK,SAAS,KAAK,GAC/B,MAAM,SAAS,GACf,CAAC,KAAK,EAAE,KAAK,KAAK,SAAS,CAAA;CAChC,GAAG;KACD,GAAG,IAAI,MAAM,SAAS,IAAI,QAAQ,UAAU,CAC3C,GAAG,SAAS,MAAM,GAAG,GAAG,GAAG,KAAK,CACjC,EAAE,GAAG,MAAM,KAAK,SAAS,KAAK,GAC3B,MAAM,MAAM,SAAS,CAAC,GAAG,CAAC,GAC1B,MAAM,CAAC,KAAK,EAAE,KAAK,KAAK,SAAS,CAAC,GAAG,CAAC;CAC3C,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hook.js","sourceRoot":"","sources":["../../../src/types/methods/hook.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Methods for mocking the value returned by a given stage,
|
|
3
|
-
* replacing the stage and bypassing its transform function
|
|
4
|
-
*/
|
|
5
|
-
import { ModularComponent } from '../modular-component';
|
|
6
|
-
import { MethodRecord } from '../methods';
|
|
7
|
-
import { ValidateIndex } from '../validation';
|
|
8
|
-
import { ComputeArguments } from '../arguments';
|
|
9
|
-
import { FilterNever, Last, ToIndices } from '../utils';
|
|
10
|
-
import { BeforeStage, ModularStages, StageIndices, StageTuple } from '../stage';
|
|
11
|
-
interface ModularMockMethodIndices<Props extends {}, Ref, Methods extends Record<string, MethodRecord>, Stages extends StageTuple, Method extends keyof Methods, Indices extends number[], Symbol extends keyof ModularStages = Methods[Method]['symbol']> {
|
|
12
|
-
<Arguments extends ComputeArguments<Props, Ref, Methods, BeforeStage<Stages, StageIndex>>, Value extends Stages[StageIndex]['value'], Mock extends ModularStages<Arguments, Value>[Symbol] extends {
|
|
13
|
-
transform: infer T;
|
|
14
|
-
} ? T : Value, StageIndex extends Index extends number ? Indices[Index] : Last<Indices>, ValidIndex extends ValidateIndex<Index, ToIndices<Indices>>, Index extends number>(mock: Mock, index: ValidIndex extends true ? Index : ToIndices<Indices>): ModularComponent<Props, Ref, Methods, Stages>;
|
|
15
|
-
}
|
|
16
|
-
interface ModularMockMethodLast<Props extends {}, Ref, Methods extends Record<string, MethodRecord>, Stages extends StageTuple, Method extends keyof Methods, Index extends number, Symbol extends keyof ModularStages = Methods[Method]['symbol']> {
|
|
17
|
-
<Value extends Stages[Index]['value'], Mock extends ModularStages<any, Value>[Symbol] extends {
|
|
18
|
-
transform: infer T;
|
|
19
|
-
} ? T : Value>(mock: Mock): ModularComponent<Props, Ref, Methods, Stages>;
|
|
20
|
-
}
|
|
21
|
-
declare type ModularMockMethod<Props extends {}, Ref, Methods extends Record<string, MethodRecord>, Stages extends StageTuple, Method extends keyof Methods, Symbol extends keyof ModularStages = Methods[Method]['symbol'], Indices extends StageIndices<Stages, Symbol> = StageIndices<Stages, Symbol>> = Indices['length'] extends 0 ? never : ModularMockMethodIndices<Props, Ref, Methods, Stages, Method, Indices> & ModularMockMethodLast<Props, Ref, Methods, Stages, Method, Last<Indices>>;
|
|
22
|
-
export declare type ModularMockMethods<Props extends {}, Ref, Methods extends Record<string, MethodRecord>, Stages extends StageTuple> = FilterNever<{
|
|
23
|
-
[Method in keyof Methods as `mock${Method extends string ? Method : never}`]: ModularMockMethod<Props, Ref, Methods, Stages, Method>;
|
|
24
|
-
}>;
|
|
25
|
-
export {};
|
|
26
|
-
//# sourceMappingURL=mock.d.ts.map
|