Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions packages/ai/test/pages/TextArea.html
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ <h1 class="demo-title">AI TextArea Component</h1>
textarea.value = versionHistory[versionIndex].value;
}

textarea.currentVersion = currentIndexHistory;
textarea.currentVersion = currentIndexHistory + 1;
textarea.totalVersions = versionHistory.length;

if (versionHistory[currentIndexHistory]) {
Expand Down Expand Up @@ -366,13 +366,30 @@ <h1 class="demo-title">AI TextArea Component</h1>
stopTypingAnimation();
currentGenerationIndex += 1;

// Restore the previous content instead of saving the cancelled action
textarea.value = contentBeforeGeneration;
// Save the stopped generation if there is content
const stoppedValue = textarea.value;
if (stoppedValue.trim()) {
const menuItem = findMenuItemByAction(currentActionInProgress);
const completedLabel = (menuItem && menuItem.dataset.completedLabel)
? menuItem.dataset.completedLabel + " (stopped)"
: "Generation stopped";

versionHistory.push({
value: stoppedValue,
action: currentActionInProgress,
endAction: completedLabel,
timestamp: new Date().toISOString()
});

// Restore the previous content
textarea.value = contentBeforeGeneration;
currentIndexHistory = versionHistory.length - 1;
buildMenuFromConfig();
updateComponentState();
}

currentActionInProgress = null;
textarea.loading = false;
textarea.promptDescription = "";

updateComponentState();
}

function handleVersionChange(event) {
Expand Down
39 changes: 24 additions & 15 deletions packages/website/docs/_samples/ai/TextArea/Extended/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ let currentIndexHistory = 0;
let currentActionInProgress = null;
let typingInterval = null;
let currentGenerationIndex = 0;
let contentBeforeGeneration = "";

const textarea = document.getElementById('ai-textarea');
const menu = document.getElementById('ai-menu');
Expand All @@ -95,7 +96,7 @@ function updateComponentState(versionIndex = null) {
textarea.value = versionHistory[versionIndex].value;
}

textarea.currentVersion = currentIndexHistory;
textarea.currentVersion = currentIndexHistory + 1;
textarea.totalVersions = versionHistory.length;

if (versionHistory[currentIndexHistory]) {
Expand Down Expand Up @@ -242,6 +243,7 @@ async function executeAction(action) {
const textKey = menuItem.dataset.textKey || 'en';

saveCurrentVersion();
contentBeforeGeneration = textarea.value;
currentActionInProgress = action;
currentGenerationIndex += 1;
const generationIdForThisRun = currentGenerationIndex;
Expand All @@ -267,22 +269,29 @@ function stopGeneration() {

stopTypingAnimation();
currentGenerationIndex += 1;
const action = currentActionInProgress || 'generate';
const menuItem = findMenuItemByAction(action);
const completedLabel = (menuItem && menuItem.dataset.completedLabel) ? menuItem.dataset.completedLabel : 'Action completed';

versionHistory.push({
value: textarea.value,
action,
endAction: completedLabel + " (stopped)",
timestamp: new Date().toISOString()
});

// Save the stopped generation if there is content
const stoppedValue = textarea.value;
if (stoppedValue.trim()) {
const action = currentActionInProgress || 'generate';
const menuItem = findMenuItemByAction(action);
const completedLabel = (menuItem && menuItem.dataset.completedLabel) ? menuItem.dataset.completedLabel : 'Action completed';

versionHistory.push({
value: stoppedValue,
action,
endAction: completedLabel + " (stopped)",
timestamp: new Date().toISOString()
});

// Restore the previous content
textarea.value = contentBeforeGeneration;
currentIndexHistory = versionHistory.length - 1;
buildMenuFromConfig();
updateComponentState();
}

currentIndexHistory = versionHistory.length - 1;
currentActionInProgress = null;

buildMenuFromConfig();
updateComponentState();
textarea.loading = false;
}

Expand Down
Loading