@modular-component/core 0.1.7 → 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.
Files changed (67) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/index.d.ts +31 -354
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +53 -157
  5. package/dist/index.js.map +1 -1
  6. package/package.json +2 -2
  7. package/src/index.ts +155 -240
  8. package/dist/types/arguments.d.ts +0 -33
  9. package/dist/types/arguments.d.ts.map +0 -1
  10. package/dist/types/arguments.js +0 -6
  11. package/dist/types/arguments.js.map +0 -1
  12. package/dist/types/methods/add.d.ts +0 -23
  13. package/dist/types/methods/add.d.ts.map +0 -1
  14. package/dist/types/methods/add.js +0 -8
  15. package/dist/types/methods/add.js.map +0 -1
  16. package/dist/types/methods/at.d.ts +0 -22
  17. package/dist/types/methods/at.d.ts.map +0 -1
  18. package/dist/types/methods/at.js +0 -7
  19. package/dist/types/methods/at.js.map +0 -1
  20. package/dist/types/methods/before.d.ts +0 -22
  21. package/dist/types/methods/before.d.ts.map +0 -1
  22. package/dist/types/methods/before.js +0 -7
  23. package/dist/types/methods/before.js.map +0 -1
  24. package/dist/types/methods/hook.d.ts +0 -14
  25. package/dist/types/methods/hook.d.ts.map +0 -1
  26. package/dist/types/methods/hook.js +0 -7
  27. package/dist/types/methods/hook.js.map +0 -1
  28. package/dist/types/methods/mock.d.ts +0 -26
  29. package/dist/types/methods/mock.d.ts.map +0 -1
  30. package/dist/types/methods/mock.js +0 -6
  31. package/dist/types/methods/mock.js.map +0 -1
  32. package/dist/types/methods/with.d.ts +0 -52
  33. package/dist/types/methods/with.d.ts.map +0 -1
  34. package/dist/types/methods/with.js +0 -8
  35. package/dist/types/methods/with.js.map +0 -1
  36. package/dist/types/methods.d.ts +0 -10
  37. package/dist/types/methods.d.ts.map +0 -1
  38. package/dist/types/methods.js +0 -5
  39. package/dist/types/methods.js.map +0 -1
  40. package/dist/types/modular-component.d.ts +0 -16
  41. package/dist/types/modular-component.d.ts.map +0 -1
  42. package/dist/types/modular-component.js +0 -5
  43. package/dist/types/modular-component.js.map +0 -1
  44. package/dist/types/stage.d.ts +0 -41
  45. package/dist/types/stage.d.ts.map +0 -1
  46. package/dist/types/stage.js +0 -5
  47. package/dist/types/stage.js.map +0 -1
  48. package/dist/types/utils.d.ts +0 -24
  49. package/dist/types/utils.d.ts.map +0 -1
  50. package/dist/types/utils.js +0 -5
  51. package/dist/types/utils.js.map +0 -1
  52. package/dist/types/validation.d.ts +0 -4
  53. package/dist/types/validation.d.ts.map +0 -1
  54. package/dist/types/validation.js +0 -2
  55. package/dist/types/validation.js.map +0 -1
  56. package/src/types/arguments.ts +0 -57
  57. package/src/types/methods/add.ts +0 -52
  58. package/src/types/methods/at.ts +0 -64
  59. package/src/types/methods/before.ts +0 -64
  60. package/src/types/methods/hook.ts +0 -27
  61. package/src/types/methods/mock.ts +0 -90
  62. package/src/types/methods/with.ts +0 -173
  63. package/src/types/methods.ts +0 -11
  64. package/src/types/modular-component.ts +0 -27
  65. package/src/types/stage.ts +0 -91
  66. package/src/types/utils.ts +0 -63
  67. package/src/types/validation.ts +0 -13
package/src/index.ts CHANGED
@@ -1,256 +1,171 @@
1
- import { ForwardedRef, FunctionComponent, forwardRef, memo } from 'react'
2
-
3
- import { ModularComponent } from './types/modular-component'
4
- import { MethodRecord } from './types/methods'
5
- import { StageTuple } from './types/stage'
6
-
7
- export type { ModularStages } from './types/stage'
8
-
9
- function ModularFactory<Methods extends Record<string, MethodRecord>>(
10
- methods: Methods,
11
- ) {
12
- type CleanMethods = Methods extends infer U
13
- ? { [key in keyof U]: U[key] }
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
- }
159
-
160
- // @ts-ignore
161
- Component[`before${method}`] =
162
- stageIndices.length < 1
163
- ? undefined
164
- : (forceIndex?: number) => {
165
- // Find the needed stage
166
- const stageIndex =
167
- (forceIndex !== undefined
168
- ? stageIndices[forceIndex]
169
- : lastIndex) ?? lastIndex
170
-
171
- // Otherwise, keep all stages up to but excluding the found stage
172
- return ModularFactory<Methods>(methods).build(
173
- stages.slice(0, stageIndex),
174
- )<Props>(displayName)
175
- }
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
+ }
176
14
 
177
- // @ts-ignore
178
- Component[`mock${method}`] =
179
- stageIndices.length < 1
180
- ? () => Component as unknown
181
- : (value: unknown, forceIndex?: number) => {
182
- // Prepare the mocked stage
183
- const stage = {
184
- stage: methods[method].symbol,
185
- value,
186
- mocked: true,
187
- } as const
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
+ }
188
73
 
189
- // Find the needed stage
190
- const stageIndex =
191
- (forceIndex !== undefined
192
- ? stageIndices[forceIndex]
193
- : lastIndex) ?? lastIndex
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
+ }
194
90
 
195
- // Replace the stage with its mock
196
- const nextStages = [...stages]
197
- nextStages[stageIndex] = stage
198
- return ModularFactory(methods).build(nextStages)<Props>(
199
- displayName,
200
- )
201
- }
91
+ useComponent.with = (stage: ModularStage<string, (args: Args) => any>) => {
92
+ const index = stages.findIndex((s) => s.field === stage.field)
202
93
 
203
- const capitalize = (str: string) =>
204
- str[0].toUpperCase() + str.slice(1)
94
+ if (index !== -1) {
95
+ const next = [...stages]
96
+ next[index] = stage
97
+ return InternalFactory<Props, Ref, Args>(next)
98
+ }
205
99
 
206
- // @ts-ignore
207
- Component[`asUse${capitalize(methods[method].field)}`] =
208
- generateAsHook(undefined, methods[method].field)
209
- })
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
+ }
210
117
 
211
- return (options?.memo ? memo(Component) : Component) as typeof Component
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)
212
123
  }
124
+ return returnStage?.useStage(args as Args, ref) ?? null
125
+ }
213
126
 
214
- factory.memo = <Props extends {} = {}, Ref = FunctionComponent<Props>>(
215
- displayName?: string,
216
- ) => factory<Props, Ref>(displayName, { memo: true })
127
+ useComponent.stage = (field: keyof Args) => {
128
+ const stage = stages.find((stage) => stage.field === field)
129
+ return stage?.useStage ?? (() => null)
130
+ }
217
131
 
218
- return factory
219
- },
220
- extend: <_Methods extends Record<string, MethodRecord>>(
221
- _methods: _Methods,
222
- ) => {
223
- return ModularFactory<Methods & _Methods>({
224
- ...methods,
225
- ..._methods,
226
- })
227
- },
132
+ useComponent.setDisplayName = (displayName: string) => {
133
+ ;(useComponent as any).displayName = displayName
228
134
  }
229
- }
230
135
 
231
- const withRender = Symbol()
136
+ return useComponent as unknown as ModularComponent<Props, Ref, Args>
137
+ }
232
138
 
233
- declare module './types/stage' {
234
- export interface ModularStages<Args, Value> {
235
- [withRender]: {
236
- restrict: FunctionComponent<Args>
237
- transform: ReturnType<
238
- Value extends FunctionComponent<Args> ? Value : never
239
- >
240
- }
241
- }
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
242
153
  }
243
154
 
244
- export const modularFactory = ModularFactory({
245
- Render: {
246
- symbol: withRender,
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 {
247
168
  field: 'render',
248
- transform: (args, useStage) => useStage(args),
249
- },
250
- } as const)
251
-
252
- export function createMethodRecord<R extends Record<string, MethodRecord>>(
253
- record: R,
254
- ): R {
255
- return record
169
+ useStage: render,
170
+ }
256
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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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"}
@@ -1,6 +0,0 @@
1
- /**
2
- * Helpers for computing the arguments map generated by a given
3
- * set of stages
4
- */
5
- export {};
6
- //# sourceMappingURL=arguments.js.map
@@ -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,MAAM,YAAY,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEtC,UAAU,gBAAgB,CACxB,KAAK,SAAS,EAAE,EAChB,GAAG,EACH,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,EAC5C,MAAM,SAAS,UAAU,EACzB,MAAM,SAAS,MAAM,OAAO,EAC5B,MAAM,SAAS,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC;IAE9D,CACE,KAAK,SAAS,aAAa,CAAC,SAAS,EAAE,MAAM,CAAC,EAC9C,SAAS,SAAS,gBAAgB,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,EAE/D,GAAG,IAAI,EAAE,SAAS,SAAS,aAAa,CAAC,SAAS,EAAE,MAAM,CAAC,GACvD,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,GACf,CAAC,KAAK,EAAE,KAAK,CAAC,GACjB,gBAAgB,CACjB,KAAK,EACL,GAAG,EACH,OAAO,EACP,QAAQ,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC,CAClD,CAAA;CACF;AAED,oBAAY,iBAAiB,CAC3B,KAAK,SAAS,EAAE,EAChB,GAAG,EACH,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,EAC5C,MAAM,SAAS,UAAU,IACvB,WAAW,CAAC;KACb,MAAM,IAAI,MAAM,OAAO,IAAI,MAAM,MAAM,SAAS,MAAM,GACnD,MAAM,GACN,KAAK,EAAE,GAAG,YAAY,CACxB,MAAM,EACN,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAC1B,CAAC,QAAQ,CAAC,SAAS,CAAC,GACjB,KAAK,GACL,gBAAgB,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC;CAC1D,CAAC,CAAA"}
@@ -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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AAM,SAAS,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EACjD,OAAO,SAAS,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,IACzE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,GAC3B,KAAK,GACL,sBAAsB,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,GAClE,mBAAmB,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;AAE7E,oBAAY,gBAAgB,CAC1B,KAAK,SAAS,EAAE,EAChB,GAAG,EACH,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,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"}
@@ -1,7 +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
- export {};
7
- //# sourceMappingURL=at.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"at.js","sourceRoot":"","sources":["../../../src/types/methods/at.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -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 { BeforeStage, StageIndices, StageTuple } from '../stage';
8
- import { FilterNever, Last, ToIndices } from '../utils';
9
- import { ValidateIndex } from '../validation';
10
- import { MethodRecord } from '../methods';
11
- interface ModularBeforeMethodIndices<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, BeforeStage<Stages, StageIndex>>;
13
- }
14
- interface ModularBeforeMethodLast<Props extends {}, Ref, Methods extends Record<string, MethodRecord>, Stages extends StageTuple, Method extends keyof Methods, Index extends number> {
15
- (): ModularComponent<Props, Ref, Methods, BeforeStage<Stages, Index>>;
16
- }
17
- declare type ModularBeforeMethod<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 : ModularBeforeMethodIndices<Props, Ref, Methods, Stages, Method, Indices> & ModularBeforeMethodLast<Props, Ref, Methods, Stages, Method, Last<Indices>>;
18
- export declare type ModularBeforeMethods<Props extends {}, Ref, Methods extends Record<string, MethodRecord>, Stages extends StageTuple> = FilterNever<{
19
- [Method in keyof Methods as `before${Method extends string ? Method : never}`]: ModularBeforeMethod<Props, Ref, Methods, Stages, Method>;
20
- }>;
21
- export {};
22
- //# sourceMappingURL=before.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"before.d.ts","sourceRoot":"","sources":["../../../src/types/methods/before.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAChE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA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C,EACjD,OAAO,SAAS,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,IACzE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,GAC3B,KAAK,GACL,0BAA0B,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,GACtE,uBAAuB,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;AAEjF,oBAAY,oBAAoB,CAC9B,KAAK,SAAS,EAAE,EAChB,GAAG,EACH,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,EAC5C,MAAM,SAAS,UAAU,IACvB,WAAW,CAAC;KACb,MAAM,IAAI,MAAM,OAAO,IAAI,SAAS,MAAM,SAAS,MAAM,GACtD,MAAM,GACN,KAAK,EAAE,GAAG,mBAAmB,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC;CACvE,CAAC,CAAA"}
@@ -1,7 +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
- export {};
7
- //# sourceMappingURL=before.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"before.js","sourceRoot":"","sources":["../../../src/types/methods/before.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,7 +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
- export {};
7
- //# sourceMappingURL=hook.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hook.js","sourceRoot":"","sources":["../../../src/types/methods/hook.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}