@astroapps/forms-core 1.2.2 → 2.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/TODO.txt CHANGED
@@ -1,3 +1,8 @@
1
- * Support formData in jsonata
2
1
  * nuances with default value
3
2
  * Data grid group
3
+
4
+
5
+ Test for:
6
+ * jsonata path updating on change of array index
7
+ * Check and radio list tree structure
8
+ * Ensuring calculated visibility doesn't become visible if it were never hidden - vop
package/jest.config.js ADDED
@@ -0,0 +1,8 @@
1
+ /** @type {import('ts-jest').JestConfigWithTsJest} **/
2
+ export default {
3
+ testEnvironment: "node",
4
+ transform: {
5
+ "^.+\\.tsx?$": ["ts-jest", { tsconfig: "tsconfig.test.json" }],
6
+ },
7
+ preset: "ts-jest",
8
+ };
@@ -0,0 +1,60 @@
1
+ import { AccordionAdornment, ActionControlDefinition, AutocompleteRenderOptions, CheckListRenderOptions, ControlAdornmentType, ControlDefinition, DataControlDefinition, DataRenderType, DisplayControlDefinition, DisplayOnlyRenderOptions, DynamicProperty, GroupedControlsDefinition, JsonataRenderOptions, RadioButtonRenderOptions, RenderOptions, TextfieldRenderOptions } from "./controlDefinition";
2
+ import { DateValidator, JsonataValidator, LengthValidator, ValidatorType } from "./schemaValidator";
3
+ import { DataExpression, DataMatchExpression, EntityExpression, ExpressionType, JsonataExpression, NotEmptyExpression } from "./entityExpression";
4
+ export declare function dataControl(field: string, title?: string | null, options?: Partial<DataControlDefinition>): DataControlDefinition;
5
+ export declare function validatorOptions<A extends {
6
+ type: string;
7
+ }>(type: ValidatorType): (options: Omit<A, "type">) => A;
8
+ export declare function adornmentOptions<A extends {
9
+ type: string;
10
+ }>(type: ControlAdornmentType): (options: Omit<A, "type">) => A;
11
+ export declare function renderOptionsFor<A extends RenderOptions>(type: DataRenderType): (options: Omit<A, "type">) => {
12
+ renderOptions: A;
13
+ };
14
+ export declare const autocompleteOptions: (options: Omit<AutocompleteRenderOptions, "type">) => {
15
+ renderOptions: AutocompleteRenderOptions;
16
+ };
17
+ export declare const checkListOptions: (options: Omit<CheckListRenderOptions, "type">) => {
18
+ renderOptions: CheckListRenderOptions;
19
+ };
20
+ export declare const radioButtonOptions: (options: Omit<RadioButtonRenderOptions, "type">) => {
21
+ renderOptions: RadioButtonRenderOptions;
22
+ };
23
+ export declare const lengthValidatorOptions: (options: Omit<LengthValidator, "type">) => LengthValidator;
24
+ export declare const jsonataValidatorOptions: (options: Omit<JsonataValidator, "type">) => JsonataValidator;
25
+ export declare const dateValidatorOptions: (options: Omit<DateValidator, "type">) => DateValidator;
26
+ export declare const accordionOptions: (options: Omit<AccordionAdornment, "type">) => AccordionAdornment;
27
+ export declare const textfieldOptions: (options: Omit<TextfieldRenderOptions, "type">) => {
28
+ renderOptions: TextfieldRenderOptions;
29
+ };
30
+ export declare const displayOnlyOptions: (options: Omit<DisplayOnlyRenderOptions, "type">) => {
31
+ renderOptions: DisplayOnlyRenderOptions;
32
+ };
33
+ export declare const jsonataOptions: (options: Omit<JsonataRenderOptions, "type">) => {
34
+ renderOptions: JsonataRenderOptions;
35
+ };
36
+ export declare function textDisplayControl(text: string, options?: Partial<DisplayControlDefinition>): DisplayControlDefinition;
37
+ export declare function htmlDisplayControl(html: string, options?: Partial<DisplayControlDefinition>): DisplayControlDefinition;
38
+ export declare function dynamicDefaultValue(expr: EntityExpression): DynamicProperty;
39
+ export declare function dynamicReadonly(expr: EntityExpression): DynamicProperty;
40
+ export declare function dynamicVisibility(expr: EntityExpression): DynamicProperty;
41
+ export declare function dynamicDisabled(expr: EntityExpression): DynamicProperty;
42
+ export declare function dataExpr(field: string): DataExpression;
43
+ /**
44
+ * @deprecated Use dataExpr
45
+ */
46
+ export declare const fieldExpr: typeof dataExpr;
47
+ /**
48
+ * @deprecated Use dataMatchExpr
49
+ */
50
+ export declare const fieldEqExpr: typeof dataMatchExpr;
51
+ export declare const uuidExpr: {
52
+ type: ExpressionType;
53
+ };
54
+ export declare function dataMatchExpr(field: string, value: any): DataMatchExpression;
55
+ export declare function notEmptyExpr(field: string, empty?: boolean): NotEmptyExpression;
56
+ export declare function jsonataExpr(expression: string): JsonataExpression;
57
+ export declare function groupedControl(children: ControlDefinition[], title?: string, options?: Partial<GroupedControlsDefinition>): GroupedControlsDefinition;
58
+ export declare function compoundControl(field: string, title: string | undefined | null, children: ControlDefinition[], options?: Partial<DataControlDefinition>): DataControlDefinition;
59
+ export declare function actionControl(actionText: string, actionId: string, options?: Partial<ActionControlDefinition>): ActionControlDefinition;
60
+ export declare const emptyGroupDefinition: GroupedControlsDefinition;
@@ -16,6 +16,8 @@ export interface ControlDefinition {
16
16
  childRefId?: string | null;
17
17
  title?: string | null;
18
18
  hidden?: boolean | null;
19
+ disabled?: boolean | null;
20
+ readonly?: boolean | null;
19
21
  styleClass?: string | null;
20
22
  textClass?: string | null;
21
23
  layoutClass?: string | null;
@@ -46,7 +48,8 @@ export declare enum DynamicPropertyType {
46
48
  LayoutStyle = "LayoutStyle",
47
49
  AllowedOptions = "AllowedOptions",
48
50
  Label = "Label",
49
- ActionData = "ActionData"
51
+ ActionData = "ActionData",
52
+ GridColumns = "GridColumns"
50
53
  }
51
54
  export interface ControlAdornment {
52
55
  type: string;
@@ -112,11 +115,10 @@ export interface DataControlDefinition extends ControlDefinition {
112
115
  required?: boolean | null;
113
116
  renderOptions?: RenderOptions | null;
114
117
  defaultValue?: any;
115
- readonly?: boolean | null;
116
- disabled?: boolean | null;
117
118
  validators?: SchemaValidator[] | null;
118
119
  hideTitle?: boolean | null;
119
120
  dontClearHidden?: boolean | null;
121
+ requiredErrorText?: string | null;
120
122
  }
121
123
  export interface RenderOptions {
122
124
  type: string;
@@ -141,7 +143,8 @@ export declare enum DataRenderType {
141
143
  Jsonata = "Jsonata",
142
144
  Array = "Array",
143
145
  ArrayElement = "ArrayElement",
144
- ElementSelected = "ElementSelected"
146
+ ElementSelected = "ElementSelected",
147
+ ScrollList = "ScrollList"
145
148
  }
146
149
  export interface TextfieldRenderOptions extends RenderOptions {
147
150
  type: DataRenderType.Textfield;
@@ -216,6 +219,7 @@ export interface ArrayRenderOptions extends RenderOptions {
216
219
  noRemove?: boolean | null;
217
220
  noReorder?: boolean | null;
218
221
  editExternal?: boolean | null;
222
+ childOverrideClass?: string | null;
219
223
  }
220
224
  export interface ArrayElementRenderOptions extends RenderOptions {
221
225
  type: DataRenderType.ArrayElement;
@@ -251,6 +255,11 @@ export interface UserSelectionRenderOptions extends RenderOptions {
251
255
  export interface IconSelectionRenderOptions extends RenderOptions {
252
256
  type: DataRenderType.IconSelector;
253
257
  }
258
+ export interface ScrollListRenderOptions extends RenderOptions {
259
+ type: DataRenderType.ScrollList;
260
+ bottomActionId?: string;
261
+ refreshActionId?: string;
262
+ }
254
263
  export interface GroupedControlsDefinition extends ControlDefinition {
255
264
  type: ControlDefinitionType.Group;
256
265
  compoundField?: string | null;
@@ -282,11 +291,18 @@ export declare enum GroupRenderType {
282
291
  Inline = "Inline",
283
292
  Wizard = "Wizard",
284
293
  Dialog = "Dialog",
285
- Contents = "Contents"
294
+ Contents = "Contents",
295
+ Accordion = "Accordion"
296
+ }
297
+ export interface AccordionRenderer extends GroupRenderOptions {
298
+ type: GroupRenderType.Accordion;
299
+ defaultExpanded?: boolean | null;
300
+ expandStateField?: string | null;
286
301
  }
287
302
  export interface DialogRenderOptions extends GroupRenderOptions {
288
303
  type: GroupRenderType.Dialog;
289
304
  title?: string | null;
305
+ portalHost?: string | null;
290
306
  }
291
307
  export interface StandardGroupRenderer extends GroupRenderOptions {
292
308
  type: GroupRenderType.Standard;
@@ -300,10 +316,11 @@ export interface GroupElementRenderer extends GroupRenderOptions {
300
316
  type: GroupRenderType.GroupElement;
301
317
  value: any;
302
318
  }
303
- export interface GridRenderer extends GroupRenderOptions {
319
+ export interface GridRendererOptions extends GroupRenderOptions {
304
320
  type: GroupRenderType.Grid;
305
321
  columns?: number | null;
306
322
  rowClass?: string | null;
323
+ cellClass?: string | null;
307
324
  }
308
325
  export interface TabsRenderOptions extends GroupRenderOptions {
309
326
  type: GroupRenderType.Tabs;
@@ -346,6 +363,11 @@ export interface CustomDisplay extends DisplayData {
346
363
  type: DisplayDataType.Custom;
347
364
  customId: string;
348
365
  }
366
+ export declare enum ControlDisableType {
367
+ None = "None",
368
+ Self = "Self",
369
+ Global = "Global"
370
+ }
349
371
  export interface ActionControlDefinition extends ControlDefinition {
350
372
  type: ControlDefinitionType.Action;
351
373
  actionId: string;
@@ -353,6 +375,7 @@ export interface ActionControlDefinition extends ControlDefinition {
353
375
  icon?: IconReference | null;
354
376
  actionStyle?: ActionStyle | null;
355
377
  iconPlacement?: IconPlacement | null;
378
+ disableType?: ControlDisableType | null;
356
379
  }
357
380
  export declare enum ActionStyle {
358
381
  Button = "Button",
@@ -372,10 +395,11 @@ export interface ControlVisitor<A> {
372
395
  action(d: ActionControlDefinition): A;
373
396
  }
374
397
  export declare function visitControlDefinition<A>(x: ControlDefinition, visitor: ControlVisitor<A>, defaultValue: (c: ControlDefinition) => A): A;
375
- export declare function isGridRenderer(options: GroupRenderOptions): options is GridRenderer;
398
+ export declare function isGridRenderer(options: GroupRenderOptions): options is GridRendererOptions;
376
399
  export declare function isWizardRenderer(options: GroupRenderOptions): options is WizardRenderOptions;
377
400
  export declare function isDialogRenderer(options: GroupRenderOptions): options is DialogRenderOptions;
378
- export declare function isInlineRenderer(options: GroupRenderOptions): options is GridRenderer;
401
+ export declare function isAccordionRenderer(options: GroupRenderOptions): options is AccordionRenderer;
402
+ export declare function isInlineRenderer(options: GroupRenderOptions): boolean;
379
403
  export declare function isSelectChildRenderer(options: GroupRenderOptions): options is SelectChildRenderer;
380
404
  export declare function isTabsRenderer(options: GroupRenderOptions): options is TabsRenderOptions;
381
405
  export declare function isFlexRenderer(options: GroupRenderOptions): options is FlexRenderer;
@@ -1,5 +1,5 @@
1
1
  import { EntityExpression, JsonataExpression } from "./entityExpression";
2
- import { CleanupScope, Value } from "@astroapps/controls";
2
+ import { ChangeListenerFunc, CleanupScope, Control } from "@astroapps/controls";
3
3
  import { SchemaDataNode } from "./schemaDataNode";
4
4
  import { SchemaInterface } from "./schemaInterface";
5
5
  export interface ExpressionEvalContext {
@@ -7,10 +7,11 @@ export interface ExpressionEvalContext {
7
7
  returnResult: (k: unknown) => void;
8
8
  dataNode: SchemaDataNode;
9
9
  schemaInterface: SchemaInterface;
10
- variables?: Value<Record<string, any> | undefined>;
10
+ variables?: (changes: ChangeListenerFunc<any>) => Record<string, any>;
11
11
  runAsync(effect: () => void): void;
12
12
  }
13
13
  export type ExpressionEval<T extends EntityExpression> = (expr: T, context: ExpressionEvalContext) => void;
14
14
  export declare const jsonataEval: ExpressionEval<JsonataExpression>;
15
15
  export declare const uuidEval: ExpressionEval<EntityExpression>;
16
16
  export declare const defaultEvaluators: Record<string, ExpressionEval<any>>;
17
+ export declare function createEvalExpr(evalExpression: (e: EntityExpression, ctx: ExpressionEvalContext) => void, context: Omit<ExpressionEvalContext, "returnResult" | "scope">): <A>(scope: CleanupScope, init: A, nk: Control<A>, e: EntityExpression | undefined, coerce: (t: unknown) => any) => boolean;
package/lib/formNode.d.ts CHANGED
@@ -43,10 +43,3 @@ export declare function visitControlData<A>(definition: ControlDefinition, ctx:
43
43
  export type ControlDataVisitor<A> = (dataNode: SchemaDataNode, definition: DataControlDefinition) => A | undefined;
44
44
  export declare function visitFormData<A>(node: FormNode, dataNode: SchemaDataNode, cb: ControlDataVisitor<A>, notSelf?: boolean): A | undefined;
45
45
  export declare function visitFormDataInContext<A>(parentContext: SchemaDataNode, node: FormNode, cb: ControlDataVisitor<A>): A | undefined;
46
- export interface FormDataNode {
47
- parent?: FormDataNode;
48
- formNode: FormNode;
49
- parentData: SchemaDataNode;
50
- childIndex?: number;
51
- }
52
- export declare function visitFormDataNode<A>(node: FormDataNode, visitFn: (node: FormDataNode, data?: SchemaDataNode) => A | undefined): A | undefined;
@@ -0,0 +1,134 @@
1
+ import { FormNode } from "./formNode";
2
+ import { SchemaDataNode } from "./schemaDataNode";
3
+ import { SchemaInterface } from "./schemaInterface";
4
+ import { FieldOption } from "./schemaField";
5
+ import { ChangeListenerFunc, CleanupScope, Control } from "@astroapps/controls";
6
+ import { ExpressionEvalContext } from "./evalExpression";
7
+ import { EntityExpression } from "./entityExpression";
8
+ import { ControlDefinition, ControlDisableType } from "./controlDefinition";
9
+ import { ChildNodeSpec, ChildResolverFunc } from "./resolveChildren";
10
+ export type EvalExpr = <A>(scope: CleanupScope, init: A, nk: Control<A>, e: EntityExpression | undefined, coerce: (t: unknown) => any) => boolean;
11
+ export type VariablesFunc = (changes: ChangeListenerFunc<any>) => Record<string, any>;
12
+ export interface FormNodeOptions {
13
+ forceReadonly?: boolean;
14
+ forceDisabled?: boolean;
15
+ forceHidden?: boolean;
16
+ variables?: VariablesFunc;
17
+ }
18
+ export interface FormGlobalOptions {
19
+ schemaInterface: SchemaInterface;
20
+ evalExpression: (e: EntityExpression, ctx: ExpressionEvalContext) => void;
21
+ resolveChildren(c: FormStateNode): ChildNodeSpec[];
22
+ runAsync: (af: () => void) => void;
23
+ clearHidden: boolean;
24
+ }
25
+ export interface ResolvedDefinition {
26
+ definition: ControlDefinition;
27
+ display?: string;
28
+ stateId?: string;
29
+ style?: object;
30
+ layoutStyle?: object;
31
+ fieldOptions?: FieldOption[];
32
+ }
33
+ export interface FormStateBase {
34
+ parent: SchemaDataNode;
35
+ dataNode?: SchemaDataNode | undefined;
36
+ readonly: boolean;
37
+ visible: boolean | null;
38
+ disabled: boolean;
39
+ resolved: ResolvedDefinition;
40
+ childIndex: number;
41
+ busy: boolean;
42
+ }
43
+ export interface FormNodeUi {
44
+ ensureVisible(): void;
45
+ ensureChildVisible(childIndex: number): void;
46
+ getDisabler(type: ControlDisableType): () => () => void;
47
+ }
48
+ export interface FormStateNode extends FormStateBase, FormNodeOptions {
49
+ childKey: string | number;
50
+ uniqueId: string;
51
+ definition: ControlDefinition;
52
+ schemaInterface: SchemaInterface;
53
+ valid: boolean;
54
+ touched: boolean;
55
+ clearHidden: boolean;
56
+ variables?: (changes: ChangeListenerFunc<any>) => Record<string, any>;
57
+ meta: Record<string, any>;
58
+ form: FormNode | undefined | null;
59
+ children: FormStateNode[];
60
+ parentNode: FormStateNode | undefined;
61
+ setTouched(b: boolean, notChildren?: boolean): void;
62
+ validate(): boolean;
63
+ getChildCount(): number;
64
+ getChild(index: number): FormStateNode | undefined;
65
+ ensureMeta<A>(key: string, init: (scope: CleanupScope) => A): A;
66
+ cleanup(): void;
67
+ ui: FormNodeUi;
68
+ attachUi(f: FormNodeUi): void;
69
+ setBusy(busy: boolean): void;
70
+ setForceDisabled(forceDisable: boolean): void;
71
+ }
72
+ export declare function createEvaluatedDefinition(def: ControlDefinition, evalExpr: EvalExpr, scope: CleanupScope, display: Control<string | undefined>): ControlDefinition;
73
+ export declare function coerceStyle(v: unknown): any;
74
+ export declare function coerceString(v: unknown): string;
75
+ export declare function createFormStateNode(formNode: FormNode, parent: SchemaDataNode, options: FormGlobalOptions, nodeOptions: FormNodeOptions): FormStateNodeImpl;
76
+ export interface FormStateBaseImpl extends FormStateBase {
77
+ children: FormStateBaseImpl[];
78
+ allowedOptions?: unknown;
79
+ nodeOptions: FormNodeOptions;
80
+ busy: boolean;
81
+ }
82
+ export declare const noopUi: FormNodeUi;
83
+ declare class FormStateNodeImpl implements FormStateNode {
84
+ childKey: string | number;
85
+ meta: Record<string, any>;
86
+ form: FormNode | undefined | null;
87
+ readonly globals: Control<FormGlobalOptions>;
88
+ parent: SchemaDataNode;
89
+ parentNode: FormStateNode | undefined;
90
+ readonly base: Control<FormStateBaseImpl>;
91
+ readonly options: Control<FormNodeOptions>;
92
+ readonly resolveChildren: ChildResolverFunc;
93
+ ui: FormNodeUi;
94
+ constructor(childKey: string | number, meta: Record<string, any>, definition: ControlDefinition, form: FormNode | undefined | null, nodeOptions: FormNodeOptions, globals: Control<FormGlobalOptions>, parent: SchemaDataNode, parentNode: FormStateNode | undefined, childIndex: number, resolveChildren?: ChildResolverFunc);
95
+ get busy(): boolean;
96
+ setBusy(busy: boolean): void;
97
+ get evalExpression(): (e: EntityExpression, ctx: ExpressionEvalContext) => void;
98
+ get runAsync(): (af: () => void) => void;
99
+ get schemaInterface(): SchemaInterface;
100
+ get forceDisabled(): boolean | undefined;
101
+ setForceDisabled(value: boolean): boolean;
102
+ get forceReadonly(): boolean | undefined;
103
+ get forceHidden(): boolean | undefined;
104
+ attachUi(f: FormNodeUi): void;
105
+ get childIndex(): number;
106
+ get children(): FormStateNode[];
107
+ get uniqueId(): string;
108
+ get valid(): boolean;
109
+ get touched(): boolean;
110
+ setTouched(touched: boolean, notChildren?: boolean): void;
111
+ validate(): boolean;
112
+ get readonly(): boolean;
113
+ get visible(): boolean | null;
114
+ get disabled(): boolean;
115
+ get clearHidden(): boolean;
116
+ get variables(): VariablesFunc | undefined;
117
+ get definition(): ControlDefinition;
118
+ getChild(index: number): FormStateNode;
119
+ getChildCount(): number;
120
+ cleanup(): void;
121
+ get resolved(): ResolvedDefinition;
122
+ get dataNode(): SchemaDataNode | undefined;
123
+ ensureMeta<A>(key: string, init: (scope: CleanupScope) => A): A;
124
+ }
125
+ export declare function combineVariables(v1?: VariablesFunc, v2?: VariablesFunc): VariablesFunc | undefined;
126
+ /**
127
+ * Interface representing the form context data.
128
+ */
129
+ export interface FormContextData {
130
+ option?: FieldOption;
131
+ optionSelected?: boolean;
132
+ }
133
+ export declare function visitFormState<A>(node: FormStateNode, visitFn: (node: FormStateNode) => A | undefined): A | undefined;
134
+ export {};