@tpitre/story-ui 2.8.0 → 2.8.1
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StoryUIPanel.d.ts","sourceRoot":"","sources":["../../../templates/StoryUI/StoryUIPanel.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"StoryUIPanel.d.ts","sourceRoot":"","sources":["../../../templates/StoryUI/StoryUIPanel.tsx"],"names":[],"mappings":"AA85CA,iBAAS,YAAY,4CA8sCpB;AAED,eAAe,YAAY,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -115,6 +115,27 @@ const isEdgeMode = () => {
|
|
|
115
115
|
return baseUrl.includes('workers.dev') || baseUrl.includes('pages.dev') ||
|
|
116
116
|
baseUrl.startsWith('https://') && !baseUrl.includes('localhost');
|
|
117
117
|
};
|
|
118
|
+
// Helper to convert story title to Storybook URL format
|
|
119
|
+
// e.g., "Simple Card With Image" -> "generated-simple-card-with-image--default"
|
|
120
|
+
const titleToStoryPath = (title) => {
|
|
121
|
+
const kebabTitle = title.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
|
|
122
|
+
return `generated-${kebabTitle}--default`;
|
|
123
|
+
};
|
|
124
|
+
// Helper to navigate to a newly created story after generation completes
|
|
125
|
+
// In dev mode with HMR, this prevents the "Couldn't find story after HMR" error
|
|
126
|
+
// In all modes, this provides a better UX by auto-navigating to the new story
|
|
127
|
+
const navigateToNewStory = (title, delayMs = 4000) => {
|
|
128
|
+
const storyPath = titleToStoryPath(title);
|
|
129
|
+
console.log(`[Story UI] Will navigate to story "${storyPath}" in ${delayMs}ms...`);
|
|
130
|
+
setTimeout(() => {
|
|
131
|
+
// Navigate the TOP window (parent Storybook UI), not the iframe
|
|
132
|
+
// The Story UI panel runs inside an iframe, so we need window.top to escape it
|
|
133
|
+
const topWindow = window.top || window;
|
|
134
|
+
const newUrl = `${topWindow.location.origin}/?path=/story/${storyPath}`;
|
|
135
|
+
console.log(`[Story UI] Navigating parent window to: ${newUrl}`);
|
|
136
|
+
topWindow.location.href = newUrl;
|
|
137
|
+
}, delayMs);
|
|
138
|
+
};
|
|
118
139
|
// Legacy helper for backwards compatibility
|
|
119
140
|
const getApiPort = () => {
|
|
120
141
|
const baseUrl = getApiBaseUrl();
|
|
@@ -1414,6 +1435,10 @@ function StoryUIPanel() {
|
|
|
1414
1435
|
}
|
|
1415
1436
|
saveChats(chats);
|
|
1416
1437
|
setRecentChats(chats);
|
|
1438
|
+
// Auto-navigate to the newly created story after HMR processes the file
|
|
1439
|
+
// This prevents the "Couldn't find story after HMR" error by refreshing
|
|
1440
|
+
// after the file system has been updated and HMR has processed the change
|
|
1441
|
+
navigateToNewStory(chatTitle);
|
|
1417
1442
|
}
|
|
1418
1443
|
}, [activeChatId, activeTitle, conversation.length]);
|
|
1419
1444
|
const handleSend = async (e) => {
|
|
@@ -1589,11 +1614,12 @@ function StoryUIPanel() {
|
|
|
1589
1614
|
}
|
|
1590
1615
|
else {
|
|
1591
1616
|
const chatId = data.storyId || data.fileName || Date.now().toString();
|
|
1617
|
+
const chatTitle = data.title || userInput;
|
|
1592
1618
|
setActiveChatId(chatId);
|
|
1593
|
-
setActiveTitle(
|
|
1619
|
+
setActiveTitle(chatTitle);
|
|
1594
1620
|
const newSession = {
|
|
1595
1621
|
id: chatId,
|
|
1596
|
-
title:
|
|
1622
|
+
title: chatTitle,
|
|
1597
1623
|
fileName: data.fileName || '',
|
|
1598
1624
|
conversation: updatedConversation,
|
|
1599
1625
|
lastUpdated: Date.now(),
|
|
@@ -1604,6 +1630,8 @@ function StoryUIPanel() {
|
|
|
1604
1630
|
chats.splice(MAX_RECENT_CHATS);
|
|
1605
1631
|
saveChats(chats);
|
|
1606
1632
|
setRecentChats(chats);
|
|
1633
|
+
// Auto-navigate to the newly created story
|
|
1634
|
+
navigateToNewStory(chatTitle);
|
|
1607
1635
|
}
|
|
1608
1636
|
}
|
|
1609
1637
|
catch (fallbackErr) {
|
package/package.json
CHANGED
|
@@ -284,6 +284,30 @@ const isEdgeMode = () => {
|
|
|
284
284
|
baseUrl.startsWith('https://') && !baseUrl.includes('localhost');
|
|
285
285
|
};
|
|
286
286
|
|
|
287
|
+
// Helper to convert story title to Storybook URL format
|
|
288
|
+
// e.g., "Simple Card With Image" -> "generated-simple-card-with-image--default"
|
|
289
|
+
const titleToStoryPath = (title: string): string => {
|
|
290
|
+
const kebabTitle = title.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
|
|
291
|
+
return `generated-${kebabTitle}--default`;
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// Helper to navigate to a newly created story after generation completes
|
|
295
|
+
// In dev mode with HMR, this prevents the "Couldn't find story after HMR" error
|
|
296
|
+
// In all modes, this provides a better UX by auto-navigating to the new story
|
|
297
|
+
const navigateToNewStory = (title: string, delayMs: number = 4000) => {
|
|
298
|
+
const storyPath = titleToStoryPath(title);
|
|
299
|
+
console.log(`[Story UI] Will navigate to story "${storyPath}" in ${delayMs}ms...`);
|
|
300
|
+
|
|
301
|
+
setTimeout(() => {
|
|
302
|
+
// Navigate the TOP window (parent Storybook UI), not the iframe
|
|
303
|
+
// The Story UI panel runs inside an iframe, so we need window.top to escape it
|
|
304
|
+
const topWindow = window.top || window;
|
|
305
|
+
const newUrl = `${topWindow.location.origin}/?path=/story/${storyPath}`;
|
|
306
|
+
console.log(`[Story UI] Navigating parent window to: ${newUrl}`);
|
|
307
|
+
topWindow.location.href = newUrl;
|
|
308
|
+
}, delayMs);
|
|
309
|
+
};
|
|
310
|
+
|
|
287
311
|
// Legacy helper for backwards compatibility
|
|
288
312
|
const getApiPort = () => {
|
|
289
313
|
const baseUrl = getApiBaseUrl();
|
|
@@ -1899,6 +1923,11 @@ function StoryUIPanel() {
|
|
|
1899
1923
|
}
|
|
1900
1924
|
saveChats(chats);
|
|
1901
1925
|
setRecentChats(chats);
|
|
1926
|
+
|
|
1927
|
+
// Auto-navigate to the newly created story after HMR processes the file
|
|
1928
|
+
// This prevents the "Couldn't find story after HMR" error by refreshing
|
|
1929
|
+
// after the file system has been updated and HMR has processed the change
|
|
1930
|
+
navigateToNewStory(chatTitle);
|
|
1902
1931
|
}
|
|
1903
1932
|
}, [activeChatId, activeTitle, conversation.length]);
|
|
1904
1933
|
|
|
@@ -2091,11 +2120,12 @@ function StoryUIPanel() {
|
|
|
2091
2120
|
setRecentChats(chats);
|
|
2092
2121
|
} else {
|
|
2093
2122
|
const chatId = data.storyId || data.fileName || Date.now().toString();
|
|
2123
|
+
const chatTitle = data.title || userInput;
|
|
2094
2124
|
setActiveChatId(chatId);
|
|
2095
|
-
setActiveTitle(
|
|
2125
|
+
setActiveTitle(chatTitle);
|
|
2096
2126
|
const newSession: ChatSession = {
|
|
2097
2127
|
id: chatId,
|
|
2098
|
-
title:
|
|
2128
|
+
title: chatTitle,
|
|
2099
2129
|
fileName: data.fileName || '',
|
|
2100
2130
|
conversation: updatedConversation,
|
|
2101
2131
|
lastUpdated: Date.now(),
|
|
@@ -2105,6 +2135,9 @@ function StoryUIPanel() {
|
|
|
2105
2135
|
if (chats.length > MAX_RECENT_CHATS) chats.splice(MAX_RECENT_CHATS);
|
|
2106
2136
|
saveChats(chats);
|
|
2107
2137
|
setRecentChats(chats);
|
|
2138
|
+
|
|
2139
|
+
// Auto-navigate to the newly created story
|
|
2140
|
+
navigateToNewStory(chatTitle);
|
|
2108
2141
|
}
|
|
2109
2142
|
} catch (fallbackErr: unknown) {
|
|
2110
2143
|
const errorMessage = fallbackErr instanceof Error ? fallbackErr.message : 'Unknown error';
|