ballerina-core 1.0.89 → 1.0.91

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 (31) hide show
  1. package/package.json +1 -1
  2. package/src/forms/domains/parser/domains/built-ins/state.ts +6 -1
  3. package/src/forms/domains/parser/domains/predicates/state.ts +50 -30
  4. package/src/forms/domains/parser/state.tsx +2 -0
  5. package/src/forms/domains/primitives/domains/base-64-file/state.ts +1 -0
  6. package/src/forms/domains/primitives/domains/base-64-file/template.tsx +2 -2
  7. package/src/forms/domains/primitives/domains/boolean/state.ts +1 -0
  8. package/src/forms/domains/primitives/domains/boolean/template.tsx +2 -2
  9. package/src/forms/domains/primitives/domains/date/state.ts +3 -1
  10. package/src/forms/domains/primitives/domains/date/template.tsx +2 -2
  11. package/src/forms/domains/primitives/domains/enum/state.ts +1 -0
  12. package/src/forms/domains/primitives/domains/enum/template.tsx +3 -3
  13. package/src/forms/domains/primitives/domains/enum-multiselect/state.ts +1 -0
  14. package/src/forms/domains/primitives/domains/enum-multiselect/template.tsx +5 -3
  15. package/src/forms/domains/primitives/domains/list/template.tsx +17 -6
  16. package/src/forms/domains/primitives/domains/map/template.tsx +71 -46
  17. package/src/forms/domains/primitives/domains/number/state.ts +1 -0
  18. package/src/forms/domains/primitives/domains/number/template.tsx +2 -2
  19. package/src/forms/domains/primitives/domains/searchable-infinite-stream/state.ts +1 -0
  20. package/src/forms/domains/primitives/domains/searchable-infinite-stream/template.tsx +3 -3
  21. package/src/forms/domains/primitives/domains/searchable-infinite-stream-multiselect/state.ts +1 -0
  22. package/src/forms/domains/primitives/domains/searchable-infinite-stream-multiselect/template.tsx +3 -3
  23. package/src/forms/domains/primitives/domains/secret/state.ts +1 -0
  24. package/src/forms/domains/primitives/domains/secret/template.tsx +2 -2
  25. package/src/forms/domains/primitives/domains/string/state.ts +1 -1
  26. package/src/forms/domains/primitives/domains/string/template.tsx +2 -2
  27. package/src/forms/domains/primitives/domains/sum/state.ts +1 -0
  28. package/src/forms/domains/primitives/domains/sum/template.tsx +45 -33
  29. package/src/forms/domains/primitives/domains/tuple/template.tsx +35 -16
  30. package/src/forms/domains/singleton/state.ts +2 -0
  31. package/src/forms/domains/singleton/template.tsx +8 -3
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "ballerina-core",
3
3
  "author": "Dr. Giuseppe Maggiore",
4
4
  "private": false,
5
- "version": "1.0.89",
5
+ "version": "1.0.91",
6
6
  "main": "main.ts",
7
7
  "scripts": {
8
8
  "prettier": "prettier --write ."
@@ -573,10 +573,12 @@ export const fromAPIRawValue =
573
573
  return ValueOrErrors.Default.throwOne(
574
574
  `Array expected but got ${JSON.stringify(raw)}`,
575
575
  );
576
- if (raw.length != t.args.length)
576
+ if (raw.length != t.args.length) {
577
+ console.debug("tuple", t, raw);
577
578
  return ValueOrErrors.Default.throwOne(
578
579
  `Array length mismatch expected tuple length: ${t.args.length} expected but got ${raw.length}`,
579
580
  );
581
+ }
580
582
 
581
583
  const result = converters[t.value].fromAPIRawValue(raw);
582
584
  return ValueOrErrors.Operations.All(
@@ -690,6 +692,9 @@ export const toAPIRawValue =
690
692
  ) =>
691
693
  (raw: PredicateValue, formState: any): ValueOrErrors<any, string> => {
692
694
  if (t.kind == "primitive") {
695
+ if (t.value == "unit") {
696
+ return ValueOrErrors.Default.return(unit);
697
+ }
693
698
  return ValueOrErrors.Operations.Return(
694
699
  converters[t.value as string | keyof T].toAPIRawValue([
695
700
  raw,
@@ -11,6 +11,12 @@ import {
11
11
  ListRepo,
12
12
  } from "../../../../../../main";
13
13
 
14
+ export type TuplePredicateExpression = {
15
+ kind: "tuple";
16
+ value: Expr;
17
+ elementExpressions: FieldPredicateExpression[];
18
+ };
19
+
14
20
  export type FieldPredicateExpression =
15
21
  | { kind: "unit"; value: Expr }
16
22
  | { kind: "primitive"; value: Expr }
@@ -22,11 +28,7 @@ export type FieldPredicateExpression =
22
28
  keyExpression: FieldPredicateExpression;
23
29
  valueExpression: FieldPredicateExpression;
24
30
  }
25
- | {
26
- kind: "tuple";
27
- value: Expr;
28
- elementExpressions: FieldPredicateExpression[];
29
- }
31
+ | TuplePredicateExpression
30
32
  | {
31
33
  kind: "sum";
32
34
  value: Expr;
@@ -102,33 +104,47 @@ export type FieldPredicateExpressions = Map<
102
104
  FieldPredicateExpression
103
105
  >;
104
106
 
107
+ export type TupleFieldPredicateEvaluation = {
108
+ kind: "tuple";
109
+ value: boolean;
110
+ elementValues: FormFieldPredicateEvaluation[];
111
+ };
112
+
113
+ export type ListFieldPredicateEvaluation = {
114
+ kind: "list";
115
+ value: boolean;
116
+ elementValues: FormFieldPredicateEvaluation[];
117
+ };
118
+
119
+ export type MapFieldPredicateEvaluation = {
120
+ kind: "map";
121
+ value: boolean;
122
+ elementValues: {
123
+ key: FormFieldPredicateEvaluation;
124
+ value: FormFieldPredicateEvaluation;
125
+ }[];
126
+ };
127
+
128
+ export type SumFieldPredicateEvaluation = {
129
+ kind: "sum";
130
+ value: boolean;
131
+ innerValue: FormFieldPredicateEvaluation;
132
+ };
133
+
134
+ export type FormsFieldPredicateEvaluation = {
135
+ kind: "form";
136
+ value: boolean;
137
+ fields: FormFieldPredicateEvaluations;
138
+ };
139
+
105
140
  export type FormFieldPredicateEvaluation =
106
141
  | { kind: "primitive"; value: boolean }
107
142
  | { kind: "unit"; value: boolean }
108
- | { kind: "form"; value: boolean; fields: FormFieldPredicateEvaluations }
109
- | {
110
- kind: "list";
111
- value: boolean;
112
- elementValues: FormFieldPredicateEvaluation[];
113
- }
114
- | {
115
- kind: "map";
116
- value: boolean;
117
- elementValues: {
118
- key: FormFieldPredicateEvaluation;
119
- value: FormFieldPredicateEvaluation;
120
- }[];
121
- }
122
- | {
123
- kind: "tuple";
124
- value: boolean;
125
- elementValues: FormFieldPredicateEvaluation[];
126
- }
127
- | {
128
- kind: "sum";
129
- value: boolean;
130
- innerValue: FormFieldPredicateEvaluation;
131
- };
143
+ | FormsFieldPredicateEvaluation
144
+ | ListFieldPredicateEvaluation
145
+ | MapFieldPredicateEvaluation
146
+ | TupleFieldPredicateEvaluation
147
+ | SumFieldPredicateEvaluation;
132
148
 
133
149
  export const FormFieldPredicateEvaluation = {
134
150
  Default: {
@@ -147,7 +163,11 @@ export const FormFieldPredicateEvaluation = {
147
163
  list: (
148
164
  value: boolean,
149
165
  elementValues: FormFieldPredicateEvaluation[],
150
- ): FormFieldPredicateEvaluation => ({ kind: "list", value, elementValues }),
166
+ ): FormFieldPredicateEvaluation => ({
167
+ kind: "list",
168
+ value,
169
+ elementValues,
170
+ }),
151
171
  map: (
152
172
  value: boolean,
153
173
  elementValues: {
@@ -206,6 +206,8 @@ export const ParseForms =
206
206
  })
207
207
  .mapContext<Unit>((_) => {
208
208
  return {
209
+ visible: (_ as any).visible ?? true,
210
+ disabled: (_ as any).disabled ?? false,
209
211
  label: (_ as any).label,
210
212
  value: (_ as any).value,
211
213
  commonFormState: (_ as any).commonFormState,
@@ -11,6 +11,7 @@ export type Base64FileView<
11
11
  Context &
12
12
  Value<string> & { commonFormState: CommonFormState } & {
13
13
  disabled: boolean;
14
+ visible: boolean;
14
15
  },
15
16
  { commonFormState: CommonFormState },
16
17
  ForeignMutationsExpected & {
@@ -18,7 +18,7 @@ export const Base64FileForm = <
18
18
  validation?: BasicFun<string, Promise<FieldValidation>>,
19
19
  ) => {
20
20
  return Template.Default<
21
- Context & Value<string> & { disabled: boolean },
21
+ Context & Value<string> & { disabled: boolean; visible: boolean },
22
22
  { commonFormState: CommonFormState },
23
23
  ForeignMutationsExpected & { onChange: OnChange<string> },
24
24
  Base64FileView<Context, ForeignMutationsExpected>
@@ -35,7 +35,7 @@ export const Base64FileForm = <
35
35
  </>
36
36
  )).any([
37
37
  ValidateRunner<
38
- Context & { disabled: boolean },
38
+ Context & { disabled: boolean; visible: boolean },
39
39
  { commonFormState: CommonFormState },
40
40
  ForeignMutationsExpected,
41
41
  string
@@ -11,6 +11,7 @@ export type BooleanView<
11
11
  Context &
12
12
  Value<boolean> & { commonFormState: CommonFormState } & {
13
13
  disabled: boolean;
14
+ visible: boolean;
14
15
  },
15
16
  { commonFormState: CommonFormState },
16
17
  ForeignMutationsExpected & {
@@ -22,7 +22,7 @@ export const BooleanForm = <
22
22
  validation?: BasicFun<boolean, Promise<FieldValidation>>,
23
23
  ) => {
24
24
  return Template.Default<
25
- Context & Value<boolean> & { disabled: boolean },
25
+ Context & Value<boolean> & { disabled: boolean; visible: boolean },
26
26
  { commonFormState: CommonFormState },
27
27
  ForeignMutationsExpected & { onChange: OnChange<boolean> },
28
28
  BooleanView<Context, ForeignMutationsExpected>
@@ -39,7 +39,7 @@ export const BooleanForm = <
39
39
  </>
40
40
  )).any([
41
41
  ValidateRunner<
42
- Context & { disabled: boolean },
42
+ Context & { disabled: boolean; visible: boolean },
43
43
  { commonFormState: CommonFormState },
44
44
  ForeignMutationsExpected,
45
45
  boolean
@@ -32,7 +32,9 @@ export type DateView<
32
32
  Context extends FormLabel,
33
33
  ForeignMutationsExpected,
34
34
  > = View<
35
- Context & Value<Maybe<Date>> & DateFormState & { disabled: boolean },
35
+ Context &
36
+ Value<Maybe<Date>> &
37
+ DateFormState & { disabled: boolean; visible: boolean },
36
38
  DateFormState,
37
39
  ForeignMutationsExpected & {
38
40
  onChange: OnChange<Date>;
@@ -21,7 +21,7 @@ export const DateForm = <Context extends FormLabel, ForeignMutationsExpected>(
21
21
  validation?: BasicFun<Date, Promise<FieldValidation>>,
22
22
  ) => {
23
23
  return Template.Default<
24
- Context & Value<Date> & { disabled: boolean },
24
+ Context & Value<Date> & { disabled: boolean; visible: boolean },
25
25
  DateFormState,
26
26
  ForeignMutationsExpected & { onChange: OnChange<Date> },
27
27
  DateView<Context, ForeignMutationsExpected>
@@ -52,7 +52,7 @@ export const DateForm = <Context extends FormLabel, ForeignMutationsExpected>(
52
52
  </>
53
53
  )).any([
54
54
  ValidateRunner<
55
- Context & { disabled: boolean },
55
+ Context & { disabled: boolean; visible: boolean },
56
56
  DateFormState,
57
57
  ForeignMutationsExpected,
58
58
  Date
@@ -37,6 +37,7 @@ export type EnumView<
37
37
  Value<ValueOption> &
38
38
  EnumFormState & {
39
39
  activeOptions: "loading" | Array<ValueRecord>;
40
+ visible: boolean;
40
41
  } & { disabled: boolean },
41
42
  EnumFormState,
42
43
  ForeignMutationsExpected & {
@@ -29,11 +29,11 @@ export const EnumForm = <
29
29
  validation?: BasicFun<ValueOption, Promise<FieldValidation>>,
30
30
  ) => {
31
31
  const Co = CoTypedFactory<
32
- Context & Value<ValueOption> & { disabled: boolean },
32
+ Context & Value<ValueOption> & { disabled: boolean; visible: boolean },
33
33
  EnumFormState
34
34
  >();
35
35
  return Template.Default<
36
- Context & Value<ValueOption> & { disabled: boolean },
36
+ Context & Value<ValueOption> & { disabled: boolean; visible: boolean },
37
37
  EnumFormState,
38
38
  ForeignMutationsExpected & {
39
39
  onChange: OnChange<ValueOption>;
@@ -89,7 +89,7 @@ export const EnumForm = <
89
89
  );
90
90
  }).any([
91
91
  ValidateRunner<
92
- Context & { disabled: boolean },
92
+ Context & { disabled: boolean; visible: boolean },
93
93
  EnumFormState,
94
94
  ForeignMutationsExpected,
95
95
  ValueOption
@@ -15,6 +15,7 @@ export type EnumMultiselectView<
15
15
  selectedIds: Array<Guid>;
16
16
  activeOptions: "loading" | Array<ValueRecord>;
17
17
  disabled: boolean;
18
+ visible: boolean;
18
19
  },
19
20
  EnumFormState,
20
21
  ForeignMutationsExpected & {
@@ -29,11 +29,13 @@ export const EnumMultiselectForm = <
29
29
  validation?: BasicFun<ValueRecord, Promise<FieldValidation>>,
30
30
  ) => {
31
31
  const Co = CoTypedFactory<
32
- Context & Value<ValueRecord> & EnumFormState & { disabled: boolean },
32
+ Context &
33
+ Value<ValueRecord> &
34
+ EnumFormState & { disabled: boolean; visible: boolean },
33
35
  EnumFormState
34
36
  >();
35
37
  return Template.Default<
36
- Context & Value<ValueRecord> & { disabled: boolean },
38
+ Context & Value<ValueRecord> & { disabled: boolean; visible: boolean },
37
39
  EnumFormState,
38
40
  ForeignMutationsExpected & {
39
41
  onChange: OnChange<ValueRecord>;
@@ -84,7 +86,7 @@ export const EnumMultiselectForm = <
84
86
  );
85
87
  }).any([
86
88
  ValidateRunner<
87
- Context & { disabled: boolean },
89
+ Context & { disabled: boolean; visible: boolean },
88
90
  EnumFormState,
89
91
  ForeignMutationsExpected,
90
92
  ValueRecord
@@ -8,9 +8,9 @@ import {
8
8
  BasicUpdater,
9
9
  MapRepo,
10
10
  ListRepo,
11
- FormFieldPredicateEvaluation,
12
11
  ValueTuple,
13
12
  PredicateValue,
13
+ ListFieldPredicateEvaluation,
14
14
  } from "../../../../../../main";
15
15
  import { Template } from "../../../../../template/state";
16
16
  import { Value } from "../../../../../value/state";
@@ -25,8 +25,8 @@ import { ListFieldState, ListFieldView } from "./state";
25
25
  export const ListForm = <
26
26
  ElementFormState extends { commonFormState: { modifiedByUser: boolean } },
27
27
  Context extends FormLabel & {
28
- visibilities: FormFieldPredicateEvaluation;
29
- disabledFields: FormFieldPredicateEvaluation;
28
+ visibilities: ListFieldPredicateEvaluation;
29
+ disabledFields: ListFieldPredicateEvaluation;
30
30
  },
31
31
  ForeignMutationsExpected,
32
32
  >(
@@ -76,7 +76,10 @@ export const ListForm = <
76
76
  );
77
77
  props.setState((_) => ({
78
78
  ..._,
79
- commonFormState: { ..._.commonFormState, modifiedByUser: true },
79
+ commonFormState: {
80
+ ..._.commonFormState,
81
+ modifiedByUser: true,
82
+ },
80
83
  }));
81
84
  },
82
85
  add: () => {},
@@ -91,8 +94,14 @@ export const ListForm = <
91
94
  _: Context & Value<ValueTuple> & ListFieldState<ElementFormState>,
92
95
  ): (Context & Value<ValueTuple> & ElementFormState) | undefined => {
93
96
  if (!_.value.values.has(elementIndex)) return undefined;
94
- if (_.visibilities.kind != "list") return undefined;
95
- if (_.disabledFields.kind != "list") return undefined;
97
+ if (_.visibilities == undefined || _.visibilities.kind != "list")
98
+ return undefined;
99
+ if (_.disabledFields == undefined || _.disabledFields.kind != "list")
100
+ return undefined;
101
+ const disabled =
102
+ _.disabledFields.elementValues[elementIndex]?.value ?? true;
103
+ const visible =
104
+ _.visibilities.elementValues[elementIndex]?.value ?? false;
96
105
  const element = _.value.values.get(elementIndex);
97
106
  const elementFormState =
98
107
  _.elementFormStates.get(elementIndex) || ElementFormState.Default();
@@ -105,6 +114,8 @@ export const ListForm = <
105
114
  value: element,
106
115
  visibilities: elementVisibility,
107
116
  disabledFields: elementDisabled,
117
+ disabled: disabled,
118
+ visible: visible,
108
119
  };
109
120
  return elementContext;
110
121
  },
@@ -11,6 +11,7 @@ import {
11
11
  FormFieldPredicateEvaluation,
12
12
  PredicateValue,
13
13
  ValueTuple,
14
+ MapFieldPredicateEvaluation,
14
15
  } from "../../../../../../main";
15
16
  import { Template } from "../../../../../template/state";
16
17
  import { Value } from "../../../../../value/state";
@@ -27,8 +28,8 @@ export const MapForm = <
27
28
  KeyFormState extends { commonFormState: CommonFormState },
28
29
  ValueFormState extends { commonFormState: CommonFormState },
29
30
  Context extends FormLabel & {
30
- visibilities: FormFieldPredicateEvaluation;
31
- disabledFields: FormFieldPredicateEvaluation;
31
+ visibilities: MapFieldPredicateEvaluation;
32
+ disabledFields: MapFieldPredicateEvaluation;
32
33
  },
33
34
  ForeignMutationsExpected,
34
35
  >(
@@ -92,7 +93,10 @@ export const MapForm = <
92
93
  );
93
94
  props.setState((_) => ({
94
95
  ..._,
95
- commonFormState: { ..._.commonFormState, modifiedByUser: true },
96
+ commonFormState: {
97
+ ..._.commonFormState,
98
+ modifiedByUser: true,
99
+ },
96
100
  }));
97
101
  },
98
102
  add: (newElement: ValueTuple) => {},
@@ -107,8 +111,14 @@ export const MapForm = <
107
111
  ): (Context & Value<ValueTuple> & KeyFormState) | undefined => {
108
112
  const element = _.value.values.get(elementIndex) as ValueTuple;
109
113
  if (element == undefined) return undefined;
110
- if (_.visibilities.kind != "map") return undefined;
111
- if (_.disabledFields.kind != "map") return undefined;
114
+ if (_.visibilities == undefined || _.visibilities.kind != "map")
115
+ return undefined;
116
+ if (_.disabledFields == undefined || _.disabledFields.kind != "map")
117
+ return undefined;
118
+ const disabled =
119
+ _.disabledFields.elementValues[elementIndex].key.value ?? true;
120
+ const visible =
121
+ _.visibilities.elementValues[elementIndex].key.value ?? false;
112
122
  const elementFormState = _.elementFormStates.get(elementIndex) || {
113
123
  KeyFormState: KeyFormState.Default(),
114
124
  ValueFormState: ValueFormState.Default(),
@@ -123,6 +133,8 @@ export const MapForm = <
123
133
  value: element.values.get(0)!,
124
134
  visibilities: elementVisibility,
125
135
  disabledFields: elementDisabled,
136
+ disabled: disabled,
137
+ visible: visible,
126
138
  };
127
139
  return elementContext;
128
140
  },
@@ -188,7 +200,10 @@ export const MapForm = <
188
200
  );
189
201
  props.setState((_) => ({
190
202
  ..._,
191
- commonFormState: { ..._.commonFormState, modifiedByUser: true },
203
+ commonFormState: {
204
+ ..._.commonFormState,
205
+ modifiedByUser: true,
206
+ },
192
207
  }));
193
208
  },
194
209
  add: (newElement: ValueTuple) => {},
@@ -203,8 +218,14 @@ export const MapForm = <
203
218
  ): (Context & Value<ValueTuple> & ValueFormState) | undefined => {
204
219
  const element = _.value.values.get(elementIndex) as ValueTuple;
205
220
  if (element == undefined) return undefined;
206
- if (_.visibilities.kind != "map") return undefined;
207
- if (_.disabledFields.kind != "map") return undefined;
221
+ if (_.visibilities == undefined || _.visibilities.kind != "map")
222
+ return undefined;
223
+ if (_.disabledFields == undefined || _.disabledFields.kind != "map")
224
+ return undefined;
225
+ const disabled =
226
+ _.disabledFields.elementValues[elementIndex].value.value ?? true;
227
+ const visible =
228
+ _.visibilities.elementValues[elementIndex].value.value ?? false;
208
229
  const elementFormState = _.elementFormStates.get(elementIndex) || {
209
230
  KeyFormState: KeyFormState.Default(),
210
231
  ValueFormState: ValueFormState.Default(),
@@ -219,6 +240,8 @@ export const MapForm = <
219
240
  value: element.values.get(1)!,
220
241
  visibilities: elementVisibility,
221
242
  disabledFields: elementDisabled,
243
+ disabled: disabled,
244
+ visible: visible,
222
245
  };
223
246
  return elementContext;
224
247
  },
@@ -254,47 +277,49 @@ export const MapForm = <
254
277
  Context,
255
278
  ForeignMutationsExpected
256
279
  >
257
- >((props) => (
258
- <>
259
- <props.view
260
- {...props}
261
- context={{
262
- ...props.context,
263
- }}
264
- foreignMutations={{
265
- ...props.foreignMutations,
266
- add: (_) => {
267
- props.foreignMutations.onChange(
268
- Updater((list) =>
269
- PredicateValue.Default.tuple(
270
- ListRepo.Updaters.push<ValueTuple>(
271
- PredicateValue.Default.tuple(
272
- List([Key.Default(), Value.Default()]),
273
- ),
274
- )(list.values as List<ValueTuple>),
280
+ >((props) => {
281
+ return (
282
+ <>
283
+ <props.view
284
+ {...props}
285
+ context={{
286
+ ...props.context,
287
+ }}
288
+ foreignMutations={{
289
+ ...props.foreignMutations,
290
+ add: (_) => {
291
+ props.foreignMutations.onChange(
292
+ Updater((list) =>
293
+ PredicateValue.Default.tuple(
294
+ ListRepo.Updaters.push<ValueTuple>(
295
+ PredicateValue.Default.tuple(
296
+ List([Key.Default(), Value.Default()]),
297
+ ),
298
+ )(list.values as List<ValueTuple>),
299
+ ),
275
300
  ),
276
- ),
277
- List([{ kind: "add" }]),
278
- );
279
- },
280
- remove: (_) => {
281
- props.foreignMutations.onChange(
282
- Updater((list) =>
283
- PredicateValue.Default.tuple(
284
- ListRepo.Updaters.remove<ValueTuple>(_)(
285
- list.values as List<ValueTuple>,
301
+ List([{ kind: "add" }]),
302
+ );
303
+ },
304
+ remove: (_) => {
305
+ props.foreignMutations.onChange(
306
+ Updater((list) =>
307
+ PredicateValue.Default.tuple(
308
+ ListRepo.Updaters.remove<ValueTuple>(_)(
309
+ list.values as List<ValueTuple>,
310
+ ),
286
311
  ),
287
312
  ),
288
- ),
289
- List([_, { kind: "remove" }]),
290
- );
291
- },
292
- }}
293
- embeddedKeyTemplate={embeddedKeyTemplate}
294
- embeddedValueTemplate={embeddedValueTemplate}
295
- />
296
- </>
297
- )).any([
313
+ List([_, { kind: "remove" }]),
314
+ );
315
+ },
316
+ }}
317
+ embeddedKeyTemplate={embeddedKeyTemplate}
318
+ embeddedValueTemplate={embeddedValueTemplate}
319
+ />
320
+ </>
321
+ );
322
+ }).any([
298
323
  ValidateRunner<
299
324
  Context & { disabled: boolean },
300
325
  MapFieldState<KeyFormState, ValueFormState>,
@@ -11,6 +11,7 @@ export type NumberView<
11
11
  Context &
12
12
  Value<number> & { commonFormState: CommonFormState } & {
13
13
  disabled: boolean;
14
+ visible: boolean;
14
15
  },
15
16
  { commonFormState: CommonFormState },
16
17
  ForeignMutationsExpected & {
@@ -19,7 +19,7 @@ export const NumberForm = <Context extends FormLabel, ForeignMutationsExpected>(
19
19
  validation?: BasicFun<number, Promise<FieldValidation>>,
20
20
  ) => {
21
21
  return Template.Default<
22
- Context & Value<number> & { disabled: boolean },
22
+ Context & Value<number> & { disabled: boolean; visible: boolean },
23
23
  { commonFormState: CommonFormState },
24
24
  ForeignMutationsExpected & { onChange: OnChange<number> },
25
25
  NumberView<Context, ForeignMutationsExpected>
@@ -36,7 +36,7 @@ export const NumberForm = <Context extends FormLabel, ForeignMutationsExpected>(
36
36
  </>
37
37
  )).any([
38
38
  ValidateRunner<
39
- Context & { disabled: boolean },
39
+ Context & { disabled: boolean; visible: boolean },
40
40
  { commonFormState: CommonFormState },
41
41
  ForeignMutationsExpected,
42
42
  number
@@ -81,6 +81,7 @@ export type SearchableInfiniteStreamView<
81
81
  SearchableInfiniteStreamState & {
82
82
  hasMoreValues: boolean;
83
83
  disabled: boolean;
84
+ visible: boolean;
84
85
  },
85
86
  SearchableInfiniteStreamState,
86
87
  ForeignMutationsExpected & {
@@ -34,7 +34,7 @@ export const SearchableInfiniteStreamForm = <
34
34
  validation?: BasicFun<ValueOption, Promise<FieldValidation>>,
35
35
  ) => {
36
36
  const Co = CoTypedFactory<
37
- Context & Value<ValueOption> & { disabled: boolean },
37
+ Context & Value<ValueOption> & { disabled: boolean; visible: boolean },
38
38
  SearchableInfiniteStreamState
39
39
  >();
40
40
  const DebouncerCo = CoTypedFactory<
@@ -92,7 +92,7 @@ export const SearchableInfiniteStreamForm = <
92
92
  );
93
93
 
94
94
  return Template.Default<
95
- Context & Value<ValueOption> & { disabled: boolean },
95
+ Context & Value<ValueOption> & { disabled: boolean; visible: boolean },
96
96
  SearchableInfiniteStreamState,
97
97
  ForeignMutationsExpected & {
98
98
  onChange: OnChange<ValueOption>;
@@ -180,7 +180,7 @@ export const SearchableInfiniteStreamForm = <
180
180
  ),
181
181
  })),
182
182
  ValidateRunner<
183
- Context & { disabled: boolean },
183
+ Context & { disabled: boolean; visible: boolean },
184
184
  SearchableInfiniteStreamState,
185
185
  ForeignMutationsExpected,
186
186
  ValueOption
@@ -18,6 +18,7 @@ export type InfiniteStreamMultiselectView<
18
18
  isLoading: boolean;
19
19
  availableOptions: Array<CollectionReference>;
20
20
  disabled: boolean;
21
+ visible: boolean;
21
22
  },
22
23
  SearchableInfiniteStreamState,
23
24
  ForeignMutationsExpected & {
@@ -41,7 +41,7 @@ export const InfiniteMultiselectDropdownForm = <
41
41
  validation?: BasicFun<ValueRecord, Promise<FieldValidation>>,
42
42
  ) => {
43
43
  const Co = CoTypedFactory<
44
- Context & Value<ValueRecord> & { disabled: boolean },
44
+ Context & Value<ValueRecord> & { disabled: boolean; visible: boolean },
45
45
  SearchableInfiniteStreamState
46
46
  >();
47
47
  const DebouncerCo = CoTypedFactory<
@@ -95,7 +95,7 @@ export const InfiniteMultiselectDropdownForm = <
95
95
  );
96
96
 
97
97
  return Template.Default<
98
- Context & Value<ValueRecord> & { disabled: boolean },
98
+ Context & Value<ValueRecord> & { disabled: boolean; visible: boolean },
99
99
  SearchableInfiniteStreamState,
100
100
  ForeignMutationsExpected & {
101
101
  onChange: OnChange<ValueRecord>;
@@ -199,7 +199,7 @@ export const InfiniteMultiselectDropdownForm = <
199
199
  ),
200
200
  })),
201
201
  ValidateRunner<
202
- Context & { disabled: boolean },
202
+ Context & { disabled: boolean; visible: boolean },
203
203
  SearchableInfiniteStreamState,
204
204
  ForeignMutationsExpected,
205
205
  ValueRecord
@@ -11,6 +11,7 @@ export type SecretView<
11
11
  Context &
12
12
  Value<string> & { commonFormState: CommonFormState } & {
13
13
  disabled: boolean;
14
+ visible: boolean;
14
15
  },
15
16
  { commonFormState: CommonFormState },
16
17
  ForeignMutationsExpected & {
@@ -15,7 +15,7 @@ export const SecretForm = <Context extends FormLabel, ForeignMutationsExpected>(
15
15
  validation?: BasicFun<string, Promise<FieldValidation>>,
16
16
  ) => {
17
17
  return Template.Default<
18
- Context & Value<string> & { disabled: boolean },
18
+ Context & Value<string> & { disabled: boolean; visible: boolean },
19
19
  { commonFormState: CommonFormState },
20
20
  ForeignMutationsExpected & { onChange: OnChange<string> },
21
21
  SecretView<Context, ForeignMutationsExpected>
@@ -32,7 +32,7 @@ export const SecretForm = <Context extends FormLabel, ForeignMutationsExpected>(
32
32
  </>
33
33
  )).any([
34
34
  ValidateRunner<
35
- Context & { disabled: boolean },
35
+ Context & { disabled: boolean; visible: boolean },
36
36
  { commonFormState: CommonFormState },
37
37
  ForeignMutationsExpected,
38
38
  string
@@ -12,7 +12,7 @@ export type StringView<
12
12
  Value<string> & {
13
13
  commonFormState: CommonFormState;
14
14
  customFormState: Unit;
15
- } & { disabled: boolean },
15
+ } & { disabled: boolean; visible: boolean },
16
16
  { commonFormState: CommonFormState; customFormState: Unit },
17
17
  ForeignMutationsExpected & {
18
18
  onChange: OnChange<string>;
@@ -26,7 +26,7 @@ export const StringForm = <Context extends FormLabel, ForeignMutationsExpected>(
26
26
  validation?: BasicFun<string, Promise<FieldValidation>>,
27
27
  ) => {
28
28
  return Template.Default<
29
- Context & Value<string> & { disabled: boolean },
29
+ Context & Value<string> & { disabled: boolean; visible: boolean },
30
30
  { commonFormState: CommonFormState; customFormState: Unit },
31
31
  ForeignMutationsExpected & { onChange: OnChange<string> },
32
32
  StringView<Context, ForeignMutationsExpected>
@@ -43,7 +43,7 @@ export const StringForm = <Context extends FormLabel, ForeignMutationsExpected>(
43
43
  </>
44
44
  )).any([
45
45
  ValidateRunner<
46
- Context & { disabled: boolean },
46
+ Context & { disabled: boolean; visible: boolean },
47
47
  { commonFormState: CommonFormState; customFormState: Unit },
48
48
  ForeignMutationsExpected,
49
49
  string
@@ -6,6 +6,7 @@ import {
6
6
  simpleUpdater,
7
7
  Sum,
8
8
  Template,
9
+ Unit,
9
10
  Value,
10
11
  ValueSum,
11
12
  View,
@@ -2,9 +2,9 @@ import { List } from "immutable";
2
2
  import {
3
3
  BasicFun,
4
4
  BasicUpdater,
5
- FormFieldPredicateEvaluation,
6
5
  PredicateValue,
7
6
  Sum,
7
+ SumFieldPredicateEvaluation,
8
8
  Updater,
9
9
  ValidateRunner,
10
10
  Value,
@@ -25,8 +25,10 @@ export const SumForm = <
25
25
  LeftFormState,
26
26
  RightFormState,
27
27
  Context extends FormLabel & {
28
- visibilities: FormFieldPredicateEvaluation;
29
- disabledFields: FormFieldPredicateEvaluation;
28
+ visibilities: SumFieldPredicateEvaluation;
29
+ disabledFields: SumFieldPredicateEvaluation;
30
+ disabled: boolean;
31
+ visible: boolean;
30
32
  },
31
33
  ForeignMutationsExpected,
32
34
  >(
@@ -84,13 +86,17 @@ export const SumForm = <
84
86
  SumFieldState<LeftFormState, RightFormState>,
85
87
  ): (Context & Value<PredicateValue> & LeftFormState) | undefined => {
86
88
  if (_.value.value.kind != "l") return undefined;
87
- if (_.visibilities.kind != "sum") return undefined;
88
- if (_.disabledFields.kind != "sum") return undefined;
89
+ if (_.visibilities == undefined || _.visibilities.kind != "sum")
90
+ return undefined;
91
+ if (_.disabledFields == undefined || _.disabledFields.kind != "sum")
92
+ return undefined;
89
93
  const leftFormState =
90
94
  _.customFormState.left || LeftFormState.Default();
91
95
  const leftContext: Context & Value<PredicateValue> & LeftFormState = {
92
96
  ..._,
93
97
  ...leftFormState,
98
+ disabled: _.disabledFields.innerValue.value ?? true,
99
+ visible: _.visibilities.innerValue.value ?? false,
94
100
  value: _.value.value.value,
95
101
  visibilities: _.visibilities.innerValue,
96
102
  disabledFields: _.disabledFields.innerValue,
@@ -144,14 +150,18 @@ export const SumForm = <
144
150
  SumFieldState<LeftFormState, RightFormState>,
145
151
  ): (Context & Value<PredicateValue> & RightFormState) | undefined => {
146
152
  if (_.value.value.kind != "r") return undefined;
147
- if (_.visibilities.kind != "sum") return undefined;
148
- if (_.disabledFields.kind != "sum") return undefined;
153
+ if (_.visibilities == undefined || _.visibilities.kind != "sum")
154
+ return undefined;
155
+ if (_.disabledFields == undefined || _.disabledFields.kind != "sum")
156
+ return undefined;
149
157
  const rightFormState =
150
158
  _.customFormState.right || RightFormState.Default();
151
159
  const rightContext: Context & Value<PredicateValue> & RightFormState =
152
160
  {
153
161
  ..._,
154
162
  ...rightFormState,
163
+ disabled: _.disabledFields.innerValue.value,
164
+ visible: _.visibilities.innerValue.value,
155
165
  value: _.value.value.value,
156
166
  visibilities: _.visibilities.innerValue,
157
167
  disabledFields: _.disabledFields.innerValue,
@@ -183,32 +193,34 @@ export const SumForm = <
183
193
  Context,
184
194
  ForeignMutationsExpected
185
195
  >
186
- >((props) => (
187
- <>
188
- <props.view
189
- {...props}
190
- context={{ ...props.context }}
191
- foreignMutations={{
192
- ...props.foreignMutations,
193
- onSwitch: () => {
194
- props.foreignMutations.onChange(
195
- (_) =>
196
- _.value.kind === "l"
197
- ? PredicateValue.Default.sum(
198
- Sum.Default.right(Right.Default()),
199
- )
200
- : PredicateValue.Default.sum(
201
- Sum.Default.left(Left.Default()),
202
- ),
203
- List(["switch"]),
204
- );
205
- },
206
- }}
207
- embeddedLeftTemplate={embeddedLeftTemplate}
208
- embeddedRightTemplate={embeddedRightTemplate}
209
- />
210
- </>
211
- )).any([
196
+ >((props) => {
197
+ return (
198
+ <>
199
+ <props.view
200
+ {...props}
201
+ context={{ ...props.context }}
202
+ foreignMutations={{
203
+ ...props.foreignMutations,
204
+ onSwitch: () => {
205
+ props.foreignMutations.onChange(
206
+ (_) =>
207
+ _.value.kind === "l"
208
+ ? PredicateValue.Default.sum(
209
+ Sum.Default.right(Right.Default()),
210
+ )
211
+ : PredicateValue.Default.sum(
212
+ Sum.Default.left(Left.Default()),
213
+ ),
214
+ List(["switch"]),
215
+ );
216
+ },
217
+ }}
218
+ embeddedLeftTemplate={embeddedLeftTemplate}
219
+ embeddedRightTemplate={embeddedRightTemplate}
220
+ />
221
+ </>
222
+ );
223
+ }).any([
212
224
  ValidateRunner<
213
225
  Context & { disabled: boolean },
214
226
  SumFieldState<LeftFormState, RightFormState>,
@@ -12,6 +12,9 @@ import {
12
12
  FormFieldPredicateEvaluation,
13
13
  ValueTuple,
14
14
  PredicateValue,
15
+ FieldPredicateExpression,
16
+ TuplePredicateExpression,
17
+ TupleFieldPredicateEvaluation,
15
18
  } from "../../../../../../main";
16
19
  import { Template } from "../../../../../template/state";
17
20
  import { Value } from "../../../../../value/state";
@@ -28,8 +31,10 @@ export const TupleForm = <
28
31
  commonFormState: { modifiedByUser: boolean };
29
32
  }>,
30
33
  Context extends FormLabel & {
31
- visibilities: FormFieldPredicateEvaluation;
32
- disabledFields: FormFieldPredicateEvaluation;
34
+ visibilities: TupleFieldPredicateEvaluation;
35
+ disabledFields: TupleFieldPredicateEvaluation;
36
+ disabled: boolean;
37
+ visible: boolean;
33
38
  },
34
39
  ForeignMutationsExpected,
35
40
  >(
@@ -37,16 +42,17 @@ export const TupleForm = <
37
42
  Default: () => { commonFormState: { modifiedByUser: boolean } };
38
43
  }>,
39
44
  elementTemplates: List<
40
- Template<
41
- Context &
42
- Value<PredicateValue> & {
43
- commonFormState: { modifiedByUser: boolean };
44
- },
45
- any,
46
- ForeignMutationsExpected & {
47
- onChange: OnChange<PredicateValue>;
48
- }
49
- >
45
+ | Template<
46
+ Context &
47
+ Value<PredicateValue> & {
48
+ commonFormState: { modifiedByUser: boolean };
49
+ },
50
+ any,
51
+ ForeignMutationsExpected & {
52
+ onChange: OnChange<PredicateValue>;
53
+ }
54
+ >
55
+ | undefined
50
56
  >,
51
57
  validation?: BasicFun<ValueTuple, Promise<FieldValidation>>,
52
58
  ) => {
@@ -81,7 +87,10 @@ export const TupleForm = <
81
87
  );
82
88
  props.setState((_) => ({
83
89
  ..._,
84
- commonFormState: { ..._.commonFormState, modifiedByUser: true },
90
+ commonFormState: {
91
+ ..._.commonFormState,
92
+ modifiedByUser: true,
93
+ },
85
94
  }));
86
95
  },
87
96
  }),
@@ -96,8 +105,14 @@ export const TupleForm = <
96
105
  })
97
106
  | undefined => {
98
107
  if (!_.value.values.has(elementIndex)) return undefined;
99
- if (_.visibilities.kind != "tuple") return undefined;
100
- if (_.disabledFields.kind != "tuple") return undefined;
108
+ if (_.visibilities == undefined || _.visibilities.kind != "tuple")
109
+ return undefined;
110
+ if (_.disabledFields == undefined || _.disabledFields.kind != "tuple")
111
+ return undefined;
112
+ const disabled =
113
+ _.disabledFields.elementValues[elementIndex].value ?? true;
114
+ const visible =
115
+ _.visibilities.elementValues[elementIndex].value ?? false;
101
116
  const element = _.value.values.get(elementIndex);
102
117
  const elementFormState =
103
118
  _.elementFormStates.get(elementIndex) ||
@@ -110,6 +125,8 @@ export const TupleForm = <
110
125
  } = {
111
126
  ..._,
112
127
  ...elementFormState,
128
+ disabled: disabled,
129
+ visible: visible,
113
130
  value: element,
114
131
  visibilities: elementVisibility,
115
132
  disabledFields: elementDisabled,
@@ -119,7 +136,9 @@ export const TupleForm = <
119
136
  )
120
137
  .mapState(
121
138
  (
122
- _: BasicUpdater<{ commonFormState: { modifiedByUser: boolean } }>,
139
+ _: BasicUpdater<{
140
+ commonFormState: { modifiedByUser: boolean };
141
+ }>,
123
142
  ): Updater<TupleFieldState<ElementFormStates>> =>
124
143
  TupleFieldState<ElementFormStates>().Updaters.Core.elementFormStates(
125
144
  MapRepo.Updaters.upsert(
@@ -87,6 +87,8 @@ export type EntityFormContext<
87
87
  ForeignMutationsExpected,
88
88
  > = Context &
89
89
  EntityFormState<Fields, FieldStates, Context, ForeignMutationsExpected> & {
90
+ disabled: boolean;
91
+ visible: boolean;
90
92
  elementVisibilities: FormFieldPredicateEvaluation[] | undefined;
91
93
  elementDisabledFields: FormFieldPredicateEvaluation | undefined;
92
94
  extraContext: any;
@@ -45,7 +45,7 @@ export const Form = <
45
45
  Context & {
46
46
  customFormState: State["formFieldStates"][f]["customFormState"];
47
47
  commonFormState: State["formFieldStates"][f]["commonFormState"];
48
- } & Value<f> & { disabled: boolean },
48
+ } & Value<f> & { disabled: boolean; visible: boolean },
49
49
  {
50
50
  customFormState: State["formFieldStates"][f]["customFormState"];
51
51
  commonFormState: State["formFieldStates"][f]["commonFormState"];
@@ -84,7 +84,7 @@ export const Form = <
84
84
  FieldStates,
85
85
  Context,
86
86
  ForeignMutationsExpected
87
- > & { disabled: boolean }
87
+ > & { disabled: boolean; visible: boolean }
88
88
  >((_) => {
89
89
  // disabled flag is passed in from the wrapping container when mapping over fields
90
90
  const visibilitiesFromParent =
@@ -102,6 +102,7 @@ export const Form = <
102
102
  value: (_.value as ValueRecord).fields.get(field as string),
103
103
  extraContext: _.extraContext,
104
104
  disabled: _.disabled,
105
+ visible: _.visible,
105
106
  commonFormState: _.formFieldStates[field].commonFormState,
106
107
  customFormState: _.formFieldStates[field].customFormState,
107
108
  formFieldStates: _.formFieldStates[field].formFieldStates,
@@ -222,6 +223,7 @@ export const Form = <
222
223
  const visibleFieldKeys: OrderedSet<FieldName> = (() => {
223
224
  if (
224
225
  props.context.visibilities == undefined ||
226
+ props.context.visible == false ||
225
227
  props.context.visibilities.kind != "form"
226
228
  )
227
229
  return OrderedSet();
@@ -235,9 +237,12 @@ export const Form = <
235
237
  const disabledFieldKeys: OrderedSet<FieldName> = (() => {
236
238
  if (
237
239
  props.context.disabledFields == undefined ||
240
+ props.context.disabled ||
238
241
  props.context.disabledFields.kind != "form"
239
242
  )
240
- return OrderedSet(Object.keys(props.context.value as object));
243
+ return OrderedSet(
244
+ Object.keys(props.context.value.fields.toJS() as object),
245
+ );
241
246
 
242
247
  return props.context.disabledFields.fields
243
248
  .filter((_) => _.value == true)