@jsonforms/core 3.7.0-alpha.1 → 3.7.0-alpha.3

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.
@@ -124,6 +124,8 @@ export interface ValidateFunctionContext {
124
124
  path: string | undefined;
125
125
  /** The `UISchemaElement` containing the rule that uses the ValidateFunctionCondition, e.g. a `ControlElement` */
126
126
  uischemaElement: UISchemaElement;
127
+ /** The form config */
128
+ config: unknown;
127
129
  }
128
130
  /**
129
131
  * A composable condition.
@@ -1,8 +1,8 @@
1
1
  import { UISchemaElement } from '../models';
2
2
  import type Ajv from 'ajv';
3
- export declare const evalVisibility: (uischema: UISchemaElement, data: any, path: string, ajv: Ajv) => boolean;
4
- export declare const evalEnablement: (uischema: UISchemaElement, data: any, path: string, ajv: Ajv) => boolean;
3
+ export declare const evalVisibility: (uischema: UISchemaElement, data: any, path: string, ajv: Ajv, config: unknown) => boolean;
4
+ export declare const evalEnablement: (uischema: UISchemaElement, data: any, path: string, ajv: Ajv, config: unknown) => boolean;
5
5
  export declare const hasShowRule: (uischema: UISchemaElement) => boolean;
6
6
  export declare const hasEnableRule: (uischema: UISchemaElement) => boolean;
7
- export declare const isVisible: (uischema: UISchemaElement, data: any, path: string, ajv: Ajv) => boolean;
8
- export declare const isEnabled: (uischema: UISchemaElement, data: any, path: string, ajv: Ajv) => boolean;
7
+ export declare const isVisible: (uischema: UISchemaElement, data: any, path: string, ajv: Ajv, config: unknown) => boolean;
8
+ export declare const isEnabled: (uischema: UISchemaElement, data: any, path: string, ajv: Ajv, config: unknown) => boolean;
@@ -51,6 +51,6 @@ export declare const Paths: {
51
51
  fromScoped: (scopable: Scoped) => string;
52
52
  };
53
53
  export declare const Runtime: {
54
- isEnabled(uischema: UISchemaElement, data: any, ajv: Ajv): boolean;
55
- isVisible(uischema: UISchemaElement, data: any, ajv: Ajv): boolean;
54
+ isEnabled(uischema: UISchemaElement, data: any, ajv: Ajv, config: unknown): boolean;
55
+ isVisible(uischema: UISchemaElement, data: any, ajv: Ajv, config: unknown): boolean;
56
56
  };
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@jsonforms/core",
3
- "version": "3.7.0-alpha.1",
3
+ "version": "3.7.0-alpha.3",
4
4
  "description": "Core module of JSON Forms",
5
- "repository": "https://github.com/eclipsesource/jsonforms",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/eclipsesource/jsonforms.git",
8
+ "directory": "packages/core"
9
+ },
6
10
  "bugs": "https://github.com/eclipsesource/jsonforms/issues",
7
11
  "homepage": "http://jsonforms.io/",
8
12
  "license": "MIT",
@@ -112,13 +112,13 @@ export const mapStateToCellProps = (
112
112
  ): StatePropsOfCell => {
113
113
  const { id, schema, path, uischema, renderers, cells } = ownProps;
114
114
  const rootData = getData(state);
115
+ const config = getConfig(state);
115
116
  const visible =
116
117
  ownProps.visible !== undefined
117
118
  ? ownProps.visible
118
- : isVisible(uischema, rootData, undefined, getAjv(state));
119
+ : isVisible(uischema, rootData, undefined, getAjv(state), config);
119
120
 
120
121
  const rootSchema = getSchema(state);
121
- const config = getConfig(state);
122
122
 
123
123
  /* When determining the enabled state of cells we take a shortcut: At the
124
124
  * moment it's only possible to configure enablement and disablement at the
@@ -582,9 +582,11 @@ export const mapStateToControlProps = (
582
582
  const { uischema } = ownProps;
583
583
  const rootData = getData(state);
584
584
  const path = composeWithUi(uischema, ownProps.path);
585
+ const config = getConfig(state);
586
+
585
587
  const visible: boolean =
586
588
  ownProps.visible === undefined || hasShowRule(uischema)
587
- ? isVisible(uischema, rootData, ownProps.path, getAjv(state))
589
+ ? isVisible(uischema, rootData, ownProps.path, getAjv(state), config)
588
590
  : ownProps.visible;
589
591
  const controlElement = uischema as ControlElement;
590
592
  const id = ownProps.id;
@@ -604,7 +606,6 @@ export const mapStateToControlProps = (
604
606
  const data = Resolve.data(rootData, path);
605
607
  const labelDesc = createLabelDescriptionFrom(uischema, resolvedSchema);
606
608
  const label = labelDesc.show ? labelDesc.text : '';
607
- const config = getConfig(state);
608
609
  const enabled: boolean = isInherentlyEnabled(
609
610
  state,
610
611
  ownProps,
@@ -1042,7 +1043,13 @@ export const mapStateToLayoutProps = (
1042
1043
  const { uischema } = ownProps;
1043
1044
  const visible: boolean =
1044
1045
  ownProps.visible === undefined || hasShowRule(uischema)
1045
- ? isVisible(ownProps.uischema, rootData, ownProps.path, getAjv(state))
1046
+ ? isVisible(
1047
+ ownProps.uischema,
1048
+ rootData,
1049
+ ownProps.path,
1050
+ getAjv(state),
1051
+ getConfig(state)
1052
+ )
1046
1053
  : ownProps.visible;
1047
1054
 
1048
1055
  const data = Resolve.data(rootData, ownProps.path);
@@ -1280,7 +1287,13 @@ export const mapStateToLabelProps = (
1280
1287
 
1281
1288
  const visible: boolean =
1282
1289
  props.visible === undefined || hasShowRule(uischema)
1283
- ? isVisible(props.uischema, getData(state), props.path, getAjv(state))
1290
+ ? isVisible(
1291
+ props.uischema,
1292
+ getData(state),
1293
+ props.path,
1294
+ getAjv(state),
1295
+ getConfig(state)
1296
+ )
1284
1297
  : props.visible;
1285
1298
 
1286
1299
  const text = uischema.text;
@@ -19,7 +19,7 @@ export const isInherentlyEnabled = (
19
19
  return false;
20
20
  }
21
21
  if (uischema && hasEnableRule(uischema)) {
22
- return isEnabled(uischema, rootData, ownProps?.path, getAjv(state));
22
+ return isEnabled(uischema, rootData, ownProps?.path, getAjv(state), config);
23
23
  }
24
24
  if (typeof uischema?.options?.readonly === 'boolean') {
25
25
  return !uischema.options.readonly;
@@ -169,6 +169,8 @@ export interface ValidateFunctionContext {
169
169
  path: string | undefined;
170
170
  /** The `UISchemaElement` containing the rule that uses the ValidateFunctionCondition, e.g. a `ControlElement` */
171
171
  uischemaElement: UISchemaElement;
172
+ /** The form config */
173
+ config: unknown;
172
174
  }
173
175
 
174
176
  /**
@@ -67,16 +67,19 @@ const evaluateCondition = (
67
67
  uischema: UISchemaElement,
68
68
  condition: Condition,
69
69
  path: string,
70
- ajv: Ajv
70
+ ajv: Ajv,
71
+ config: unknown
71
72
  ): boolean => {
72
73
  if (isAndCondition(condition)) {
73
74
  return condition.conditions.reduce(
74
- (acc, cur) => acc && evaluateCondition(data, uischema, cur, path, ajv),
75
+ (acc, cur) =>
76
+ acc && evaluateCondition(data, uischema, cur, path, ajv, config),
75
77
  true
76
78
  );
77
79
  } else if (isOrCondition(condition)) {
78
80
  return condition.conditions.reduce(
79
- (acc, cur) => acc || evaluateCondition(data, uischema, cur, path, ajv),
81
+ (acc, cur) =>
82
+ acc || evaluateCondition(data, uischema, cur, path, ajv, config),
80
83
  false
81
84
  );
82
85
  } else if (isLeafCondition(condition)) {
@@ -95,6 +98,7 @@ const evaluateCondition = (
95
98
  fullData: data,
96
99
  path,
97
100
  uischemaElement: uischema,
101
+ config,
98
102
  };
99
103
  return condition.validate(context);
100
104
  } else {
@@ -107,19 +111,21 @@ const isRuleFulfilled = (
107
111
  uischema: UISchemaElement,
108
112
  data: any,
109
113
  path: string,
110
- ajv: Ajv
114
+ ajv: Ajv,
115
+ config: unknown
111
116
  ): boolean => {
112
117
  const condition = uischema.rule.condition;
113
- return evaluateCondition(data, uischema, condition, path, ajv);
118
+ return evaluateCondition(data, uischema, condition, path, ajv, config);
114
119
  };
115
120
 
116
121
  export const evalVisibility = (
117
122
  uischema: UISchemaElement,
118
123
  data: any,
119
124
  path: string = undefined,
120
- ajv: Ajv
125
+ ajv: Ajv,
126
+ config: unknown
121
127
  ): boolean => {
122
- const fulfilled = isRuleFulfilled(uischema, data, path, ajv);
128
+ const fulfilled = isRuleFulfilled(uischema, data, path, ajv, config);
123
129
 
124
130
  switch (uischema.rule.effect) {
125
131
  case RuleEffect.HIDE:
@@ -136,9 +142,10 @@ export const evalEnablement = (
136
142
  uischema: UISchemaElement,
137
143
  data: any,
138
144
  path: string = undefined,
139
- ajv: Ajv
145
+ ajv: Ajv,
146
+ config: unknown
140
147
  ): boolean => {
141
- const fulfilled = isRuleFulfilled(uischema, data, path, ajv);
148
+ const fulfilled = isRuleFulfilled(uischema, data, path, ajv, config);
142
149
 
143
150
  switch (uischema.rule.effect) {
144
151
  case RuleEffect.DISABLE:
@@ -177,10 +184,11 @@ export const isVisible = (
177
184
  uischema: UISchemaElement,
178
185
  data: any,
179
186
  path: string = undefined,
180
- ajv: Ajv
187
+ ajv: Ajv,
188
+ config: unknown
181
189
  ): boolean => {
182
190
  if (uischema.rule) {
183
- return evalVisibility(uischema, data, path, ajv);
191
+ return evalVisibility(uischema, data, path, ajv, config);
184
192
  }
185
193
 
186
194
  return true;
@@ -190,10 +198,11 @@ export const isEnabled = (
190
198
  uischema: UISchemaElement,
191
199
  data: any,
192
200
  path: string = undefined,
193
- ajv: Ajv
201
+ ajv: Ajv,
202
+ config: unknown
194
203
  ): boolean => {
195
204
  if (uischema.rule) {
196
- return evalEnablement(uischema, data, path, ajv);
205
+ return evalEnablement(uischema, data, path, ajv, config);
197
206
  }
198
207
 
199
208
  return true;
package/src/util/util.ts CHANGED
@@ -163,10 +163,20 @@ export const Paths = {
163
163
 
164
164
  // Runtime --
165
165
  export const Runtime = {
166
- isEnabled(uischema: UISchemaElement, data: any, ajv: Ajv): boolean {
167
- return isEnabled(uischema, data, undefined, ajv);
166
+ isEnabled(
167
+ uischema: UISchemaElement,
168
+ data: any,
169
+ ajv: Ajv,
170
+ config: unknown
171
+ ): boolean {
172
+ return isEnabled(uischema, data, undefined, ajv, config);
168
173
  },
169
- isVisible(uischema: UISchemaElement, data: any, ajv: Ajv): boolean {
170
- return isVisible(uischema, data, undefined, ajv);
174
+ isVisible(
175
+ uischema: UISchemaElement,
176
+ data: any,
177
+ ajv: Ajv,
178
+ config: unknown
179
+ ): boolean {
180
+ return isVisible(uischema, data, undefined, ajv, config);
171
181
  },
172
182
  };