Skip to content

Commit 85d5a3c

Browse files
committed
support for multiple expressions in textExpression
1 parent 14b82ed commit 85d5a3c

File tree

4 files changed

+42
-54
lines changed

4 files changed

+42
-54
lines changed

apps/vps-web/src/app/custom-nodes-v2/form/VanillaFormCore.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { IFlowCanvasBase } from '@devhelpr/visual-programming-system';
77
import {
88
getVariablePayloadInputUtils,
99
NodeInfo,
10+
replaceExpressionScript,
1011
} from '@devhelpr/web-flow-executor';
1112

1213
interface FormPage extends Page {
@@ -287,20 +288,8 @@ export class VanillaFormCore {
287288
this.scopeId,
288289
this.canvasAppInstance
289290
);
290-
const compiledExpression = compileExpressionAsInfo(expression);
291-
const expressionFunction = (
292-
new Function('payload', `${compiledExpression.script}`) as unknown as (
293-
payload?: any
294-
) => any
295-
).bind(compiledExpression.bindings);
296-
return (
297-
runExpression(
298-
expressionFunction,
299-
payloadForExpression,
300-
false,
301-
compiledExpression.payloadProperties
302-
) ?? ''
303-
).toString();
291+
292+
return replaceExpressionScript(expression, payloadForExpression);
304293
}
305294
private getOptonsViaExpression(expression: string) {
306295
const compiledExpression = compileExpressionAsInfo(expression);

examples-test-flows/learn-swedish2.json

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
},
3939
{
4040
"id": "4360f032-9fbf-403b-af9f-f2dec001ddf6",
41-
"x": -3856.6332883515397,
42-
"y": 441.66501263880014,
43-
"width": 239.99985162012172,
44-
"height": 367.9999948977943,
41+
"x": -3892.511179242742,
42+
"y": 531.2552153837826,
43+
"width": 240.00000501389866,
44+
"height": 392.0003163165241,
4545
"nodeType": "Shape",
4646
"nodeInfo": {
4747
"type": "show-object",
@@ -52,15 +52,15 @@
5252
},
5353
{
5454
"id": "8f99faef-2ab2-4ea9-9bb4-3b26d5dc511e",
55-
"x": -3449.472489728539,
56-
"y": 351.77912326545294,
57-
"width": 483.1329126889236,
58-
"height": 490.94379671085414,
55+
"x": -3453.459590179823,
56+
"y": 249.25551699329014,
57+
"width": 485.5518584489778,
58+
"height": 648.8295761150445,
5959
"nodeType": "Shape",
6060
"nodeInfo": {
6161
"type": "form",
6262
"formValues": {
63-
"formJson": "{\n \"app\": {\n \"title\": \"Basic quiz\",\n \"pages\": [\n {\n \"id\": \"personal-info\",\n \"title\": \"Personal Information\",\n \"route\": \"/personal\",\n \"isEndPage\": true,\n \"components\": [\n {\n \"type\": \"text\",\n \"id\": \"intro\",\n \"props\": {\n \"textExpression\": \"sv\"\n }\n },\n {\n \"type\": \"radio\",\n \"id\": \"question\",\n \"label\": \"Question\",\n \"props\": {\n \"optionsExpression\": \"o\"\n },\n \"validation\": {\n \"required\": true\n }\n }\n ]\n }\n ]\n }\n}\n"
63+
"formJson": "{\n \"app\": {\n \"title\": \"Basic quiz\",\n \"pages\": [\n {\n \"id\": \"personal-info\",\n \"title\": \"Personal Information\",\n \"route\": \"/personal\",\n \"isEndPage\": true,\n \"components\": [\n {\n \"type\": \"text\",\n \"id\": \"intro\",\n \"props\": {\n \"textExpression\": \"{{sv}} {{score}} / {{questionIndex}}\"\n }\n },\n {\n \"type\": \"radio\",\n \"id\": \"question\",\n \"label\": \"Question\",\n \"props\": {\n \"optionsExpression\": \"o\"\n },\n \"validation\": {\n \"required\": true\n }\n }\n ]\n }\n ]\n }\n}\n"
6464
},
6565
"fillColor": "black",
6666
"strokeColor": "white",
@@ -73,10 +73,10 @@
7373
},
7474
{
7575
"id": "5d3ca1b6-c787-416c-b5ec-61b3a3c2ddcd",
76-
"x": -2807.358803728899,
77-
"y": 435.0029362261489,
78-
"width": 240.00003696479476,
79-
"height": 103.99995423652004,
76+
"x": -2821.1193745788464,
77+
"y": 442.91646460963153,
78+
"width": 239.9998854478763,
79+
"height": 104.00003144674852,
8080
"nodeType": "Shape",
8181
"nodeInfo": {
8282
"type": "show-object",
@@ -119,8 +119,8 @@
119119
"id": "a8e8565b-ea0d-4d23-a36a-8fe11446e943",
120120
"x": -168.24803602749932,
121121
"y": 49.0272223505593,
122-
"width": 119.99992581006086,
123-
"height": 55.99999317972936,
122+
"width": 119.99994235782867,
123+
"height": 56.00003727553041,
124124
"nodeType": "Shape",
125125
"nodeInfo": {
126126
"type": "show-input",
@@ -230,8 +230,8 @@
230230
"id": "c9d5b004-6139-470e-8090-9ece55c8e25d",
231231
"x": -3417.8759889489697,
232232
"y": -337.8770009511329,
233-
"width": 91.5157857661005,
234-
"height": 83.99998976959404,
233+
"width": 91.5157078781082,
234+
"height": 83.99999322521023,
235235
"nodeType": "Shape",
236236
"nodeInfo": {
237237
"type": "variable",
@@ -305,8 +305,8 @@
305305
"id": "d447f6e0-1f6c-4064-a082-e2a5fcd91928",
306306
"x": -3153.152793043027,
307307
"y": -321.09091730623317,
308-
"width": 91.51560042142746,
309-
"height": 84.00001293767816,
308+
"width": 91.515454422619,
309+
"height": 83.9999983159156,
310310
"nodeType": "Shape",
311311
"nodeInfo": {
312312
"type": "variable",
@@ -352,15 +352,15 @@
352352
},
353353
{
354354
"id": "25c94012-db83-4783-be5f-517f8f4c40e7",
355-
"x": 848.1260001955592,
356-
"y": 599.7825363198851,
355+
"x": 848.1258801884392,
356+
"y": 599.7825713960938,
357357
"width": 434.81809202725157,
358358
"height": 294.1138665386298,
359359
"nodeType": "Shape",
360360
"nodeInfo": {
361361
"type": "form",
362362
"formValues": {
363-
"formJson": "{\n \"app\": {\n \"title\": \"Basic quiz score\",\n \"pages\": [\n {\n \"id\": \"personal-info\",\n \"title\": \"Personal Information\",\n \"route\": \"/personal\",\n \"isEndPage\": true,\n \"hasSubmitButtons\" : false,\n \"hasStepIndicator\" : false,\n \"components\": [\n {\n \"type\": \"text\",\n \"label\": \"correct\",\n \"id\": \"score\",\n \"props\": {\n \"textExpression\": \"score\"\n }\n },\n {\n \"type\": \"text\",\n \"label\": \"questions count\",\n \"id\": \"count\",\n \"props\": {\n \"textExpression\": \"questionIndex\"\n }\n }\n ]\n }\n ]\n }\n}\n"
363+
"formJson": "{\n \"app\": {\n \"title\": \"Basic quiz score\",\n \"pages\": [\n {\n \"id\": \"personal-info\",\n \"title\": \"Personal Information\",\n \"route\": \"/personal\",\n \"isEndPage\": true,\n \"hasSubmitButtons\" : false,\n \"hasStepIndicator\" : false,\n \"components\": [\n {\n \"type\": \"text\",\n \"label\": \"correct\",\n \"id\": \"score\",\n \"props\": {\n \"textExpression\": \"{{score}}\"\n }\n },\n {\n \"type\": \"text\",\n \"label\": \"questions count\",\n \"id\": \"count\",\n \"props\": {\n \"textExpression\": \"{{questionIndex}}\"\n }\n }\n ]\n }\n ]\n }\n}\n"
364364
},
365365
"fillColor": "black",
366366
"strokeColor": "white",
@@ -390,8 +390,8 @@
390390
"id": "1f985d07-8955-4b8d-9b92-39846c4be941",
391391
"x": -4028.084945363141,
392392
"y": 228.69484350289937,
393-
"endX": -3856.6332883515397,
394-
"endY": 471.66501263880014,
393+
"endX": -3892.511179242742,
394+
"endY": 561.2552153837826,
395395
"startNodeId": "75c87169-4c29-476b-8de8-5fd7df6059b6",
396396
"endNodeId": "4360f032-9fbf-403b-af9f-f2dec001ddf6",
397397
"startThumbName": "output",
@@ -403,10 +403,10 @@
403403
},
404404
{
405405
"id": "81f7f7e4-c235-4a2c-9120-4099cc25ac54",
406-
"x": -3207.906033384077,
407-
"y": 597.25102162088,
408-
"endX": -2807.358803728899,
409-
"endY": 465.0029362261489,
406+
"x": -3210.683660955334,
407+
"y": 573.6703050508124,
408+
"endX": -2821.1193745788464,
409+
"endY": 472.91646460963153,
410410
"startNodeId": "8f99faef-2ab2-4ea9-9bb4-3b26d5dc511e",
411411
"endNodeId": "5d3ca1b6-c787-416c-b5ec-61b3a3c2ddcd",
412412
"startThumbName": "input-output",
@@ -508,8 +508,8 @@
508508
},
509509
{
510510
"id": "8a9bf305-2989-4c5b-806b-26d422df2cc7",
511-
"x": -2567.3587667641045,
512-
"y": 465.0029362261489,
511+
"x": -2581.11948913097,
512+
"y": 472.91646460963153,
513513
"endX": -2490.4288625824847,
514514
"endY": 476.9815596884095,
515515
"startNodeId": "5d3ca1b6-c787-416c-b5ec-61b3a3c2ddcd",
@@ -553,10 +553,10 @@
553553
},
554554
{
555555
"id": "d4ffa17b-01ae-4a35-b0cc-d31bc3fa9ab5",
556-
"x": -3616.633436731418,
557-
"y": 471.66501263880014,
558-
"endX": -3449.472489728539,
559-
"endY": 597.25102162088,
556+
"x": -3652.511174228843,
557+
"y": 561.2552153837826,
558+
"endX": -3453.459590179823,
559+
"endY": 573.6703050508124,
560560
"startNodeId": "4360f032-9fbf-403b-af9f-f2dec001ddf6",
561561
"endNodeId": "8f99faef-2ab2-4ea9-9bb4-3b26d5dc511e",
562562
"startThumbName": "output",
@@ -568,7 +568,7 @@
568568
},
569569
{
570570
"id": "8d89234b-0b8f-40bd-a275-898a744cc2b8",
571-
"x": -48.248110217438466,
571+
"x": -48.24809366967065,
572572
"y": 79.0272223505593,
573573
"endX": 57.49521448749903,
574574
"endY": 942.5097333674655,
@@ -705,8 +705,8 @@
705705
"id": "bfbaca27-2c2e-4062-8dc9-6e73c72af990",
706706
"x": 584.0800631666957,
707707
"y": 940.2958187569535,
708-
"endX": 848.1260001955592,
709-
"endY": 746.8394695892,
708+
"endX": 848.1258801884392,
709+
"endY": 746.8395046654086,
710710
"startNodeId": "74edb67f-3e70-46df-99ff-8d591b0bda56",
711711
"endNodeId": "25c94012-db83-4783-be5f-517f8f4c40e7",
712712
"startThumbName": "output",

libs/web-flow-executor/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ export * from './nodes/variable-payload-input-utils/variable-payload-input-utils
99
export type { ComputeAsync } from './types/compute-async';
1010
export * from './interface/flow-engine';
1111
export * from './consts/llm-keys';
12+
export * from './utils/replace-expression-script';

libs/web-flow-executor/src/utils/replace-expression-script.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ export const replaceExpressionScript = (
2323
try {
2424
const result = runExpression(
2525
expressionFunction,
26-
{
27-
...payload,
28-
},
26+
payload,
2927
true,
3028
info.payloadProperties
3129
);

0 commit comments

Comments
 (0)