@goplasmatic/datalogic-ui 4.0.9 → 4.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.cjs +78 -22
  2. package/dist/index.js +79 -22
  3. package/package.json +15 -16
package/dist/index.cjs CHANGED
@@ -2654,11 +2654,21 @@ function createIfElseNodeFromTrace(nodeId, expression, children, context, parent
2654
2654
  argIndex: idx
2655
2655
  });
2656
2656
  } else {
2657
- conditionBranchId = `${nodeId}-cond-${idx}`;
2658
- createFallbackNode(conditionBranchId, condition, context, {
2659
- parentId: nodeId,
2660
- argIndex: idx
2661
- });
2657
+ const condNodeType = determineNodeType(condition, context.preserveStructure);
2658
+ const nextUnused = condNodeType !== "literal" ? getNextUnusedChild(children, usedChildIndices) : null;
2659
+ if (nextUnused) {
2660
+ usedChildIndices.add(nextUnused.index);
2661
+ conditionBranchId = processExpressionNode(nextUnused.child, context, {
2662
+ parentId: nodeId,
2663
+ argIndex: idx
2664
+ }, condition);
2665
+ } else {
2666
+ conditionBranchId = `${nodeId}-cond-${idx}`;
2667
+ createFallbackNode(conditionBranchId, condition, context, {
2668
+ parentId: nodeId,
2669
+ argIndex: idx
2670
+ });
2671
+ }
2662
2672
  }
2663
2673
  context.edges.push(createBranchEdge(nodeId, conditionBranchId, branchIndex));
2664
2674
  const conditionText = generateExpressionText(condition, 40);
@@ -2682,12 +2692,23 @@ function createIfElseNodeFromTrace(nodeId, expression, children, context, parent
2682
2692
  branchType: "yes"
2683
2693
  });
2684
2694
  } else {
2685
- thenBranchId = `${nodeId}-then-${idx}`;
2686
- createFallbackNode(thenBranchId, thenValue, context, {
2687
- parentId: nodeId,
2688
- argIndex: idx + 1,
2689
- branchType: "yes"
2690
- });
2695
+ const thenNodeType = determineNodeType(thenValue, context.preserveStructure);
2696
+ const nextUnused = thenNodeType !== "literal" ? getNextUnusedChild(children, usedChildIndices) : null;
2697
+ if (nextUnused) {
2698
+ usedChildIndices.add(nextUnused.index);
2699
+ thenBranchId = processExpressionNode(nextUnused.child, context, {
2700
+ parentId: nodeId,
2701
+ argIndex: idx + 1,
2702
+ branchType: "yes"
2703
+ }, thenValue);
2704
+ } else {
2705
+ thenBranchId = `${nodeId}-then-${idx}`;
2706
+ createFallbackNode(thenBranchId, thenValue, context, {
2707
+ parentId: nodeId,
2708
+ argIndex: idx + 1,
2709
+ branchType: "yes"
2710
+ });
2711
+ }
2691
2712
  }
2692
2713
  context.edges.push(createBranchEdge(nodeId, thenBranchId, branchIndex));
2693
2714
  const thenText = generateExpressionText(thenValue, 40);
@@ -2716,12 +2737,23 @@ function createIfElseNodeFromTrace(nodeId, expression, children, context, parent
2716
2737
  branchType: "no"
2717
2738
  });
2718
2739
  } else {
2719
- elseBranchId = `${nodeId}-else`;
2720
- createFallbackNode(elseBranchId, elseValue, context, {
2721
- parentId: nodeId,
2722
- argIndex: ifArgs.length - 1,
2723
- branchType: "no"
2724
- });
2740
+ const elseNodeType = determineNodeType(elseValue, context.preserveStructure);
2741
+ const nextUnused = elseNodeType !== "literal" ? getNextUnusedChild(children, usedChildIndices) : null;
2742
+ if (nextUnused) {
2743
+ usedChildIndices.add(nextUnused.index);
2744
+ elseBranchId = processExpressionNode(nextUnused.child, context, {
2745
+ parentId: nodeId,
2746
+ argIndex: ifArgs.length - 1,
2747
+ branchType: "no"
2748
+ }, elseValue);
2749
+ } else {
2750
+ elseBranchId = `${nodeId}-else`;
2751
+ createFallbackNode(elseBranchId, elseValue, context, {
2752
+ parentId: nodeId,
2753
+ argIndex: ifArgs.length - 1,
2754
+ branchType: "no"
2755
+ });
2756
+ }
2725
2757
  }
2726
2758
  context.edges.push(createBranchEdge(nodeId, elseBranchId, branchIndex));
2727
2759
  const elseText = generateExpressionText(elseValue, 40);
@@ -2777,6 +2809,14 @@ function findMatchingChild(operand, children, usedIndices) {
2777
2809
  }
2778
2810
  return null;
2779
2811
  }
2812
+ function getNextUnusedChild(children, usedIndices) {
2813
+ for (let i = 0; i < children.length; i++) {
2814
+ if (!usedIndices.has(i)) {
2815
+ return { child: children[i], index: i };
2816
+ }
2817
+ }
2818
+ return null;
2819
+ }
2780
2820
  function createVerticalCellNodeFromTrace(nodeId, expression, children, context, parentInfo) {
2781
2821
  const obj = expression;
2782
2822
  const operator = Object.keys(obj)[0];
@@ -2994,7 +3034,9 @@ function createStructureNodeFromTrace(nodeId, expression, children, context, par
2994
3034
  return EXPR_PLACEHOLDER;
2995
3035
  }
2996
3036
  return item;
2997
- });
3037
+ },
3038
+ context
3039
+ );
2998
3040
  const formattedJson = JSON.stringify(structureWithPlaceholders, null, 2);
2999
3041
  let searchPos = 0;
3000
3042
  for (const element of elements) {
@@ -3037,14 +3079,19 @@ function createStructureNodeFromTrace(nodeId, expression, children, context, par
3037
3079
  }
3038
3080
  }
3039
3081
  }
3082
+ function isExpressionBranch(item, preserveStructure) {
3083
+ if (isJsonLogicExpression(item)) return true;
3084
+ if (preserveStructure && isDataStructure(item)) return true;
3085
+ return false;
3086
+ }
3040
3087
  function walkAndCollectFromTrace(value, path, onValue, context) {
3041
3088
  if (Array.isArray(value)) {
3042
3089
  return value.map((item, index) => {
3043
3090
  const itemPath = [...path, String(index)];
3044
- if (isJsonLogicExpression(item)) {
3091
+ if (isExpressionBranch(item, context.preserveStructure)) {
3045
3092
  return onValue(itemPath, item);
3046
3093
  } else if (typeof item === "object" && item !== null) {
3047
- return walkAndCollectFromTrace(item, itemPath, onValue);
3094
+ return walkAndCollectFromTrace(item, itemPath, onValue, context);
3048
3095
  }
3049
3096
  return item;
3050
3097
  });
@@ -3053,10 +3100,10 @@ function walkAndCollectFromTrace(value, path, onValue, context) {
3053
3100
  const result = {};
3054
3101
  for (const [key, item] of Object.entries(value)) {
3055
3102
  const itemPath = [...path, key];
3056
- if (isJsonLogicExpression(item)) {
3103
+ if (isExpressionBranch(item, context.preserveStructure)) {
3057
3104
  result[key] = onValue(itemPath, item, key);
3058
3105
  } else if (typeof item === "object" && item !== null) {
3059
- result[key] = walkAndCollectFromTrace(item, itemPath, onValue);
3106
+ result[key] = walkAndCollectFromTrace(item, itemPath, onValue, context);
3060
3107
  } else {
3061
3108
  result[key] = item;
3062
3109
  }
@@ -9238,6 +9285,11 @@ function collectCellBranchIds(cell, target) {
9238
9285
  if (cell.conditionBranchId) target.add(cell.conditionBranchId);
9239
9286
  if (cell.thenBranchId) target.add(cell.thenBranchId);
9240
9287
  }
9288
+ function collectStructureBranchIds(elements, target) {
9289
+ elements.forEach((element) => {
9290
+ if (element.branchId) target.add(element.branchId);
9291
+ });
9292
+ }
9241
9293
  function buildParentChildMap(nodes) {
9242
9294
  const parentChildMap = /* @__PURE__ */ new Map();
9243
9295
  nodes.forEach((node) => {
@@ -9274,6 +9326,10 @@ function getHiddenNodeIds(nodes) {
9274
9326
  }
9275
9327
  });
9276
9328
  }
9329
+ } else if (isStructureNode(node)) {
9330
+ if (node.data.collapsed && node.data.elements) {
9331
+ collectStructureBranchIds(node.data.elements, collapsedBranchIds);
9332
+ }
9277
9333
  }
9278
9334
  });
9279
9335
  function markDescendantsHidden(parentId) {
package/dist/index.js CHANGED
@@ -3286,11 +3286,21 @@ let __tla = (async () => {
3286
3286
  argIndex: idx
3287
3287
  });
3288
3288
  } else {
3289
- conditionBranchId = `${nodeId}-cond-${idx}`;
3290
- createFallbackNode(conditionBranchId, condition, context, {
3291
- parentId: nodeId,
3292
- argIndex: idx
3293
- });
3289
+ const condNodeType = determineNodeType(condition, context.preserveStructure);
3290
+ const nextUnused = condNodeType !== "literal" ? getNextUnusedChild(children, usedChildIndices) : null;
3291
+ if (nextUnused) {
3292
+ usedChildIndices.add(nextUnused.index);
3293
+ conditionBranchId = processExpressionNode(nextUnused.child, context, {
3294
+ parentId: nodeId,
3295
+ argIndex: idx
3296
+ }, condition);
3297
+ } else {
3298
+ conditionBranchId = `${nodeId}-cond-${idx}`;
3299
+ createFallbackNode(conditionBranchId, condition, context, {
3300
+ parentId: nodeId,
3301
+ argIndex: idx
3302
+ });
3303
+ }
3294
3304
  }
3295
3305
  context.edges.push(createBranchEdge(nodeId, conditionBranchId, branchIndex));
3296
3306
  const conditionText = generateExpressionText(condition, 40);
@@ -3314,12 +3324,23 @@ let __tla = (async () => {
3314
3324
  branchType: "yes"
3315
3325
  });
3316
3326
  } else {
3317
- thenBranchId = `${nodeId}-then-${idx}`;
3318
- createFallbackNode(thenBranchId, thenValue, context, {
3319
- parentId: nodeId,
3320
- argIndex: idx + 1,
3321
- branchType: "yes"
3322
- });
3327
+ const thenNodeType = determineNodeType(thenValue, context.preserveStructure);
3328
+ const nextUnused = thenNodeType !== "literal" ? getNextUnusedChild(children, usedChildIndices) : null;
3329
+ if (nextUnused) {
3330
+ usedChildIndices.add(nextUnused.index);
3331
+ thenBranchId = processExpressionNode(nextUnused.child, context, {
3332
+ parentId: nodeId,
3333
+ argIndex: idx + 1,
3334
+ branchType: "yes"
3335
+ }, thenValue);
3336
+ } else {
3337
+ thenBranchId = `${nodeId}-then-${idx}`;
3338
+ createFallbackNode(thenBranchId, thenValue, context, {
3339
+ parentId: nodeId,
3340
+ argIndex: idx + 1,
3341
+ branchType: "yes"
3342
+ });
3343
+ }
3323
3344
  }
3324
3345
  context.edges.push(createBranchEdge(nodeId, thenBranchId, branchIndex));
3325
3346
  const thenText = generateExpressionText(thenValue, 40);
@@ -3348,12 +3369,23 @@ let __tla = (async () => {
3348
3369
  branchType: "no"
3349
3370
  });
3350
3371
  } else {
3351
- elseBranchId = `${nodeId}-else`;
3352
- createFallbackNode(elseBranchId, elseValue, context, {
3353
- parentId: nodeId,
3354
- argIndex: ifArgs.length - 1,
3355
- branchType: "no"
3356
- });
3372
+ const elseNodeType = determineNodeType(elseValue, context.preserveStructure);
3373
+ const nextUnused = elseNodeType !== "literal" ? getNextUnusedChild(children, usedChildIndices) : null;
3374
+ if (nextUnused) {
3375
+ usedChildIndices.add(nextUnused.index);
3376
+ elseBranchId = processExpressionNode(nextUnused.child, context, {
3377
+ parentId: nodeId,
3378
+ argIndex: ifArgs.length - 1,
3379
+ branchType: "no"
3380
+ }, elseValue);
3381
+ } else {
3382
+ elseBranchId = `${nodeId}-else`;
3383
+ createFallbackNode(elseBranchId, elseValue, context, {
3384
+ parentId: nodeId,
3385
+ argIndex: ifArgs.length - 1,
3386
+ branchType: "no"
3387
+ });
3388
+ }
3357
3389
  }
3358
3390
  context.edges.push(createBranchEdge(nodeId, elseBranchId, branchIndex));
3359
3391
  const elseText = generateExpressionText(elseValue, 40);
@@ -3418,6 +3450,17 @@ let __tla = (async () => {
3418
3450
  }
3419
3451
  return null;
3420
3452
  }
3453
+ function getNextUnusedChild(children, usedIndices) {
3454
+ for (let i = 0; i < children.length; i++) {
3455
+ if (!usedIndices.has(i)) {
3456
+ return {
3457
+ child: children[i],
3458
+ index: i
3459
+ };
3460
+ }
3461
+ }
3462
+ return null;
3463
+ }
3421
3464
  function createVerticalCellNodeFromTrace(nodeId, expression, children, context, parentInfo) {
3422
3465
  const obj = expression;
3423
3466
  const operator = Object.keys(obj)[0];
@@ -3644,7 +3687,7 @@ let __tla = (async () => {
3644
3687
  return EXPR_PLACEHOLDER;
3645
3688
  }
3646
3689
  return item;
3647
- });
3690
+ }, context);
3648
3691
  const formattedJson = JSON.stringify(structureWithPlaceholders, null, 2);
3649
3692
  let searchPos = 0;
3650
3693
  for (const element of elements) {
@@ -3690,6 +3733,11 @@ let __tla = (async () => {
3690
3733
  }
3691
3734
  }
3692
3735
  }
3736
+ function isExpressionBranch(item, preserveStructure) {
3737
+ if (isJsonLogicExpression(item)) return true;
3738
+ if (preserveStructure && isDataStructure(item)) return true;
3739
+ return false;
3740
+ }
3693
3741
  function walkAndCollectFromTrace(value, path, onValue, context) {
3694
3742
  if (Array.isArray(value)) {
3695
3743
  return value.map((item, index) => {
@@ -3697,10 +3745,10 @@ let __tla = (async () => {
3697
3745
  ...path,
3698
3746
  String(index)
3699
3747
  ];
3700
- if (isJsonLogicExpression(item)) {
3748
+ if (isExpressionBranch(item, context.preserveStructure)) {
3701
3749
  return onValue(itemPath, item);
3702
3750
  } else if (typeof item === "object" && item !== null) {
3703
- return walkAndCollectFromTrace(item, itemPath, onValue);
3751
+ return walkAndCollectFromTrace(item, itemPath, onValue, context);
3704
3752
  }
3705
3753
  return item;
3706
3754
  });
@@ -3712,10 +3760,10 @@ let __tla = (async () => {
3712
3760
  ...path,
3713
3761
  key
3714
3762
  ];
3715
- if (isJsonLogicExpression(item)) {
3763
+ if (isExpressionBranch(item, context.preserveStructure)) {
3716
3764
  result[key] = onValue(itemPath, item, key);
3717
3765
  } else if (typeof item === "object" && item !== null) {
3718
- result[key] = walkAndCollectFromTrace(item, itemPath, onValue);
3766
+ result[key] = walkAndCollectFromTrace(item, itemPath, onValue, context);
3719
3767
  } else {
3720
3768
  result[key] = item;
3721
3769
  }
@@ -8988,6 +9036,11 @@ let __tla = (async () => {
8988
9036
  if (cell.conditionBranchId) target.add(cell.conditionBranchId);
8989
9037
  if (cell.thenBranchId) target.add(cell.thenBranchId);
8990
9038
  }
9039
+ function collectStructureBranchIds(elements, target) {
9040
+ elements.forEach((element) => {
9041
+ if (element.branchId) target.add(element.branchId);
9042
+ });
9043
+ }
8991
9044
  function buildParentChildMap(nodes) {
8992
9045
  const parentChildMap = /* @__PURE__ */ new Map();
8993
9046
  nodes.forEach((node) => {
@@ -9024,6 +9077,10 @@ let __tla = (async () => {
9024
9077
  }
9025
9078
  });
9026
9079
  }
9080
+ } else if (isStructureNode(node)) {
9081
+ if (node.data.collapsed && node.data.elements) {
9082
+ collectStructureBranchIds(node.data.elements, collapsedBranchIds);
9083
+ }
9027
9084
  }
9028
9085
  });
9029
9086
  function markDescendantsHidden(parentId) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@goplasmatic/datalogic-ui",
3
3
  "private": false,
4
- "version": "4.0.9",
4
+ "version": "4.0.11",
5
5
  "type": "module",
6
6
  "description": "DataLogic Debugger - Visual JSONLogic Debugger & Editor for debugging and visualizing JSONLogic expressions",
7
7
  "keywords": [
@@ -51,23 +51,11 @@
51
51
  "sideEffects": [
52
52
  "**/*.css"
53
53
  ],
54
- "scripts": {
55
- "dev": "vite",
56
- "build": "tsc -b && vite build",
57
- "build:lib": "vite build --config vite.lib.config.ts",
58
- "build:embed": "vite build --config vite.embed.config.ts",
59
- "lint": "eslint .",
60
- "preview": "vite preview",
61
- "prepublishOnly": "npm run build:lib",
62
- "release:patch": "npm version patch && npm publish --access public",
63
- "release:minor": "npm version minor && npm publish --access public",
64
- "release:major": "npm version major && npm publish --access public"
65
- },
66
54
  "dependencies": {
67
55
  "@dagrejs/dagre": "^1.1.8",
68
- "@goplasmatic/datalogic": "workspace:*",
69
56
  "lucide-react": "^0.562.0",
70
- "uuid": "^13.0.0"
57
+ "uuid": "^13.0.0",
58
+ "@goplasmatic/datalogic": "4.0.9"
71
59
  },
72
60
  "peerDependencies": {
73
61
  "@xyflow/react": "^12.0.0",
@@ -94,5 +82,16 @@
94
82
  "vite-plugin-dts": "^4.5.4",
95
83
  "vite-plugin-top-level-await": "^1.6.0",
96
84
  "vite-plugin-wasm": "^3.5.0"
85
+ },
86
+ "scripts": {
87
+ "dev": "vite",
88
+ "build": "tsc -b && vite build",
89
+ "build:lib": "vite build --config vite.lib.config.ts",
90
+ "build:embed": "vite build --config vite.embed.config.ts",
91
+ "lint": "eslint .",
92
+ "preview": "vite preview",
93
+ "release:patch": "npm version patch && pnpm publish --access public --no-git-checks",
94
+ "release:minor": "npm version minor && pnpm publish --access public --no-git-checks",
95
+ "release:major": "npm version major && pnpm publish --access public --no-git-checks"
97
96
  }
98
- }
97
+ }