@storybook/addon-mcp
Version:
Help agents automatically write and test stories for your UI components
28 lines (26 loc) • 1.24 kB
JavaScript
// src/constants.ts
var MCP_APP_PARAM = "mcp-app", MCP_APP_SIZE_CHANGED_EVENT = "storybook-mcp:size-changed";
// src/preview.ts
var isMcpApp = new URLSearchParams(window.location.search).has(MCP_APP_PARAM);
if (isMcpApp) {
let sendSizeToParent2 = function() {
let height = document.body.scrollHeight;
Math.abs(height - lastSentHeight) <= 2 || (lastSentHeight = height, window.parent.postMessage(
{
type: MCP_APP_SIZE_CHANGED_EVENT,
height
},
"*"
));
}, debouncedSendSize2 = function() {
debounceTimer && clearTimeout(debounceTimer), debounceTimer = setTimeout(sendSizeToParent2, DEBOUNCE_MS);
};
sendSizeToParent = sendSizeToParent2, debouncedSendSize = debouncedSendSize2;
let SIZE_CHANGE_THRESHOLD = 2, debounceTimer = null, lastSentHeight = 0, DEBOUNCE_MS = 100;
document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", sendSizeToParent2) : sendSizeToParent2(), window.addEventListener("load", sendSizeToParent2), new ResizeObserver(debouncedSendSize2).observe(document.body), new MutationObserver(debouncedSendSize2).observe(document.body, {
childList: !0,
subtree: !0,
attributes: !0
});
}
var sendSizeToParent, debouncedSendSize;