@contember/react-binding 1.3.0-alpha.25 → 1.3.0-alpha.27

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 (29) hide show
  1. package/dist/development/helperComponents/If.cjs +22 -19
  2. package/dist/development/helperComponents/If.cjs.map +1 -1
  3. package/dist/development/helperComponents/If.js +22 -19
  4. package/dist/development/helperComponents/If.js.map +1 -1
  5. package/dist/production/helperComponents/If.cjs +9 -6
  6. package/dist/production/helperComponents/If.cjs.map +1 -1
  7. package/dist/production/helperComponents/If.js +9 -6
  8. package/dist/production/helperComponents/If.js.map +1 -1
  9. package/dist/types/accessorPropagation/useEntityListSubTreeLoader.d.ts +1 -1
  10. package/dist/types/accessorPropagation/useEntityListSubTreeLoader.d.ts.map +1 -1
  11. package/dist/types/accessorPropagation/useGetEntityListSubTree.d.ts +2 -2
  12. package/dist/types/accessorPropagation/useGetEntityListSubTree.d.ts.map +1 -1
  13. package/dist/types/accessorPropagation/useGetEntitySubTree.d.ts +2 -2
  14. package/dist/types/accessorPropagation/useGetEntitySubTree.d.ts.map +1 -1
  15. package/dist/types/coreComponents/DataBindingProvider.d.ts.map +1 -1
  16. package/dist/types/coreComponents/EntityList.d.ts.map +1 -1
  17. package/dist/types/coreComponents/EntityListSubTree.d.ts.map +1 -1
  18. package/dist/types/coreComponents/EntitySubTree.d.ts.map +1 -1
  19. package/dist/types/coreComponents/Field.d.ts.map +1 -1
  20. package/dist/types/coreComponents/HasMany.d.ts.map +1 -1
  21. package/dist/types/coreComponents/HasOne.d.ts.map +1 -1
  22. package/dist/types/entityEvents/useDerivedField.d.ts.map +1 -1
  23. package/dist/types/helperComponents/If.d.ts +4 -0
  24. package/dist/types/helperComponents/If.d.ts.map +1 -1
  25. package/dist/types/helperComponents/LabelMiddleware.d.ts.map +1 -1
  26. package/dist/types/helperComponents/SugaredField.d.ts.map +1 -1
  27. package/dist/types/tsconfig.tsbuildinfo +1 -1
  28. package/package.json +11 -11
  29. 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.25",
4
+ "version": "1.3.0-alpha.27",
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.25",
39
- "@contember/client": "1.3.0-alpha.25",
40
- "@contember/react-client": "1.3.0-alpha.25",
41
- "@contember/react-multipass-rendering": "1.3.0-alpha.25",
42
- "@contember/react-utils": "1.3.0-alpha.25",
43
- "@contember/utilities": "1.3.0-alpha.25"
38
+ "@contember/binding": "1.3.0-alpha.27",
39
+ "@contember/client": "1.3.0-alpha.27",
40
+ "@contember/react-client": "1.3.0-alpha.27",
41
+ "@contember/react-multipass-rendering": "1.3.0-alpha.27",
42
+ "@contember/react-utils": "1.3.0-alpha.27",
43
+ "@contember/utilities": "1.3.0-alpha.27"
44
44
  },
45
45
  "peerDependencies": {
46
- "react": "^17 || ^18",
47
- "react-dom": "^17 || ^18"
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.2.0",
53
- "react-dom": "^18.2.0"
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
- return typeof props.condition !== 'function'
30
- ? <IfFilter condition={props.condition}>{props.children}</IfFilter>
31
- : <IfCallback condition={props.condition}>{props.children}</IfCallback>
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 ? <>{children}</> : null
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
-