feat: assignment

This commit is contained in:
cha0s 2021-01-30 20:10:40 -06:00
parent d35f9bd598
commit d877180476

View File

@ -11,6 +11,7 @@ import classnames from 'classnames';
import Invocation from './expression/invocation';
import Key from './expression/key';
import Variant from './variant';
const Expression = ({
context,
@ -21,7 +22,7 @@ const Expression = ({
const latus = useLatus();
const patch = useJsonPatcher();
let i = 0;
const {ops} = value;
const {ops, value: expressionValue} = value;
const Renderables = [];
let opsCount = 0;
// eslint-disable-next-line react/destructuring-assignment
@ -205,6 +206,57 @@ const Expression = ({
opsCount += 1;
}
const [lastOp] = ops.slice(-1);
if (
'void' === type
&& !description.args
&& isKey(lastOp)
) {
const opPath = join(path, 'value');
Renderables.push(
<Key
childrenDescription={{
'.': {label: '', type: description.type},
'≔': {label: '', type: 'void'},
}}
key={opPath}
onChange={(event, value) => {
if ('.' === value) {
patch({
op: 'remove',
path: opPath,
});
}
else {
patch({
path: opPath,
value: {
type: 'literal',
},
});
}
}}
path={opPath}
value={expressionValue ? '≔' : '.'}
/>,
);
if (expressionValue) {
Renderables.push(
<Variant
context={context}
onChange={(event, value, localPath) => {
patch({
path: localPath,
value,
});
}}
key={join(opPath, 'expression')}
path={opPath}
type={description.type}
value={expressionValue}
/>,
);
}
}
let realType;
if (isKey(lastOp)) {
realType = description.args
@ -214,6 +266,9 @@ const Expression = ({
if (isInvocation(lastOp)) {
realType = description.type;
}
if (expressionValue) {
realType = 'void';
}
return (
<div
className={classnames(
@ -244,6 +299,8 @@ Expression.propTypes = {
key: PropTypes.string,
}),
),
// eslint-disable-next-line react/forbid-prop-types
value: PropTypes.any,
}).isRequired,
path: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,