Socket
Socket
Sign inDemoInstall

@storybook/instrumenter

Package Overview
Dependencies
Maintainers
29
Versions
955
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@storybook/instrumenter - npm Package Compare versions

Comparing version 6.4.0-rc.7 to 6.4.0-rc.8

251

dist/cjs/instrumenter.js

@@ -47,6 +47,6 @@ "use strict";

require("core-js/modules/es.object.values.js");
require("core-js/modules/web.dom-collections.for-each.js");
require("core-js/modules/es.object.values.js");
require("core-js/modules/es.object.entries.js");

@@ -64,2 +64,4 @@

require("core-js/modules/es.string.includes.js");
var _addons = require("@storybook/addons");

@@ -75,2 +77,4 @@

var _global$FEATURES;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -119,3 +123,2 @@

SYNC: 'instrumenter/sync',
LOCK: 'instrumenter/lock',
START: 'instrumenter/start',

@@ -128,2 +131,11 @@ BACK: 'instrumenter/back',

exports.EVENTS = EVENTS;
var debuggerDisabled = ((_global$FEATURES = _global.default.FEATURES) === null || _global$FEATURES === void 0 ? void 0 : _global$FEATURES.interactionsDebugger) !== true;
var controlsDisabled = {
debugger: !debuggerDisabled,
start: false,
back: false,
goto: false,
next: false,
end: false
};
var alreadyCompletedException = new Error("This function ran after the play function completed. Did you forget to `await` it?");

@@ -160,2 +172,4 @@

isDebugging: false,
isPlaying: false,
isLocked: false,
cursor: 0,

@@ -166,3 +180,3 @@ calls: [],

chainedCallIds: new Set(),
parentCall: undefined,
parentId: undefined,
playUntil: undefined,

@@ -214,3 +228,6 @@ resolvers: {},

var storyId = _ref3.storyId,
isDebugging = _ref3.isDebugging;
_ref3$isPlaying = _ref3.isPlaying,
isPlaying = _ref3$isPlaying === void 0 ? true : _ref3$isPlaying,
_ref3$isDebugging = _ref3.isDebugging,
isDebugging = _ref3$isDebugging === void 0 ? false : _ref3$isDebugging;

@@ -223,2 +240,3 @@ var state = _this.getState(storyId);

playUntil: isDebugging ? state.playUntil : undefined,
isPlaying: isPlaying,
isDebugging: isDebugging

@@ -228,3 +246,3 @@ })); // Don't sync while debugging, as it'll cause flicker.

if (!isDebugging) _this.channel.emit(EVENTS.SYNC, _this.getLog(storyId));
if (!isDebugging) _this.sync(storyId);
}; // A forceRemount might be triggered for debugging (on `start`), or elsewhere in Storybook.

@@ -256,2 +274,3 @@

_this.setState(storyId, {
isPlaying: false,
isDebugging: false,

@@ -281,3 +300,3 @@ forwardedException: undefined

return Object.assign({}, call, {
state: _types.CallStates.WAITING
status: _types.CallStates.WAITING
});

@@ -324,4 +343,4 @@ }),

var next = isDebugging ? log.findIndex(function (_ref9) {
var state = _ref9.state;
return state === _types.CallStates.WAITING;
var status = _ref9.status;
return status === _types.CallStates.WAITING;
}) : log.length;

@@ -352,10 +371,9 @@ start({

if (!call && shadowCall) {
if (!call && shadowCall && Object.values(resolvers).length > 0) {
var _this$getLog$find;
var nextCallId = (_this$getLog$find = _this.getLog(storyId).find(function (_ref13) {
var state = _ref13.state;
return state === _types.CallStates.WAITING;
var nextId = (_this$getLog$find = _this.getLog(storyId).find(function (c) {
return c.status === _types.CallStates.WAITING;
})) === null || _this$getLog$find === void 0 ? void 0 : _this$getLog$find.callId;
if (shadowCall.id !== nextCallId) _this.setState(storyId, {
if (shadowCall.id !== nextId) _this.setState(storyId, {
playUntil: shadowCall.id

@@ -374,11 +392,29 @@ });

var next = function next(_ref14) {
var storyId = _ref14.storyId;
Object.values(_this.getState(storyId).resolvers).forEach(function (resolve) {
return resolve();
});
var next = function next(_ref13) {
var storyId = _ref13.storyId;
var _this$getState4 = _this.getState(storyId),
resolvers = _this$getState4.resolvers;
if (Object.values(resolvers).length > 0) {
Object.values(resolvers).forEach(function (resolve) {
return resolve();
});
} else {
var _this$getLog$find2;
var nextId = (_this$getLog$find2 = _this.getLog(storyId).find(function (c) {
return c.status === _types.CallStates.WAITING;
})) === null || _this$getLog$find2 === void 0 ? void 0 : _this$getLog$find2.callId;
if (nextId) start({
storyId: storyId,
playUntil: nextId
});else end({
storyId: storyId
});
}
};
var end = function end(_ref15) {
var storyId = _ref15.storyId;
var end = function end(_ref14) {
var storyId = _ref14.storyId;

@@ -420,6 +456,6 @@ _this.setState(storyId, {

// Reset stories with retained state to their initial state, and drop the rest.
this.state = Object.entries(this.state).reduce(function (acc, _ref16) {
var _ref17 = _slicedToArray(_ref16, 2),
storyId = _ref17[0],
state = _ref17[1];
this.state = Object.entries(this.state).reduce(function (acc, _ref15) {
var _ref16 = _slicedToArray(_ref15, 2),
storyId = _ref16[0],
state = _ref16[1];

@@ -431,3 +467,6 @@ var retainedState = getRetainedState(state);

}, {});
this.channel.emit(EVENTS.SYNC, []);
this.channel.emit(EVENTS.SYNC, {
controlStates: controlsDisabled,
logItems: []
});
_global.default.window.parent.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER_STATE__ = this.state;

@@ -438,5 +477,5 @@ }

value: function getLog(storyId) {
var _this$getState4 = this.getState(storyId),
calls = _this$getState4.calls,
shadowCalls = _this$getState4.shadowCalls;
var _this$getState5 = this.getState(storyId),
calls = _this$getState5.calls,
shadowCalls = _this$getState5.shadowCalls;

@@ -461,12 +500,8 @@ var merged = _toConsumableArray(shadowCalls);

if (call.interceptable && !seen.has(call.id) && !seen.has(call.parentId)) {
if (call.interceptable && !seen.has(call.id)) {
acc.unshift({
callId: call.id,
state: call.state
status: call.status
});
seen.add(call.id);
if (call.parentId) {
seen.add(call.parentId);
}
}

@@ -540,7 +575,11 @@

var storyId = (args === null || args === void 0 ? void 0 : (_args$ = args[0]) === null || _args$ === void 0 ? void 0 : _args$.__storyId__) || ((_global$window$__STOR = _global.default.window.__STORYBOOK_PREVIEW__) === null || _global$window$__STOR === void 0 ? void 0 : (_global$window$__STOR2 = _global$window$__STOR.urlStore) === null || _global$window$__STOR2 === void 0 ? void 0 : (_global$window$__STOR3 = _global$window$__STOR2.selection) === null || _global$window$__STOR3 === void 0 ? void 0 : _global$window$__STOR3.storyId);
var index = this.getState(storyId).cursor;
var _this$getState6 = this.getState(storyId),
cursor = _this$getState6.cursor,
parentId = _this$getState6.parentId;
this.setState(storyId, {
cursor: index + 1
cursor: cursor + 1
});
var id = "".concat(storyId, " [").concat(index, "] ").concat(method);
var id = "".concat(parentId || storyId, " [").concat(cursor, "] ").concat(method);
var _options$path2 = options.path,

@@ -555,5 +594,7 @@ path = _options$path2 === void 0 ? [] : _options$path2,

id: id,
parentId: parentId,
storyId: storyId,
cursor: cursor,
path: path,
method: method,
storyId: storyId,
args: args,

@@ -576,6 +617,6 @@ interceptable: interceptable,

var _this$getState5 = this.getState(call.storyId),
chainedCallIds = _this$getState5.chainedCallIds,
isDebugging = _this$getState5.isDebugging,
playUntil = _this$getState5.playUntil; // For a "jump to step" action, continue playing until we hit a call by that ID.
var _this$getState7 = this.getState(call.storyId),
chainedCallIds = _this$getState7.chainedCallIds,
isDebugging = _this$getState7.isDebugging,
playUntil = _this$getState7.playUntil; // For a "jump to step" action, continue playing until we hit a call by that ID.
// For chained calls, we can only return a Promise for the last call in the chain.

@@ -598,7 +639,6 @@

return new Promise(function (resolve) {
_this3.channel.emit(EVENTS.LOCK, false);
_this3.setState(call.storyId, function (_ref18) {
var resolvers = _ref18.resolvers;
_this3.setState(call.storyId, function (_ref17) {
var resolvers = _ref17.resolvers;
return {
isLocked: false,
resolvers: Object.assign({}, resolvers, _defineProperty({}, call.id, resolve))

@@ -608,4 +648,2 @@ };

}).then(function () {
_this3.channel.emit(EVENTS.LOCK, true);
_this3.setState(call.storyId, function (state) {

@@ -618,2 +656,3 @@ var _state$resolvers = state.resolvers,

return {
isLocked: true,
resolvers: resolvers

@@ -634,12 +673,8 @@ };

// if (abortSignal && abortSignal.aborted) throw IGNORED_EXCEPTION;
var _this$getState6 = this.getState(call.storyId),
parentCall = _this$getState6.parentCall,
callRefsByResult = _this$getState6.callRefsByResult,
forwardedException = _this$getState6.forwardedException,
renderPhase = _this$getState6.renderPhase;
var _this$getState8 = this.getState(call.storyId),
callRefsByResult = _this$getState8.callRefsByResult,
forwardedException = _this$getState8.forwardedException,
renderPhase = _this$getState8.renderPhase;
var callWithParent = Object.assign({}, call, {
parentId: parentCall === null || parentCall === void 0 ? void 0 : parentCall.id
});
var info = Object.assign({}, callWithParent, {
var info = Object.assign({}, call, {
// Map args that originate from a tracked function call to a call reference to enable nesting.

@@ -676,4 +711,4 @@ // These values are often not fully serializable anyway (e.g. HTML elements).

if (ref !== null && ref !== void 0 && ref.__callId__) {
_this4.setState(call.storyId, function (_ref19) {
var chainedCallIds = _ref19.chainedCallIds;
_this4.setState(call.storyId, function (_ref18) {
var chainedCallIds = _ref18.chainedCallIds;
return {

@@ -694,8 +729,7 @@ chainedCallIds: new Set(Array.from(chainedCallIds).concat(ref.__callId__))

message: message,
stack: stack,
callId: call.id
stack: stack
};
_this4.sync(Object.assign({}, info, {
state: _types.CallStates.ERROR,
_this4.update(Object.assign({}, info, {
status: _types.CallStates.ERROR,
exception: exception

@@ -745,18 +779,24 @@ })); // Always track errors to their originating call.

var finalArgs = options.getArgs ? options.getArgs(callWithParent, this.getState(call.storyId)) : call.args;
var finalArgs = options.getArgs ? options.getArgs(call, this.getState(call.storyId)) : call.args;
var result = fn.apply(void 0, _toConsumableArray(finalArgs.map(function (arg) {
if (typeof arg !== 'function' || Object.keys(arg).length) return arg;
return function () {
var prev = _this4.getState(call.storyId).parentCall;
var _this4$getState = _this4.getState(call.storyId),
cursor = _this4$getState.cursor,
parentId = _this4$getState.parentId;
_this4.setState(call.storyId, {
parentCall: call
cursor: 0,
parentId: call.id
});
var restore = function restore() {
return _this4.setState(call.storyId, {
cursor: cursor,
parentId: parentId
});
};
var res = arg.apply(void 0, arguments);
_this4.setState(call.storyId, {
parentCall: prev
});
if (res instanceof Promise) res.then(restore, restore);else restore();
return res;

@@ -778,4 +818,4 @@ };

this.sync(Object.assign({}, info, {
state: result instanceof Promise ? _types.CallStates.ACTIVE : _types.CallStates.DONE
this.update(Object.assign({}, info, {
status: result instanceof Promise ? _types.CallStates.ACTIVE : _types.CallStates.DONE
}));

@@ -785,4 +825,4 @@

return result.then(function (value) {
_this4.sync(Object.assign({}, info, {
state: _types.CallStates.DONE
_this4.update(Object.assign({}, info, {
status: _types.CallStates.DONE
}));

@@ -802,4 +842,4 @@

}, {
key: "sync",
value: function sync(call) {
key: "update",
value: function update(call) {
var _this5 = this;

@@ -809,8 +849,19 @@

this.channel.emit(EVENTS.CALL, call);
this.setState(call.storyId, function (_ref20) {
var calls = _ref20.calls;
this.setState(call.storyId, function (_ref19) {
var calls = _ref19.calls,
isLocked = _ref19.isLocked;
// Omit earlier calls for the same ID, which may have been superceded by a later invocation.
// This typically happens when calls are part of a callback which runs multiple times.
var callsById = calls.concat(call).reduce(function (a, c) {
return Object.assign(a, _defineProperty({}, c.id, c));
}, {});
return {
calls: calls.concat(call),
// Calls are sorted to ensure parent calls always come before calls in their callback.
calls: Object.values(callsById).sort(function (a, b) {
return a.id.localeCompare(b.id, undefined, {
numeric: true
});
}),
syncTimeout: setTimeout(function () {
return _this5.channel.emit(EVENTS.SYNC, _this5.getLog(call.storyId));
return _this5.sync(call.storyId);
}, 0)

@@ -820,2 +871,38 @@ };

}
}, {
key: "sync",
value: function sync(storyId) {
var _this$getState9 = this.getState(storyId),
isLocked = _this$getState9.isLocked,
isPlaying = _this$getState9.isPlaying;
var logItems = this.getLog(storyId);
var hasActive = logItems.some(function (item) {
return item.status === _types.CallStates.ACTIVE;
});
if (debuggerDisabled || isLocked || hasActive || logItems.length === 0) {
this.channel.emit(EVENTS.SYNC, {
controlStates: controlsDisabled,
logItems: logItems
});
return;
}
var hasPrevious = logItems.some(function (item) {
return [_types.CallStates.DONE, _types.CallStates.ERROR].includes(item.status);
});
var controlStates = {
debugger: true,
start: hasPrevious,
back: hasPrevious,
goto: true,
next: isPlaying,
end: isPlaying
};
this.channel.emit(EVENTS.SYNC, {
controlStates: controlStates,
logItems: logItems
});
}
}]);

@@ -822,0 +909,0 @@

@@ -0,1 +1,10 @@

import "core-js/modules/es.symbol.js";
import "core-js/modules/es.symbol.description.js";
import "core-js/modules/es.symbol.iterator.js";
import "core-js/modules/es.symbol.to-primitive.js";
import "core-js/modules/es.date.to-primitive.js";
import "core-js/modules/es.number.constructor.js";
var _global$FEATURES;
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

@@ -52,4 +61,4 @@

import "core-js/modules/es.array.find.js";
import "core-js/modules/es.object.values.js";
import "core-js/modules/web.dom-collections.for-each.js";
import "core-js/modules/es.object.values.js";
import "core-js/modules/es.object.entries.js";

@@ -61,8 +70,3 @@ import "core-js/modules/es.object.keys.js";

import "core-js/modules/es.array.includes.js";
import "core-js/modules/es.symbol.js";
import "core-js/modules/es.symbol.description.js";
import "core-js/modules/es.symbol.iterator.js";
import "core-js/modules/es.symbol.to-primitive.js";
import "core-js/modules/es.date.to-primitive.js";
import "core-js/modules/es.number.constructor.js";
import "core-js/modules/es.string.includes.js";

@@ -78,3 +82,2 @@ /* eslint-disable no-underscore-dangle */

SYNC: 'instrumenter/sync',
LOCK: 'instrumenter/lock',
START: 'instrumenter/start',

@@ -86,2 +89,11 @@ BACK: 'instrumenter/back',

};
var debuggerDisabled = ((_global$FEATURES = global.FEATURES) === null || _global$FEATURES === void 0 ? void 0 : _global$FEATURES.interactionsDebugger) !== true;
var controlsDisabled = {
debugger: !debuggerDisabled,
start: false,
back: false,
goto: false,
next: false,
end: false
};
var alreadyCompletedException = new Error("This function ran after the play function completed. Did you forget to `await` it?");

@@ -118,2 +130,4 @@

isDebugging: false,
isPlaying: false,
isLocked: false,
cursor: 0,

@@ -124,3 +138,3 @@ calls: [],

chainedCallIds: new Set(),
parentCall: undefined,
parentId: undefined,
playUntil: undefined,

@@ -172,3 +186,6 @@ resolvers: {},

var storyId = _ref3.storyId,
isDebugging = _ref3.isDebugging;
_ref3$isPlaying = _ref3.isPlaying,
isPlaying = _ref3$isPlaying === void 0 ? true : _ref3$isPlaying,
_ref3$isDebugging = _ref3.isDebugging,
isDebugging = _ref3$isDebugging === void 0 ? false : _ref3$isDebugging;

@@ -181,2 +198,3 @@ var state = _this.getState(storyId);

playUntil: isDebugging ? state.playUntil : undefined,
isPlaying: isPlaying,
isDebugging: isDebugging

@@ -186,3 +204,3 @@ })); // Don't sync while debugging, as it'll cause flicker.

if (!isDebugging) _this.channel.emit(EVENTS.SYNC, _this.getLog(storyId));
if (!isDebugging) _this.sync(storyId);
}; // A forceRemount might be triggered for debugging (on `start`), or elsewhere in Storybook.

@@ -214,2 +232,3 @@

_this.setState(storyId, {
isPlaying: false,
isDebugging: false,

@@ -239,3 +258,3 @@ forwardedException: undefined

return Object.assign({}, call, {
state: CallStates.WAITING
status: CallStates.WAITING
});

@@ -282,4 +301,4 @@ }),

var next = isDebugging ? log.findIndex(function (_ref9) {
var state = _ref9.state;
return state === CallStates.WAITING;
var status = _ref9.status;
return status === CallStates.WAITING;
}) : log.length;

@@ -310,10 +329,9 @@ start({

if (!call && shadowCall) {
if (!call && shadowCall && Object.values(resolvers).length > 0) {
var _this$getLog$find;
var nextCallId = (_this$getLog$find = _this.getLog(storyId).find(function (_ref13) {
var state = _ref13.state;
return state === CallStates.WAITING;
var nextId = (_this$getLog$find = _this.getLog(storyId).find(function (c) {
return c.status === CallStates.WAITING;
})) === null || _this$getLog$find === void 0 ? void 0 : _this$getLog$find.callId;
if (shadowCall.id !== nextCallId) _this.setState(storyId, {
if (shadowCall.id !== nextId) _this.setState(storyId, {
playUntil: shadowCall.id

@@ -332,11 +350,29 @@ });

var next = function next(_ref14) {
var storyId = _ref14.storyId;
Object.values(_this.getState(storyId).resolvers).forEach(function (resolve) {
return resolve();
});
var next = function next(_ref13) {
var storyId = _ref13.storyId;
var _this$getState4 = _this.getState(storyId),
resolvers = _this$getState4.resolvers;
if (Object.values(resolvers).length > 0) {
Object.values(resolvers).forEach(function (resolve) {
return resolve();
});
} else {
var _this$getLog$find2;
var nextId = (_this$getLog$find2 = _this.getLog(storyId).find(function (c) {
return c.status === CallStates.WAITING;
})) === null || _this$getLog$find2 === void 0 ? void 0 : _this$getLog$find2.callId;
if (nextId) start({
storyId: storyId,
playUntil: nextId
});else end({
storyId: storyId
});
}
};
var end = function end(_ref15) {
var storyId = _ref15.storyId;
var end = function end(_ref14) {
var storyId = _ref14.storyId;

@@ -378,6 +414,6 @@ _this.setState(storyId, {

// Reset stories with retained state to their initial state, and drop the rest.
this.state = Object.entries(this.state).reduce(function (acc, _ref16) {
var _ref17 = _slicedToArray(_ref16, 2),
storyId = _ref17[0],
state = _ref17[1];
this.state = Object.entries(this.state).reduce(function (acc, _ref15) {
var _ref16 = _slicedToArray(_ref15, 2),
storyId = _ref16[0],
state = _ref16[1];

@@ -389,3 +425,6 @@ var retainedState = getRetainedState(state);

}, {});
this.channel.emit(EVENTS.SYNC, []);
this.channel.emit(EVENTS.SYNC, {
controlStates: controlsDisabled,
logItems: []
});
global.window.parent.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER_STATE__ = this.state;

@@ -396,5 +435,5 @@ }

value: function getLog(storyId) {
var _this$getState4 = this.getState(storyId),
calls = _this$getState4.calls,
shadowCalls = _this$getState4.shadowCalls;
var _this$getState5 = this.getState(storyId),
calls = _this$getState5.calls,
shadowCalls = _this$getState5.shadowCalls;

@@ -419,12 +458,8 @@ var merged = _toConsumableArray(shadowCalls);

if (call.interceptable && !seen.has(call.id) && !seen.has(call.parentId)) {
if (call.interceptable && !seen.has(call.id)) {
acc.unshift({
callId: call.id,
state: call.state
status: call.status
});
seen.add(call.id);
if (call.parentId) {
seen.add(call.parentId);
}
}

@@ -498,7 +533,11 @@

var storyId = (args === null || args === void 0 ? void 0 : (_args$ = args[0]) === null || _args$ === void 0 ? void 0 : _args$.__storyId__) || ((_global$window$__STOR = global.window.__STORYBOOK_PREVIEW__) === null || _global$window$__STOR === void 0 ? void 0 : (_global$window$__STOR2 = _global$window$__STOR.urlStore) === null || _global$window$__STOR2 === void 0 ? void 0 : (_global$window$__STOR3 = _global$window$__STOR2.selection) === null || _global$window$__STOR3 === void 0 ? void 0 : _global$window$__STOR3.storyId);
var index = this.getState(storyId).cursor;
var _this$getState6 = this.getState(storyId),
cursor = _this$getState6.cursor,
parentId = _this$getState6.parentId;
this.setState(storyId, {
cursor: index + 1
cursor: cursor + 1
});
var id = "".concat(storyId, " [").concat(index, "] ").concat(method);
var id = "".concat(parentId || storyId, " [").concat(cursor, "] ").concat(method);
var _options$path2 = options.path,

@@ -513,5 +552,7 @@ path = _options$path2 === void 0 ? [] : _options$path2,

id: id,
parentId: parentId,
storyId: storyId,
cursor: cursor,
path: path,
method: method,
storyId: storyId,
args: args,

@@ -534,6 +575,6 @@ interceptable: interceptable,

var _this$getState5 = this.getState(call.storyId),
chainedCallIds = _this$getState5.chainedCallIds,
isDebugging = _this$getState5.isDebugging,
playUntil = _this$getState5.playUntil; // For a "jump to step" action, continue playing until we hit a call by that ID.
var _this$getState7 = this.getState(call.storyId),
chainedCallIds = _this$getState7.chainedCallIds,
isDebugging = _this$getState7.isDebugging,
playUntil = _this$getState7.playUntil; // For a "jump to step" action, continue playing until we hit a call by that ID.
// For chained calls, we can only return a Promise for the last call in the chain.

@@ -556,7 +597,6 @@

return new Promise(function (resolve) {
_this3.channel.emit(EVENTS.LOCK, false);
_this3.setState(call.storyId, function (_ref18) {
var resolvers = _ref18.resolvers;
_this3.setState(call.storyId, function (_ref17) {
var resolvers = _ref17.resolvers;
return {
isLocked: false,
resolvers: Object.assign({}, resolvers, _defineProperty({}, call.id, resolve))

@@ -566,4 +606,2 @@ };

}).then(function () {
_this3.channel.emit(EVENTS.LOCK, true);
_this3.setState(call.storyId, function (state) {

@@ -576,2 +614,3 @@ var _state$resolvers = state.resolvers,

return {
isLocked: true,
resolvers: resolvers

@@ -592,12 +631,8 @@ };

// if (abortSignal && abortSignal.aborted) throw IGNORED_EXCEPTION;
var _this$getState6 = this.getState(call.storyId),
parentCall = _this$getState6.parentCall,
callRefsByResult = _this$getState6.callRefsByResult,
forwardedException = _this$getState6.forwardedException,
renderPhase = _this$getState6.renderPhase;
var _this$getState8 = this.getState(call.storyId),
callRefsByResult = _this$getState8.callRefsByResult,
forwardedException = _this$getState8.forwardedException,
renderPhase = _this$getState8.renderPhase;
var callWithParent = Object.assign({}, call, {
parentId: parentCall === null || parentCall === void 0 ? void 0 : parentCall.id
});
var info = Object.assign({}, callWithParent, {
var info = Object.assign({}, call, {
// Map args that originate from a tracked function call to a call reference to enable nesting.

@@ -634,4 +669,4 @@ // These values are often not fully serializable anyway (e.g. HTML elements).

if (ref !== null && ref !== void 0 && ref.__callId__) {
_this4.setState(call.storyId, function (_ref19) {
var chainedCallIds = _ref19.chainedCallIds;
_this4.setState(call.storyId, function (_ref18) {
var chainedCallIds = _ref18.chainedCallIds;
return {

@@ -652,8 +687,7 @@ chainedCallIds: new Set(Array.from(chainedCallIds).concat(ref.__callId__))

message: message,
stack: stack,
callId: call.id
stack: stack
};
_this4.sync(Object.assign({}, info, {
state: CallStates.ERROR,
_this4.update(Object.assign({}, info, {
status: CallStates.ERROR,
exception: exception

@@ -703,18 +737,24 @@ })); // Always track errors to their originating call.

var finalArgs = options.getArgs ? options.getArgs(callWithParent, this.getState(call.storyId)) : call.args;
var finalArgs = options.getArgs ? options.getArgs(call, this.getState(call.storyId)) : call.args;
var result = fn.apply(void 0, _toConsumableArray(finalArgs.map(function (arg) {
if (typeof arg !== 'function' || Object.keys(arg).length) return arg;
return function () {
var prev = _this4.getState(call.storyId).parentCall;
var _this4$getState = _this4.getState(call.storyId),
cursor = _this4$getState.cursor,
parentId = _this4$getState.parentId;
_this4.setState(call.storyId, {
parentCall: call
cursor: 0,
parentId: call.id
});
var restore = function restore() {
return _this4.setState(call.storyId, {
cursor: cursor,
parentId: parentId
});
};
var res = arg.apply(void 0, arguments);
_this4.setState(call.storyId, {
parentCall: prev
});
if (res instanceof Promise) res.then(restore, restore);else restore();
return res;

@@ -736,4 +776,4 @@ };

this.sync(Object.assign({}, info, {
state: result instanceof Promise ? CallStates.ACTIVE : CallStates.DONE
this.update(Object.assign({}, info, {
status: result instanceof Promise ? CallStates.ACTIVE : CallStates.DONE
}));

@@ -743,4 +783,4 @@

return result.then(function (value) {
_this4.sync(Object.assign({}, info, {
state: CallStates.DONE
_this4.update(Object.assign({}, info, {
status: CallStates.DONE
}));

@@ -760,4 +800,4 @@

}, {
key: "sync",
value: function sync(call) {
key: "update",
value: function update(call) {
var _this5 = this;

@@ -767,8 +807,19 @@

this.channel.emit(EVENTS.CALL, call);
this.setState(call.storyId, function (_ref20) {
var calls = _ref20.calls;
this.setState(call.storyId, function (_ref19) {
var calls = _ref19.calls,
isLocked = _ref19.isLocked;
// Omit earlier calls for the same ID, which may have been superceded by a later invocation.
// This typically happens when calls are part of a callback which runs multiple times.
var callsById = calls.concat(call).reduce(function (a, c) {
return Object.assign(a, _defineProperty({}, c.id, c));
}, {});
return {
calls: calls.concat(call),
// Calls are sorted to ensure parent calls always come before calls in their callback.
calls: Object.values(callsById).sort(function (a, b) {
return a.id.localeCompare(b.id, undefined, {
numeric: true
});
}),
syncTimeout: setTimeout(function () {
return _this5.channel.emit(EVENTS.SYNC, _this5.getLog(call.storyId));
return _this5.sync(call.storyId);
}, 0)

@@ -778,2 +829,38 @@ };

}
}, {
key: "sync",
value: function sync(storyId) {
var _this$getState9 = this.getState(storyId),
isLocked = _this$getState9.isLocked,
isPlaying = _this$getState9.isPlaying;
var logItems = this.getLog(storyId);
var hasActive = logItems.some(function (item) {
return item.status === CallStates.ACTIVE;
});
if (debuggerDisabled || isLocked || hasActive || logItems.length === 0) {
this.channel.emit(EVENTS.SYNC, {
controlStates: controlsDisabled,
logItems: logItems
});
return;
}
var hasPrevious = logItems.some(function (item) {
return [CallStates.DONE, CallStates.ERROR].includes(item.status);
});
var controlStates = {
debugger: true,
start: hasPrevious,
back: hasPrevious,
goto: true,
next: isPlaying,
end: isPlaying
};
this.channel.emit(EVENTS.SYNC, {
controlStates: controlStates,
logItems: logItems
});
}
}]);

@@ -780,0 +867,0 @@

@@ -0,1 +1,3 @@

var _global$FEATURES;
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

@@ -19,3 +21,2 @@

SYNC: 'instrumenter/sync',
LOCK: 'instrumenter/lock',
START: 'instrumenter/start',

@@ -27,2 +28,11 @@ BACK: 'instrumenter/back',

};
const debuggerDisabled = ((_global$FEATURES = global.FEATURES) === null || _global$FEATURES === void 0 ? void 0 : _global$FEATURES.interactionsDebugger) !== true;
const controlsDisabled = {
debugger: !debuggerDisabled,
start: false,
back: false,
goto: false,
next: false,
end: false
};
const alreadyCompletedException = new Error(`This function ran after the play function completed. Did you forget to \`await\` it?`);

@@ -54,2 +64,4 @@

isDebugging: false,
isPlaying: false,
isLocked: false,
cursor: 0,

@@ -60,3 +72,3 @@ calls: [],

chainedCallIds: new Set(),
parentCall: undefined,
parentId: undefined,
playUntil: undefined,

@@ -95,3 +107,4 @@ resolvers: {},

storyId,
isDebugging
isPlaying = true,
isDebugging = false
}) => {

@@ -103,6 +116,7 @@ const state = this.getState(storyId);

playUntil: isDebugging ? state.playUntil : undefined,
isPlaying,
isDebugging
})); // Don't sync while debugging, as it'll cause flicker.
if (!isDebugging) this.channel.emit(EVENTS.SYNC, this.getLog(storyId));
if (!isDebugging) this.sync(storyId);
}; // A forceRemount might be triggered for debugging (on `start`), or elsewhere in Storybook.

@@ -134,2 +148,3 @@

this.setState(storyId, {
isPlaying: false,
isDebugging: false,

@@ -157,3 +172,3 @@ forwardedException: undefined

shadowCalls: calls.map(call => Object.assign({}, call, {
state: CallStates.WAITING
status: CallStates.WAITING
})),

@@ -192,4 +207,4 @@ isDebugging: true

const next = isDebugging ? log.findIndex(({
state
}) => state === CallStates.WAITING) : log.length;
status
}) => status === CallStates.WAITING) : log.length;
start({

@@ -217,9 +232,7 @@ storyId,

if (!call && shadowCall) {
if (!call && shadowCall && Object.values(resolvers).length > 0) {
var _this$getLog$find;
const nextCallId = (_this$getLog$find = this.getLog(storyId).find(({
state
}) => state === CallStates.WAITING)) === null || _this$getLog$find === void 0 ? void 0 : _this$getLog$find.callId;
if (shadowCall.id !== nextCallId) this.setState(storyId, {
const nextId = (_this$getLog$find = this.getLog(storyId).find(c => c.status === CallStates.WAITING)) === null || _this$getLog$find === void 0 ? void 0 : _this$getLog$find.callId;
if (shadowCall.id !== nextId) this.setState(storyId, {
playUntil: shadowCall.id

@@ -239,3 +252,19 @@ });

}) => {
Object.values(this.getState(storyId).resolvers).forEach(resolve => resolve());
const {
resolvers
} = this.getState(storyId);
if (Object.values(resolvers).length > 0) {
Object.values(resolvers).forEach(resolve => resolve());
} else {
var _this$getLog$find2;
const nextId = (_this$getLog$find2 = this.getLog(storyId).find(c => c.status === CallStates.WAITING)) === null || _this$getLog$find2 === void 0 ? void 0 : _this$getLog$find2.callId;
if (nextId) start({
storyId,
playUntil: nextId
});else end({
storyId
});
}
};

@@ -282,3 +311,6 @@

}, {});
this.channel.emit(EVENTS.SYNC, []);
this.channel.emit(EVENTS.SYNC, {
controlStates: controlsDisabled,
logItems: []
});
global.window.parent.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER_STATE__ = this.state;

@@ -309,12 +341,8 @@ }

if (call.interceptable && !seen.has(call.id) && !seen.has(call.parentId)) {
if (call.interceptable && !seen.has(call.id)) {
acc.unshift({
callId: call.id,
state: call.state
status: call.status
});
seen.add(call.id);
if (call.parentId) {
seen.add(call.parentId);
}
}

@@ -378,7 +406,10 @@

const storyId = (args === null || args === void 0 ? void 0 : (_args$ = args[0]) === null || _args$ === void 0 ? void 0 : _args$.__storyId__) || ((_global$window$__STOR = global.window.__STORYBOOK_PREVIEW__) === null || _global$window$__STOR === void 0 ? void 0 : (_global$window$__STOR2 = _global$window$__STOR.urlStore) === null || _global$window$__STOR2 === void 0 ? void 0 : (_global$window$__STOR3 = _global$window$__STOR2.selection) === null || _global$window$__STOR3 === void 0 ? void 0 : _global$window$__STOR3.storyId);
const index = this.getState(storyId).cursor;
const {
cursor,
parentId
} = this.getState(storyId);
this.setState(storyId, {
cursor: index + 1
cursor: cursor + 1
});
const id = `${storyId} [${index}] ${method}`;
const id = `${parentId || storyId} [${cursor}] ${method}`;
const {

@@ -392,5 +423,7 @@ path = [],

id,
parentId,
storyId,
cursor,
path,
method,
storyId,
args,

@@ -431,6 +464,6 @@ interceptable,

return new Promise(resolve => {
this.channel.emit(EVENTS.LOCK, false);
this.setState(call.storyId, ({
resolvers
}) => ({
isLocked: false,
resolvers: Object.assign({}, resolvers, {

@@ -441,3 +474,2 @@ [call.id]: resolve

}).then(() => {
this.channel.emit(EVENTS.LOCK, true);
this.setState(call.storyId, state => {

@@ -449,2 +481,3 @@ const _state$resolvers = state.resolvers,

return {
isLocked: true,
resolvers

@@ -462,3 +495,2 @@ };

const {
parentCall,
callRefsByResult,

@@ -468,6 +500,3 @@ forwardedException,

} = this.getState(call.storyId);
const callWithParent = Object.assign({}, call, {
parentId: parentCall === null || parentCall === void 0 ? void 0 : parentCall.id
});
const info = Object.assign({}, callWithParent, {
const info = Object.assign({}, call, {
// Map args that originate from a tracked function call to a call reference to enable nesting.

@@ -524,7 +553,6 @@ // These values are often not fully serializable anyway (e.g. HTML elements).

message,
stack,
callId: call.id
stack
};
this.sync(Object.assign({}, info, {
state: CallStates.ERROR,
this.update(Object.assign({}, info, {
status: CallStates.ERROR,
exception

@@ -569,15 +597,24 @@ })); // Always track errors to their originating call.

const finalArgs = options.getArgs ? options.getArgs(callWithParent, this.getState(call.storyId)) : call.args;
const finalArgs = options.getArgs ? options.getArgs(call, this.getState(call.storyId)) : call.args;
const result = fn( // Wrap any callback functions to provide a way to access their "parent" call.
// This is picked up in the `track` function and used for call metadata.
...finalArgs.map(arg => {
if (typeof arg !== 'function' || Object.keys(arg).length) return arg;
return (...args) => {
const prev = this.getState(call.storyId).parentCall;
const {
cursor,
parentId
} = this.getState(call.storyId);
this.setState(call.storyId, {
parentCall: call
cursor: 0,
parentId: call.id
});
const restore = () => this.setState(call.storyId, {
cursor,
parentId
});
const res = arg(...args);
this.setState(call.storyId, {
parentCall: prev
});
if (res instanceof Promise) res.then(restore, restore);else restore();
return res;

@@ -597,4 +634,4 @@ };

this.sync(Object.assign({}, info, {
state: result instanceof Promise ? CallStates.ACTIVE : CallStates.DONE
this.update(Object.assign({}, info, {
status: result instanceof Promise ? CallStates.ACTIVE : CallStates.DONE
}));

@@ -604,4 +641,4 @@

return result.then(value => {
this.sync(Object.assign({}, info, {
state: CallStates.DONE
this.update(Object.assign({}, info, {
status: CallStates.DONE
}));

@@ -620,13 +657,55 @@ return value;

sync(call) {
update(call) {
clearTimeout(this.getState(call.storyId).syncTimeout);
this.channel.emit(EVENTS.CALL, call);
this.setState(call.storyId, ({
calls
}) => ({
calls: calls.concat(call),
syncTimeout: setTimeout(() => this.channel.emit(EVENTS.SYNC, this.getLog(call.storyId)), 0)
}));
calls,
isLocked
}) => {
// Omit earlier calls for the same ID, which may have been superceded by a later invocation.
// This typically happens when calls are part of a callback which runs multiple times.
const callsById = calls.concat(call).reduce((a, c) => Object.assign(a, {
[c.id]: c
}), {});
return {
// Calls are sorted to ensure parent calls always come before calls in their callback.
calls: Object.values(callsById).sort((a, b) => a.id.localeCompare(b.id, undefined, {
numeric: true
})),
syncTimeout: setTimeout(() => this.sync(call.storyId), 0)
};
});
}
sync(storyId) {
const {
isLocked,
isPlaying
} = this.getState(storyId);
const logItems = this.getLog(storyId);
const hasActive = logItems.some(item => item.status === CallStates.ACTIVE);
if (debuggerDisabled || isLocked || hasActive || logItems.length === 0) {
this.channel.emit(EVENTS.SYNC, {
controlStates: controlsDisabled,
logItems
});
return;
}
const hasPrevious = logItems.some(item => [CallStates.DONE, CallStates.ERROR].includes(item.status));
const controlStates = {
debugger: true,
start: hasPrevious,
back: hasPrevious,
goto: true,
next: isPlaying,
end: isPlaying
};
this.channel.emit(EVENTS.SYNC, {
controlStates,
logItems
});
}
}

@@ -633,0 +712,0 @@ /**

import { Channel, StoryId } from '@storybook/addons';
import { Call, CallRef, LogItem } from './types';
import { Call, State, Options, LogItem } from './types';
export declare const EVENTS: {
CALL: string;
SYNC: string;
LOCK: string;
START: string;

@@ -13,26 +12,3 @@ BACK: string;

};
export interface Options {
intercept?: boolean | ((method: string, path: Array<string | CallRef>) => boolean);
retain?: boolean;
mutate?: boolean;
path?: Array<string | CallRef>;
getArgs?: (call: Call, state: State) => Call['args'];
}
export interface State {
renderPhase: 'loading' | 'rendering' | 'playing' | 'played' | 'completed' | 'aborted' | 'errored';
isDebugging: boolean;
cursor: number;
calls: Call[];
shadowCalls: Call[];
callRefsByResult: Map<any, CallRef & {
retain: boolean;
}>;
chainedCallIds: Set<Call['id']>;
parentCall?: Call;
playUntil?: Call['id'];
resolvers: Record<Call['id'], Function>;
syncTimeout: ReturnType<typeof setTimeout>;
forwardedException?: Error;
}
export declare type PatchedObj<TObj> = {
declare type PatchedObj<TObj> = {
[Property in keyof TObj]: TObj[Property] & {

@@ -60,3 +36,4 @@ __originalFn__: PatchedObj<TObj>;

invoke(fn: Function, call: Call, options: Options): any;
sync(call: Call): void;
update(call: Call): void;
sync(storyId: StoryId): void;
}

@@ -70,1 +47,2 @@ /**

export declare function instrument<TObj extends Record<string, any>>(obj: TObj, options?: Options): TObj;
export {};
import { StoryId } from '@storybook/addons';
export interface Call {
id: string;
parentId?: Call['id'];
storyId: StoryId;
cursor: number;
path: Array<string | CallRef>;
method: string;
storyId: StoryId;
args: any[];
interceptable: boolean;
retain: boolean;
state?: CallStates.DONE | CallStates.ERROR | CallStates.ACTIVE | CallStates.WAITING;
exception?: {
callId: Call['id'];
message: Error['message'];
stack: Error['stack'];
};
parentId?: Call['id'];
status?: CallStates.DONE | CallStates.ERROR | CallStates.ACTIVE | CallStates.WAITING;
exception?: Error;
}

@@ -36,5 +33,42 @@ export declare enum CallStates {

}
export interface ControlStates {
debugger: boolean;
start: boolean;
back: boolean;
goto: boolean;
next: boolean;
end: boolean;
}
export interface LogItem {
callId: Call['id'];
state: Call['state'];
status: Call['status'];
}
export interface Payload {
controlStates: ControlStates;
logItems: LogItem[];
}
export interface State {
renderPhase: 'loading' | 'rendering' | 'playing' | 'played' | 'completed' | 'aborted' | 'errored';
isDebugging: boolean;
isPlaying: boolean;
isLocked: boolean;
cursor: number;
calls: Call[];
shadowCalls: Call[];
callRefsByResult: Map<any, CallRef & {
retain: boolean;
}>;
chainedCallIds: Set<Call['id']>;
parentId?: Call['id'];
playUntil?: Call['id'];
resolvers: Record<Call['id'], Function>;
syncTimeout: ReturnType<typeof setTimeout>;
forwardedException?: Error;
}
export interface Options {
intercept?: boolean | ((method: string, path: Array<string | CallRef>) => boolean);
retain?: boolean;
mutate?: boolean;
path?: Array<string | CallRef>;
getArgs?: (call: Call, state: State) => Call['args'];
}
import { Channel, StoryId } from '@storybook/addons';
import { Call, CallRef, LogItem } from './types';
import { Call, State, Options, LogItem } from './types';
export declare const EVENTS: {
CALL: string;
SYNC: string;
LOCK: string;
START: string;

@@ -13,26 +12,3 @@ BACK: string;

};
export interface Options {
intercept?: boolean | ((method: string, path: Array<string | CallRef>) => boolean);
retain?: boolean;
mutate?: boolean;
path?: Array<string | CallRef>;
getArgs?: (call: Call, state: State) => Call['args'];
}
export interface State {
renderPhase: 'loading' | 'rendering' | 'playing' | 'played' | 'completed' | 'aborted' | 'errored';
isDebugging: boolean;
cursor: number;
calls: Call[];
shadowCalls: Call[];
callRefsByResult: Map<any, CallRef & {
retain: boolean;
}>;
chainedCallIds: Set<Call['id']>;
parentCall?: Call;
playUntil?: Call['id'];
resolvers: Record<Call['id'], Function>;
syncTimeout: ReturnType<typeof setTimeout>;
forwardedException?: Error;
}
export declare type PatchedObj<TObj> = {
declare type PatchedObj<TObj> = {
[Property in keyof TObj]: TObj[Property] & {

@@ -60,3 +36,4 @@ __originalFn__: PatchedObj<TObj>;

invoke(fn: Function, call: Call, options: Options): any;
sync(call: Call): void;
update(call: Call): void;
sync(storyId: StoryId): void;
}

@@ -70,1 +47,2 @@ /**

export declare function instrument<TObj extends Record<string, any>>(obj: TObj, options?: Options): TObj;
export {};
import { StoryId } from '@storybook/addons';
export interface Call {
id: string;
parentId?: Call['id'];
storyId: StoryId;
cursor: number;
path: Array<string | CallRef>;
method: string;
storyId: StoryId;
args: any[];
interceptable: boolean;
retain: boolean;
state?: CallStates.DONE | CallStates.ERROR | CallStates.ACTIVE | CallStates.WAITING;
exception?: {
callId: Call['id'];
message: Error['message'];
stack: Error['stack'];
};
parentId?: Call['id'];
status?: CallStates.DONE | CallStates.ERROR | CallStates.ACTIVE | CallStates.WAITING;
exception?: Error;
}

@@ -36,5 +33,42 @@ export declare enum CallStates {

}
export interface ControlStates {
debugger: boolean;
start: boolean;
back: boolean;
goto: boolean;
next: boolean;
end: boolean;
}
export interface LogItem {
callId: Call['id'];
state: Call['state'];
status: Call['status'];
}
export interface Payload {
controlStates: ControlStates;
logItems: LogItem[];
}
export interface State {
renderPhase: 'loading' | 'rendering' | 'playing' | 'played' | 'completed' | 'aborted' | 'errored';
isDebugging: boolean;
isPlaying: boolean;
isLocked: boolean;
cursor: number;
calls: Call[];
shadowCalls: Call[];
callRefsByResult: Map<any, CallRef & {
retain: boolean;
}>;
chainedCallIds: Set<Call['id']>;
parentId?: Call['id'];
playUntil?: Call['id'];
resolvers: Record<Call['id'], Function>;
syncTimeout: ReturnType<typeof setTimeout>;
forwardedException?: Error;
}
export interface Options {
intercept?: boolean | ((method: string, path: Array<string | CallRef>) => boolean);
retain?: boolean;
mutate?: boolean;
path?: Array<string | CallRef>;
getArgs?: (call: Call, state: State) => Call['args'];
}
{
"name": "@storybook/instrumenter",
"version": "6.4.0-rc.7",
"version": "6.4.0-rc.8",
"description": "",

@@ -43,5 +43,5 @@ "keywords": [

"dependencies": {
"@storybook/addons": "6.4.0-rc.7",
"@storybook/client-logger": "6.4.0-rc.7",
"@storybook/core-events": "6.4.0-rc.7",
"@storybook/addons": "6.4.0-rc.8",
"@storybook/client-logger": "6.4.0-rc.8",
"@storybook/core-events": "6.4.0-rc.8",
"global": "^4.4.0"

@@ -52,4 +52,4 @@ },

},
"gitHead": "7162286c0d8d122c7206265fab41c4c191c86d40",
"gitHead": "0be6dde43b848e310e705a4354c6c8abe0431448",
"sbmodern": "dist/modern/index.js"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc