@contember/binding 1.2.0-alpha.0 → 1.2.0-alpha.1

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 (101) hide show
  1. package/dist/development/accessorTree/AccessorTree.js +2 -2
  2. package/dist/development/accessorTree/AccessorTree.js.map +1 -1
  3. package/dist/development/coreComponents/DataBindingProvider.js.map +1 -1
  4. package/dist/development/coreComponents/Entity.js.map +1 -1
  5. package/dist/development/coreComponents/EntityList.js.map +1 -1
  6. package/dist/development/coreComponents/EntityListSubTree.js.map +1 -1
  7. package/dist/development/coreComponents/EntitySubTree.js.map +1 -1
  8. package/dist/development/coreComponents/Field.js.map +1 -1
  9. package/dist/development/coreComponents/HasMany.js.map +1 -1
  10. package/dist/development/coreComponents/HasOne.js.map +1 -1
  11. package/dist/development/coreComponents/ParentEntity.js.map +1 -1
  12. package/dist/development/helperComponents/DeferredSubTrees.js.map +1 -1
  13. package/dist/development/helperComponents/EntityView.js.map +1 -1
  14. package/dist/development/helperComponents/FieldView.js.map +1 -1
  15. package/dist/development/helperComponents/If.js.map +1 -1
  16. package/dist/development/helperComponents/StaticRender.js.map +1 -1
  17. package/dist/development/helperComponents/SugaredField.js.map +1 -1
  18. package/dist/development/helperComponents/helpers/evaluateCondition.js.map +1 -1
  19. package/dist/development/treeParameters/LeafField.js.map +1 -1
  20. package/dist/production/accessorTree/AccessorTree.js +2 -2
  21. package/dist/production/accessorTree/AccessorTree.js.map +1 -1
  22. package/dist/production/coreComponents/DataBindingProvider.js.map +1 -1
  23. package/dist/production/coreComponents/Entity.js.map +1 -1
  24. package/dist/production/coreComponents/EntityList.js.map +1 -1
  25. package/dist/production/coreComponents/EntityListSubTree.js.map +1 -1
  26. package/dist/production/coreComponents/EntitySubTree.js.map +1 -1
  27. package/dist/production/coreComponents/Field.js.map +1 -1
  28. package/dist/production/coreComponents/HasMany.js.map +1 -1
  29. package/dist/production/coreComponents/HasOne.js.map +1 -1
  30. package/dist/production/coreComponents/ParentEntity.js.map +1 -1
  31. package/dist/production/helperComponents/DeferredSubTrees.js.map +1 -1
  32. package/dist/production/helperComponents/EntityView.js.map +1 -1
  33. package/dist/production/helperComponents/FieldView.js.map +1 -1
  34. package/dist/production/helperComponents/If.js.map +1 -1
  35. package/dist/production/helperComponents/StaticRender.js.map +1 -1
  36. package/dist/production/helperComponents/SugaredField.js.map +1 -1
  37. package/dist/production/helperComponents/helpers/evaluateCondition.js.map +1 -1
  38. package/dist/production/treeParameters/LeafField.js.map +1 -1
  39. package/dist/types/accessorTree/AccessorTree.d.ts +7 -4
  40. package/dist/types/accessorTree/AccessorTree.d.ts.map +1 -1
  41. package/dist/types/coreComponents/DataBindingProvider.d.ts +10 -0
  42. package/dist/types/coreComponents/DataBindingProvider.d.ts.map +1 -1
  43. package/dist/types/coreComponents/Entity.d.ts +3 -0
  44. package/dist/types/coreComponents/Entity.d.ts.map +1 -1
  45. package/dist/types/coreComponents/EntityList.d.ts +3 -0
  46. package/dist/types/coreComponents/EntityList.d.ts.map +1 -1
  47. package/dist/types/coreComponents/EntityListSubTree.d.ts +10 -0
  48. package/dist/types/coreComponents/EntityListSubTree.d.ts.map +1 -1
  49. package/dist/types/coreComponents/EntitySubTree.d.ts +10 -0
  50. package/dist/types/coreComponents/EntitySubTree.d.ts.map +1 -1
  51. package/dist/types/coreComponents/Field.d.ts +3 -0
  52. package/dist/types/coreComponents/Field.d.ts.map +1 -1
  53. package/dist/types/coreComponents/HasMany.d.ts +3 -0
  54. package/dist/types/coreComponents/HasMany.d.ts.map +1 -1
  55. package/dist/types/coreComponents/HasOne.d.ts +3 -0
  56. package/dist/types/coreComponents/HasOne.d.ts.map +1 -1
  57. package/dist/types/coreComponents/ParentEntity.d.ts +3 -0
  58. package/dist/types/coreComponents/ParentEntity.d.ts.map +1 -1
  59. package/dist/types/helperComponents/DeferredSubTrees.d.ts +3 -0
  60. package/dist/types/helperComponents/DeferredSubTrees.d.ts.map +1 -1
  61. package/dist/types/helperComponents/EntityView.d.ts +3 -0
  62. package/dist/types/helperComponents/EntityView.d.ts.map +1 -1
  63. package/dist/types/helperComponents/FieldView.d.ts +13 -0
  64. package/dist/types/helperComponents/FieldView.d.ts.map +1 -1
  65. package/dist/types/helperComponents/If.d.ts +3 -0
  66. package/dist/types/helperComponents/If.d.ts.map +1 -1
  67. package/dist/types/helperComponents/StaticRender.d.ts +3 -0
  68. package/dist/types/helperComponents/StaticRender.d.ts.map +1 -1
  69. package/dist/types/helperComponents/SugaredField.d.ts +3 -0
  70. package/dist/types/helperComponents/SugaredField.d.ts.map +1 -1
  71. package/dist/types/treeParameters/FieldEventListeners.d.ts +5 -2
  72. package/dist/types/treeParameters/FieldEventListeners.d.ts.map +1 -1
  73. package/dist/types/treeParameters/LeafField.d.ts +2 -2
  74. package/dist/types/treeParameters/LeafField.d.ts.map +1 -1
  75. package/dist/types/treeParameters/QualifiedFieldList.d.ts +7 -8
  76. package/dist/types/treeParameters/QualifiedFieldList.d.ts.map +1 -1
  77. package/dist/types/treeParameters/RelativeSingleField.d.ts +8 -8
  78. package/dist/types/treeParameters/RelativeSingleField.d.ts.map +1 -1
  79. package/dist/types/tsconfig.tsbuildinfo +1 -1
  80. package/package.json +5 -5
  81. package/src/accessorTree/AccessorTree.tsx +4 -1
  82. package/src/coreComponents/DataBindingProvider.tsx +10 -0
  83. package/src/coreComponents/Entity.tsx +3 -0
  84. package/src/coreComponents/EntityList.tsx +3 -0
  85. package/src/coreComponents/EntityListSubTree.tsx +10 -0
  86. package/src/coreComponents/EntitySubTree.tsx +10 -0
  87. package/src/coreComponents/Field.tsx +3 -0
  88. package/src/coreComponents/HasMany.tsx +3 -0
  89. package/src/coreComponents/HasOne.tsx +3 -0
  90. package/src/coreComponents/ParentEntity.tsx +3 -0
  91. package/src/helperComponents/DeferredSubTrees.tsx +3 -0
  92. package/src/helperComponents/EntityView.tsx +3 -0
  93. package/src/helperComponents/FieldView.tsx +13 -0
  94. package/src/helperComponents/If.tsx +3 -0
  95. package/src/helperComponents/StaticRender.tsx +3 -0
  96. package/src/helperComponents/SugaredField.tsx +3 -0
  97. package/src/helperComponents/helpers/evaluateCondition.ts +1 -1
  98. package/src/treeParameters/FieldEventListeners.ts +15 -5
  99. package/src/treeParameters/LeafField.ts +6 -4
  100. package/src/treeParameters/QualifiedFieldList.ts +24 -17
  101. package/src/treeParameters/RelativeSingleField.ts +19 -12
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@contember/binding",
3
3
  "license": "Apache-2.0",
4
- "version": "1.2.0-alpha.0",
4
+ "version": "1.2.0-alpha.1",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "main": "./dist/production/index.js",
@@ -28,10 +28,10 @@
28
28
  "test": "vitest"
29
29
  },
30
30
  "dependencies": {
31
- "@contember/client": "1.2.0-alpha.0",
32
- "@contember/react-client": "1.2.0-alpha.0",
33
- "@contember/react-multipass-rendering": "1.2.0-alpha.0",
34
- "@contember/react-utils": "1.2.0-alpha.0",
31
+ "@contember/client": "1.2.0-alpha.1",
32
+ "@contember/react-client": "1.2.0-alpha.1",
33
+ "@contember/react-multipass-rendering": "1.2.0-alpha.1",
34
+ "@contember/react-utils": "1.2.0-alpha.1",
35
35
  "chevrotain": "6.5.0",
36
36
  "fast-deep-equal": "^3.1.3",
37
37
  "js-levenshtein": "1.1.6",
@@ -10,7 +10,10 @@ export interface AccessorTreeProps {
10
10
  children: ReactNode
11
11
  }
12
12
 
13
- export function AccessorTree({ state, children }: AccessorTreeProps) {
13
+ /**
14
+ * @group Data binding
15
+ */
16
+ export const AccessorTree = ({ state, children }: AccessorTreeProps) => {
14
17
  const stateData = state.name === 'initialized' ? state.data : {
15
18
  hasUnpersistedChanges: false,
16
19
  isMutating: false,
@@ -18,6 +18,16 @@ export type DataBindingProviderProps<StateProps> = DataBindingProviderBaseProps
18
18
  }
19
19
  )
20
20
 
21
+ /**
22
+ * The `DataBindingProvider` is a root component for all other data binding related components.
23
+ *
24
+ * @example
25
+ * ```
26
+ * <DataBindingProvider stateComponent={FeedbackRenderer} />
27
+ * ```
28
+ *
29
+ * @group Data binding
30
+ */
21
31
  export const DataBindingProvider = memo(function DataBindingProvider<StateProps extends DataBindingStateComponentProps>(
22
32
  props: DataBindingProviderProps<StateProps>,
23
33
  ) {
@@ -10,6 +10,9 @@ export interface EntityBaseProps {
10
10
 
11
11
  export type EntityProps = EntityBaseProps
12
12
 
13
+ /**
14
+ * @group Data binding
15
+ */
13
16
  export const Entity = Component(
14
17
  ({ children, accessor }: EntityProps) => {
15
18
  return (
@@ -17,6 +17,9 @@ export type EntityListProps<ListProps> = EntityListBaseProps &
17
17
  }
18
18
  )
19
19
 
20
+ /**
21
+ * @group Data binding
22
+ */
20
23
  export const EntityList = Component(
21
24
  <ListProps extends {}>(props: EntityListProps<ListProps>) => {
22
25
  if ('listComponent' in props && props.listComponent) {
@@ -31,6 +31,16 @@ export type EntityListSubTreeProps<ListProps, EntityProps> = {
31
31
  }
32
32
  )
33
33
 
34
+ /**
35
+ * Creates a subtree with list of entities in current data binding context.
36
+ *
37
+ * @example
38
+ * ```
39
+ * <EntityListSubTree entities="Post" />
40
+ * ```
41
+ *
42
+ * @group Data binding
43
+ */
34
44
  export const EntityListSubTree = Component(
35
45
  <ListProps, EntityProps>(props: EntityListSubTreeProps<ListProps, EntityProps>) => {
36
46
  useConstantValueInvariant(props.isCreating, 'EntityListSubTree: cannot update isCreating')
@@ -32,6 +32,16 @@ export type EntitySubTreeProps<EntityProps> =
32
32
  | (SugaredUnconstrainedQualifiedSingleEntity & EntitySubTreeAdditionalCreationProps)
33
33
  )
34
34
 
35
+ /**
36
+ * Creates a single entity subtree in current data binding context.
37
+ *
38
+ * @example
39
+ * ```
40
+ * <EntitySubTree entity="Post(id = $id)" />
41
+ * ```
42
+ *
43
+ * @group Data binding
44
+ */
35
45
  export const EntitySubTree = Component(
36
46
  <EntityProps extends {}>(props: EntitySubTreeProps<EntityProps>) => {
37
47
  useConstantValueInvariant(props.isCreating, 'EntitySubTree: cannot update isCreating')
@@ -16,6 +16,9 @@ export interface FieldProps<Persisted extends FieldValue = FieldValue>
16
16
  extends FieldBasicProps,
17
17
  FieldRuntimeProps<Persisted> {}
18
18
 
19
+ /**
20
+ * @group Data binding
21
+ */
19
22
  export const Field = Component(
20
23
  <Persisted extends FieldValue = FieldValue>(props: FieldProps<Persisted>) => {
21
24
  const field = useField<Persisted>(props)
@@ -20,6 +20,9 @@ export type HasManyProps<ListProps = never, EntityProps = never> = SugaredRelati
20
20
  }
21
21
  )
22
22
 
23
+ /**
24
+ * @group Data binding
25
+ */
23
26
  export const HasMany = Component(
24
27
  <ListProps, EntityProps>(props: HasManyProps<ListProps, EntityProps>) => {
25
28
  const entityList = useEntityList(props)
@@ -14,6 +14,9 @@ export type HasOneProps<EntityProps = never> = SugaredRelativeSingleEntity & {
14
14
  variables?: Environment.ValuesMapWithFactory
15
15
  }
16
16
 
17
+ /**
18
+ * @group Data binding
19
+ */
17
20
  export const HasOne = Component(
18
21
  <EntityProps extends {}>(props: HasOneProps<EntityProps>) => {
19
22
  const entity = useEntity(props)
@@ -7,6 +7,9 @@ export interface ParentEntityProps extends SugaredParentEntityParameters {
7
7
  children?: ReactNode
8
8
  }
9
9
 
10
+ /**
11
+ * @group Data binding
12
+ */
10
13
  export const ParentEntity = Component<ParentEntityProps>(
11
14
  props => <>{props.children}</>,
12
15
  {
@@ -22,6 +22,9 @@ type LoadState =
22
22
  treeRootId: TreeRootId | undefined
23
23
  }
24
24
 
25
+ /**
26
+ * @group Data binding
27
+ */
25
28
  export const DeferredSubTrees = Component<DeferredSubTreesProps>(
26
29
  props => {
27
30
  const { extendTree } = useBindingOperations()
@@ -8,6 +8,9 @@ export interface EntityViewProps {
8
8
  field?: string | SugaredRelativeSingleEntity
9
9
  }
10
10
 
11
+ /**
12
+ * @group Data binding
13
+ */
11
14
  export function EntityView(props: EntityViewProps) {
12
15
  // eslint-disable-next-line react-hooks/rules-of-hooks
13
16
  const entity = 'field' in props ? useEntity(props.field)! : useEntity()
@@ -31,6 +31,19 @@ type CP = FieldViewCommonProps
31
31
  type RN = ReactNode
32
32
  type REN = ReactElement | null
33
33
 
34
+ /**
35
+ * Base field view component with no default formatting.
36
+ *
37
+ * @example
38
+ * ```
39
+ * <FieldView
40
+ * field="startsAt"
41
+ * render={(accessor) => <>{accessor.value}</>}
42
+ * />
43
+ * ```
44
+ *
45
+ * @group Field Views
46
+ */
34
47
  export const FieldView = Component<FieldViewProps>(
35
48
  props => {
36
49
  const { fallbackIfUnpersisted, render } = props
@@ -22,6 +22,9 @@ export interface IfCallbackProps {
22
22
  children?: ReactNode
23
23
  }
24
24
 
25
+ /**
26
+ * @group Logic Components
27
+ */
25
28
  export const If = Component<IfProps>(props => {
26
29
  return typeof props.condition !== 'function'
27
30
  ? <IfFilter condition={props.condition}>{props.children}</IfFilter>
@@ -5,6 +5,9 @@ export interface StaticRenderProps {
5
5
  children?: ReactNode
6
6
  }
7
7
 
8
+ /**
9
+ * @group Data binding
10
+ */
8
11
  export const StaticRender = Component<StaticRenderProps>(
9
12
  () => null,
10
13
  ({ children }) => <>{children}</>,
@@ -7,6 +7,9 @@ export interface SugaredFieldProps<Persisted extends FieldValue = FieldValue> ex
7
7
  field: string | SugaredRelativeSingleField
8
8
  }
9
9
 
10
+ /**
11
+ * @group Data binding
12
+ */
10
13
  export const SugaredField = Component(<Persisted extends FieldValue = FieldValue>(props: SugaredFieldProps<Persisted>) => {
11
14
  if (typeof props.field === 'string') {
12
15
  return <Field {...props} field={props.field} />
@@ -47,6 +47,6 @@ export const evaluateCondition = (value: FieldValue | null, condition: Input.Con
47
47
  if (!handler) {
48
48
  throw new BindingError()
49
49
  }
50
- return handler(argument)
50
+ return (handler as any)(argument)
51
51
  })
52
52
  }
@@ -13,10 +13,20 @@ export interface FieldEventListeners {
13
13
  eventListeners: FieldEventListenerStore | undefined
14
14
  }
15
15
 
16
-
17
- export type UnsugarableFieldEventListeners<
16
+ export type FieldEventListenerValue<
17
+ E extends keyof FieldAccessor.FieldEventListenerMap,
18
18
  Persisted extends FieldValue = FieldValue,
19
- Produced extends Persisted = Persisted,
20
- > = {
21
- [EventName in keyof Events & string as `on${Capitalize<EventName>}`]?: Events[EventName] | Set<Events[EventName]>
19
+ > = Events<Persisted>[E] | Set<Events<Persisted>[E]>
20
+
21
+ export type UnsugarableFieldEventListeners<Persisted extends FieldValue = FieldValue> = {
22
+ onInitialize?: FieldEventListenerValue<'initialize', Persisted>
23
+ onBeforeUpdate?: FieldEventListenerValue<'beforeUpdate', Persisted>
24
+ onUpdate?: FieldEventListenerValue<'update', Persisted>
22
25
  }
26
+
27
+ const check:
28
+ keyof UnsugarableFieldEventListeners extends `on${Capitalize<keyof Events>}`
29
+ ? `on${Capitalize<keyof Events>}` extends keyof UnsugarableFieldEventListeners
30
+ ? true
31
+ : false
32
+ : false = true
@@ -12,7 +12,9 @@ export interface LeafField extends FieldEventListeners {
12
12
  defaultValue: FieldValue | undefined
13
13
  }
14
14
 
15
- export interface UnsugarableLeafField extends UnsugarableFieldEventListeners {
16
- isNonbearing?: boolean
17
- defaultValue?: OptionallyVariableFieldValue
18
- }
15
+ export type UnsugarableLeafField =
16
+ & UnsugarableFieldEventListeners
17
+ & {
18
+ isNonbearing?: boolean
19
+ defaultValue?: OptionallyVariableFieldValue
20
+ }
@@ -12,25 +12,32 @@ import type {
12
12
  UnsugarableQualifiedEntityParameters,
13
13
  } from './QualifiedEntityParameters'
14
14
 
15
- export interface QualifiedFieldList extends EntityListParameters, QualifiedEntityParameters, AnyField, LeafField {
16
- hasOneRelationPath: HasOneRelation[]
17
- }
15
+ export type QualifiedFieldList =
16
+ & EntityListParameters
17
+ & QualifiedEntityParameters
18
+ & AnyField
19
+ & LeafField
20
+ & {
21
+ hasOneRelationPath: HasOneRelation[]
22
+ }
18
23
 
19
- export interface SugarableQualifiedFieldList
20
- extends SugarableEntityListParameters,
21
- SugarableQualifiedEntityParameters,
22
- SugarableAnyField {
23
- hasOneRelationPath?: SugarableHasOneRelation[] | SugarableHasOneRelation
24
- }
24
+ export type SugarableQualifiedFieldList =
25
+ & SugarableEntityListParameters
26
+ & SugarableQualifiedEntityParameters
27
+ & SugarableAnyField
28
+ & {
29
+ hasOneRelationPath?: SugarableHasOneRelation[] | SugarableHasOneRelation
30
+ }
25
31
 
26
- export interface UnsugarableQualifiedFieldList
27
- extends UnsugarableEntityListParameters,
28
- UnsugarableQualifiedEntityParameters,
29
- UnsugarableLeafField {
32
+ export type UnsugarableQualifiedFieldList =
33
+ & UnsugarableEntityListParameters
34
+ & UnsugarableQualifiedEntityParameters
35
+ & UnsugarableLeafField
30
36
  // Deliberately leaving out UnsugarableHasOneRelation
31
- }
32
37
 
33
38
  // E.g. Author[age < 123].son.sister.name
34
- export interface SugaredQualifiedFieldList extends UnsugarableQualifiedFieldList {
35
- fields: string | SugarableQualifiedFieldList
36
- }
39
+ export type SugaredQualifiedFieldList =
40
+ & UnsugarableQualifiedFieldList
41
+ & {
42
+ fields: string | SugarableQualifiedFieldList
43
+ }
@@ -2,19 +2,26 @@ import type { AnyField, SugarableAnyField } from './AnyField'
2
2
  import type { HasOneRelation, SugarableHasOneRelation } from './HasOneRelation'
3
3
  import type { LeafField, UnsugarableLeafField } from './LeafField'
4
4
 
5
- export interface RelativeSingleField extends AnyField, LeafField {
6
- hasOneRelationPath: HasOneRelation[]
7
- }
5
+ export type RelativeSingleField =
6
+ & AnyField
7
+ & LeafField
8
+ & {
9
+ hasOneRelationPath: HasOneRelation[]
10
+ }
8
11
 
9
- export interface SugarableRelativeSingleField extends SugarableAnyField {
10
- hasOneRelationPath?: SugarableHasOneRelation[] | SugarableHasOneRelation
11
- }
12
+ export type SugarableRelativeSingleField =
13
+ & SugarableAnyField
14
+ & {
15
+ hasOneRelationPath?: SugarableHasOneRelation[] | SugarableHasOneRelation
16
+ }
12
17
 
13
- export interface UnsugarableRelativeSingleField extends UnsugarableLeafField {
18
+ export type UnsugarableRelativeSingleField =
19
+ & UnsugarableLeafField
14
20
  // Deliberately leaving out UnsugarableHasOneRelation
15
- }
16
21
 
17
- export interface SugaredRelativeSingleField extends UnsugarableRelativeSingleField {
18
- // E.g. authors(id = 123).person.name
19
- field: string | SugarableRelativeSingleField
20
- }
22
+ export type SugaredRelativeSingleField =
23
+ & UnsugarableRelativeSingleField
24
+ & {
25
+ /** E.g. authors(id = 123).person.name */
26
+ field: string | SugarableRelativeSingleField
27
+ }