@modular-component/with-conditional-render 0.1.2 → 0.1.4
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 +16 -0
- package/dist/index.d.ts +23 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -16
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +32 -24
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @modular-component/with-conditional-render
|
|
2
2
|
|
|
3
|
+
## 0.1.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 820a836: Refactor tuple system for better typescript performance
|
|
8
|
+
- Updated dependencies [f7af9ea]
|
|
9
|
+
- Updated dependencies [820a836]
|
|
10
|
+
- @modular-component/core@0.1.4
|
|
11
|
+
|
|
12
|
+
## 0.1.3
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [d5c9031]
|
|
17
|
+
- @modular-component/core@0.1.3
|
|
18
|
+
|
|
3
19
|
## 0.1.2
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,40 +1,47 @@
|
|
|
1
1
|
import { FunctionComponent } from 'react';
|
|
2
|
+
declare const withCondition: unique symbol;
|
|
2
3
|
declare const withConditionalFallback: unique symbol;
|
|
3
4
|
declare const withConditionalRender: unique symbol;
|
|
5
|
+
declare module '@modular-component/core' {
|
|
6
|
+
interface ModularStages<Args, Value> {
|
|
7
|
+
[withCondition]: {
|
|
8
|
+
restrict: (args: Args) => boolean;
|
|
9
|
+
transform: ReturnType<Value extends (args: Args) => boolean ? Value : never>;
|
|
10
|
+
};
|
|
11
|
+
[withConditionalFallback]: {
|
|
12
|
+
restrict: FunctionComponent<Args>;
|
|
13
|
+
transform: ReturnType<FunctionComponent<Args>> | null;
|
|
14
|
+
};
|
|
15
|
+
[withConditionalRender]: {
|
|
16
|
+
restrict: FunctionComponent<Args>;
|
|
17
|
+
transform: ReturnType<FunctionComponent<Args>> | null;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
4
21
|
export declare const WithConditionalRender: {
|
|
5
|
-
readonly
|
|
22
|
+
readonly Condition: {
|
|
23
|
+
readonly symbol: typeof withCondition;
|
|
6
24
|
readonly field: "condition";
|
|
7
|
-
readonly multiple: true;
|
|
8
25
|
readonly transform: <A extends {
|
|
9
26
|
condition?: boolean | undefined;
|
|
10
27
|
}, C extends (args: A) => boolean>(args: A, useCondition: C) => boolean;
|
|
11
|
-
readonly restrict: boolean;
|
|
12
28
|
};
|
|
13
|
-
readonly
|
|
29
|
+
readonly ConditionalRender: {
|
|
30
|
+
readonly symbol: typeof withConditionalRender;
|
|
14
31
|
readonly field: "render";
|
|
15
|
-
readonly multiple: true;
|
|
16
|
-
readonly symbol: typeof withConditionalFallback;
|
|
17
32
|
readonly transform: <A_1 extends {
|
|
18
33
|
condition?: boolean | undefined;
|
|
19
34
|
render?: import("react").ReactElement<any, any> | null | undefined;
|
|
20
35
|
}, P extends FunctionComponent<A_1>>(args: A_1, useRender: P) => import("react").ReactElement<any, any> | null | undefined;
|
|
21
|
-
readonly restrict: import("react").ReactElement<any, any> | null;
|
|
22
36
|
};
|
|
23
|
-
readonly
|
|
37
|
+
readonly ConditionalFallback: {
|
|
38
|
+
readonly symbol: typeof withConditionalFallback;
|
|
24
39
|
readonly field: "render";
|
|
25
|
-
readonly symbol: typeof withConditionalRender;
|
|
26
40
|
readonly transform: <A_2 extends {
|
|
27
41
|
condition?: boolean | undefined;
|
|
28
42
|
render?: import("react").ReactElement<any, any> | null | undefined;
|
|
29
43
|
}, P_1 extends FunctionComponent<A_2>>(args: A_2, useRender: P_1) => import("react").ReactElement<any, any> | null | undefined;
|
|
30
|
-
readonly restrict: import("react").ReactElement<any, any> | null;
|
|
31
44
|
};
|
|
32
45
|
};
|
|
33
|
-
declare module '@modular-component/core' {
|
|
34
|
-
interface ModularStageTransform<T> {
|
|
35
|
-
[withConditionalFallback]: T | null;
|
|
36
|
-
[withConditionalRender]: T | null;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
46
|
export {};
|
|
40
47
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAEzC,QAAA,MAAM,aAAa,eAAW,CAAA;AAC9B,QAAA,MAAM,uBAAuB,eAAW,CAAA;AACxC,QAAA,MAAM,qBAAqB,eAAW,CAAA;AAEtC,OAAO,QAAQ,yBAAyB,CAAC;IACvC,UAAiB,aAAa,CAAC,IAAI,EAAE,KAAK;QACxC,CAAC,aAAa,CAAC,EAAE;YACf,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAA;YACjC,SAAS,EAAE,UAAU,CACnB,KAAK,SAAS,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,GAAG,KAAK,GAAG,KAAK,CACtD,CAAA;SACF,CAAA;QACD,CAAC,uBAAuB,CAAC,EAAE;YACzB,QAAQ,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAA;YACjC,SAAS,EAAE,UAAU,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAA;SACtD,CAAA;QACD,CAAC,qBAAqB,CAAC,EAAE;YACvB,QAAQ,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAA;YACjC,SAAS,EAAE,UAAU,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAA;SACtD,CAAA;KACF;CACF;AAED,eAAO,MAAM,qBAAqB;;;;;;kCAML,OAAO;;;;;;;;;;;;;;;;;;CAwCzB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,36 +1,32 @@
|
|
|
1
1
|
import { createMethodRecord } from '@modular-component/core';
|
|
2
|
+
const withCondition = Symbol();
|
|
2
3
|
const withConditionalFallback = Symbol();
|
|
3
4
|
const withConditionalRender = Symbol();
|
|
4
5
|
export const WithConditionalRender = createMethodRecord({
|
|
5
|
-
|
|
6
|
+
Condition: {
|
|
7
|
+
symbol: withCondition,
|
|
6
8
|
field: 'condition',
|
|
7
|
-
|
|
8
|
-
transform: (args, useCondition) => args.condition !== false &&
|
|
9
|
-
(typeof useCondition === 'function' ? useCondition(args) : useCondition),
|
|
10
|
-
restrict: {},
|
|
9
|
+
transform: (args, useCondition) => args.condition !== false && useCondition(args),
|
|
11
10
|
},
|
|
12
|
-
|
|
11
|
+
ConditionalRender: {
|
|
12
|
+
symbol: withConditionalRender,
|
|
13
13
|
field: 'render',
|
|
14
|
-
multiple: true,
|
|
15
|
-
symbol: withConditionalFallback,
|
|
16
14
|
transform: (args, useRender) => {
|
|
17
|
-
if (args.condition
|
|
15
|
+
if (args.condition === false) {
|
|
18
16
|
return args.render;
|
|
19
17
|
}
|
|
20
|
-
return
|
|
18
|
+
return useRender(args);
|
|
21
19
|
},
|
|
22
|
-
restrict: {},
|
|
23
20
|
},
|
|
24
|
-
|
|
21
|
+
ConditionalFallback: {
|
|
22
|
+
symbol: withConditionalFallback,
|
|
25
23
|
field: 'render',
|
|
26
|
-
symbol: withConditionalRender,
|
|
27
24
|
transform: (args, useRender) => {
|
|
28
|
-
if (args.condition
|
|
25
|
+
if (args.condition !== false || args.render) {
|
|
29
26
|
return args.render;
|
|
30
27
|
}
|
|
31
|
-
return
|
|
28
|
+
return useRender(args);
|
|
32
29
|
},
|
|
33
|
-
restrict: {},
|
|
34
30
|
},
|
|
35
31
|
});
|
|
36
32
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAI5D,MAAM,aAAa,GAAG,MAAM,EAAE,CAAA;AAC9B,MAAM,uBAAuB,GAAG,MAAM,EAAE,CAAA;AACxC,MAAM,qBAAqB,GAAG,MAAM,EAAE,CAAA;AAqBtC,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;IACtD,SAAS,EAAE;QACT,MAAM,EAAE,aAAa;QACrB,KAAK,EAAE,WAAW;QAClB,SAAS,EAAE,CAIT,IAAO,EACP,YAAe,EACf,EAAE,CAAC,IAAI,CAAC,SAAS,KAAK,KAAK,IAAI,YAAY,CAAC,IAAI,CAAC;KACpD;IACD,iBAAiB,EAAE;QACjB,MAAM,EAAE,qBAAqB;QAC7B,KAAK,EAAE,QAAQ;QACf,SAAS,EAAE,CAIT,IAAO,EACP,SAAY,EACZ,EAAE;YACF,IAAI,IAAI,CAAC,SAAS,KAAK,KAAK,EAAE;gBAC5B,OAAO,IAAI,CAAC,MAAM,CAAA;aACnB;YAED,OAAO,SAAS,CAAC,IAAI,CAAC,CAAA;QACxB,CAAC;KACF;IACD,mBAAmB,EAAE;QACnB,MAAM,EAAE,uBAAuB;QAC/B,KAAK,EAAE,QAAQ;QACf,SAAS,EAAE,CAIT,IAAO,EACP,SAAY,EACZ,EAAE;YACF,IAAI,IAAI,CAAC,SAAS,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;gBAC3C,OAAO,IAAI,CAAC,MAAM,CAAA;aACnB;YAED,OAAO,SAAS,CAAC,IAAI,CAAC,CAAA;QACxB,CAAC;KACF;CACO,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"Default",
|
|
9
9
|
"Conditional"
|
|
10
10
|
],
|
|
11
|
-
"version": "0.1.
|
|
11
|
+
"version": "0.1.4",
|
|
12
12
|
"type": "module",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"publishConfig": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"license": "cp ../../LICENSE ./LICENSE"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@modular-component/core": "0.1.
|
|
29
|
+
"@modular-component/core": "0.1.4"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"react": ">=17 <19"
|
package/src/index.ts
CHANGED
|
@@ -1,28 +1,45 @@
|
|
|
1
1
|
import { createMethodRecord } from '@modular-component/core'
|
|
2
|
+
|
|
2
3
|
import { FunctionComponent } from 'react'
|
|
3
4
|
|
|
5
|
+
const withCondition = Symbol()
|
|
4
6
|
const withConditionalFallback = Symbol()
|
|
5
7
|
const withConditionalRender = Symbol()
|
|
6
8
|
|
|
9
|
+
declare module '@modular-component/core' {
|
|
10
|
+
export interface ModularStages<Args, Value> {
|
|
11
|
+
[withCondition]: {
|
|
12
|
+
restrict: (args: Args) => boolean
|
|
13
|
+
transform: ReturnType<
|
|
14
|
+
Value extends (args: Args) => boolean ? Value : never
|
|
15
|
+
>
|
|
16
|
+
}
|
|
17
|
+
[withConditionalFallback]: {
|
|
18
|
+
restrict: FunctionComponent<Args>
|
|
19
|
+
transform: ReturnType<FunctionComponent<Args>> | null
|
|
20
|
+
}
|
|
21
|
+
[withConditionalRender]: {
|
|
22
|
+
restrict: FunctionComponent<Args>
|
|
23
|
+
transform: ReturnType<FunctionComponent<Args>> | null
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
7
28
|
export const WithConditionalRender = createMethodRecord({
|
|
8
|
-
|
|
29
|
+
Condition: {
|
|
30
|
+
symbol: withCondition,
|
|
9
31
|
field: 'condition',
|
|
10
|
-
multiple: true,
|
|
11
32
|
transform: <
|
|
12
33
|
A extends { condition?: boolean },
|
|
13
34
|
C extends (args: A) => boolean,
|
|
14
35
|
>(
|
|
15
36
|
args: A,
|
|
16
37
|
useCondition: C,
|
|
17
|
-
) =>
|
|
18
|
-
args.condition !== false &&
|
|
19
|
-
(typeof useCondition === 'function' ? useCondition(args) : useCondition),
|
|
20
|
-
restrict: {} as boolean,
|
|
38
|
+
) => args.condition !== false && useCondition(args),
|
|
21
39
|
},
|
|
22
|
-
|
|
40
|
+
ConditionalRender: {
|
|
41
|
+
symbol: withConditionalRender,
|
|
23
42
|
field: 'render',
|
|
24
|
-
multiple: true,
|
|
25
|
-
symbol: withConditionalFallback,
|
|
26
43
|
transform: <
|
|
27
44
|
A extends { condition?: boolean; render?: ReturnType<FunctionComponent> },
|
|
28
45
|
P extends FunctionComponent<A>,
|
|
@@ -30,17 +47,16 @@ export const WithConditionalRender = createMethodRecord({
|
|
|
30
47
|
args: A,
|
|
31
48
|
useRender: P,
|
|
32
49
|
) => {
|
|
33
|
-
if (args.condition
|
|
50
|
+
if (args.condition === false) {
|
|
34
51
|
return args.render
|
|
35
52
|
}
|
|
36
53
|
|
|
37
|
-
return
|
|
54
|
+
return useRender(args)
|
|
38
55
|
},
|
|
39
|
-
restrict: {} as ReturnType<FunctionComponent>,
|
|
40
56
|
},
|
|
41
|
-
|
|
57
|
+
ConditionalFallback: {
|
|
58
|
+
symbol: withConditionalFallback,
|
|
42
59
|
field: 'render',
|
|
43
|
-
symbol: withConditionalRender,
|
|
44
60
|
transform: <
|
|
45
61
|
A extends { condition?: boolean; render?: ReturnType<FunctionComponent> },
|
|
46
62
|
P extends FunctionComponent<A>,
|
|
@@ -48,19 +64,11 @@ export const WithConditionalRender = createMethodRecord({
|
|
|
48
64
|
args: A,
|
|
49
65
|
useRender: P,
|
|
50
66
|
) => {
|
|
51
|
-
if (args.condition
|
|
67
|
+
if (args.condition !== false || args.render) {
|
|
52
68
|
return args.render
|
|
53
69
|
}
|
|
54
70
|
|
|
55
|
-
return
|
|
71
|
+
return useRender(args)
|
|
56
72
|
},
|
|
57
|
-
restrict: {} as ReturnType<FunctionComponent>,
|
|
58
73
|
},
|
|
59
74
|
} as const)
|
|
60
|
-
|
|
61
|
-
declare module '@modular-component/core' {
|
|
62
|
-
export interface ModularStageTransform<T> {
|
|
63
|
-
[withConditionalFallback]: T | null
|
|
64
|
-
[withConditionalRender]: T | null
|
|
65
|
-
}
|
|
66
|
-
}
|