@react-typed-forms/schemas 16.2.2 → 17.0.0

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/src/renderers.tsx CHANGED
@@ -16,8 +16,11 @@ import {
16
16
  } from "./controlRender";
17
17
  import {
18
18
  AccordionAdornment,
19
+ ChildNodeSpec,
20
+ ChildResolverFunc,
19
21
  ControlAdornment,
20
22
  ControlAdornmentType,
23
+ FormStateNode,
21
24
  IconAdornment,
22
25
  OptionalAdornment,
23
26
  RenderOptions,
@@ -53,11 +56,12 @@ export interface DataRendererRegistration {
53
56
  renderType?: string | string[];
54
57
  options?: boolean;
55
58
  collection?: boolean;
56
- match?: (props: DataRendererProps, renderOptions: RenderOptions) => boolean;
59
+ match?: (props: FormStateNode, renderOptions: RenderOptions) => boolean;
57
60
  render: (
58
61
  props: DataRendererProps,
59
62
  renderers: FormRenderer,
60
63
  ) => ReactNode | ((layout: ControlLayoutProps) => ControlLayoutProps);
64
+ resolveChildren?: ChildResolverFunc;
61
65
  }
62
66
 
63
67
  export interface LabelRendererRegistration {
@@ -75,6 +79,7 @@ export interface ActionRendererRegistration {
75
79
  type: "action";
76
80
  actionType?: string | string[];
77
81
  render: (props: ActionRendererProps, renderers: FormRenderer) => ReactElement;
82
+ resolveChildren?: ChildResolverFunc;
78
83
  }
79
84
 
80
85
  export interface ArrayRendererRegistration {
@@ -89,6 +94,7 @@ export interface GroupRendererRegistration {
89
94
  props: GroupRendererProps,
90
95
  renderers: FormRenderer,
91
96
  ) => ReactElement | ((layout: ControlLayoutProps) => ControlLayoutProps);
97
+ resolveChildren?: ChildResolverFunc;
92
98
  }
93
99
 
94
100
  export interface DisplayRendererRegistration {
@@ -98,6 +104,7 @@ export interface DisplayRendererRegistration {
98
104
  props: DisplayRendererProps,
99
105
  renderers: FormRenderer,
100
106
  ) => ReactElement;
107
+ resolveChildren?: ChildResolverFunc;
101
108
  }
102
109
 
103
110
  export interface AdornmentRendererRegistration {
package/src/types.ts CHANGED
@@ -6,9 +6,10 @@ import {
6
6
  IconReference,
7
7
  SchemaDataNode,
8
8
  SchemaInterface,
9
+ ControlDisableType,
9
10
  } from "@astroapps/forms-core";
10
11
  import React, { Key, ReactNode } from "react";
11
- import { CleanupScope } from "@react-typed-forms/core";
12
+ import { ChangeListenerFunc, CleanupScope } from "@react-typed-forms/core";
12
13
 
13
14
  /**
14
15
  * Interface representing the control data context.
@@ -17,14 +18,22 @@ export interface ControlDataContext {
17
18
  schemaInterface: SchemaInterface;
18
19
  dataNode: SchemaDataNode | undefined;
19
20
  parentNode: SchemaDataNode;
20
- variables: Record<string, any>;
21
21
  }
22
+ export interface ControlActionContext {
23
+ disableForm(disable: ControlDisableType): void;
24
+ runAction(action: string, actionData?: any): void | Promise<any>;
25
+ }
26
+
27
+ export const NoOpControlActionContext: ControlActionContext = {
28
+ disableForm(disable: ControlDisableType) {},
29
+ runAction(actionId: string, actionData?: any): void | Promise<any> {},
30
+ };
22
31
 
23
32
  export type ControlActionHandler = (
24
33
  actionId: string,
25
34
  actionData: any,
26
- ctx: ControlDataContext,
27
- ) => (() => void) | undefined;
35
+ dataContext: ControlDataContext,
36
+ ) => ((actionContext: ControlActionContext) => void | Promise<any>) | undefined;
28
37
 
29
38
  export interface ActionRendererProps {
30
39
  key?: Key;
@@ -42,11 +51,12 @@ export interface ActionRendererProps {
42
51
  disabled?: boolean;
43
52
  hidden?: boolean;
44
53
  inline?: boolean;
54
+ busy?: boolean;
45
55
  }
46
56
 
47
57
  export type RunExpression = (
48
58
  scope: CleanupScope,
49
59
  expression: EntityExpression,
50
60
  returnResult: (v: unknown) => void,
51
- bindings?: FormContextData,
61
+ variables?: (changes: ChangeListenerFunc<any>) => Record<string, any>,
52
62
  ) => void;
package/src/util.ts CHANGED
@@ -35,6 +35,7 @@ import {
35
35
  import { MutableRefObject, useRef } from "react";
36
36
  import clsx from "clsx";
37
37
  import {
38
+ ChangeListenerFunc,
38
39
  Control,
39
40
  ControlChange,
40
41
  createScopedEffect,
@@ -1022,7 +1023,7 @@ export function useExpression<T>(
1022
1023
  runExpression: RunExpression,
1023
1024
  expression: EntityExpression | null | undefined,
1024
1025
  coerce: (x: any) => T,
1025
- bindings?: Record<string, any>,
1026
+ bindings?: (changes: ChangeListenerFunc<any>) => Record<string, any>,
1026
1027
  ): Control<T> {
1027
1028
  const value = useControl<T>(defaultValue);
1028
1029
  createScopedEffect((scope) => {
@@ -1037,3 +1038,14 @@ export function useExpression<T>(
1037
1038
  }, value);
1038
1039
  return value;
1039
1040
  }
1041
+
1042
+ export function setIncluded<A>(array: A[], elem: A, included: boolean): A[] {
1043
+ const already = array.includes(elem);
1044
+ if (included === already) {
1045
+ return array;
1046
+ }
1047
+ if (included) {
1048
+ return [...array, elem];
1049
+ }
1050
+ return array.filter((e) => e !== elem);
1051
+ }