eligius 1.0.17 → 1.0.19

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,47 @@ 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
+ get currentIndex() {
568
+ return parentContext.currentIndex;
569
+ },
570
+
571
+ set currentIndex(value) {
572
+ parentContext.currentIndex = value;
573
+ },
574
+
575
+ eventbus: parentContext.eventbus,
576
+ operations: parentContext.operations,
577
+ parent: parentContext
578
+ };
579
+
580
+ this._contextStack.push(newContext);
581
+
582
+ return newContext;
583
+ };
584
+
585
+ _proto._popContext = function _popContext() {
586
+ this._contextStack.pop();
587
+ };
588
+
589
+ _proto.executeOperation = function executeOperation(operations, idx, resolve, reject, previousOperationData) {
558
590
  var _this2 = this;
559
591
 
560
592
  if (previousOperationData === void 0) {
561
593
  previousOperationData = {};
562
594
  }
563
595
 
596
+ var context = this._contextStack[this._contextStack.length - 1];
597
+
564
598
  if (context.newIndex !== undefined) {
565
599
  idx = context.newIndex;
566
600
  delete context.newIndex;
@@ -568,18 +602,20 @@ var Action = /*#__PURE__*/function () {
568
602
 
569
603
  context.currentIndex = idx;
570
604
 
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
605
  if (idx < operations.length) {
606
+ var _operationInfo$operat;
607
+
580
608
  var operationInfo = operations[idx];
581
- var copy = operationInfo.operationData ? deepCopy(operationInfo.operationData) : {};
609
+ var copy = deepCopy((_operationInfo$operat = operationInfo.operationData) != null ? _operationInfo$operat : {});
582
610
  var mergedOperationData = Object.assign(previousOperationData, copy);
611
+
612
+ if (operationInfo.systemName === 'when') {
613
+ context = this._pushContext(context);
614
+ } else if (operationInfo.systemName === 'startLoop' && context.owner !== operationInfo) {
615
+ context = this._pushContext(context);
616
+ context.owner = operationInfo;
617
+ }
618
+
583
619
  Diagnostics.active && Diagnostics.send('eligius-diagnostics-operation', {
584
620
  systemName: operationInfo.systemName,
585
621
  operationData: mergedOperationData,
@@ -589,14 +625,18 @@ var Action = /*#__PURE__*/function () {
589
625
  });
590
626
  var operationResult = operationInfo.instance.call(context, mergedOperationData);
591
627
 
628
+ if (operationInfo.systemName === 'endWhen' || operationInfo.systemName === 'endLoop' && context.newIndex === undefined) {
629
+ this._popContext();
630
+ }
631
+
592
632
  if (isPromise(operationResult)) {
593
633
  operationResult.then(function (promisedOperationResult) {
594
- return _this2.executeOperation(operations, ++idx, resolve, reject, promisedOperationResult, context);
634
+ return _this2.executeOperation(operations, ++idx, resolve, reject, promisedOperationResult);
595
635
  })["catch"](function (error) {
596
636
  reject(error);
597
637
  });
598
638
  } else {
599
- this.executeOperation(operations, ++idx, resolve, reject, operationResult, context);
639
+ this.executeOperation(operations, ++idx, resolve, reject, operationResult);
600
640
  }
601
641
  } else {
602
642
  resolve(previousOperationData);
@@ -627,16 +667,18 @@ var EndableAction = /*#__PURE__*/function (_Action) {
627
667
  Diagnostics.active && Diagnostics.send('eligius-diagnostics-action', ((_this$name = this.name) != null ? _this$name : 'Action') + " begins executing end operations");
628
668
 
629
669
  if (!this.endOperations.length) {
630
- return Promise.resolve(initOperationData);
670
+ return Promise.resolve(initOperationData != null ? initOperationData : {});
631
671
  }
632
672
 
633
- var context = {
634
- currentIndex: -1,
635
- eventbus: this.eventbus
636
- };
673
+ this._initializeContextStack();
674
+
637
675
  var result = new Promise(function (resolve, reject) {
638
- _this2.executeOperation(_this2.endOperations, 0, resolve, reject, initOperationData, context);
676
+ _this2.executeOperation(_this2.endOperations, 0, resolve, reject, initOperationData);
639
677
  })["catch"](function (e) {
678
+ Diagnostics.active && Diagnostics.send('eligius-diagnostics-action-error', {
679
+ name: _this2.name,
680
+ error: e
681
+ });
640
682
  console.error("Error in action end '" + _this2.name + "'");
641
683
  throw e;
642
684
  });
@@ -672,7 +714,7 @@ var TimelineAction = /*#__PURE__*/function (_EndableAction) {
672
714
  return _EndableAction.prototype.start.call(this, initOperationData);
673
715
  }
674
716
 
675
- return Promise.resolve(undefined);
717
+ return Promise.resolve({});
676
718
  };
677
719
 
678
720
  _proto.end = function end(initOperationData) {
@@ -1102,7 +1144,7 @@ var setGlobals = /*#__PURE__*/_setGlobals.bind(null, cache$1);
1102
1144
  * @returns
1103
1145
  */
1104
1146
 
1105
- function resolveOperationOrGlobalDataPropertyChain(sourceObject, propertyChainOrRegularObject) {
1147
+ function resolveExternalPropertyChain(sourceObject, operationContext, propertyChainOrRegularObject) {
1106
1148
  if (isString(propertyChainOrRegularObject)) {
1107
1149
  var _propNames$shift;
1108
1150
 
@@ -1115,19 +1157,22 @@ function resolveOperationOrGlobalDataPropertyChain(sourceObject, propertyChainOr
1115
1157
 
1116
1158
  case 'globaldata':
1117
1159
  return getPropertyChainValue(propNames, getGlobals());
1160
+
1161
+ case 'context':
1162
+ return getPropertyChainValue(propNames, operationContext);
1118
1163
  }
1119
1164
  }
1120
1165
 
1121
1166
  return propertyChainOrRegularObject;
1122
1167
  }
1123
1168
 
1124
- function resolveEventArguments(operationData, eventArgs) {
1169
+ function resolveEventArguments(operationData, operationContext, eventArgs) {
1125
1170
  if (!eventArgs) {
1126
1171
  return;
1127
1172
  }
1128
1173
 
1129
- var extract = resolveOperationOrGlobalDataPropertyChain.bind(null, operationData);
1130
- return eventArgs.map(extract);
1174
+ var resolve = resolveExternalPropertyChain.bind(null, operationData, operationContext);
1175
+ return eventArgs.map(resolve);
1131
1176
  }
1132
1177
 
1133
1178
  /**
@@ -1141,7 +1186,7 @@ var broadcastEvent$1 = function broadcastEvent(operationData) {
1141
1186
  var eventArgs = operationData.eventArgs,
1142
1187
  eventTopic = operationData.eventTopic,
1143
1188
  eventName = operationData.eventName;
1144
- var eventArguments = resolveEventArguments(operationData, eventArgs);
1189
+ var eventArguments = resolveEventArguments(operationData, this, eventArgs);
1145
1190
 
1146
1191
  if (eventTopic) {
1147
1192
  this.eventbus.broadcastForTopic(eventName, eventTopic, eventArguments);
@@ -1154,9 +1199,9 @@ var broadcastEvent$1 = function broadcastEvent(operationData) {
1154
1199
  };
1155
1200
 
1156
1201
  var cache = [];
1157
- function resolvePropertyValues(operationData, properties) {
1202
+ function resolvePropertyValues(operationData, operationContext, properties) {
1158
1203
  var copy = properties !== operationData ? deepCopy(properties) : properties;
1159
- var resolvePropertyChain = resolveOperationOrGlobalDataPropertyChain.bind(null, operationData);
1204
+ var resolvePropertyChain = resolveExternalPropertyChain.bind(null, operationData, operationContext);
1160
1205
  resolveProperties(properties, copy, resolvePropertyChain);
1161
1206
  return copy;
1162
1207
  }
@@ -1225,7 +1270,7 @@ var calcFunctions = {
1225
1270
  */
1226
1271
 
1227
1272
  var calc$1 = function calc(operationData) {
1228
- operationData = resolvePropertyValues(operationData, operationData);
1273
+ operationData = resolvePropertyValues(operationData, this, operationData);
1229
1274
  var _operationData = operationData,
1230
1275
  left = _operationData.left,
1231
1276
  right = _operationData.right,
@@ -1271,7 +1316,7 @@ var clearOperationData$1 = function clearOperationData(operationData) {
1271
1316
  */
1272
1317
 
1273
1318
  var createElement$1 = function createElement(operationData) {
1274
- operationData = resolvePropertyValues(operationData, operationData);
1319
+ operationData = resolvePropertyValues(operationData, this, operationData);
1275
1320
  var _operationData = operationData,
1276
1321
  elementName = _operationData.elementName,
1277
1322
  attributes = _operationData.attributes,
@@ -1388,27 +1433,17 @@ var endAction$1 = function endAction(operationData) {
1388
1433
  * @returns
1389
1434
  */
1390
1435
  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;
1436
+ if (this.loopIndex !== undefined && this.loopLength !== undefined && this.loopIndex < this.loopLength) {
1437
+ this.loopIndex = this.loopIndex + 1;
1438
+ this.newIndex = this.loopStartIndex;
1439
+ delete this.currentItem;
1405
1440
  }
1406
1441
 
1407
1442
  return operationData;
1408
1443
  };
1409
1444
 
1410
1445
  var endWhen$1 = function endWhen(operationData) {
1411
- delete this.skipNextOperation;
1446
+ delete this.whenEvaluation;
1412
1447
  return operationData;
1413
1448
  };
1414
1449
 
@@ -1810,7 +1845,7 @@ var log$1 = function log(operationData) {
1810
1845
  */
1811
1846
 
1812
1847
  var math$1 = function math(operationData) {
1813
- operationData = resolvePropertyValues(operationData, operationData);
1848
+ operationData = resolvePropertyValues(operationData, this, operationData);
1814
1849
  operationData.args = resolveMathConstants(operationData.args);
1815
1850
  var _operationData = operationData,
1816
1851
  args = _operationData.args,
@@ -1833,14 +1868,70 @@ function isMathProperty(value) {
1833
1868
  return isString(value) && value in Math && !isFunction(Math[value]);
1834
1869
  }
1835
1870
 
1871
+ /**
1872
+ * This function can be used to find the index of a matching operation within a list of operations.
1873
+ *
1874
+ * Given the array of operations:
1875
+ * ```ts
1876
+ * [
1877
+ * {systemName:'name1'}, // index 0
1878
+ * {systemName:'startLoop'}, // index 1
1879
+ * {systemName:'name2'}, // index 2
1880
+ * {systemName:'startLoop'} // index 3
1881
+ * {systemName:'name3'} // index 4
1882
+ * {systemName:'endLoop'} // index 5
1883
+ * {systemName:'endLoop'} // index 6
1884
+ * {systemName:'name3'} // index 7
1885
+ * ]
1886
+ * ```
1887
+ *
1888
+ * Given the startLoop instance at index 1, this function will return index 6. Given the startLoop at index 3, it will yield index 5.
1889
+ *
1890
+ * Returns true when the given operation.systemName equals the specified matchingName and the current counter value is zero.
1891
+ *
1892
+ * If the matchingName matches operation.systemName but the counter is greater than zero, the counter is decremented.
1893
+ *
1894
+ * If the operation.systemName equal self (the name of the operation that requires to find its match), then counter is incremented.
1895
+ *
1896
+ * @param this
1897
+ * @param operation
1898
+ * @returns
1899
+ */
1900
+ function findMatchingOperationIndex(operation) {
1901
+ if (operation.systemName === this.self) {
1902
+ this.counter = this.counter + 1;
1903
+ return false;
1904
+ }
1905
+
1906
+ if (operation.systemName === this.matchingName && this.counter === 0) {
1907
+ return true;
1908
+ }
1909
+
1910
+ if (operation.systemName === this.matchingName && this.counter > 0) {
1911
+ this.counter = this.counter - 1;
1912
+ }
1913
+
1914
+ return false;
1915
+ }
1916
+
1836
1917
  var otherwise$1 = function otherwise(operationData) {
1837
- if (this.skipNextOperation === false) {
1838
- this.skipNextOperation = true;
1918
+ if (this.whenEvaluation) {
1919
+ this.newIndex = findEndWhenIndex(this);
1839
1920
  }
1840
1921
 
1841
1922
  return operationData;
1842
1923
  };
1843
1924
 
1925
+ function findEndWhenIndex(context) {
1926
+ var list = context.operations.slice(context.currentIndex);
1927
+ var endWhenIndex = list.findIndex(findMatchingOperationIndex.bind({
1928
+ counter: 0,
1929
+ self: 'when',
1930
+ matchingName: 'endWhen'
1931
+ }));
1932
+ return endWhenIndex > -1 ? endWhenIndex + (context.currentIndex + 1) : context.operations.length;
1933
+ }
1934
+
1844
1935
  /**
1845
1936
  * This operation removes the spcified class name from the specified selected element.
1846
1937
  *
@@ -2093,7 +2184,7 @@ var setOperationData$1 = function setOperationData(operationData) {
2093
2184
  properties = _operationData.properties;
2094
2185
  delete operationData.properties;
2095
2186
  delete operationData.override;
2096
- var resolvedProperties = resolvePropertyValues(operationData, properties);
2187
+ var resolvedProperties = resolvePropertyValues(operationData, this, properties);
2097
2188
 
2098
2189
  if (override) {
2099
2190
  operationData = resolvedProperties;
@@ -2113,7 +2204,7 @@ var setOperationData$1 = function setOperationData(operationData) {
2113
2204
  */
2114
2205
 
2115
2206
  var setStyle$1 = function setStyle(operationData) {
2116
- var properties = resolvePropertyValues(operationData, operationData.properties);
2207
+ var properties = resolvePropertyValues(operationData, this, operationData.properties);
2117
2208
  operationData.selectedElement.css(properties);
2118
2209
  return operationData;
2119
2210
  };
@@ -2149,36 +2240,54 @@ var startAction$1 = function startAction(operationData) {
2149
2240
  * This operation starts a loop using the given collection.
2150
2241
  *
2151
2242
  * Each iteration the current item from the specified collection is
2152
- * assigned to the `currentItem` property on the current operation data.
2243
+ * assigned to the `currentItem` property on the operation context.
2153
2244
  *
2154
2245
  * @param operationData
2155
2246
  * @returns
2156
2247
  */
2248
+
2157
2249
  var startLoop$1 = function startLoop(operationData) {
2158
- var context = this;
2159
2250
  var collection = operationData.collection;
2160
2251
 
2161
2252
  if (collection !== null && !Array.isArray(collection)) {
2162
2253
  throw new Error('Expected collection to be array type, string value was probably not resolved correctly');
2163
- }
2254
+ } // First iteration of the loop
2255
+
2256
+
2257
+ if (this.loopIndex === undefined) {
2258
+ this.loopEndIndex = findLoopEndIndex(this);
2164
2259
 
2165
- if (context.loopIndex === undefined) {
2166
2260
  if (collection != null && collection.length) {
2167
- context.loopIndex = 0;
2168
- context.loopLength = collection.length - 1;
2169
- context.startIndex = context.currentIndex;
2261
+ this.loopIndex = 0;
2262
+ this.loopLength = collection.length - 1;
2263
+ this.loopStartIndex = this.currentIndex;
2170
2264
  } else {
2171
- context.skipNextOperation = true;
2265
+ this.newIndex = this.loopEndIndex;
2266
+ delete this.loopIndex;
2267
+ delete this.loopLength;
2268
+ delete this.loopStartIndex;
2269
+ delete this.loopEndIndex;
2172
2270
  }
2173
2271
  }
2174
2272
 
2175
- if (collection != null && collection.length && context.loopIndex !== undefined) {
2176
- operationData.currentItem = collection[context.loopIndex];
2273
+ if (collection != null && collection.length && this.loopIndex !== undefined) {
2274
+ this.currentItem = collection[this.loopIndex];
2177
2275
  }
2178
2276
 
2179
2277
  return operationData;
2180
2278
  };
2181
2279
 
2280
+ function findLoopEndIndex(context) {
2281
+ var list = context.operations.slice(context.currentIndex + 1);
2282
+ var index = list.findIndex(findMatchingOperationIndex.bind({
2283
+ counter: 0,
2284
+ self: 'startLoop',
2285
+ matchingName: 'endLoop'
2286
+ }));
2287
+ var endLoopIndex = index > -1 ? index + (context.currentIndex + 1) : context.operations.length;
2288
+ return endLoopIndex;
2289
+ }
2290
+
2182
2291
  /**
2183
2292
  * This operation toggles the specfied class name on the specified selected element.
2184
2293
  *
@@ -2229,18 +2338,22 @@ var wait$2 = function wait(operationData) {
2229
2338
  */
2230
2339
 
2231
2340
  var when = function when(operationData) {
2232
- var _parseExpression = parseExpression(operationData.expression, operationData),
2341
+ var _parseExpression = parseExpression(operationData.expression, operationData, this),
2233
2342
  left = _parseExpression[0],
2234
2343
  operator = _parseExpression[1],
2235
2344
  right = _parseExpression[2];
2236
2345
 
2237
- var evaluationResult = evaluations[operator](left, right);
2238
- this.skipNextOperation = !evaluationResult;
2346
+ this.whenEvaluation = evaluations[operator](left, right);
2347
+
2348
+ if (!this.whenEvaluation) {
2349
+ this.newIndex = findNextFlowControlIndex(this);
2350
+ }
2351
+
2239
2352
  delete operationData.expression;
2240
2353
  return operationData;
2241
2354
  };
2242
2355
 
2243
- function parseExpression(expression, operationData) {
2356
+ function parseExpression(expression, operationData, operationContext) {
2244
2357
  var _expression$split = expression.split(/!=|==|>=|<=|>|</),
2245
2358
  left = _expression$split[0],
2246
2359
  right = _expression$split[1];
@@ -2248,7 +2361,7 @@ function parseExpression(expression, operationData) {
2248
2361
  var operator = expression.substring(left.length, expression.length - right.length);
2249
2362
  var leftNr = +left;
2250
2363
  var rightNr = +right;
2251
- return [isNaN(leftNr) ? resolveOperationOrGlobalDataPropertyChain(operationData, left) : leftNr, operator, isNaN(rightNr) ? resolveOperationOrGlobalDataPropertyChain(operationData, right) : rightNr];
2364
+ return [isNaN(leftNr) ? resolveExternalPropertyChain(operationData, operationContext, left) : leftNr, operator, isNaN(rightNr) ? resolveExternalPropertyChain(operationData, operationContext, right) : rightNr];
2252
2365
  }
2253
2366
 
2254
2367
  var evaluations = {
@@ -2272,6 +2385,26 @@ var evaluations = {
2272
2385
  }
2273
2386
  };
2274
2387
 
2388
+ function findNextFlowControlIndex(context) {
2389
+ var list = context.operations.slice(context.currentIndex + 1);
2390
+ var otherWiseIndex = list.findIndex(findMatchingOperationIndex.bind({
2391
+ counter: 0,
2392
+ self: 'when',
2393
+ matchingName: 'otherwise'
2394
+ }));
2395
+
2396
+ if (otherWiseIndex > -1) {
2397
+ return otherWiseIndex + context.currentIndex + 1;
2398
+ }
2399
+
2400
+ var endWhenIndex = list.findIndex(findMatchingOperationIndex.bind({
2401
+ counter: 0,
2402
+ self: 'when',
2403
+ matchingName: 'endWhen'
2404
+ }));
2405
+ return endWhenIndex > -1 ? endWhenIndex + (context.currentIndex + 1) : context.operations.length;
2406
+ }
2407
+
2275
2408
  var ops = {
2276
2409
  __proto__: null,
2277
2410
  addClass: addClass$1,
@@ -5217,8 +5350,7 @@ function startLoop() {
5217
5350
  collection: {
5218
5351
  type: 'ParameterType:array',
5219
5352
  required: true
5220
- },
5221
- currentItem: 'ParameterType:object'
5353
+ }
5222
5354
  }
5223
5355
  };
5224
5356
  }