@movable/studio-framework 3.5.2 → 3.6.0

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.
package/dist/index.es.js CHANGED
@@ -2691,11 +2691,62 @@ class StudioFramework {
2691
2691
  conditionalDynamicProperty
2692
2692
  } = model;
2693
2693
  if (!conditionalDynamicProperty) return [true, null];
2694
+ return this.resolveCondition(conditionalDynamicProperty);
2695
+ }
2696
+
2697
+ async resolveCondition(expression) {
2698
+ if ('operator' in expression) {
2699
+ const {
2700
+ operator,
2701
+ operands
2702
+ } = expression;
2703
+
2704
+ if (!operands?.length) {
2705
+ return [false, new Error(`Missing operands for logical operation: ${operator}`)];
2706
+ }
2707
+
2708
+ switch (operator) {
2709
+ case 'AND':
2710
+ {
2711
+ for (const operand of operands) {
2712
+ const [result, error] = await this.evaluateOperand(operand);
2713
+ if (error) return [false, error];
2714
+ if (!result) return [false, null]; // Short-circuit AND on first false
2715
+ }
2716
+
2717
+ return [true, null]; // All conditions were true
2718
+ }
2719
+
2720
+ case 'OR':
2721
+ {
2722
+ for (const operand of operands) {
2723
+ const [result, error] = await this.evaluateOperand(operand);
2724
+ if (error) return [false, error];
2725
+ if (result) return [true, null]; // Short-circuit OR on first true
2726
+ }
2727
+
2728
+ return [false, null]; // No conditions were true
2729
+ }
2730
+
2731
+ default:
2732
+ return [false, new Error(`Unsupported operator: ${operator}`)];
2733
+ }
2734
+ } // Simple dynamic property case
2735
+
2736
+
2737
+ return this.evaluateOperand(expression);
2738
+ }
2739
+
2740
+ async evaluateOperand(operand) {
2741
+ if ('operator' in operand) {
2742
+ return this.resolveCondition(operand);
2743
+ }
2744
+
2694
2745
  const {
2695
2746
  propertyGroupKey = '',
2696
2747
  propertyPath = '',
2697
2748
  context = {}
2698
- } = conditionalDynamicProperty;
2749
+ } = operand;
2699
2750
  return this.getPropertyTuple(propertyGroupKey, propertyPath, context);
2700
2751
  }
2701
2752
 
package/dist/index.js CHANGED
@@ -2701,11 +2701,62 @@ class StudioFramework {
2701
2701
  conditionalDynamicProperty
2702
2702
  } = model;
2703
2703
  if (!conditionalDynamicProperty) return [true, null];
2704
+ return this.resolveCondition(conditionalDynamicProperty);
2705
+ }
2706
+
2707
+ async resolveCondition(expression) {
2708
+ if ('operator' in expression) {
2709
+ const {
2710
+ operator,
2711
+ operands
2712
+ } = expression;
2713
+
2714
+ if (!operands?.length) {
2715
+ return [false, new Error(`Missing operands for logical operation: ${operator}`)];
2716
+ }
2717
+
2718
+ switch (operator) {
2719
+ case 'AND':
2720
+ {
2721
+ for (const operand of operands) {
2722
+ const [result, error] = await this.evaluateOperand(operand);
2723
+ if (error) return [false, error];
2724
+ if (!result) return [false, null]; // Short-circuit AND on first false
2725
+ }
2726
+
2727
+ return [true, null]; // All conditions were true
2728
+ }
2729
+
2730
+ case 'OR':
2731
+ {
2732
+ for (const operand of operands) {
2733
+ const [result, error] = await this.evaluateOperand(operand);
2734
+ if (error) return [false, error];
2735
+ if (result) return [true, null]; // Short-circuit OR on first true
2736
+ }
2737
+
2738
+ return [false, null]; // No conditions were true
2739
+ }
2740
+
2741
+ default:
2742
+ return [false, new Error(`Unsupported operator: ${operator}`)];
2743
+ }
2744
+ } // Simple dynamic property case
2745
+
2746
+
2747
+ return this.evaluateOperand(expression);
2748
+ }
2749
+
2750
+ async evaluateOperand(operand) {
2751
+ if ('operator' in operand) {
2752
+ return this.resolveCondition(operand);
2753
+ }
2754
+
2704
2755
  const {
2705
2756
  propertyGroupKey = '',
2706
2757
  propertyPath = '',
2707
2758
  context = {}
2708
- } = conditionalDynamicProperty;
2759
+ } = operand;
2709
2760
  return this.getPropertyTuple(propertyGroupKey, propertyPath, context);
2710
2761
  }
2711
2762
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movable/studio-framework",
3
- "version": "3.5.2",
3
+ "version": "3.6.0",
4
4
  "description": "A Component library for reactive Studio apps.",
5
5
  "author": "Movable Ink",
6
6
  "repository": "movableink/studio-framework",
@@ -31,8 +31,8 @@
31
31
  "@babel/preset-react": "^7.14.5",
32
32
  "@babel/preset-typescript": "^7.13.0",
33
33
  "@movable/eslint-config-react": "^1.0.1",
34
- "@movable/framework-types": "^3.5.2",
35
- "@movable/studio-framework-test-helpers": "^3.5.2",
34
+ "@movable/framework-types": "^3.6.0",
35
+ "@movable/studio-framework-test-helpers": "^3.6.0",
36
36
  "@types/qunit": "^2.11.1",
37
37
  "@types/qunit-dom": "^0.7.0",
38
38
  "@types/react": "^17.0.6",
@@ -66,5 +66,5 @@
66
66
  "volta": {
67
67
  "extends": "../../package.json"
68
68
  },
69
- "gitHead": "e146b839b3e0b887a31eace3d0daf4b16cc1b128"
69
+ "gitHead": "f147d1c8f7b5f0abb762d8cd1c7f8709b890be2b"
70
70
  }