eligius 1.0.17 → 1.0.18

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.
@@ -519,6 +519,7 @@ var Action = /*#__PURE__*/function () {
519
519
  this.startOperations = void 0;
520
520
  this.eventbus = void 0;
521
521
  this.id = '';
522
+ this._contextStack = [];
522
523
  this.name = name;
523
524
  this.startOperations = startOperations;
524
525
  this.eventbus = eventbus;
@@ -531,15 +532,14 @@ var Action = /*#__PURE__*/function () {
531
532
  _this = this;
532
533
 
533
534
  Diagnostics.active && Diagnostics.send('eligius-diagnostics-action', ((_this$name = this.name) != null ? _this$name : 'Action') + " begins executing start operations");
534
- var context = {
535
- currentIndex: -1,
536
- eventbus: this.eventbus
537
- };
535
+
536
+ this._initializeContextStack();
537
+
538
538
  var result = new Promise(function (resolve, reject) {
539
- _this.executeOperation(_this.startOperations, 0, resolve, reject, initOperationData, context);
539
+ _this.executeOperation(_this.startOperations, 0, resolve, reject, initOperationData);
540
540
  })["catch"](function (e) {
541
541
  Diagnostics.active && Diagnostics.send('eligius-diagnostics-action-error', {
542
- name: name,
542
+ name: _this.name,
543
543
  error: e
544
544
  });
545
545
  console.error("Error in action start '" + _this.name + "'");
@@ -554,13 +554,42 @@ var Action = /*#__PURE__*/function () {
554
554
  });
555
555
  };
556
556
 
557
- _proto.executeOperation = function executeOperation(operations, idx, resolve, reject, previousOperationData, context) {
557
+ _proto._initializeContextStack = function _initializeContextStack() {
558
+ this._contextStack = [{
559
+ currentIndex: -1,
560
+ eventbus: this.eventbus,
561
+ operations: this.startOperations
562
+ }];
563
+ };
564
+
565
+ _proto._pushContext = function _pushContext(parentContext) {
566
+ var newContext = {
567
+ currentIndex: parentContext.currentIndex,
568
+ eventbus: parentContext.eventbus,
569
+ operations: parentContext.operations
570
+ };
571
+
572
+ this._contextStack.push(newContext);
573
+
574
+ return newContext;
575
+ };
576
+
577
+ _proto._popContext = function _popContext() {
578
+ var previousContext = this._contextStack.pop();
579
+
580
+ var newCurrentContext = this._contextStack[this._contextStack.length - 1];
581
+ newCurrentContext.currentIndex = previousContext.currentIndex;
582
+ };
583
+
584
+ _proto.executeOperation = function executeOperation(operations, idx, resolve, reject, previousOperationData) {
558
585
  var _this2 = this;
559
586
 
560
587
  if (previousOperationData === void 0) {
561
588
  previousOperationData = {};
562
589
  }
563
590
 
591
+ var context = this._contextStack[this._contextStack.length - 1];
592
+
564
593
  if (context.newIndex !== undefined) {
565
594
  idx = context.newIndex;
566
595
  delete context.newIndex;
@@ -568,18 +597,20 @@ var Action = /*#__PURE__*/function () {
568
597
 
569
598
  context.currentIndex = idx;
570
599
 
571
- if (context.skipNextOperation) {
572
- if (idx < operations.length) {
573
- this.executeOperation(operations, ++idx, resolve, reject, previousOperationData, context);
574
- } else {
575
- resolve(previousOperationData);
576
- }
577
- }
578
-
579
600
  if (idx < operations.length) {
601
+ var _operationInfo$operat;
602
+
580
603
  var operationInfo = operations[idx];
581
- var copy = operationInfo.operationData ? deepCopy(operationInfo.operationData) : {};
604
+ var copy = deepCopy((_operationInfo$operat = operationInfo.operationData) != null ? _operationInfo$operat : {});
582
605
  var mergedOperationData = Object.assign(previousOperationData, copy);
606
+
607
+ if (operationInfo.systemName === 'when') {
608
+ context = this._pushContext(context);
609
+ } else if (operationInfo.systemName === 'startLoop' && context.owner !== operationInfo) {
610
+ context = this._pushContext(context);
611
+ context.owner = operationInfo;
612
+ }
613
+
583
614
  Diagnostics.active && Diagnostics.send('eligius-diagnostics-operation', {
584
615
  systemName: operationInfo.systemName,
585
616
  operationData: mergedOperationData,
@@ -589,14 +620,18 @@ var Action = /*#__PURE__*/function () {
589
620
  });
590
621
  var operationResult = operationInfo.instance.call(context, mergedOperationData);
591
622
 
623
+ if (operationInfo.systemName === 'endWhen' || operationInfo.systemName === 'endLoop' && context.newIndex === undefined) {
624
+ this._popContext();
625
+ }
626
+
592
627
  if (isPromise(operationResult)) {
593
628
  operationResult.then(function (promisedOperationResult) {
594
- return _this2.executeOperation(operations, ++idx, resolve, reject, promisedOperationResult, context);
629
+ return _this2.executeOperation(operations, ++idx, resolve, reject, promisedOperationResult);
595
630
  })["catch"](function (error) {
596
631
  reject(error);
597
632
  });
598
633
  } else {
599
- this.executeOperation(operations, ++idx, resolve, reject, operationResult, context);
634
+ this.executeOperation(operations, ++idx, resolve, reject, operationResult);
600
635
  }
601
636
  } else {
602
637
  resolve(previousOperationData);
@@ -627,16 +662,18 @@ var EndableAction = /*#__PURE__*/function (_Action) {
627
662
  Diagnostics.active && Diagnostics.send('eligius-diagnostics-action', ((_this$name = this.name) != null ? _this$name : 'Action') + " begins executing end operations");
628
663
 
629
664
  if (!this.endOperations.length) {
630
- return Promise.resolve(initOperationData);
665
+ return Promise.resolve(initOperationData != null ? initOperationData : {});
631
666
  }
632
667
 
633
- var context = {
634
- currentIndex: -1,
635
- eventbus: this.eventbus
636
- };
668
+ this._initializeContextStack();
669
+
637
670
  var result = new Promise(function (resolve, reject) {
638
- _this2.executeOperation(_this2.endOperations, 0, resolve, reject, initOperationData, context);
671
+ _this2.executeOperation(_this2.endOperations, 0, resolve, reject, initOperationData);
639
672
  })["catch"](function (e) {
673
+ Diagnostics.active && Diagnostics.send('eligius-diagnostics-action-error', {
674
+ name: _this2.name,
675
+ error: e
676
+ });
640
677
  console.error("Error in action end '" + _this2.name + "'");
641
678
  throw e;
642
679
  });
@@ -672,7 +709,7 @@ var TimelineAction = /*#__PURE__*/function (_EndableAction) {
672
709
  return _EndableAction.prototype.start.call(this, initOperationData);
673
710
  }
674
711
 
675
- return Promise.resolve(undefined);
712
+ return Promise.resolve({});
676
713
  };
677
714
 
678
715
  _proto.end = function end(initOperationData) {
@@ -1102,7 +1139,7 @@ var setGlobals = /*#__PURE__*/_setGlobals.bind(null, cache$1);
1102
1139
  * @returns
1103
1140
  */
1104
1141
 
1105
- function resolveOperationOrGlobalDataPropertyChain(sourceObject, propertyChainOrRegularObject) {
1142
+ function resolveExternalPropertyChain(sourceObject, operationContext, propertyChainOrRegularObject) {
1106
1143
  if (isString(propertyChainOrRegularObject)) {
1107
1144
  var _propNames$shift;
1108
1145
 
@@ -1115,19 +1152,22 @@ function resolveOperationOrGlobalDataPropertyChain(sourceObject, propertyChainOr
1115
1152
 
1116
1153
  case 'globaldata':
1117
1154
  return getPropertyChainValue(propNames, getGlobals());
1155
+
1156
+ case 'context':
1157
+ return getPropertyChainValue(propNames, operationContext);
1118
1158
  }
1119
1159
  }
1120
1160
 
1121
1161
  return propertyChainOrRegularObject;
1122
1162
  }
1123
1163
 
1124
- function resolveEventArguments(operationData, eventArgs) {
1164
+ function resolveEventArguments(operationData, operationContext, eventArgs) {
1125
1165
  if (!eventArgs) {
1126
1166
  return;
1127
1167
  }
1128
1168
 
1129
- var extract = resolveOperationOrGlobalDataPropertyChain.bind(null, operationData);
1130
- return eventArgs.map(extract);
1169
+ var resolve = resolveExternalPropertyChain.bind(null, operationData, operationContext);
1170
+ return eventArgs.map(resolve);
1131
1171
  }
1132
1172
 
1133
1173
  /**
@@ -1141,7 +1181,7 @@ var broadcastEvent$1 = function broadcastEvent(operationData) {
1141
1181
  var eventArgs = operationData.eventArgs,
1142
1182
  eventTopic = operationData.eventTopic,
1143
1183
  eventName = operationData.eventName;
1144
- var eventArguments = resolveEventArguments(operationData, eventArgs);
1184
+ var eventArguments = resolveEventArguments(operationData, this, eventArgs);
1145
1185
 
1146
1186
  if (eventTopic) {
1147
1187
  this.eventbus.broadcastForTopic(eventName, eventTopic, eventArguments);
@@ -1154,9 +1194,9 @@ var broadcastEvent$1 = function broadcastEvent(operationData) {
1154
1194
  };
1155
1195
 
1156
1196
  var cache = [];
1157
- function resolvePropertyValues(operationData, properties) {
1197
+ function resolvePropertyValues(operationData, operationContext, properties) {
1158
1198
  var copy = properties !== operationData ? deepCopy(properties) : properties;
1159
- var resolvePropertyChain = resolveOperationOrGlobalDataPropertyChain.bind(null, operationData);
1199
+ var resolvePropertyChain = resolveExternalPropertyChain.bind(null, operationData, operationContext);
1160
1200
  resolveProperties(properties, copy, resolvePropertyChain);
1161
1201
  return copy;
1162
1202
  }
@@ -1225,7 +1265,7 @@ var calcFunctions = {
1225
1265
  */
1226
1266
 
1227
1267
  var calc$1 = function calc(operationData) {
1228
- operationData = resolvePropertyValues(operationData, operationData);
1268
+ operationData = resolvePropertyValues(operationData, this, operationData);
1229
1269
  var _operationData = operationData,
1230
1270
  left = _operationData.left,
1231
1271
  right = _operationData.right,
@@ -1271,7 +1311,7 @@ var clearOperationData$1 = function clearOperationData(operationData) {
1271
1311
  */
1272
1312
 
1273
1313
  var createElement$1 = function createElement(operationData) {
1274
- operationData = resolvePropertyValues(operationData, operationData);
1314
+ operationData = resolvePropertyValues(operationData, this, operationData);
1275
1315
  var _operationData = operationData,
1276
1316
  elementName = _operationData.elementName,
1277
1317
  attributes = _operationData.attributes,
@@ -1388,27 +1428,17 @@ var endAction$1 = function endAction(operationData) {
1388
1428
  * @returns
1389
1429
  */
1390
1430
  var endLoop$1 = function endLoop(operationData) {
1391
- var context = this;
1392
-
1393
- if (!context.skipNextOperation) {
1394
- if (context.loopIndex !== undefined && context.loopLength !== undefined && context.loopIndex < context.loopLength) {
1395
- context.loopIndex = context.loopIndex + 1;
1396
- context.newIndex = context.startIndex;
1397
- } else {
1398
- delete context.loopIndex;
1399
- delete context.loopLength;
1400
- delete context.startIndex;
1401
- delete context.newIndex;
1402
- }
1403
- } else {
1404
- delete context.skipNextOperation;
1431
+ if (this.loopIndex !== undefined && this.loopLength !== undefined && this.loopIndex < this.loopLength) {
1432
+ this.loopIndex = this.loopIndex + 1;
1433
+ this.newIndex = this.loopStartIndex;
1434
+ delete this.currentItem;
1405
1435
  }
1406
1436
 
1407
1437
  return operationData;
1408
1438
  };
1409
1439
 
1410
1440
  var endWhen$1 = function endWhen(operationData) {
1411
- delete this.skipNextOperation;
1441
+ delete this.whenEvaluation;
1412
1442
  return operationData;
1413
1443
  };
1414
1444
 
@@ -1810,7 +1840,7 @@ var log$1 = function log(operationData) {
1810
1840
  */
1811
1841
 
1812
1842
  var math$1 = function math(operationData) {
1813
- operationData = resolvePropertyValues(operationData, operationData);
1843
+ operationData = resolvePropertyValues(operationData, this, operationData);
1814
1844
  operationData.args = resolveMathConstants(operationData.args);
1815
1845
  var _operationData = operationData,
1816
1846
  args = _operationData.args,
@@ -1833,14 +1863,70 @@ function isMathProperty(value) {
1833
1863
  return isString(value) && value in Math && !isFunction(Math[value]);
1834
1864
  }
1835
1865
 
1866
+ /**
1867
+ * This function can be used to find the index of a matching operation within a list of operations.
1868
+ *
1869
+ * Given the array of operations:
1870
+ * ```ts
1871
+ * [
1872
+ * {systemName:'name1'}, // index 0
1873
+ * {systemName:'startLoop'}, // index 1
1874
+ * {systemName:'name2'}, // index 2
1875
+ * {systemName:'startLoop'} // index 3
1876
+ * {systemName:'name3'} // index 4
1877
+ * {systemName:'endLoop'} // index 5
1878
+ * {systemName:'endLoop'} // index 6
1879
+ * {systemName:'name3'} // index 7
1880
+ * ]
1881
+ * ```
1882
+ *
1883
+ * Given the startLoop instance at index 1, this function will return index 6. Given the startLoop at index 3, it will yield index 5.
1884
+ *
1885
+ * Returns true when the given operation.systemName equals the specified matchingName and the current counter value is zero.
1886
+ *
1887
+ * If the matchingName matches operation.systemName but the counter is greater than zero, the counter is decremented.
1888
+ *
1889
+ * If the operation.systemName equal self (the name of the operation that requires to find its match), then counter is incremented.
1890
+ *
1891
+ * @param this
1892
+ * @param operation
1893
+ * @returns
1894
+ */
1895
+ function findMatchingOperationIndex(operation) {
1896
+ if (operation.systemName === this.self) {
1897
+ this.counter = this.counter + 1;
1898
+ return false;
1899
+ }
1900
+
1901
+ if (operation.systemName === this.matchingName && this.counter === 0) {
1902
+ return true;
1903
+ }
1904
+
1905
+ if (operation.systemName === this.matchingName && this.counter > 0) {
1906
+ this.counter = this.counter - 1;
1907
+ }
1908
+
1909
+ return false;
1910
+ }
1911
+
1836
1912
  var otherwise$1 = function otherwise(operationData) {
1837
- if (this.skipNextOperation === false) {
1838
- this.skipNextOperation = true;
1913
+ if (this.whenEvaluation) {
1914
+ this.newIndex = findEndWhenIndex(this);
1839
1915
  }
1840
1916
 
1841
1917
  return operationData;
1842
1918
  };
1843
1919
 
1920
+ function findEndWhenIndex(context) {
1921
+ var list = context.operations.slice(context.currentIndex);
1922
+ var endWhenIndex = list.findIndex(findMatchingOperationIndex.bind({
1923
+ counter: 0,
1924
+ self: 'when',
1925
+ matchingName: 'endWhen'
1926
+ }));
1927
+ return endWhenIndex > -1 ? endWhenIndex + (context.currentIndex + 1) : context.operations.length;
1928
+ }
1929
+
1844
1930
  /**
1845
1931
  * This operation removes the spcified class name from the specified selected element.
1846
1932
  *
@@ -2093,7 +2179,7 @@ var setOperationData$1 = function setOperationData(operationData) {
2093
2179
  properties = _operationData.properties;
2094
2180
  delete operationData.properties;
2095
2181
  delete operationData.override;
2096
- var resolvedProperties = resolvePropertyValues(operationData, properties);
2182
+ var resolvedProperties = resolvePropertyValues(operationData, this, properties);
2097
2183
 
2098
2184
  if (override) {
2099
2185
  operationData = resolvedProperties;
@@ -2113,7 +2199,7 @@ var setOperationData$1 = function setOperationData(operationData) {
2113
2199
  */
2114
2200
 
2115
2201
  var setStyle$1 = function setStyle(operationData) {
2116
- var properties = resolvePropertyValues(operationData, operationData.properties);
2202
+ var properties = resolvePropertyValues(operationData, this, operationData.properties);
2117
2203
  operationData.selectedElement.css(properties);
2118
2204
  return operationData;
2119
2205
  };
@@ -2149,36 +2235,54 @@ var startAction$1 = function startAction(operationData) {
2149
2235
  * This operation starts a loop using the given collection.
2150
2236
  *
2151
2237
  * Each iteration the current item from the specified collection is
2152
- * assigned to the `currentItem` property on the current operation data.
2238
+ * assigned to the `currentItem` property on the operation context.
2153
2239
  *
2154
2240
  * @param operationData
2155
2241
  * @returns
2156
2242
  */
2243
+
2157
2244
  var startLoop$1 = function startLoop(operationData) {
2158
- var context = this;
2159
2245
  var collection = operationData.collection;
2160
2246
 
2161
2247
  if (collection !== null && !Array.isArray(collection)) {
2162
2248
  throw new Error('Expected collection to be array type, string value was probably not resolved correctly');
2163
- }
2249
+ } // First iteration of the loop
2250
+
2251
+
2252
+ if (this.loopIndex === undefined) {
2253
+ this.loopEndIndex = findLoopEndIndex(this);
2164
2254
 
2165
- if (context.loopIndex === undefined) {
2166
2255
  if (collection != null && collection.length) {
2167
- context.loopIndex = 0;
2168
- context.loopLength = collection.length - 1;
2169
- context.startIndex = context.currentIndex;
2256
+ this.loopIndex = 0;
2257
+ this.loopLength = collection.length - 1;
2258
+ this.loopStartIndex = this.currentIndex;
2170
2259
  } else {
2171
- context.skipNextOperation = true;
2260
+ this.newIndex = this.loopEndIndex;
2261
+ delete this.loopIndex;
2262
+ delete this.loopLength;
2263
+ delete this.loopStartIndex;
2264
+ delete this.loopEndIndex;
2172
2265
  }
2173
2266
  }
2174
2267
 
2175
- if (collection != null && collection.length && context.loopIndex !== undefined) {
2176
- operationData.currentItem = collection[context.loopIndex];
2268
+ if (collection != null && collection.length && this.loopIndex !== undefined) {
2269
+ this.currentItem = collection[this.loopIndex];
2177
2270
  }
2178
2271
 
2179
2272
  return operationData;
2180
2273
  };
2181
2274
 
2275
+ function findLoopEndIndex(context) {
2276
+ var list = context.operations.slice(context.currentIndex + 1);
2277
+ var index = list.findIndex(findMatchingOperationIndex.bind({
2278
+ counter: 0,
2279
+ self: 'startLoop',
2280
+ matchingName: 'endLoop'
2281
+ }));
2282
+ var endLoopIndex = index > -1 ? index + (context.currentIndex + 1) : context.operations.length;
2283
+ return endLoopIndex;
2284
+ }
2285
+
2182
2286
  /**
2183
2287
  * This operation toggles the specfied class name on the specified selected element.
2184
2288
  *
@@ -2229,18 +2333,22 @@ var wait$2 = function wait(operationData) {
2229
2333
  */
2230
2334
 
2231
2335
  var when = function when(operationData) {
2232
- var _parseExpression = parseExpression(operationData.expression, operationData),
2336
+ var _parseExpression = parseExpression(operationData.expression, operationData, this),
2233
2337
  left = _parseExpression[0],
2234
2338
  operator = _parseExpression[1],
2235
2339
  right = _parseExpression[2];
2236
2340
 
2237
- var evaluationResult = evaluations[operator](left, right);
2238
- this.skipNextOperation = !evaluationResult;
2341
+ this.whenEvaluation = evaluations[operator](left, right);
2342
+
2343
+ if (!this.whenEvaluation) {
2344
+ this.newIndex = findNextFlowControlIndex(this);
2345
+ }
2346
+
2239
2347
  delete operationData.expression;
2240
2348
  return operationData;
2241
2349
  };
2242
2350
 
2243
- function parseExpression(expression, operationData) {
2351
+ function parseExpression(expression, operationData, operationContext) {
2244
2352
  var _expression$split = expression.split(/!=|==|>=|<=|>|</),
2245
2353
  left = _expression$split[0],
2246
2354
  right = _expression$split[1];
@@ -2248,7 +2356,7 @@ function parseExpression(expression, operationData) {
2248
2356
  var operator = expression.substring(left.length, expression.length - right.length);
2249
2357
  var leftNr = +left;
2250
2358
  var rightNr = +right;
2251
- return [isNaN(leftNr) ? resolveOperationOrGlobalDataPropertyChain(operationData, left) : leftNr, operator, isNaN(rightNr) ? resolveOperationOrGlobalDataPropertyChain(operationData, right) : rightNr];
2359
+ return [isNaN(leftNr) ? resolveExternalPropertyChain(operationData, operationContext, left) : leftNr, operator, isNaN(rightNr) ? resolveExternalPropertyChain(operationData, operationContext, right) : rightNr];
2252
2360
  }
2253
2361
 
2254
2362
  var evaluations = {
@@ -2272,6 +2380,26 @@ var evaluations = {
2272
2380
  }
2273
2381
  };
2274
2382
 
2383
+ function findNextFlowControlIndex(context) {
2384
+ var list = context.operations.slice(context.currentIndex + 1);
2385
+ var otherWiseIndex = list.findIndex(findMatchingOperationIndex.bind({
2386
+ counter: 0,
2387
+ self: 'when',
2388
+ matchingName: 'otherwise'
2389
+ }));
2390
+
2391
+ if (otherWiseIndex > -1) {
2392
+ return otherWiseIndex + context.currentIndex + 1;
2393
+ }
2394
+
2395
+ var endWhenIndex = list.findIndex(findMatchingOperationIndex.bind({
2396
+ counter: 0,
2397
+ self: 'when',
2398
+ matchingName: 'endWhen'
2399
+ }));
2400
+ return endWhenIndex > -1 ? endWhenIndex + (context.currentIndex + 1) : context.operations.length;
2401
+ }
2402
+
2275
2403
  var ops = {
2276
2404
  __proto__: null,
2277
2405
  addClass: addClass$1,
@@ -5217,8 +5345,7 @@ function startLoop() {
5217
5345
  collection: {
5218
5346
  type: 'ParameterType:array',
5219
5347
  required: true
5220
- },
5221
- currentItem: 'ParameterType:object'
5348
+ }
5222
5349
  }
5223
5350
  };
5224
5351
  }