Skip to content

Commit 962ec55

Browse files
nnaydenowMartin Hristov
authored andcommitted
fix(playground): tsx support in editor (#12599)
1 parent 8b6b947 commit 962ec55

File tree

4 files changed

+30
-26
lines changed

4 files changed

+30
-26
lines changed

packages/ai/src/Input.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from "@ui5/webcomponents-base/dist/Keys.js";
1010
import BaseInput from "@ui5/webcomponents/dist/Input.js";
1111
import type Menu from "@ui5/webcomponents/dist/Menu.js";
12+
import type { MenuItemClickEventDetail } from "@ui5/webcomponents/dist/Menu.js";
1213
import type Button from "./Button.js";
1314

1415
// styles
@@ -26,6 +27,10 @@ import {
2627
WRITING_ASSISTANT_GENERATING_ANNOUNCEMENT,
2728
} from "./generated/i18n/i18n-defaults.js";
2829

30+
type VersionChangeEventDetail = {
31+
backwards: boolean,
32+
};
33+
2934
/**
3035
* @class
3136
*
@@ -80,6 +85,11 @@ import {
8085
cancelable: true,
8186
})
8287

88+
/** Fired when an item from the AI actions menu is clicked.
89+
* @public
90+
*/
91+
@event("item-click")
92+
8393
/**
8494
* Fired when the user selects the "Stop" button to stop ongoing AI text generation.
8595
* @public
@@ -96,11 +106,10 @@ import {
96106

97107
class Input extends BaseInput {
98108
eventDetails!: BaseInput["eventDetails"] & {
99-
"version-change": {
100-
backwards: boolean;
101-
};
102-
"stop-generation": object;
103-
"button-click": object;
109+
"version-change": VersionChangeEventDetail;
110+
"stop-generation": void;
111+
"button-click": void;
112+
"item-click": MenuItemClickEventDetail;
104113
};
105114

106115
/**
@@ -246,15 +255,8 @@ class Input extends BaseInput {
246255
this._handleVersionChange(new CustomEvent("version-change", { detail: { backwards: false } }));
247256
}
248257

249-
_onMenuIconClick(): void {
250-
this.menu?.addEventListener("item-click", (e: Event) => {
251-
const customEvent = e as CustomEvent;
252-
this.dispatchEvent(new CustomEvent("item-click", {
253-
detail: customEvent.detail,
254-
bubbles: true,
255-
composed: true,
256-
}));
257-
});
258+
_onMenuIconClick(e: CustomEvent<MenuItemClickEventDetail>): void {
259+
this.fireDecoratorEvent("item-click", e.detail);
258260
}
259261

260262
/**
@@ -309,7 +311,7 @@ class Input extends BaseInput {
309311
}
310312

311313
get menu() {
312-
return this.shadowRoot?.querySelector("ui5-menu") as Menu;
314+
return this.shadowRoot?.querySelector("[ui5-menu]") as Menu;
313315
}
314316
}
315317

packages/ai/src/TextArea.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import valueStateMessageStyles from "@ui5/webcomponents/dist/generated/themes/Va
2020
import TextAreaTemplate from "./TextAreaTemplate.js";
2121
import WritingAssistant from "./WritingAssistant.js";
2222

23+
type VersionChangeEventDetail = {
24+
backwards: boolean,
25+
};
26+
2327
/**
2428
* @class
2529
*
@@ -78,10 +82,8 @@ import WritingAssistant from "./WritingAssistant.js";
7882

7983
class TextArea extends BaseTextArea {
8084
eventDetails!: BaseTextArea["eventDetails"] & {
81-
"version-change": {
82-
backwards: boolean;
83-
};
84-
"stop-generation": object;
85+
"version-change": VersionChangeEventDetail;
86+
"stop-generation": void;
8587
};
8688

8789
// Store bound handler for proper cleanup

packages/ai/src/WritingAssistantTemplate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default function WritingAssistantTemplate(this: WritingAssistant) {
1818
>
1919
{isMultiResults && !this.loading && (
2020
<Versioning
21-
currentStep={this.currentVersion + 1}
21+
currentStep={this.currentVersion}
2222
totalSteps={this.totalVersions}
2323
onVersion-change={this.handleVersionChange}
2424
/>

packages/website/docs/_samples/ai/TextArea/Basic/main.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function animateTextGeneration(text) {
4747
function completeGeneration() {
4848
versionHistory.push({
4949
value: textarea.value,
50-
actionText: "Generated text",
50+
promptDescription: "Generated text",
5151
timestamp: new Date().toISOString()
5252
});
5353

@@ -57,11 +57,11 @@ function completeGeneration() {
5757
}
5858

5959
function updateComponentState() {
60-
textarea.currentVersionIndex = currentVersionIndex + 1;
60+
textarea.currentVersion = currentVersionIndex + 1;
6161
textarea.totalVersions = versionHistory.length;
6262

6363
if (versionHistory[currentVersionIndex]) {
64-
textarea.actionText = versionHistory[currentVersionIndex].actionText;
64+
textarea.promptDescription = versionHistory[currentVersionIndex].promptDescription;
6565
}
6666
}
6767

@@ -75,7 +75,7 @@ async function executeGeneration() {
7575

7676
// Set loading state
7777
textarea.loading = true;
78-
textarea.actionText = "Generating text...";
78+
textarea.promptDescription = "Generating text...";
7979

8080
try {
8181
// Simulate processing delay
@@ -92,7 +92,7 @@ async function executeGeneration() {
9292
} catch (error) {
9393
console.error('Generation failed:', error);
9494
textarea.loading = false;
95-
textarea.actionText = 'Generation failed';
95+
textarea.promptDescription = 'Generation failed';
9696
}
9797
}
9898

@@ -107,7 +107,7 @@ function stopGeneration() {
107107
if (textarea.value.trim()) {
108108
versionHistory.push({
109109
value: textarea.value,
110-
actionText: "Generated text (stopped)",
110+
promptDescription: "Generated text (stopped)",
111111
timestamp: new Date().toISOString()
112112
});
113113

0 commit comments

Comments
 (0)