From abf457d28c18fd52b50f830b88a60fac88b6aa29 Mon Sep 17 00:00:00 2001 From: cha0s Date: Fri, 29 Jan 2021 14:15:04 -0600 Subject: [PATCH] feat: invocation toggle --- .../src/behavior-components/expression.jsx | 61 ++++++++++++++++--- .../src/behavior-components/expression.scss | 7 +++ 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/packages/entity/src/behavior-components/expression.jsx b/packages/entity/src/behavior-components/expression.jsx index 9ea3a65..04e407a 100644 --- a/packages/entity/src/behavior-components/expression.jsx +++ b/packages/entity/src/behavior-components/expression.jsx @@ -17,7 +17,8 @@ const Expression = ({ const patch = useJsonPatcher(); let i = 0; const {ops} = expression; - const Ops = []; + const Renderables = []; + let opsCount = 0; let walk = context; // eslint-disable-next-line react/destructuring-assignment let description = context.constructor.descriptionFor(walk); @@ -57,10 +58,11 @@ const Expression = ({ do { const op = ops[i]; const opKey = JSON.stringify(op); - const opPath = join(path, 'ops', Ops.length.toString()); + const opPath = join(path, 'ops', opsCount.toString()); + const nextOp = i === ops.length - 1 ? undefined : ops[i + 1]; if (isKey(op)) { const isLast = i === ops.length - 1 ? true : isInvocation(ops[i + 1]); - Ops.push( + Renderables.push( , ); + opsCount += 1; } if (isInvocation(op)) { - Ops.push( + Renderables.push( + , + ); + Renderables.push( , ); + opsCount += 1; } if (isKey(op)) { if (context === walk) { @@ -101,6 +120,33 @@ const Expression = ({ ...context.constructor.descriptionFor(walk), ...description.children[op.key], }; + if (description.args && (!nextOp || !isInvocation(nextOp))) { + Renderables.push( + , + ); + } } } while (i++ < ops.length - 1); if (description.children) { @@ -109,8 +155,8 @@ const Expression = ({ key: '.', }; const opKey = JSON.stringify(op); - const opPath = join(path, 'ops', Ops.length.toString()); - Ops.push( + const opPath = join(path, 'ops', opsCount.toString()); + Renderables.push( , ); + opsCount += 1; } return (
- {Ops} + {Renderables}
); }; diff --git a/packages/entity/src/behavior-components/expression.scss b/packages/entity/src/behavior-components/expression.scss index 3692c4e..2d7da27 100644 --- a/packages/entity/src/behavior-components/expression.scss +++ b/packages/entity/src/behavior-components/expression.scss @@ -3,3 +3,10 @@ display: flex; flex-wrap: wrap; } + +.expression__invocation-toggle { + padding: 0.25em; + &.from { + transform: rotate(180deg); + } +}