@myinterview/widget-react 1.1.21-development-51cf6ea → 1.1.21-development-1c53386

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/cjs/index.js CHANGED
@@ -19903,6 +19903,9 @@ function toObserver(nextHandler, errorHandler, completionHandler) {
19903
19903
  function createInvokeId(stateNodeId, index) {
19904
19904
  return "".concat(stateNodeId, ":invocation[").concat(index, "]");
19905
19905
  }
19906
+ function isRaisableAction(action) {
19907
+ return (action.type === raise$3 || action.type === send$4 && action.to === SpecialTargets.Internal) && typeof action.delay !== 'number';
19908
+ }
19906
19909
 
19907
19910
  var initEvent$1 = /*#__PURE__*/toSCXMLEvent({
19908
19911
  type: init$1
@@ -19979,28 +19982,40 @@ function toActivityDefinition$1(action) {
19979
19982
  * @param eventType The event to raise.
19980
19983
  */
19981
19984
 
19982
- function raise$2(event) {
19983
- if (!isString$1(event)) {
19984
- return send$3(event, {
19985
- to: SpecialTargets.Internal
19986
- });
19987
- }
19988
-
19985
+ function raise$2(event, options) {
19989
19986
  return {
19990
19987
  type: raise$3,
19991
- event: event
19988
+ event: typeof event === 'function' ? event : toEventObject(event),
19989
+ delay: options ? options.delay : undefined,
19990
+ id: options === null || options === void 0 ? void 0 : options.id
19992
19991
  };
19993
19992
  }
19994
- function resolveRaise$1(action) {
19995
- return {
19996
- type: raise$3,
19997
- _event: toSCXMLEvent(action.event)
19993
+ function resolveRaise$1(action, ctx, _event, delaysMap) {
19994
+ var meta = {
19995
+ _event: _event
19998
19996
  };
19997
+ var resolvedEvent = toSCXMLEvent(isFunction$2(action.event) ? action.event(ctx, _event.data, meta) : action.event);
19998
+ var resolvedDelay;
19999
+
20000
+ if (isString$1(action.delay)) {
20001
+ var configDelay = delaysMap && delaysMap[action.delay];
20002
+ resolvedDelay = isFunction$2(configDelay) ? configDelay(ctx, _event.data, meta) : configDelay;
20003
+ } else {
20004
+ resolvedDelay = isFunction$2(action.delay) ? action.delay(ctx, _event.data, meta) : action.delay;
20005
+ }
20006
+
20007
+ return __assign$2(__assign$2({}, action), {
20008
+ type: raise$3,
20009
+ _event: resolvedEvent,
20010
+ delay: resolvedDelay
20011
+ });
19999
20012
  }
20000
20013
  /**
20001
20014
  * Sends an event. This returns an action that will be read by an interpreter to
20002
20015
  * send the event in the next step, after the current step is finished executing.
20003
20016
  *
20017
+ * @deprecated Use the `sendTo(...)` action creator instead.
20018
+ *
20004
20019
  * @param event The event to send.
20005
20020
  * @param options Options to pass into the send event:
20006
20021
  * - `id` - The unique send event identifier (used with `cancel()`).
@@ -20014,6 +20029,8 @@ function send$3(event, options) {
20014
20029
  type: send$4,
20015
20030
  event: isFunction$2(event) ? event : toEventObject(event),
20016
20031
  delay: options ? options.delay : undefined,
20032
+ // TODO: don't auto-generate IDs here like that
20033
+ // there is too big chance of the ID collision
20017
20034
  id: options && options.id !== undefined ? options.id : isFunction$2(event) ? event.name : getEventType(event)
20018
20035
  };
20019
20036
  }
@@ -20193,39 +20210,83 @@ function error$2(id, data) {
20193
20210
 
20194
20211
  return eventObject;
20195
20212
  }
20196
- function resolveActions$1(machine, currentState, currentContext, _event, actions, predictableExec, preserveActionOrder) {
20213
+
20214
+ var pluckAssigns$1 = function (actionBlocks) {
20215
+ var e_1, _a;
20216
+
20217
+ var assignActions = [];
20218
+
20219
+ try {
20220
+ for (var actionBlocks_1 = __values$1(actionBlocks), actionBlocks_1_1 = actionBlocks_1.next(); !actionBlocks_1_1.done; actionBlocks_1_1 = actionBlocks_1.next()) {
20221
+ var block = actionBlocks_1_1.value;
20222
+ var i = 0;
20223
+
20224
+ while (i < block.actions.length) {
20225
+ if (block.actions[i].type === assign$4) {
20226
+ assignActions.push(block.actions[i]);
20227
+ block.actions.splice(i, 1);
20228
+ continue;
20229
+ }
20230
+
20231
+ i++;
20232
+ }
20233
+ }
20234
+ } catch (e_1_1) {
20235
+ e_1 = {
20236
+ error: e_1_1
20237
+ };
20238
+ } finally {
20239
+ try {
20240
+ if (actionBlocks_1_1 && !actionBlocks_1_1.done && (_a = actionBlocks_1.return)) _a.call(actionBlocks_1);
20241
+ } finally {
20242
+ if (e_1) throw e_1.error;
20243
+ }
20244
+ }
20245
+
20246
+ return assignActions;
20247
+ };
20248
+
20249
+ function resolveActions$1(machine, currentState, currentContext, _event, actionBlocks, predictableExec, preserveActionOrder) {
20197
20250
  if (preserveActionOrder === void 0) {
20198
20251
  preserveActionOrder = false;
20199
20252
  }
20200
20253
 
20201
- var _a = __read$3(preserveActionOrder ? [[], actions] : partition(actions, function (action) {
20202
- return action.type === assign$4;
20203
- }), 2),
20204
- assignActions = _a[0],
20205
- otherActions = _a[1];
20206
-
20254
+ var assignActions = preserveActionOrder ? [] : pluckAssigns$1(actionBlocks);
20207
20255
  var updatedContext = assignActions.length ? updateContext(currentContext, _event, assignActions, currentState) : currentContext;
20208
20256
  var preservedContexts = preserveActionOrder ? [currentContext] : undefined;
20209
- var resolvedActions = flatten(otherActions.map(function (actionObject) {
20257
+ var deferredToBlockEnd = [];
20258
+
20259
+ function handleAction(blockType, actionObject) {
20210
20260
  var _a;
20211
20261
 
20212
20262
  switch (actionObject.type) {
20213
20263
  case raise$3:
20214
20264
  {
20215
- return resolveRaise$1(actionObject);
20265
+ var raisedAction = resolveRaise$1(actionObject, updatedContext, _event, machine.options.delays);
20266
+
20267
+ if (predictableExec && typeof raisedAction.delay === 'number') {
20268
+ predictableExec(raisedAction, updatedContext, _event);
20269
+ }
20270
+
20271
+ return raisedAction;
20216
20272
  }
20217
20273
 
20218
20274
  case send$4:
20219
20275
  var sendAction = resolveSend$1(actionObject, updatedContext, _event, machine.options.delays); // TODO: fix ActionTypes.Init
20220
20276
 
20221
20277
  if (!IS_PRODUCTION$1) {
20222
- // warn after resolving as we can create better contextual message here
20223
- warn$1(!isString$1(actionObject.delay) || typeof sendAction.delay === 'number', // tslint:disable-next-line:max-line-length
20224
- "No delay reference for delay expression '".concat(actionObject.delay, "' was found on machine '").concat(machine.id, "'"));
20278
+ var configuredDelay = actionObject.delay; // warn after resolving as we can create better contextual message here
20279
+
20280
+ warn$1(!isString$1(configuredDelay) || typeof sendAction.delay === 'number', // tslint:disable-next-line:max-line-length
20281
+ "No delay reference for delay expression '".concat(configuredDelay, "' was found on machine '").concat(machine.id, "'"));
20225
20282
  }
20226
20283
 
20227
- if (sendAction.to !== SpecialTargets.Internal) {
20228
- predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(sendAction, updatedContext, _event);
20284
+ if (predictableExec && sendAction.to !== SpecialTargets.Internal) {
20285
+ if (blockType === 'entry') {
20286
+ deferredToBlockEnd.push(sendAction);
20287
+ } else {
20288
+ predictableExec(sendAction, updatedContext, _event);
20289
+ }
20229
20290
  }
20230
20291
 
20231
20292
  return sendAction;
@@ -20249,7 +20310,10 @@ function resolveActions$1(machine, currentState, currentContext, _event, actions
20249
20310
  return [];
20250
20311
  }
20251
20312
 
20252
- var _b = __read$3(resolveActions$1(machine, currentState, updatedContext, _event, toActionObjects$1(toArray$1(matchedActions), machine.options.actions), predictableExec, preserveActionOrder), 2),
20313
+ var _b = __read$3(resolveActions$1(machine, currentState, updatedContext, _event, [{
20314
+ type: blockType,
20315
+ actions: toActionObjects$1(toArray$1(matchedActions), machine.options.actions)
20316
+ }], predictableExec, preserveActionOrder), 2),
20253
20317
  resolvedActionsFromChoose = _b[0],
20254
20318
  resolvedContextFromChoose = _b[1];
20255
20319
 
@@ -20266,7 +20330,10 @@ function resolveActions$1(machine, currentState, currentContext, _event, actions
20266
20330
  return [];
20267
20331
  }
20268
20332
 
20269
- var _c = __read$3(resolveActions$1(machine, currentState, updatedContext, _event, toActionObjects$1(toArray$1(matchedActions), machine.options.actions), predictableExec, preserveActionOrder), 2),
20333
+ var _c = __read$3(resolveActions$1(machine, currentState, updatedContext, _event, [{
20334
+ type: blockType,
20335
+ actions: toActionObjects$1(toArray$1(matchedActions), machine.options.actions)
20336
+ }], predictableExec, preserveActionOrder), 2),
20270
20337
  resolvedActionsFromPure = _c[0],
20271
20338
  resolvedContext = _c[1];
20272
20339
 
@@ -20278,7 +20345,7 @@ function resolveActions$1(machine, currentState, currentContext, _event, actions
20278
20345
  case stop$3:
20279
20346
  {
20280
20347
  var resolved = resolveStop$1(actionObject, updatedContext, _event);
20281
- predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved, updatedContext, _event);
20348
+ predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved, currentContext, _event);
20282
20349
  return resolved;
20283
20350
  }
20284
20351
 
@@ -20297,7 +20364,8 @@ function resolveActions$1(machine, currentState, currentContext, _event, actions
20297
20364
  predictableExec(resolvedActionObject, updatedContext, _event);
20298
20365
  } else if (exec_1 && preservedContexts) {
20299
20366
  var contextIndex_1 = preservedContexts.length - 1;
20300
- resolvedActionObject = __assign$2(__assign$2({}, resolvedActionObject), {
20367
+
20368
+ var wrapped = __assign$2(__assign$2({}, resolvedActionObject), {
20301
20369
  exec: function (_ctx) {
20302
20370
  var args = [];
20303
20371
 
@@ -20308,13 +20376,48 @@ function resolveActions$1(machine, currentState, currentContext, _event, actions
20308
20376
  exec_1.apply(void 0, __spreadArray$1([preservedContexts[contextIndex_1]], __read$3(args), false));
20309
20377
  }
20310
20378
  });
20379
+
20380
+ resolvedActionObject = wrapped;
20311
20381
  }
20312
20382
 
20313
20383
  return resolvedActionObject;
20314
20384
  }
20315
- }).filter(function (a) {
20316
- return !!a;
20317
- }));
20385
+ }
20386
+
20387
+ function processBlock(block) {
20388
+ var e_2, _a;
20389
+
20390
+ var resolvedActions = [];
20391
+
20392
+ try {
20393
+ for (var _b = __values$1(block.actions), _c = _b.next(); !_c.done; _c = _b.next()) {
20394
+ var action = _c.value;
20395
+ var resolved = handleAction(block.type, action);
20396
+
20397
+ if (resolved) {
20398
+ resolvedActions = resolvedActions.concat(resolved);
20399
+ }
20400
+ }
20401
+ } catch (e_2_1) {
20402
+ e_2 = {
20403
+ error: e_2_1
20404
+ };
20405
+ } finally {
20406
+ try {
20407
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
20408
+ } finally {
20409
+ if (e_2) throw e_2.error;
20410
+ }
20411
+ }
20412
+
20413
+ deferredToBlockEnd.forEach(function (action) {
20414
+ predictableExec(action, updatedContext, _event);
20415
+ });
20416
+ deferredToBlockEnd.length = 0;
20417
+ return resolvedActions;
20418
+ }
20419
+
20420
+ var resolvedActions = flatten(actionBlocks.map(processBlock));
20318
20421
  return [resolvedActions, updatedContext];
20319
20422
  }
20320
20423
 
@@ -21166,12 +21269,12 @@ function () {
21166
21269
  * @param options Interpreter options
21167
21270
  */
21168
21271
  function Interpreter(machine, options) {
21169
- var _this = this;
21170
-
21171
21272
  if (options === void 0) {
21172
21273
  options = Interpreter.defaultOptions;
21173
21274
  }
21174
21275
 
21276
+ var _this = this;
21277
+
21175
21278
  this.machine = machine;
21176
21279
  this.delayedEventsMap = {};
21177
21280
  this.listeners = new Set();
@@ -21188,6 +21291,7 @@ function () {
21188
21291
  this.status = InterpreterStatus.NotStarted;
21189
21292
  this.children = new Map();
21190
21293
  this.forwardTo = new Set();
21294
+ this._outgoingQueue = [];
21191
21295
  /**
21192
21296
  * Alias for Interpreter.prototype.start
21193
21297
  */
@@ -21239,9 +21343,9 @@ function () {
21239
21343
  // tslint:disable-next-line:semicolon
21240
21344
  };
21241
21345
 
21242
- this.sendTo = function (event, to) {
21346
+ this.sendTo = function (event, to, immediate) {
21243
21347
  var isParent = _this.parent && (to === SpecialTargets.Parent || _this.parent.id === to);
21244
- var target = isParent ? _this.parent : isString$1(to) ? _this.children.get(to) || registry.get(to) : isActor$1(to) ? to : undefined;
21348
+ var target = isParent ? _this.parent : isString$1(to) ? to === SpecialTargets.Internal ? _this : _this.children.get(to) || registry.get(to) : isActor$1(to) ? to : undefined;
21245
21349
 
21246
21350
  if (!target) {
21247
21351
  if (!isParent) {
@@ -21262,14 +21366,24 @@ function () {
21262
21366
  if (_this.status !== InterpreterStatus.Stopped || _this.parent !== target || // we need to send events to the parent from exit handlers of a machine that reached its final state
21263
21367
  _this.state.done) {
21264
21368
  // Send SCXML events to machines
21265
- target.send(__assign$2(__assign$2({}, event), {
21369
+ var scxmlEvent = __assign$2(__assign$2({}, event), {
21266
21370
  name: event.name === error$3 ? "".concat(error$2(_this.id)) : event.name,
21267
21371
  origin: _this.sessionId
21268
- }));
21372
+ });
21373
+
21374
+ if (!immediate && _this.machine.config.predictableActionArguments) {
21375
+ _this._outgoingQueue.push([target, scxmlEvent]);
21376
+ } else {
21377
+ target.send(scxmlEvent);
21378
+ }
21269
21379
  }
21270
21380
  } else {
21271
21381
  // Send normal events to other targets
21272
- target.send(event.data);
21382
+ if (!immediate && _this.machine.config.predictableActionArguments) {
21383
+ _this._outgoingQueue.push([target, event.data]);
21384
+ } else {
21385
+ target.send(event.data);
21386
+ }
21273
21387
  }
21274
21388
  };
21275
21389
 
@@ -21304,6 +21418,16 @@ function () {
21304
21418
  }
21305
21419
 
21306
21420
  switch (action.type) {
21421
+ case raise$3:
21422
+ {
21423
+ // if raise action reached the interpreter then it's a delayed one
21424
+ var sendAction_1 = action;
21425
+
21426
+ _this.defer(sendAction_1);
21427
+
21428
+ break;
21429
+ }
21430
+
21307
21431
  case send$4:
21308
21432
  var sendAction = action;
21309
21433
 
@@ -21313,7 +21437,7 @@ function () {
21313
21437
  return;
21314
21438
  } else {
21315
21439
  if (sendAction.to) {
21316
- _this.sendTo(sendAction._event, sendAction.to);
21440
+ _this.sendTo(sendAction._event, sendAction.to, _event === initEvent$1);
21317
21441
  } else {
21318
21442
  _this.send(sendAction._event);
21319
21443
  }
@@ -21407,8 +21531,9 @@ function () {
21407
21531
  }
21408
21532
 
21409
21533
  case log$2:
21410
- var label = action.label,
21411
- value = action.value;
21534
+ var _a = action,
21535
+ label = _a.label,
21536
+ value = _a.value;
21412
21537
 
21413
21538
  if (label) {
21414
21539
  _this.logger(label, value);
@@ -21462,6 +21587,9 @@ function () {
21462
21587
  configurable: true
21463
21588
  });
21464
21589
  Object.defineProperty(Interpreter.prototype, "state", {
21590
+ /**
21591
+ * @deprecated Use `.getSnapshot()` instead.
21592
+ */
21465
21593
  get: function () {
21466
21594
  if (!IS_PRODUCTION$1) {
21467
21595
  warn$1(this.status !== InterpreterStatus.NotStarted, "Attempted to read state from uninitialized service '".concat(this.id, "'. Make sure the service is started first."));
@@ -21514,6 +21642,12 @@ function () {
21514
21642
  // we can't just recompute it (and execute actions while doing so) because we try to preserve identity of actors created within initial assigns
21515
21643
  _event === initEvent$1) && this.options.execute) {
21516
21644
  this.execute(this.state);
21645
+ } else {
21646
+ var item = void 0;
21647
+
21648
+ while (item = this._outgoingQueue.shift()) {
21649
+ item[0].send(item[1]);
21650
+ }
21517
21651
  } // Update children
21518
21652
 
21519
21653
 
@@ -21585,11 +21719,12 @@ function () {
21585
21719
  return sn.type === 'final' && sn.parent === _this.machine;
21586
21720
  });
21587
21721
  var doneData = finalChildStateNode && finalChildStateNode.doneData ? mapContext(finalChildStateNode.doneData, state.context, _event) : undefined;
21722
+ this._doneEvent = doneInvoke$1(this.id, doneData);
21588
21723
 
21589
21724
  try {
21590
21725
  for (var _l = __values$1(this.doneListeners), _m = _l.next(); !_m.done; _m = _l.next()) {
21591
21726
  var listener = _m.value;
21592
- listener(doneInvoke$1(this.id, doneData));
21727
+ listener(this._doneEvent);
21593
21728
  }
21594
21729
  } catch (e_5_1) {
21595
21730
  e_5 = {
@@ -21606,6 +21741,8 @@ function () {
21606
21741
  this._stop();
21607
21742
 
21608
21743
  this._stopChildren();
21744
+
21745
+ registry.free(this.sessionId);
21609
21746
  }
21610
21747
  };
21611
21748
  /*
@@ -21709,7 +21846,12 @@ function () {
21709
21846
 
21710
21847
 
21711
21848
  Interpreter.prototype.onDone = function (listener) {
21712
- this.doneListeners.add(listener);
21849
+ if (this.status === InterpreterStatus.Stopped && this._doneEvent) {
21850
+ listener(this._doneEvent);
21851
+ } else {
21852
+ this.doneListeners.add(listener);
21853
+ }
21854
+
21713
21855
  return this;
21714
21856
  };
21715
21857
  /**
@@ -21911,7 +22053,10 @@ function () {
21911
22053
  return toActionObjects$1(stateNode.onExit, _this.machine.options.actions);
21912
22054
  }));
21913
22055
 
21914
- var _a = __read$3(resolveActions$1(_this.machine, _this.state, _this.state.context, _event, exitActions, _this.machine.config.predictableActionArguments ? _this._exec : undefined, _this.machine.config.predictableActionArguments || _this.machine.config.preserveActionOrder), 2),
22056
+ var _a = __read$3(resolveActions$1(_this.machine, _this.state, _this.state.context, _event, [{
22057
+ type: 'exit',
22058
+ actions: exitActions
22059
+ }], _this.machine.config.predictableActionArguments ? _this._exec : undefined, _this.machine.config.predictableActionArguments || _this.machine.config.preserveActionOrder), 2),
21915
22060
  resolvedActions = _a[0],
21916
22061
  updatedContext = _a[1];
21917
22062
 
@@ -21923,7 +22068,7 @@ function () {
21923
22068
  historyValue: undefined,
21924
22069
  history: _this.state,
21925
22070
  actions: resolvedActions.filter(function (action) {
21926
- return action.type !== raise$3 && (action.type !== send$4 || !!action.to && action.to !== SpecialTargets.Internal);
22071
+ return !isRaisableAction(action);
21927
22072
  }),
21928
22073
  activities: {},
21929
22074
  events: [],
@@ -21960,6 +22105,11 @@ function () {
21960
22105
  "".concat(events.length, " event(s) were sent to uninitialized service \"").concat(this.machine.id, "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options."));
21961
22106
  }
21962
22107
 
22108
+ if (!events.length) {
22109
+ return;
22110
+ }
22111
+
22112
+ var exec = !!this.machine.config.predictableActionArguments && this._exec;
21963
22113
  this.scheduler.schedule(function () {
21964
22114
  var e_11, _a;
21965
22115
 
@@ -21973,9 +22123,9 @@ function () {
21973
22123
  _this.forward(_event);
21974
22124
 
21975
22125
  nextState = provide(_this, function () {
21976
- return _this.machine.transition(nextState, _event);
22126
+ return _this.machine.transition(nextState, _event, undefined, exec || undefined);
21977
22127
  });
21978
- batchedActions.push.apply(batchedActions, __spreadArray$1([], __read$3(nextState.actions.map(function (a) {
22128
+ batchedActions.push.apply(batchedActions, __spreadArray$1([], __read$3(_this.machine.config.predictableActionArguments ? nextState.actions : nextState.actions.map(function (a) {
21979
22129
  return bindActionToState(a, nextState);
21980
22130
  })), false));
21981
22131
  batchChanged = batchChanged || !!nextState.changed;
@@ -22079,13 +22229,17 @@ function () {
22079
22229
  Interpreter.prototype.defer = function (sendAction) {
22080
22230
  var _this = this;
22081
22231
 
22082
- this.delayedEventsMap[sendAction.id] = this.clock.setTimeout(function () {
22083
- if (sendAction.to) {
22084
- _this.sendTo(sendAction._event, sendAction.to);
22232
+ var timerId = this.clock.setTimeout(function () {
22233
+ if ('to' in sendAction && sendAction.to) {
22234
+ _this.sendTo(sendAction._event, sendAction.to, true);
22085
22235
  } else {
22086
22236
  _this.send(sendAction._event);
22087
22237
  }
22088
22238
  }, sendAction.delay);
22239
+
22240
+ if (sendAction.id) {
22241
+ this.delayedEventsMap[sendAction.id] = timerId;
22242
+ }
22089
22243
  };
22090
22244
 
22091
22245
  Interpreter.prototype.cancel = function (sendId) {
@@ -22662,12 +22816,12 @@ function () {
22662
22816
  */
22663
22817
  _context, // TODO: this is unsafe, but we're removing it in v5 anyway
22664
22818
  _stateInfo) {
22665
- var _this = this;
22666
-
22667
22819
  if (_context === void 0) {
22668
22820
  _context = 'context' in config ? config.context : undefined;
22669
22821
  }
22670
22822
 
22823
+ var _this = this;
22824
+
22671
22825
  var _a;
22672
22826
 
22673
22827
  this.config = config;
@@ -23130,15 +23284,11 @@ function () {
23130
23284
  return this.next(state, _event);
23131
23285
  }
23132
23286
 
23133
- var entryNodes = flatten(stateTransitions.map(function (t) {
23134
- return t.entrySet;
23135
- }));
23136
23287
  var configuration = flatten(Object.keys(transitionMap).map(function (key) {
23137
23288
  return transitionMap[key].configuration;
23138
23289
  }));
23139
23290
  return {
23140
23291
  transitions: enabledTransitions,
23141
- entrySet: entryNodes,
23142
23292
  exitSet: flatten(stateTransitions.map(function (t) {
23143
23293
  return t.exitSet;
23144
23294
  })),
@@ -23225,7 +23375,6 @@ function () {
23225
23375
  if (!nextStateNodes.length) {
23226
23376
  return {
23227
23377
  transitions: [selectedTransition],
23228
- entrySet: [],
23229
23378
  exitSet: [],
23230
23379
  configuration: state.value ? [this] : [],
23231
23380
  source: state,
@@ -23237,30 +23386,28 @@ function () {
23237
23386
  return _this.getRelativeStateNodes(stateNode, state.historyValue);
23238
23387
  }));
23239
23388
  var isInternal = !!selectedTransition.internal;
23240
- var reentryNodes = [];
23241
-
23242
- if (!isInternal) {
23243
- nextStateNodes.forEach(function (targetNode) {
23244
- reentryNodes.push.apply(reentryNodes, __spreadArray$1([], __read$3(_this.getExternalReentryNodes(targetNode)), false));
23245
- });
23246
- }
23247
-
23248
23389
  return {
23249
23390
  transitions: [selectedTransition],
23250
- entrySet: reentryNodes,
23251
- exitSet: isInternal ? [] : [this],
23391
+ exitSet: isInternal ? [] : flatten(nextStateNodes.map(function (targetNode) {
23392
+ return _this.getPotentiallyReenteringNodes(targetNode);
23393
+ })),
23252
23394
  configuration: allNextStateNodes,
23253
23395
  source: state,
23254
23396
  actions: actions
23255
23397
  };
23256
- };
23398
+ }; // even though the name of this function mentions reentry nodes
23399
+ // we are pushing its result into `exitSet`
23400
+ // that's because what we exit might be reentered (it's an invariant of reentrancy)
23257
23401
 
23258
- StateNode.prototype.getExternalReentryNodes = function (targetNode) {
23259
- var nodes = [];
23260
23402
 
23261
- var _a = __read$3(targetNode.order > this.order ? [targetNode, this] : [this, targetNode], 2),
23262
- marker = _a[0],
23263
- possibleAncestor = _a[1];
23403
+ StateNode.prototype.getPotentiallyReenteringNodes = function (targetNode) {
23404
+ if (this.order < targetNode.order) {
23405
+ return [this];
23406
+ }
23407
+
23408
+ var nodes = [];
23409
+ var marker = this;
23410
+ var possibleAncestor = targetNode;
23264
23411
 
23265
23412
  while (marker && marker !== possibleAncestor) {
23266
23413
  nodes.push(marker);
@@ -23277,17 +23424,22 @@ function () {
23277
23424
  return nodes;
23278
23425
  };
23279
23426
 
23280
- StateNode.prototype.getActions = function (resolvedConfig, isDone, transition, currentContext, _event, prevState) {
23427
+ StateNode.prototype.getActions = function (resolvedConfig, isDone, transition, currentContext, _event, prevState, predictableExec) {
23281
23428
  var e_4, _a, e_5, _b;
23282
23429
 
23283
- var prevConfig = getConfiguration([], prevState ? this.getStateNodes(prevState.value) : [this]);
23430
+ var _this = this;
23431
+
23432
+ var prevConfig = prevState ? getConfiguration([], this.getStateNodes(prevState.value)) : [];
23433
+ var entrySet = new Set();
23284
23434
 
23285
23435
  try {
23286
- for (var resolvedConfig_1 = __values$1(resolvedConfig), resolvedConfig_1_1 = resolvedConfig_1.next(); !resolvedConfig_1_1.done; resolvedConfig_1_1 = resolvedConfig_1.next()) {
23287
- var sn = resolvedConfig_1_1.value;
23436
+ for (var _c = __values$1(Array.from(resolvedConfig).sort(function (a, b) {
23437
+ return a.order - b.order;
23438
+ })), _d = _c.next(); !_d.done; _d = _c.next()) {
23439
+ var sn = _d.value;
23288
23440
 
23289
- if (!has(prevConfig, sn) || has(transition.entrySet, sn.parent)) {
23290
- transition.entrySet.push(sn);
23441
+ if (!has(prevConfig, sn) || has(transition.exitSet, sn) || sn.parent && entrySet.has(sn.parent)) {
23442
+ entrySet.add(sn);
23291
23443
  }
23292
23444
  }
23293
23445
  } catch (e_4_1) {
@@ -23296,7 +23448,7 @@ function () {
23296
23448
  };
23297
23449
  } finally {
23298
23450
  try {
23299
- if (resolvedConfig_1_1 && !resolvedConfig_1_1.done && (_a = resolvedConfig_1.return)) _a.call(resolvedConfig_1);
23451
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
23300
23452
  } finally {
23301
23453
  if (e_4) throw e_4.error;
23302
23454
  }
@@ -23322,7 +23474,14 @@ function () {
23322
23474
  }
23323
23475
  }
23324
23476
 
23325
- var doneEvents = flatten(transition.entrySet.map(function (sn) {
23477
+ transition.exitSet.sort(function (a, b) {
23478
+ return b.order - a.order;
23479
+ });
23480
+ var entryStates = Array.from(entrySet).sort(function (a, b) {
23481
+ return a.order - b.order;
23482
+ });
23483
+ var exitStates = new Set(transition.exitSet);
23484
+ var doneEvents = flatten(entryStates.map(function (sn) {
23326
23485
  var events = [];
23327
23486
 
23328
23487
  if (sn.type !== 'final') {
@@ -23349,28 +23508,33 @@ function () {
23349
23508
 
23350
23509
  return events;
23351
23510
  }));
23352
- transition.exitSet.sort(function (a, b) {
23353
- return b.order - a.order;
23511
+ var entryActions = entryStates.map(function (stateNode) {
23512
+ var entryActions = stateNode.onEntry;
23513
+ var invokeActions = stateNode.activities.map(function (activity) {
23514
+ return start$2(activity);
23515
+ });
23516
+ return {
23517
+ type: 'entry',
23518
+ actions: toActionObjects$1(predictableExec ? __spreadArray$1(__spreadArray$1([], __read$3(entryActions), false), __read$3(invokeActions), false) : __spreadArray$1(__spreadArray$1([], __read$3(invokeActions), false), __read$3(entryActions), false), _this.machine.options.actions)
23519
+ };
23520
+ }).concat({
23521
+ type: 'state_done',
23522
+ actions: doneEvents.map(function (event) {
23523
+ return raise$2(event);
23524
+ })
23354
23525
  });
23355
- transition.entrySet.sort(function (a, b) {
23356
- return a.order - b.order;
23526
+ var exitActions = Array.from(exitStates).map(function (stateNode) {
23527
+ return {
23528
+ type: 'exit',
23529
+ actions: toActionObjects$1(__spreadArray$1(__spreadArray$1([], __read$3(stateNode.onExit), false), __read$3(stateNode.activities.map(function (activity) {
23530
+ return stop$2(activity);
23531
+ })), false), _this.machine.options.actions)
23532
+ };
23357
23533
  });
23358
- var entryStates = new Set(transition.entrySet);
23359
- var exitStates = new Set(transition.exitSet);
23360
-
23361
- var _c = __read$3([flatten(Array.from(entryStates).map(function (stateNode) {
23362
- return __spreadArray$1(__spreadArray$1([], __read$3(stateNode.activities.map(function (activity) {
23363
- return start$2(activity);
23364
- })), false), __read$3(stateNode.onEntry), false);
23365
- })).concat(doneEvents.map(raise$2)), flatten(Array.from(exitStates).map(function (stateNode) {
23366
- return __spreadArray$1(__spreadArray$1([], __read$3(stateNode.onExit), false), __read$3(stateNode.activities.map(function (activity) {
23367
- return stop$2(activity);
23368
- })), false);
23369
- }))], 2),
23370
- entryActions = _c[0],
23371
- exitActions = _c[1];
23372
-
23373
- var actions = toActionObjects$1(exitActions.concat(transition.actions).concat(entryActions), this.machine.options.actions);
23534
+ var actions = exitActions.concat({
23535
+ type: 'transition',
23536
+ actions: toActionObjects$1(transition.actions, this.machine.options.actions)
23537
+ }).concat(entryActions);
23374
23538
 
23375
23539
  if (isDone) {
23376
23540
  var stopActions = toActionObjects$1(flatten(__spreadArray$1([], __read$3(resolvedConfig), false).sort(function (a, b) {
@@ -23378,9 +23542,12 @@ function () {
23378
23542
  }).map(function (stateNode) {
23379
23543
  return stateNode.onExit;
23380
23544
  })), this.machine.options.actions).filter(function (action) {
23381
- return action.type !== raise$3 && (action.type !== send$4 || !!action.to && action.to !== SpecialTargets.Internal);
23545
+ return !isRaisableAction(action);
23546
+ });
23547
+ return actions.concat({
23548
+ type: 'stop',
23549
+ actions: stopActions
23382
23550
  });
23383
- return actions.concat(stopActions);
23384
23551
  }
23385
23552
 
23386
23553
  return actions;
@@ -23424,7 +23591,6 @@ function () {
23424
23591
  var stateTransition = this._transition(currentState.value, currentState, _event) || {
23425
23592
  transitions: [],
23426
23593
  configuration: [],
23427
- entrySet: [],
23428
23594
  exitSet: [],
23429
23595
  source: currentState,
23430
23596
  actions: []
@@ -23451,7 +23617,7 @@ function () {
23451
23617
  };
23452
23618
 
23453
23619
  StateNode.prototype.resolveTransition = function (stateTransition, currentState, context, predictableExec, _event) {
23454
- var e_6, _a;
23620
+ var e_6, _a, e_7, _b;
23455
23621
 
23456
23622
  var _this = this;
23457
23623
 
@@ -23468,17 +23634,33 @@ function () {
23468
23634
  var isDone = isInFinalState(resolvedConfiguration, this);
23469
23635
  var resolvedStateValue = willTransition ? getValue(this.machine, configuration) : undefined;
23470
23636
  var historyValue = currentState ? currentState.historyValue ? currentState.historyValue : stateTransition.source ? this.machine.historyValue(currentState.value) : undefined : undefined;
23471
- var actions = this.getActions(new Set(resolvedConfiguration), isDone, stateTransition, context, _event, currentState);
23637
+ var actionBlocks = this.getActions(new Set(resolvedConfiguration), isDone, stateTransition, context, _event, currentState, predictableExec);
23472
23638
  var activities = currentState ? __assign$2({}, currentState.activities) : {};
23473
23639
 
23474
23640
  try {
23475
- for (var actions_1 = __values$1(actions), actions_1_1 = actions_1.next(); !actions_1_1.done; actions_1_1 = actions_1.next()) {
23476
- var action = actions_1_1.value;
23641
+ for (var actionBlocks_1 = __values$1(actionBlocks), actionBlocks_1_1 = actionBlocks_1.next(); !actionBlocks_1_1.done; actionBlocks_1_1 = actionBlocks_1.next()) {
23642
+ var block = actionBlocks_1_1.value;
23477
23643
 
23478
- if (action.type === start$3) {
23479
- activities[action.activity.id || action.activity.type] = action;
23480
- } else if (action.type === stop$3) {
23481
- activities[action.activity.id || action.activity.type] = false;
23644
+ try {
23645
+ for (var _c = (e_7 = void 0, __values$1(block.actions)), _d = _c.next(); !_d.done; _d = _c.next()) {
23646
+ var action = _d.value;
23647
+
23648
+ if (action.type === start$3) {
23649
+ activities[action.activity.id || action.activity.type] = action;
23650
+ } else if (action.type === stop$3) {
23651
+ activities[action.activity.id || action.activity.type] = false;
23652
+ }
23653
+ }
23654
+ } catch (e_7_1) {
23655
+ e_7 = {
23656
+ error: e_7_1
23657
+ };
23658
+ } finally {
23659
+ try {
23660
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
23661
+ } finally {
23662
+ if (e_7) throw e_7.error;
23663
+ }
23482
23664
  }
23483
23665
  }
23484
23666
  } catch (e_6_1) {
@@ -23487,21 +23669,19 @@ function () {
23487
23669
  };
23488
23670
  } finally {
23489
23671
  try {
23490
- if (actions_1_1 && !actions_1_1.done && (_a = actions_1.return)) _a.call(actions_1);
23672
+ if (actionBlocks_1_1 && !actionBlocks_1_1.done && (_a = actionBlocks_1.return)) _a.call(actionBlocks_1);
23491
23673
  } finally {
23492
23674
  if (e_6) throw e_6.error;
23493
23675
  }
23494
23676
  }
23495
23677
 
23496
- var _b = __read$3(resolveActions$1(this, currentState, context, _event, actions, predictableExec, this.machine.config.predictableActionArguments || this.machine.config.preserveActionOrder), 2),
23497
- resolvedActions = _b[0],
23498
- updatedContext = _b[1];
23678
+ var _e = __read$3(resolveActions$1(this, currentState, context, _event, actionBlocks, predictableExec, this.machine.config.predictableActionArguments || this.machine.config.preserveActionOrder), 2),
23679
+ resolvedActions = _e[0],
23680
+ updatedContext = _e[1];
23499
23681
 
23500
- var _c = __read$3(partition(resolvedActions, function (action) {
23501
- return action.type === raise$3 || action.type === send$4 && action.to === SpecialTargets.Internal;
23502
- }), 2),
23503
- raisedEvents = _c[0],
23504
- nonRaisedActions = _c[1];
23682
+ var _f = __read$3(partition(resolvedActions, isRaisableAction), 2),
23683
+ raisedEvents = _f[0],
23684
+ nonRaisedActions = _f[1];
23505
23685
 
23506
23686
  var invokeActions = resolvedActions.filter(function (action) {
23507
23687
  var _a;
@@ -23754,7 +23934,6 @@ function () {
23754
23934
  var configuration = this.getStateNodes(stateValue);
23755
23935
  return this.resolveTransition({
23756
23936
  configuration: configuration,
23757
- entrySet: __spreadArray$1([], __read$3(configuration), false),
23758
23937
  exitSet: [],
23759
23938
  transitions: [],
23760
23939
  source: undefined,
@@ -23950,7 +24129,7 @@ function () {
23950
24129
  * All the event types accepted by this state node and its descendants.
23951
24130
  */
23952
24131
  get: function () {
23953
- var e_7, _a, e_8, _b;
24132
+ var e_8, _a, e_9, _b;
23954
24133
 
23955
24134
  if (this.__cache.events) {
23956
24135
  return this.__cache.events;
@@ -23967,32 +24146,32 @@ function () {
23967
24146
 
23968
24147
  if (state.states) {
23969
24148
  try {
23970
- for (var _e = (e_8 = void 0, __values$1(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
24149
+ for (var _e = (e_9 = void 0, __values$1(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
23971
24150
  var event_1 = _f.value;
23972
24151
  events.add("".concat(event_1));
23973
24152
  }
23974
- } catch (e_8_1) {
23975
- e_8 = {
23976
- error: e_8_1
24153
+ } catch (e_9_1) {
24154
+ e_9 = {
24155
+ error: e_9_1
23977
24156
  };
23978
24157
  } finally {
23979
24158
  try {
23980
24159
  if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
23981
24160
  } finally {
23982
- if (e_8) throw e_8.error;
24161
+ if (e_9) throw e_9.error;
23983
24162
  }
23984
24163
  }
23985
24164
  }
23986
24165
  }
23987
- } catch (e_7_1) {
23988
- e_7 = {
23989
- error: e_7_1
24166
+ } catch (e_8_1) {
24167
+ e_8 = {
24168
+ error: e_8_1
23990
24169
  };
23991
24170
  } finally {
23992
24171
  try {
23993
24172
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
23994
24173
  } finally {
23995
- if (e_7) throw e_7.error;
24174
+ if (e_8) throw e_8.error;
23996
24175
  }
23997
24176
  }
23998
24177
  }
@@ -24087,7 +24266,7 @@ function () {
24087
24266
  };
24088
24267
 
24089
24268
  StateNode.prototype.formatTransitions = function () {
24090
- var e_9, _a;
24269
+ var e_10, _a;
24091
24270
 
24092
24271
  var _this = this;
24093
24272
 
@@ -24151,15 +24330,15 @@ function () {
24151
24330
  var delayedTransition = delayedTransitions_1_1.value;
24152
24331
  formattedTransitions.push(delayedTransition);
24153
24332
  }
24154
- } catch (e_9_1) {
24155
- e_9 = {
24156
- error: e_9_1
24333
+ } catch (e_10_1) {
24334
+ e_10 = {
24335
+ error: e_10_1
24157
24336
  };
24158
24337
  } finally {
24159
24338
  try {
24160
24339
  if (delayedTransitions_1_1 && !delayedTransitions_1_1.done && (_a = delayedTransitions_1.return)) _a.call(delayedTransitions_1);
24161
24340
  } finally {
24162
- if (e_9) throw e_9.error;
24341
+ if (e_10) throw e_10.error;
24163
24342
  }
24164
24343
  }
24165
24344
 
@@ -24171,7 +24350,7 @@ function () {
24171
24350
 
24172
24351
  var warned = false;
24173
24352
  function createMachine(config, options) {
24174
- if (!IS_PRODUCTION$1 && !config.predictableActionArguments && !warned) {
24353
+ if (!IS_PRODUCTION$1 && !('predictableActionArguments' in config) && !warned) {
24175
24354
  warned = true;
24176
24355
  console.warn('It is highly recommended to set `predictableActionArguments` to `true` when using `createMachine`. https://xstate.js.org/docs/guides/actions.html');
24177
24356
  }
@@ -38946,6 +39125,8 @@ environment$1.IS_PRODUCTION = IS_PRODUCTION;
38946
39125
  Object.defineProperty(exports, '__esModule', { value: true });
38947
39126
 
38948
39127
  var _tslib = _tslib$1;
39128
+ var types = types$2;
39129
+ var actionTypes = actionTypes$1;
38949
39130
  var constants$1 = constants;
38950
39131
  var environment = environment$1;
38951
39132
 
@@ -39565,6 +39746,9 @@ environment$1.IS_PRODUCTION = IS_PRODUCTION;
39565
39746
  function createInvokeId(stateNodeId, index) {
39566
39747
  return "".concat(stateNodeId, ":invocation[").concat(index, "]");
39567
39748
  }
39749
+ function isRaisableAction(action) {
39750
+ return (action.type === actionTypes.raise || action.type === actionTypes.send && action.to === types.SpecialTargets.Internal) && typeof action.delay !== 'number';
39751
+ }
39568
39752
 
39569
39753
  exports.createInvokeId = createInvokeId;
39570
39754
  exports.evaluateGuard = evaluateGuard;
@@ -39580,6 +39764,7 @@ environment$1.IS_PRODUCTION = IS_PRODUCTION;
39580
39764
  exports.isMachine = isMachine;
39581
39765
  exports.isObservable = isObservable;
39582
39766
  exports.isPromiseLike = isPromiseLike;
39767
+ exports.isRaisableAction = isRaisableAction;
39583
39768
  exports.isStateLike = isStateLike;
39584
39769
  exports.isString = isString;
39585
39770
  exports.keys = keys;
@@ -39695,28 +39880,40 @@ function toActivityDefinition(action) {
39695
39880
  * @param eventType The event to raise.
39696
39881
  */
39697
39882
 
39698
- function raise(event) {
39699
- if (!utils.isString(event)) {
39700
- return send(event, {
39701
- to: types.SpecialTargets.Internal
39702
- });
39703
- }
39704
-
39883
+ function raise(event, options) {
39705
39884
  return {
39706
39885
  type: actionTypes.raise,
39707
- event: event
39886
+ event: typeof event === 'function' ? event : utils.toEventObject(event),
39887
+ delay: options ? options.delay : undefined,
39888
+ id: options === null || options === void 0 ? void 0 : options.id
39708
39889
  };
39709
39890
  }
39710
- function resolveRaise(action) {
39711
- return {
39712
- type: actionTypes.raise,
39713
- _event: utils.toSCXMLEvent(action.event)
39891
+ function resolveRaise(action, ctx, _event, delaysMap) {
39892
+ var meta = {
39893
+ _event: _event
39714
39894
  };
39895
+ var resolvedEvent = utils.toSCXMLEvent(utils.isFunction(action.event) ? action.event(ctx, _event.data, meta) : action.event);
39896
+ var resolvedDelay;
39897
+
39898
+ if (utils.isString(action.delay)) {
39899
+ var configDelay = delaysMap && delaysMap[action.delay];
39900
+ resolvedDelay = utils.isFunction(configDelay) ? configDelay(ctx, _event.data, meta) : configDelay;
39901
+ } else {
39902
+ resolvedDelay = utils.isFunction(action.delay) ? action.delay(ctx, _event.data, meta) : action.delay;
39903
+ }
39904
+
39905
+ return _tslib.__assign(_tslib.__assign({}, action), {
39906
+ type: actionTypes.raise,
39907
+ _event: resolvedEvent,
39908
+ delay: resolvedDelay
39909
+ });
39715
39910
  }
39716
39911
  /**
39717
39912
  * Sends an event. This returns an action that will be read by an interpreter to
39718
39913
  * send the event in the next step, after the current step is finished executing.
39719
39914
  *
39915
+ * @deprecated Use the `sendTo(...)` action creator instead.
39916
+ *
39720
39917
  * @param event The event to send.
39721
39918
  * @param options Options to pass into the send event:
39722
39919
  * - `id` - The unique send event identifier (used with `cancel()`).
@@ -39730,6 +39927,8 @@ function send(event, options) {
39730
39927
  type: actionTypes.send,
39731
39928
  event: utils.isFunction(event) ? event : utils.toEventObject(event),
39732
39929
  delay: options ? options.delay : undefined,
39930
+ // TODO: don't auto-generate IDs here like that
39931
+ // there is too big chance of the ID collision
39733
39932
  id: options && options.id !== undefined ? options.id : utils.isFunction(event) ? event.name : utils.getEventType(event)
39734
39933
  };
39735
39934
  }
@@ -40040,39 +40239,83 @@ function choose(conds) {
40040
40239
  conds: conds
40041
40240
  };
40042
40241
  }
40043
- function resolveActions(machine, currentState, currentContext, _event, actions, predictableExec, preserveActionOrder) {
40242
+
40243
+ var pluckAssigns = function (actionBlocks) {
40244
+ var e_1, _a;
40245
+
40246
+ var assignActions = [];
40247
+
40248
+ try {
40249
+ for (var actionBlocks_1 = _tslib.__values(actionBlocks), actionBlocks_1_1 = actionBlocks_1.next(); !actionBlocks_1_1.done; actionBlocks_1_1 = actionBlocks_1.next()) {
40250
+ var block = actionBlocks_1_1.value;
40251
+ var i = 0;
40252
+
40253
+ while (i < block.actions.length) {
40254
+ if (block.actions[i].type === actionTypes.assign) {
40255
+ assignActions.push(block.actions[i]);
40256
+ block.actions.splice(i, 1);
40257
+ continue;
40258
+ }
40259
+
40260
+ i++;
40261
+ }
40262
+ }
40263
+ } catch (e_1_1) {
40264
+ e_1 = {
40265
+ error: e_1_1
40266
+ };
40267
+ } finally {
40268
+ try {
40269
+ if (actionBlocks_1_1 && !actionBlocks_1_1.done && (_a = actionBlocks_1.return)) _a.call(actionBlocks_1);
40270
+ } finally {
40271
+ if (e_1) throw e_1.error;
40272
+ }
40273
+ }
40274
+
40275
+ return assignActions;
40276
+ };
40277
+
40278
+ function resolveActions(machine, currentState, currentContext, _event, actionBlocks, predictableExec, preserveActionOrder) {
40044
40279
  if (preserveActionOrder === void 0) {
40045
40280
  preserveActionOrder = false;
40046
40281
  }
40047
40282
 
40048
- var _a = _tslib.__read(preserveActionOrder ? [[], actions] : utils.partition(actions, function (action) {
40049
- return action.type === actionTypes.assign;
40050
- }), 2),
40051
- assignActions = _a[0],
40052
- otherActions = _a[1];
40053
-
40283
+ var assignActions = preserveActionOrder ? [] : pluckAssigns(actionBlocks);
40054
40284
  var updatedContext = assignActions.length ? utils.updateContext(currentContext, _event, assignActions, currentState) : currentContext;
40055
40285
  var preservedContexts = preserveActionOrder ? [currentContext] : undefined;
40056
- var resolvedActions = utils.flatten(otherActions.map(function (actionObject) {
40286
+ var deferredToBlockEnd = [];
40287
+
40288
+ function handleAction(blockType, actionObject) {
40057
40289
  var _a;
40058
40290
 
40059
40291
  switch (actionObject.type) {
40060
40292
  case actionTypes.raise:
40061
40293
  {
40062
- return resolveRaise(actionObject);
40294
+ var raisedAction = resolveRaise(actionObject, updatedContext, _event, machine.options.delays);
40295
+
40296
+ if (predictableExec && typeof raisedAction.delay === 'number') {
40297
+ predictableExec(raisedAction, updatedContext, _event);
40298
+ }
40299
+
40300
+ return raisedAction;
40063
40301
  }
40064
40302
 
40065
40303
  case actionTypes.send:
40066
40304
  var sendAction = resolveSend(actionObject, updatedContext, _event, machine.options.delays); // TODO: fix ActionTypes.Init
40067
40305
 
40068
40306
  if (!environment.IS_PRODUCTION) {
40069
- // warn after resolving as we can create better contextual message here
40070
- utils.warn(!utils.isString(actionObject.delay) || typeof sendAction.delay === 'number', // tslint:disable-next-line:max-line-length
40071
- "No delay reference for delay expression '".concat(actionObject.delay, "' was found on machine '").concat(machine.id, "'"));
40307
+ var configuredDelay = actionObject.delay; // warn after resolving as we can create better contextual message here
40308
+
40309
+ utils.warn(!utils.isString(configuredDelay) || typeof sendAction.delay === 'number', // tslint:disable-next-line:max-line-length
40310
+ "No delay reference for delay expression '".concat(configuredDelay, "' was found on machine '").concat(machine.id, "'"));
40072
40311
  }
40073
40312
 
40074
- if (sendAction.to !== types.SpecialTargets.Internal) {
40075
- predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(sendAction, updatedContext, _event);
40313
+ if (predictableExec && sendAction.to !== types.SpecialTargets.Internal) {
40314
+ if (blockType === 'entry') {
40315
+ deferredToBlockEnd.push(sendAction);
40316
+ } else {
40317
+ predictableExec(sendAction, updatedContext, _event);
40318
+ }
40076
40319
  }
40077
40320
 
40078
40321
  return sendAction;
@@ -40096,7 +40339,10 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
40096
40339
  return [];
40097
40340
  }
40098
40341
 
40099
- var _b = _tslib.__read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(utils.toArray(matchedActions), machine.options.actions), predictableExec, preserveActionOrder), 2),
40342
+ var _b = _tslib.__read(resolveActions(machine, currentState, updatedContext, _event, [{
40343
+ type: blockType,
40344
+ actions: toActionObjects(utils.toArray(matchedActions), machine.options.actions)
40345
+ }], predictableExec, preserveActionOrder), 2),
40100
40346
  resolvedActionsFromChoose = _b[0],
40101
40347
  resolvedContextFromChoose = _b[1];
40102
40348
 
@@ -40113,7 +40359,10 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
40113
40359
  return [];
40114
40360
  }
40115
40361
 
40116
- var _c = _tslib.__read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(utils.toArray(matchedActions), machine.options.actions), predictableExec, preserveActionOrder), 2),
40362
+ var _c = _tslib.__read(resolveActions(machine, currentState, updatedContext, _event, [{
40363
+ type: blockType,
40364
+ actions: toActionObjects(utils.toArray(matchedActions), machine.options.actions)
40365
+ }], predictableExec, preserveActionOrder), 2),
40117
40366
  resolvedActionsFromPure = _c[0],
40118
40367
  resolvedContext = _c[1];
40119
40368
 
@@ -40125,7 +40374,7 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
40125
40374
  case actionTypes.stop:
40126
40375
  {
40127
40376
  var resolved = resolveStop(actionObject, updatedContext, _event);
40128
- predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved, updatedContext, _event);
40377
+ predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved, currentContext, _event);
40129
40378
  return resolved;
40130
40379
  }
40131
40380
 
@@ -40144,7 +40393,8 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
40144
40393
  predictableExec(resolvedActionObject, updatedContext, _event);
40145
40394
  } else if (exec_1 && preservedContexts) {
40146
40395
  var contextIndex_1 = preservedContexts.length - 1;
40147
- resolvedActionObject = _tslib.__assign(_tslib.__assign({}, resolvedActionObject), {
40396
+
40397
+ var wrapped = _tslib.__assign(_tslib.__assign({}, resolvedActionObject), {
40148
40398
  exec: function (_ctx) {
40149
40399
  var args = [];
40150
40400
 
@@ -40155,13 +40405,48 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
40155
40405
  exec_1.apply(void 0, _tslib.__spreadArray([preservedContexts[contextIndex_1]], _tslib.__read(args), false));
40156
40406
  }
40157
40407
  });
40408
+
40409
+ resolvedActionObject = wrapped;
40158
40410
  }
40159
40411
 
40160
40412
  return resolvedActionObject;
40161
40413
  }
40162
- }).filter(function (a) {
40163
- return !!a;
40164
- }));
40414
+ }
40415
+
40416
+ function processBlock(block) {
40417
+ var e_2, _a;
40418
+
40419
+ var resolvedActions = [];
40420
+
40421
+ try {
40422
+ for (var _b = _tslib.__values(block.actions), _c = _b.next(); !_c.done; _c = _b.next()) {
40423
+ var action = _c.value;
40424
+ var resolved = handleAction(block.type, action);
40425
+
40426
+ if (resolved) {
40427
+ resolvedActions = resolvedActions.concat(resolved);
40428
+ }
40429
+ }
40430
+ } catch (e_2_1) {
40431
+ e_2 = {
40432
+ error: e_2_1
40433
+ };
40434
+ } finally {
40435
+ try {
40436
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
40437
+ } finally {
40438
+ if (e_2) throw e_2.error;
40439
+ }
40440
+ }
40441
+
40442
+ deferredToBlockEnd.forEach(function (action) {
40443
+ predictableExec(action, updatedContext, _event);
40444
+ });
40445
+ deferredToBlockEnd.length = 0;
40446
+ return resolvedActions;
40447
+ }
40448
+
40449
+ var resolvedActions = utils.flatten(actionBlocks.map(processBlock));
40165
40450
  return [resolvedActions, updatedContext];
40166
40451
  }
40167
40452