11import { JsonSchema , UISchemaElement } from '../models' ;
22import { JsonFormsState , getAjv } from '../store' ;
3- import { hasEnableRule , isEnabled } from '../util' ;
3+ import { hasEnableRule , hasReadonlyRule , isEnabled , isReadonly } from '../util' ;
44
55/**
66 * Indicates whether the given `uischema` element shall be enabled or disabled.
7- * Checks the global readonly flag, uischema rule, uischema options (including the config),
7+ * Checks the global readonly flag (unless separateReadonlyFromDisabled is enabled) , uischema rule, uischema options (including the config),
88 * the schema and the enablement indicator of the parent.
99 */
1010export const isInherentlyEnabled = (
@@ -15,29 +15,80 @@ export const isInherentlyEnabled = (
1515 rootData : any ,
1616 config : any
1717) => {
18- if ( state ?. jsonforms ?. readonly ) {
18+ if ( ! config ?. separateReadonlyFromDisabled && state ?. jsonforms ?. readonly ) {
1919 return false ;
2020 }
2121 if ( uischema && hasEnableRule ( uischema ) ) {
2222 return isEnabled ( uischema , rootData , ownProps ?. path , getAjv ( state ) , config ) ;
2323 }
24+ if ( ! config ?. separateReadonlyFromDisabled ) {
25+ if ( typeof uischema ?. options ?. readonly === 'boolean' ) {
26+ return ! uischema . options . readonly ;
27+ }
28+ if ( typeof uischema ?. options ?. readOnly === 'boolean' ) {
29+ return ! uischema . options . readOnly ;
30+ }
31+ if ( typeof config ?. readonly === 'boolean' ) {
32+ return ! config . readonly ;
33+ }
34+ if ( typeof config ?. readOnly === 'boolean' ) {
35+ return ! config . readOnly ;
36+ }
37+ if ( schema ?. readOnly === true ) {
38+ return false ;
39+ }
40+ }
41+ if ( typeof ownProps ?. enabled === 'boolean' ) {
42+ return ownProps . enabled ;
43+ }
44+ return true ;
45+ } ;
46+
47+ /**
48+ * Indicates whether the given `uischema` element shall be readonly or writable.
49+ * Checks the global readonly flag, uischema rule, uischema options (including the config),
50+ * the schema and the readonly indicator of the parent.
51+ */
52+ export const isInherentlyReadonly = (
53+ state : JsonFormsState ,
54+ ownProps : any ,
55+ uischema : UISchemaElement ,
56+ schema : ( JsonSchema & { readOnly ?: boolean } ) | undefined ,
57+ rootData : any ,
58+ config : any
59+ ) => {
60+ if ( state ?. jsonforms ?. readonly ) {
61+ return true ;
62+ }
63+
64+ if ( uischema && hasReadonlyRule ( uischema ) ) {
65+ return isReadonly (
66+ uischema ,
67+ rootData ,
68+ ownProps ?. path ,
69+ getAjv ( state ) ,
70+ config
71+ ) ;
72+ }
73+
2474 if ( typeof uischema ?. options ?. readonly === 'boolean' ) {
25- return ! uischema . options . readonly ;
75+ return uischema . options . readonly ;
2676 }
2777 if ( typeof uischema ?. options ?. readOnly === 'boolean' ) {
28- return ! uischema . options . readOnly ;
78+ return uischema . options . readOnly ;
2979 }
3080 if ( typeof config ?. readonly === 'boolean' ) {
31- return ! config . readonly ;
81+ return config . readonly ;
3282 }
3383 if ( typeof config ?. readOnly === 'boolean' ) {
34- return ! config . readOnly ;
84+ return config . readOnly ;
3585 }
3686 if ( schema ?. readOnly === true ) {
37- return false ;
87+ return true ;
3888 }
39- if ( typeof ownProps ?. enabled === 'boolean' ) {
40- return ownProps . enabled ;
89+ if ( typeof ownProps ?. readonly === 'boolean' ) {
90+ return ownProps . readonly ;
4191 }
42- return true ;
92+
93+ return false ;
4394} ;
0 commit comments