import React from 'react' ; import { JSONSchema7 , JSONSchema7Definition } from 'json-schema' ; export type PropertyTypeName = JSONSchema7 [ 'type' ] | 'entity-ref' | 'eval' ; export function getPropertyTypeName ( property ) { if ( propertyIsEntityRef ( property ) ) { return 'entity-ref' ; } if ( property . format ?. startsWith ( 'eval:' ) ) { return 'eval' ; } return property . type ; } export function propertyIsEntityRef ( property ) { if ( typeof property === 'boolean' ) { return false ; } return property . $ref ?. startsWith ( '#entity/' ) || property . $ref === '#user' ; } export function getPropertyEntityRef ( property ) { if ( ! propertyIsEntityRef ( property ) || typeof property === 'boolean' ) { return ; } return property . $ref ?. startsWith ( '#entity/' ) ? property . $ref ?. substr ( '#entity/' . length ) : 'user' ; } export function handleAttrChange < M , T > ( onChange , key , value , setter ) { setter ( value ) ; onChange ( key , value ) ; } export function handleNumberAttrChange < M > ( onChange , key , value , setter ) { handleAttrChange < M , number | undefined > ( onChange , key , value ? Number ( value ) : undefined , setter ) ; }