@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.
- package/dist/development/accessorTree/AccessorTree.js +2 -2
- package/dist/development/accessorTree/AccessorTree.js.map +1 -1
- package/dist/development/coreComponents/DataBindingProvider.js.map +1 -1
- package/dist/development/coreComponents/Entity.js.map +1 -1
- package/dist/development/coreComponents/EntityList.js.map +1 -1
- package/dist/development/coreComponents/EntityListSubTree.js.map +1 -1
- package/dist/development/coreComponents/EntitySubTree.js.map +1 -1
- package/dist/development/coreComponents/Field.js.map +1 -1
- package/dist/development/coreComponents/HasMany.js.map +1 -1
- package/dist/development/coreComponents/HasOne.js.map +1 -1
- package/dist/development/coreComponents/ParentEntity.js.map +1 -1
- package/dist/development/helperComponents/DeferredSubTrees.js.map +1 -1
- package/dist/development/helperComponents/EntityView.js.map +1 -1
- package/dist/development/helperComponents/FieldView.js.map +1 -1
- package/dist/development/helperComponents/If.js.map +1 -1
- package/dist/development/helperComponents/StaticRender.js.map +1 -1
- package/dist/development/helperComponents/SugaredField.js.map +1 -1
- package/dist/development/helperComponents/helpers/evaluateCondition.js.map +1 -1
- package/dist/development/treeParameters/LeafField.js.map +1 -1
- package/dist/production/accessorTree/AccessorTree.js +2 -2
- package/dist/production/accessorTree/AccessorTree.js.map +1 -1
- package/dist/production/coreComponents/DataBindingProvider.js.map +1 -1
- package/dist/production/coreComponents/Entity.js.map +1 -1
- package/dist/production/coreComponents/EntityList.js.map +1 -1
- package/dist/production/coreComponents/EntityListSubTree.js.map +1 -1
- package/dist/production/coreComponents/EntitySubTree.js.map +1 -1
- package/dist/production/coreComponents/Field.js.map +1 -1
- package/dist/production/coreComponents/HasMany.js.map +1 -1
- package/dist/production/coreComponents/HasOne.js.map +1 -1
- package/dist/production/coreComponents/ParentEntity.js.map +1 -1
- package/dist/production/helperComponents/DeferredSubTrees.js.map +1 -1
- package/dist/production/helperComponents/EntityView.js.map +1 -1
- package/dist/production/helperComponents/FieldView.js.map +1 -1
- package/dist/production/helperComponents/If.js.map +1 -1
- package/dist/production/helperComponents/StaticRender.js.map +1 -1
- package/dist/production/helperComponents/SugaredField.js.map +1 -1
- package/dist/production/helperComponents/helpers/evaluateCondition.js.map +1 -1
- package/dist/production/treeParameters/LeafField.js.map +1 -1
- package/dist/types/accessorTree/AccessorTree.d.ts +7 -4
- package/dist/types/accessorTree/AccessorTree.d.ts.map +1 -1
- package/dist/types/coreComponents/DataBindingProvider.d.ts +10 -0
- package/dist/types/coreComponents/DataBindingProvider.d.ts.map +1 -1
- package/dist/types/coreComponents/Entity.d.ts +3 -0
- package/dist/types/coreComponents/Entity.d.ts.map +1 -1
- package/dist/types/coreComponents/EntityList.d.ts +3 -0
- package/dist/types/coreComponents/EntityList.d.ts.map +1 -1
- package/dist/types/coreComponents/EntityListSubTree.d.ts +10 -0
- package/dist/types/coreComponents/EntityListSubTree.d.ts.map +1 -1
- package/dist/types/coreComponents/EntitySubTree.d.ts +10 -0
- package/dist/types/coreComponents/EntitySubTree.d.ts.map +1 -1
- package/dist/types/coreComponents/Field.d.ts +3 -0
- package/dist/types/coreComponents/Field.d.ts.map +1 -1
- package/dist/types/coreComponents/HasMany.d.ts +3 -0
- package/dist/types/coreComponents/HasMany.d.ts.map +1 -1
- package/dist/types/coreComponents/HasOne.d.ts +3 -0
- package/dist/types/coreComponents/HasOne.d.ts.map +1 -1
- package/dist/types/coreComponents/ParentEntity.d.ts +3 -0
- package/dist/types/coreComponents/ParentEntity.d.ts.map +1 -1
- package/dist/types/helperComponents/DeferredSubTrees.d.ts +3 -0
- package/dist/types/helperComponents/DeferredSubTrees.d.ts.map +1 -1
- package/dist/types/helperComponents/EntityView.d.ts +3 -0
- package/dist/types/helperComponents/EntityView.d.ts.map +1 -1
- package/dist/types/helperComponents/FieldView.d.ts +13 -0
- package/dist/types/helperComponents/FieldView.d.ts.map +1 -1
- package/dist/types/helperComponents/If.d.ts +3 -0
- package/dist/types/helperComponents/If.d.ts.map +1 -1
- package/dist/types/helperComponents/StaticRender.d.ts +3 -0
- package/dist/types/helperComponents/StaticRender.d.ts.map +1 -1
- package/dist/types/helperComponents/SugaredField.d.ts +3 -0
- package/dist/types/helperComponents/SugaredField.d.ts.map +1 -1
- package/dist/types/treeParameters/FieldEventListeners.d.ts +5 -2
- package/dist/types/treeParameters/FieldEventListeners.d.ts.map +1 -1
- package/dist/types/treeParameters/LeafField.d.ts +2 -2
- package/dist/types/treeParameters/LeafField.d.ts.map +1 -1
- package/dist/types/treeParameters/QualifiedFieldList.d.ts +7 -8
- package/dist/types/treeParameters/QualifiedFieldList.d.ts.map +1 -1
- package/dist/types/treeParameters/RelativeSingleField.d.ts +8 -8
- package/dist/types/treeParameters/RelativeSingleField.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/accessorTree/AccessorTree.tsx +4 -1
- package/src/coreComponents/DataBindingProvider.tsx +10 -0
- package/src/coreComponents/Entity.tsx +3 -0
- package/src/coreComponents/EntityList.tsx +3 -0
- package/src/coreComponents/EntityListSubTree.tsx +10 -0
- package/src/coreComponents/EntitySubTree.tsx +10 -0
- package/src/coreComponents/Field.tsx +3 -0
- package/src/coreComponents/HasMany.tsx +3 -0
- package/src/coreComponents/HasOne.tsx +3 -0
- package/src/coreComponents/ParentEntity.tsx +3 -0
- package/src/helperComponents/DeferredSubTrees.tsx +3 -0
- package/src/helperComponents/EntityView.tsx +3 -0
- package/src/helperComponents/FieldView.tsx +13 -0
- package/src/helperComponents/If.tsx +3 -0
- package/src/helperComponents/StaticRender.tsx +3 -0
- package/src/helperComponents/SugaredField.tsx +3 -0
- package/src/helperComponents/helpers/evaluateCondition.ts +1 -1
- package/src/treeParameters/FieldEventListeners.ts +15 -5
- package/src/treeParameters/LeafField.ts +6 -4
- package/src/treeParameters/QualifiedFieldList.ts +24 -17
- 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.
|
|
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.
|
|
32
|
-
"@contember/react-client": "1.2.0-alpha.
|
|
33
|
-
"@contember/react-multipass-rendering": "1.2.0-alpha.
|
|
34
|
-
"@contember/react-utils": "1.2.0-alpha.
|
|
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
|
-
|
|
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
|
) {
|
|
@@ -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)
|
|
@@ -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>
|
|
@@ -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} />
|
|
@@ -13,10 +13,20 @@ export interface FieldEventListeners {
|
|
|
13
13
|
eventListeners: FieldEventListenerStore | undefined
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
export type FieldEventListenerValue<
|
|
17
|
+
E extends keyof FieldAccessor.FieldEventListenerMap,
|
|
18
18
|
Persisted extends FieldValue = FieldValue,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
export type QualifiedFieldList =
|
|
16
|
+
& EntityListParameters
|
|
17
|
+
& QualifiedEntityParameters
|
|
18
|
+
& AnyField
|
|
19
|
+
& LeafField
|
|
20
|
+
& {
|
|
21
|
+
hasOneRelationPath: HasOneRelation[]
|
|
22
|
+
}
|
|
18
23
|
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
export type SugarableQualifiedFieldList =
|
|
25
|
+
& SugarableEntityListParameters
|
|
26
|
+
& SugarableQualifiedEntityParameters
|
|
27
|
+
& SugarableAnyField
|
|
28
|
+
& {
|
|
29
|
+
hasOneRelationPath?: SugarableHasOneRelation[] | SugarableHasOneRelation
|
|
30
|
+
}
|
|
25
31
|
|
|
26
|
-
export
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
35
|
-
|
|
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
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export type RelativeSingleField =
|
|
6
|
+
& AnyField
|
|
7
|
+
& LeafField
|
|
8
|
+
& {
|
|
9
|
+
hasOneRelationPath: HasOneRelation[]
|
|
10
|
+
}
|
|
8
11
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
export type SugarableRelativeSingleField =
|
|
13
|
+
& SugarableAnyField
|
|
14
|
+
& {
|
|
15
|
+
hasOneRelationPath?: SugarableHasOneRelation[] | SugarableHasOneRelation
|
|
16
|
+
}
|
|
12
17
|
|
|
13
|
-
export
|
|
18
|
+
export type UnsugarableRelativeSingleField =
|
|
19
|
+
& UnsugarableLeafField
|
|
14
20
|
// Deliberately leaving out UnsugarableHasOneRelation
|
|
15
|
-
}
|
|
16
21
|
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
export type SugaredRelativeSingleField =
|
|
23
|
+
& UnsugarableRelativeSingleField
|
|
24
|
+
& {
|
|
25
|
+
/** E.g. authors(id = 123).person.name */
|
|
26
|
+
field: string | SugarableRelativeSingleField
|
|
27
|
+
}
|