@contember/react-binding 1.3.0-alpha.25 → 1.3.0-alpha.26
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/development/helperComponents/If.cjs +22 -19
- package/dist/development/helperComponents/If.cjs.map +1 -1
- package/dist/development/helperComponents/If.js +22 -19
- package/dist/development/helperComponents/If.js.map +1 -1
- package/dist/production/helperComponents/If.cjs +9 -6
- package/dist/production/helperComponents/If.cjs.map +1 -1
- package/dist/production/helperComponents/If.js +9 -6
- package/dist/production/helperComponents/If.js.map +1 -1
- package/dist/types/accessorPropagation/useEntityListSubTreeLoader.d.ts +1 -1
- package/dist/types/accessorPropagation/useEntityListSubTreeLoader.d.ts.map +1 -1
- package/dist/types/accessorPropagation/useGetEntityListSubTree.d.ts +2 -2
- package/dist/types/accessorPropagation/useGetEntityListSubTree.d.ts.map +1 -1
- package/dist/types/accessorPropagation/useGetEntitySubTree.d.ts +2 -2
- package/dist/types/accessorPropagation/useGetEntitySubTree.d.ts.map +1 -1
- package/dist/types/coreComponents/DataBindingProvider.d.ts.map +1 -1
- package/dist/types/coreComponents/EntityList.d.ts.map +1 -1
- package/dist/types/coreComponents/EntityListSubTree.d.ts.map +1 -1
- package/dist/types/coreComponents/EntitySubTree.d.ts.map +1 -1
- package/dist/types/coreComponents/Field.d.ts.map +1 -1
- package/dist/types/coreComponents/HasMany.d.ts.map +1 -1
- package/dist/types/coreComponents/HasOne.d.ts.map +1 -1
- package/dist/types/entityEvents/useDerivedField.d.ts.map +1 -1
- package/dist/types/helperComponents/If.d.ts +4 -0
- package/dist/types/helperComponents/If.d.ts.map +1 -1
- package/dist/types/helperComponents/LabelMiddleware.d.ts.map +1 -1
- package/dist/types/helperComponents/SugaredField.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -11
- package/src/helperComponents/If.tsx +15 -10
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/react-binding",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "1.3.0-alpha.
|
|
4
|
+
"version": "1.3.0-alpha.26",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/production/index.js",
|
|
@@ -35,22 +35,22 @@
|
|
|
35
35
|
"test": "vitest"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@contember/binding": "1.3.0-alpha.
|
|
39
|
-
"@contember/client": "1.3.0-alpha.
|
|
40
|
-
"@contember/react-client": "1.3.0-alpha.
|
|
41
|
-
"@contember/react-multipass-rendering": "1.3.0-alpha.
|
|
42
|
-
"@contember/react-utils": "1.3.0-alpha.
|
|
43
|
-
"@contember/utilities": "1.3.0-alpha.
|
|
38
|
+
"@contember/binding": "1.3.0-alpha.26",
|
|
39
|
+
"@contember/client": "1.3.0-alpha.26",
|
|
40
|
+
"@contember/react-client": "1.3.0-alpha.26",
|
|
41
|
+
"@contember/react-multipass-rendering": "1.3.0-alpha.26",
|
|
42
|
+
"@contember/react-utils": "1.3.0-alpha.26",
|
|
43
|
+
"@contember/utilities": "1.3.0-alpha.26"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"react": "^
|
|
47
|
-
"react-dom": "^
|
|
46
|
+
"react": "^18 || ^19",
|
|
47
|
+
"react-dom": "^18 || ^19"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/js-levenshtein": "1.1.3",
|
|
51
51
|
"@types/uuid": "9.0.7",
|
|
52
|
-
"react": "^18.
|
|
53
|
-
"react-dom": "^18.
|
|
52
|
+
"react": "^18.3.1",
|
|
53
|
+
"react-dom": "^18.3.1"
|
|
54
54
|
},
|
|
55
55
|
"stableVersion": "0.0.0"
|
|
56
56
|
}
|
|
@@ -15,30 +15,37 @@ export type IfProps =
|
|
|
15
15
|
export interface IfFilterProps {
|
|
16
16
|
condition: string | Filter
|
|
17
17
|
children?: ReactNode
|
|
18
|
+
then?: ReactNode
|
|
19
|
+
else?: ReactNode
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
export interface IfCallbackProps {
|
|
21
23
|
condition: (accessor: EntityAccessor) => boolean
|
|
22
24
|
children?: ReactNode
|
|
25
|
+
then?: ReactNode
|
|
26
|
+
else?: ReactNode
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
/**
|
|
26
30
|
* @group Logic Components
|
|
27
31
|
*/
|
|
28
|
-
export const If = Component<IfProps>(props => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
export const If = Component<IfProps>(({ condition, ...props }) => {
|
|
33
|
+
if (props.children && props.then) {
|
|
34
|
+
throw new Error('If component cannot have both children and then prop')
|
|
35
|
+
}
|
|
36
|
+
return typeof condition !== 'function'
|
|
37
|
+
? <IfFilter condition={condition} {...props} />
|
|
38
|
+
: <IfCallback condition={condition} {...props} />
|
|
32
39
|
},
|
|
33
40
|
'If',
|
|
34
41
|
)
|
|
35
42
|
|
|
36
43
|
const IfCallback = Component<IfCallbackProps>(
|
|
37
|
-
({ children, condition }) => {
|
|
44
|
+
({ children, condition, then, else: elseIn }) => {
|
|
38
45
|
const entity = useEntity()
|
|
39
46
|
const evaluated = useMemo(() => condition(entity), [condition, entity])
|
|
40
47
|
|
|
41
|
-
return evaluated ?
|
|
48
|
+
return <>{evaluated ? (children ?? then) : elseIn}</>
|
|
42
49
|
},
|
|
43
50
|
({ children }) => {
|
|
44
51
|
return <>{children}</>
|
|
@@ -47,7 +54,7 @@ const IfCallback = Component<IfCallbackProps>(
|
|
|
47
54
|
)
|
|
48
55
|
|
|
49
56
|
const IfFilter = Component<IfFilterProps>(
|
|
50
|
-
({ children, condition }) => {
|
|
57
|
+
({ children, condition, then, else: elseIn }) => {
|
|
51
58
|
const env = useEnvironment()
|
|
52
59
|
const entity = useEntity()
|
|
53
60
|
|
|
@@ -56,8 +63,7 @@ const IfFilter = Component<IfFilterProps>(
|
|
|
56
63
|
() => new FilterEvaluator(schema).evaluateFilter(entity, QueryLanguage.desugarFilter(condition, env)),
|
|
57
64
|
[condition, entity, env, schema],
|
|
58
65
|
)
|
|
59
|
-
|
|
60
|
-
return evaluated ? <>{children}</> : null
|
|
66
|
+
return <>{evaluated ? (children ?? then) : elseIn}</>
|
|
61
67
|
},
|
|
62
68
|
({ children, condition }, env) => {
|
|
63
69
|
const desugaredFilter = QueryLanguage.desugarFilter(condition, env)
|
|
@@ -71,4 +77,3 @@ const IfFilter = Component<IfFilterProps>(
|
|
|
71
77
|
},
|
|
72
78
|
'IfFilter',
|
|
73
79
|
)
|
|
74
|
-
|