diff --git a/packages/entity/src/behavior-components/expression.jsx b/packages/entity/src/behavior-components/expression.jsx index d07b109..0e2bcba 100644 --- a/packages/entity/src/behavior-components/expression.jsx +++ b/packages/entity/src/behavior-components/expression.jsx @@ -42,18 +42,27 @@ const Expression = ({ }, }); } - if ('.' !== patches[0].value) { - // eslint-disable-next-line babel/no-unused-expressions - patch(patches); - } - else { - const parts = patches[0].path.split('/'); + if ('.' === patches[patches.length - 1].value) { + const parts = patches[patches.length - 1].path.split('/'); parts.pop(); patch({ op: 'remove', path: parts.join('/'), }); } + else if ('' === patches[patches.length - 1].value) { + patch({ + op: 'replace', + path, + value: { + type: 'literal', + value: null, + }, + }); + } + else { + patch(patches); + } }; do { const op = ops[i]; @@ -61,10 +70,21 @@ const Expression = ({ const opPath = join(path, 'ops', opsCount.toString()); const nextOp = i === ops.length - 1 ? undefined : ops[i + 1]; if (isKey(op)) { + const isFirst = 0 === i; const isLast = i === ops.length - 1 ? true : isInvocation(ops[i + 1]); Renderables.push( ': { + label: '', + type, + }, + } + : {} + ), ...( isLast ? {'.': {label: '', type: description.type}} @@ -132,7 +152,7 @@ const Expression = ({ type: 'invoke', args: description.args.map(() => ({ type: 'literal', - value: 69, + value: null, })), }; patch({ diff --git a/packages/entity/src/behavior-components/expression/invocation.jsx b/packages/entity/src/behavior-components/expression/invocation.jsx index 048de55..228f1e0 100644 --- a/packages/entity/src/behavior-components/expression/invocation.jsx +++ b/packages/entity/src/behavior-components/expression/invocation.jsx @@ -1,8 +1,10 @@ import {join} from 'path'; import {PropTypes, React} from '@latus/react'; +import {useJsonPatcher} from '@persea/json'; import Literal from '../literal'; +import Key from './key'; const Invocation = ({ context, @@ -11,45 +13,80 @@ const Invocation = ({ onChange, op, path, -}) => ( -
- ( - { - op.args.map((arg, i) => ( -
- { - 'literal' === arg.type - ? ( - - ) - : ( - - ) - } - {i < op.args.length - 1 && , } -
- )) - } - ) -
-); +}) => { + // eslint-disable-next-line react/destructuring-assignment + const contextDescription = context.describe(); + const patch = useJsonPatcher(); + return ( +
+ ( + { + op.args.map((arg, i) => ( +
+ { + 'literal' === arg.type + ? ( + <> + ': { + label: '', + type: arg.type, + }, + ...contextDescription.children, + }} + onChange={(event, value) => { + patch({ + op: 'replace', + path: join(path, 'args', i.toString()), + value: { + type: 'expression', + ops: [ + { + type: 'key', + key: value, + }, + ], + }, + }); + }} + op={op} + path={path} + /> + + + ) + : ( + + ) + } + {i < op.args.length - 1 && , } +
+ )) + } + ) +
+ ); +}; Invocation.propTypes = { - context: PropTypes.shape({}).isRequired, + context: PropTypes.shape({ + describe: PropTypes.func, + }).isRequired, description: PropTypes.shape({ args: PropTypes.arrayOf( PropTypes.shape({