@nuraly/runtime 0.1.9 → 0.1.11
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.
- package/components/ui/components/base/controllers/InputHandlerController.ts +5 -0
- package/components/ui/components/inputs/ColorPicker/colorpicker.ts +1 -7
- package/components/ui/components/inputs/Form/Form.ts +3 -11
- package/components/ui/components/inputs/RadioButton/Radio-button.ts +1 -7
- package/components/ui/components/inputs/Select/Select.ts +1 -7
- package/components/ui/components/layout/Grid/Col.ts +2 -6
- package/components/ui/components/layout/Grid/Row.ts +2 -6
- package/components/ui/components/studio/FunctionsPanel/FunctionsPanel.ts +4 -16
- package/dist/AIChat-C-wFf4PD.js +220 -0
- package/dist/AIChat-Cly-frW6.js +260 -0
- package/dist/Badge-BUm76SZ2.js +70 -0
- package/dist/Badge-BarGcY8u.js +48 -0
- package/dist/{BaseElement-BNBn_IJk.js → BaseElement-wyA58UxT.js} +156 -24
- package/dist/Button-BEgayuX9.js +80 -0
- package/dist/Button-wgwjzM_f.js +92 -0
- package/dist/Card-B4r5RQgn.js +120 -0
- package/dist/Card-a1sdDpKe.js +150 -0
- package/dist/Checkbox-CC9PkwpC.js +59 -0
- package/dist/Checkbox-WVmAN9ZP.js +65 -0
- package/dist/Code-Dc66ui4C.js +109 -0
- package/dist/Code-kVoVXBbt.js +123 -0
- package/dist/{CodeEditor-B1gNuvPb.js → CodeEditor-2QHTZxKN.js} +22 -22
- package/dist/Col-BKbQ2o0P.js +217 -0
- package/dist/Col-x4rRO4dz.js +193 -0
- package/dist/Collapse-Dd2GfevD.js +74 -0
- package/dist/Collapse-Xo-jb8zs.js +96 -0
- package/dist/Collections-DEqUHWFe.js +151 -0
- package/dist/Collections-DsTr-Zt7.js +122 -0
- package/dist/Container-C1HjQgb7.js +204 -0
- package/dist/DatePicker-DRVwFJmL.js +99 -0
- package/dist/DatePicker-oAOJyU3e.js +80 -0
- package/dist/Divider-BMA6S7Pd.js +106 -0
- package/dist/Divider-zbcO-KF9.js +86 -0
- package/dist/Document-BqVezrmJ.js +90 -0
- package/dist/Document-C2lg-jdj.js +74 -0
- package/dist/Dropdown-BRN-hpgd.js +133 -0
- package/dist/Dropdown-j62nqdd-.js +112 -0
- package/dist/EmbedURL-Bgr2pdf_.js +114 -0
- package/dist/EmbedURL-DFt6rN3J.js +142 -0
- package/dist/FileUpload-B5TBQJPC.js +54 -0
- package/dist/FileUpload-sYxMn9Rj.js +47 -0
- package/dist/Form-7ZWgBVzR.js +286 -0
- package/dist/Form-CsN7UMF-.js +339 -0
- package/dist/Icon-B_2ZWGd0.js +64 -0
- package/dist/Icon-CkLIObME.js +74 -0
- package/dist/Image-CcswllGj.js +93 -0
- package/dist/Image-CihbGdKt.js +111 -0
- package/dist/Link-BEUscah_.js +95 -0
- package/dist/Link-C4HV3i5L.js +76 -0
- package/dist/Menu-B98hcumz.js +83 -0
- package/dist/Menu-BEzo-k-M.js +73 -0
- package/dist/MicroApp-BDPSu_XC.js +75 -0
- package/dist/MicroApp-DCBOKAJ4.js +100 -0
- package/dist/NumberInput-Bbo10XmQ.js +95 -0
- package/dist/NumberInput-YJKsJDcd.js +84 -0
- package/dist/Panel-C1tcqveD.js +161 -0
- package/dist/Panel-DidE5uT5.js +127 -0
- package/dist/Radio-button-CuVS3-fC.js +71 -0
- package/dist/Radio-button-Cxj0bL8i.js +53 -0
- package/dist/RefComponent-BgOcavVg.js +79 -0
- package/dist/RefComponent-DTerPZ8J.js +96 -0
- package/dist/RichText-BiZgSdNO.js +449 -0
- package/dist/RichText-CwMNVuR_.js +485 -0
- package/dist/Row-BEx5bGTR.js +202 -0
- package/dist/Row-XczXHjOV.js +229 -0
- package/dist/Select-Bd16OOiE.js +87 -0
- package/dist/Select-D0xinu-U.js +77 -0
- package/dist/Slider-BVFPWYh3.js +55 -0
- package/dist/Slider-DGulvswN.js +74 -0
- package/dist/Table-C44wa8yn.js +159 -0
- package/dist/Table-CQiS_Q-s.js +184 -0
- package/dist/Tabs-CPQxFISc.js +131 -0
- package/dist/Tabs-DW2Su8xF.js +116 -0
- package/dist/Tag-BEfAQrjG.js +61 -0
- package/dist/Tag-BLxTFDcC.js +47 -0
- package/dist/TextInput-BWhdGS3a.js +148 -0
- package/dist/TextInput-CV850FvO.js +193 -0
- package/dist/TextLabel-CbSGmoVY.js +102 -0
- package/dist/Textarea-Bncyxfts.js +83 -0
- package/dist/Textarea-SEbx4KI5.js +117 -0
- package/dist/Video--shJ014h.js +120 -0
- package/dist/Video-CflXfaiK.js +100 -0
- package/dist/aitchat-Btz9TPEN.js +23 -0
- package/dist/colorpicker-BO_4CeX4.js +64 -0
- package/dist/colorpicker-UzXsx6gP.js +75 -0
- package/dist/constants-Bs_KQRi_.js +4 -0
- package/dist/constants-CXdpxgF2.js +4 -0
- package/dist/{cssMode-D82-gS78.js → cssMode-tpaxIZJS.js} +1 -1
- package/dist/{freemarker2-CYRLpyjt.js → freemarker2-Nx-tkO9y.js} +1 -1
- package/dist/{handlebars-R8Efxi60.js → handlebars-CF3Jmmto.js} +1 -1
- package/dist/{html-czhjovcp.js → html-CdZEJTJR.js} +1 -1
- package/dist/{htmlMode-DpyKDYYs.js → htmlMode-CztruwTl.js} +1 -1
- package/dist/iconbutton-BwuZYQyh.js +53 -0
- package/dist/iconbutton-CE0Vxu1G.js +69 -0
- package/dist/{javascript-DwqkMEdb.js → javascript-CVODTc2t.js} +1 -1
- package/dist/{jsonMode-Cmxxe0W9.js → jsonMode-ChPl6moP.js} +1 -1
- package/dist/{liquid-2spuEcBh.js → liquid-BckHw388.js} +1 -1
- package/dist/{mdx-BjBXyEeR.js → mdx-DB1fiwuN.js} +1 -1
- package/dist/micro-app-entry-BgDXbkmh.js +12042 -0
- package/dist/micro-app.bundle.js +1 -1
- package/dist/micro-app.js +6 -4969
- package/dist/{python-DLI1ji08.js → python-DOQt67t7.js} +1 -1
- package/dist/{razor-oAnIJsrL.js → razor-D65ZeXuP.js} +1 -1
- package/dist/runtime.js +4 -2
- package/dist/{tsMode-D_PMsbjK.js → tsMode-CXrSAnjJ.js} +1 -1
- package/dist/{typescript-Bu3ZbtQI.js → typescript-BuKvlC_a.js} +1 -1
- package/dist/{xml-CNSSkPqy.js → xml-_nj2r-yt.js} +1 -1
- package/dist/{yaml-5RF_PGNe.js → yaml-m8PrW_TL.js} +1 -1
- package/package.json +1 -1
- package/utils/index.ts +4 -1
- package/utils/lazy-component-loader.ts +120 -0
- package/utils/register-components.ts +14 -40
- package/utils/render-util.ts +84 -0
- package/dist/micro-app-entry-DYAnCRDo.js +0 -15860
|
@@ -55,6 +55,11 @@ export class InputHandlerController implements ReactiveController, Disposable {
|
|
|
55
55
|
private setupEventListeners(): void {
|
|
56
56
|
const { component, uniqueUUID } = this.host;
|
|
57
57
|
|
|
58
|
+
// Guard: component must be defined before setting up listeners
|
|
59
|
+
if (!component?.uuid) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
58
63
|
// Platform change - reprocess all inputs
|
|
59
64
|
this.subscription.add(
|
|
60
65
|
eventDispatcher.on("Vars:currentPlatform", () => {
|
|
@@ -4,15 +4,9 @@ import { styleMap } from "lit/directives/style-map.js";
|
|
|
4
4
|
import { type ComponentElement } from '../../../../../redux/store/component/component.interface.ts';
|
|
5
5
|
import { BaseElementBlock } from "../../base/BaseElement.ts";
|
|
6
6
|
import { ref } from "lit/directives/ref.js";
|
|
7
|
+
import "@nuralyui/color-picker";
|
|
7
8
|
import { EMPTY_STRING } from '../../../../../utils/constants.ts';
|
|
8
9
|
|
|
9
|
-
// Safely import @nuralyui/color-picker
|
|
10
|
-
try {
|
|
11
|
-
await import("@nuralyui/color-picker");
|
|
12
|
-
} catch (error) {
|
|
13
|
-
console.warn('[@nuralyui/color-picker] Package not found or failed to load.');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
10
|
@customElement("color-picker-block")
|
|
17
11
|
export class ColorPickerBlock extends BaseElementBlock {
|
|
18
12
|
static styles = [
|
|
@@ -15,17 +15,9 @@ try {
|
|
|
15
15
|
console.warn('[@nuralyui/forms] Package not found or failed to load.');
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
} catch (error) {
|
|
22
|
-
console.warn('[@nuralyui/icon] Package not found or failed to load.');
|
|
23
|
-
}
|
|
24
|
-
try {
|
|
25
|
-
await import("@nuralyui/label");
|
|
26
|
-
} catch (error) {
|
|
27
|
-
console.warn('[@nuralyui/label] Package not found or failed to load.');
|
|
28
|
-
}
|
|
18
|
+
// Import icon and label for placeholder
|
|
19
|
+
import "@nuralyui/icon";
|
|
20
|
+
import "@nuralyui/label";
|
|
29
21
|
|
|
30
22
|
/**
|
|
31
23
|
* Form block component that wraps nr-form and handles field registration
|
|
@@ -3,13 +3,7 @@ import { BaseElementBlock } from "../../base/BaseElement.ts";
|
|
|
3
3
|
import type { ComponentElement } from '../../../../../redux/store/component/component.interface.ts';
|
|
4
4
|
import { html } from "lit";
|
|
5
5
|
import { styleMap } from "lit/directives/style-map.js";
|
|
6
|
-
|
|
7
|
-
// Safely import @nuralyui/radio-group
|
|
8
|
-
try {
|
|
9
|
-
await import("@nuralyui/radio-group");
|
|
10
|
-
} catch (error) {
|
|
11
|
-
console.warn('[@nuralyui/radio-group] Package not found or failed to load.');
|
|
12
|
-
}
|
|
6
|
+
import "@nuralyui/radio-group";
|
|
13
7
|
|
|
14
8
|
@customElement("radio-button-block")
|
|
15
9
|
export class RadioButtonBlock extends BaseElementBlock {
|
|
@@ -5,13 +5,7 @@ import { type ComponentElement } from '../../../../../redux/store/component/comp
|
|
|
5
5
|
import { BaseElementBlock } from "../../base/BaseElement.ts";
|
|
6
6
|
import { EMPTY_STRING } from '../../../../../utils/constants.ts';
|
|
7
7
|
import { ref } from "lit/directives/ref.js";
|
|
8
|
-
|
|
9
|
-
// Safely import @nuralyui/select
|
|
10
|
-
try {
|
|
11
|
-
await import("@nuralyui/select");
|
|
12
|
-
} catch (error) {
|
|
13
|
-
console.warn('[@nuralyui/select] Package not found or failed to load.');
|
|
14
|
-
}
|
|
8
|
+
import "@nuralyui/select";
|
|
15
9
|
|
|
16
10
|
|
|
17
11
|
@customElement("select-block")
|
|
@@ -15,12 +15,8 @@ import { BaseElementBlock } from "../../base/BaseElement.ts";
|
|
|
15
15
|
import { setCurrentComponentIdAction } from '../../../../../redux/actions/component/setCurrentComponentIdAction.ts';
|
|
16
16
|
import { setContextMenuEvent } from '../../../../../redux/actions/page/setContextMenuEvent.ts';
|
|
17
17
|
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
await import("@nuralyui/grid");
|
|
21
|
-
} catch (error) {
|
|
22
|
-
console.warn('[@nuralyui/grid] Package not found or failed to load.');
|
|
23
|
-
}
|
|
18
|
+
// Import nr-col from nuralyui grid
|
|
19
|
+
import "@nuralyui/grid";
|
|
24
20
|
|
|
25
21
|
/** Input property names that trigger re-render */
|
|
26
22
|
const COL_INPUT_PROPS = ['span', 'offset', 'order', 'pull', 'push', 'flex', 'xs', 'sm', 'md', 'lg', 'xl', 'xxl'] as const;
|
|
@@ -15,12 +15,8 @@ import { BaseElementBlock } from "../../base/BaseElement.ts";
|
|
|
15
15
|
import { setCurrentComponentIdAction } from '../../../../../redux/actions/component/setCurrentComponentIdAction.ts';
|
|
16
16
|
import { setContextMenuEvent } from '../../../../../redux/actions/page/setContextMenuEvent.ts';
|
|
17
17
|
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
await import("@nuralyui/grid");
|
|
21
|
-
} catch (error) {
|
|
22
|
-
console.warn('[@nuralyui/grid] Package not found or failed to load.');
|
|
23
|
-
}
|
|
18
|
+
// Import nr-row from nuralyui grid
|
|
19
|
+
import "@nuralyui/grid";
|
|
24
20
|
|
|
25
21
|
/** Input property names that trigger re-render */
|
|
26
22
|
const ROW_INPUT_PROPS = ['gutter', 'align', 'justify', 'wrap'] as const;
|
|
@@ -26,22 +26,10 @@ import { ExecuteInstance } from '../../../../../state/runtime-context';
|
|
|
26
26
|
import { openEditorTab, setCurrentEditorTab } from '../../../../../redux/actions/editor';
|
|
27
27
|
import { $editorState, $currentApplication } from '../../../../../redux/store/apps';
|
|
28
28
|
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
console.warn('[@nuralyui/button] Package not found or failed to load.');
|
|
34
|
-
}
|
|
35
|
-
try {
|
|
36
|
-
await import("@nuralyui/menu");
|
|
37
|
-
} catch (error) {
|
|
38
|
-
console.warn('[@nuralyui/menu] Package not found or failed to load.');
|
|
39
|
-
}
|
|
40
|
-
try {
|
|
41
|
-
await import("@nuralyui/icon");
|
|
42
|
-
} catch (error) {
|
|
43
|
-
console.warn('[@nuralyui/icon] Package not found or failed to load.');
|
|
44
|
-
}
|
|
29
|
+
// Import nuraly-ui components
|
|
30
|
+
import '@nuralyui/button';
|
|
31
|
+
import '@nuralyui/menu';
|
|
32
|
+
import '@nuralyui/icon';
|
|
45
33
|
|
|
46
34
|
|
|
47
35
|
export interface FunctionItem {
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { $ as u, k as d, l, m as g, i as m, v as f, B as y, o as b, b as h, c as x, d as c, t as v } from "./micro-app-entry-BgDXbkmh.js";
|
|
2
|
+
function C(t, e) {
|
|
3
|
+
u.set({
|
|
4
|
+
...u.get(),
|
|
5
|
+
[t]: e
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
function w(t) {
|
|
9
|
+
t.forEach((e) => {
|
|
10
|
+
d(
|
|
11
|
+
e,
|
|
12
|
+
l("global", "currentPage").value,
|
|
13
|
+
l("global", "currentEditingApplication").value.uuid
|
|
14
|
+
);
|
|
15
|
+
}), setTimeout(() => {
|
|
16
|
+
g.emit("component:refresh");
|
|
17
|
+
}, 1e3);
|
|
18
|
+
}
|
|
19
|
+
const U = m`
|
|
20
|
+
:host {
|
|
21
|
+
display:flex;
|
|
22
|
+
align-items:center;
|
|
23
|
+
}
|
|
24
|
+
.chat-input-container {
|
|
25
|
+
position: relative;
|
|
26
|
+
display: inline-block;
|
|
27
|
+
width: 100%;
|
|
28
|
+
}
|
|
29
|
+
.chat-input {
|
|
30
|
+
display: flex;
|
|
31
|
+
margin-top: 10px;
|
|
32
|
+
width: 100%;
|
|
33
|
+
}
|
|
34
|
+
.chat-input nr-input {
|
|
35
|
+
flex: 1;
|
|
36
|
+
margin-right: 10px;
|
|
37
|
+
}
|
|
38
|
+
.chat-messages {
|
|
39
|
+
margin-top: 10px;
|
|
40
|
+
max-height: 200px;
|
|
41
|
+
overflow-y: auto;
|
|
42
|
+
background-color: #f9f9f9;
|
|
43
|
+
border: 1px solid #ccc;
|
|
44
|
+
border-radius: 8px;
|
|
45
|
+
padding: 10px;
|
|
46
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
47
|
+
}
|
|
48
|
+
.chat-message {
|
|
49
|
+
border-radius: 16px;
|
|
50
|
+
padding: 8px 12px;
|
|
51
|
+
margin-bottom: 8px;
|
|
52
|
+
max-width: 80%;
|
|
53
|
+
word-wrap: break-word;
|
|
54
|
+
}
|
|
55
|
+
.ai-message {
|
|
56
|
+
background-color: #d1fae5;
|
|
57
|
+
align-self: flex-start;
|
|
58
|
+
}
|
|
59
|
+
.error-message {
|
|
60
|
+
color: red;
|
|
61
|
+
margin-top: 10px;
|
|
62
|
+
}
|
|
63
|
+
.loading-indicator {
|
|
64
|
+
margin-top: 10px;
|
|
65
|
+
font-size: 14px;
|
|
66
|
+
color: #555;
|
|
67
|
+
}
|
|
68
|
+
`;
|
|
69
|
+
function $() {
|
|
70
|
+
return fetch("/api/chat", {
|
|
71
|
+
method: "POST",
|
|
72
|
+
headers: {
|
|
73
|
+
"Content-Type": "application/json"
|
|
74
|
+
}
|
|
75
|
+
}).then((t) => {
|
|
76
|
+
if (!t.ok)
|
|
77
|
+
throw new Error(`HTTP error! status: ${t.status}`);
|
|
78
|
+
return t.json();
|
|
79
|
+
}).then((t) => t).catch((t) => {
|
|
80
|
+
throw console.error("Error creating chat:", t), t;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function k(t) {
|
|
84
|
+
const e = {};
|
|
85
|
+
return t.forEach((s) => {
|
|
86
|
+
const i = f();
|
|
87
|
+
e[s.uuid] = i;
|
|
88
|
+
}), t.forEach((s) => {
|
|
89
|
+
e[s.uuid] && (s.uuid = e[s.uuid]), s.childrenIds && (s.childrenIds = s.childrenIds.map((i) => e[i] || i));
|
|
90
|
+
}), t;
|
|
91
|
+
}
|
|
92
|
+
var I = Object.defineProperty, M = Object.getOwnPropertyDescriptor, r = (t, e, s, i) => {
|
|
93
|
+
for (var a = i > 1 ? void 0 : i ? M(e, s) : e, n = t.length - 1, p; n >= 0; n--)
|
|
94
|
+
(p = t[n]) && (a = (i ? p(e, s, a) : p(a)) || a);
|
|
95
|
+
return i && a && I(e, s, a), a;
|
|
96
|
+
};
|
|
97
|
+
try {
|
|
98
|
+
await import("@nuralyui/slider-input");
|
|
99
|
+
} catch {
|
|
100
|
+
console.warn("[@nuralyui/slider-input] Package not found or failed to load.");
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
await import("@nuralyui/button");
|
|
104
|
+
} catch {
|
|
105
|
+
console.warn("[@nuralyui/button] Package not found or failed to load.");
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
await import("@nuralyui/input");
|
|
109
|
+
} catch {
|
|
110
|
+
console.warn("[@nuralyui/input] Package not found or failed to load.");
|
|
111
|
+
}
|
|
112
|
+
let o = class extends y {
|
|
113
|
+
constructor() {
|
|
114
|
+
super(...arguments), this.preview = !1, this.rootUUID = "", this.isChatBoxVisible = !1, this.chatUuid = "", this.messages = [], this.errorMessage = "", this.inputValue = "", this.isLoading = !1;
|
|
115
|
+
}
|
|
116
|
+
connectedCallback() {
|
|
117
|
+
super.connectedCallback();
|
|
118
|
+
}
|
|
119
|
+
render() {
|
|
120
|
+
const t = this.component?.style || {};
|
|
121
|
+
return h`
|
|
122
|
+
<div class="chat-input-container" style=${b({ ...t })}>
|
|
123
|
+
<nr-button @click=${this.toggleChatBox}>Ask AI</nr-button>
|
|
124
|
+
${this.isChatBoxVisible ? h`
|
|
125
|
+
<div class="chat-input">
|
|
126
|
+
<nr-input value=${this.inputValue} placeholder="Type your message" @valueChange=${this.handleInputChange} @keyup=${this.handleKeyUp} ></nr-input>
|
|
127
|
+
<nr-button @click=${this.handleSendMessage}>Send</nr-button>
|
|
128
|
+
</div>
|
|
129
|
+
${this.messages.length > 0 ? h`
|
|
130
|
+
<div class="chat-messages">
|
|
131
|
+
${this.preview ? h`<micro-app uuid=${this.chatUuid} componentToRenderUUID=${this.rootUUID}></micro-app>` : ""}
|
|
132
|
+
<nr-button @click=${() => w(this.structureComponent)}>Insert</nr-button>
|
|
133
|
+
</div>
|
|
134
|
+
` : ""}
|
|
135
|
+
${this.errorMessage ? h`<div class="error-message">${this.errorMessage}</div>` : ""}
|
|
136
|
+
${this.isLoading ? h`<div class="loading-indicator">Loading...</div>` : ""}
|
|
137
|
+
` : ""}
|
|
138
|
+
</div>
|
|
139
|
+
`;
|
|
140
|
+
}
|
|
141
|
+
async toggleChatBox() {
|
|
142
|
+
this.isChatBoxVisible = !this.isChatBoxVisible, this.isChatBoxVisible ? await this.getChatUuid() : this.errorMessage = "";
|
|
143
|
+
}
|
|
144
|
+
async getChatUuid() {
|
|
145
|
+
this.isLoading = !0, $().then((t) => {
|
|
146
|
+
this.chatUuid = t.chat_id, this.errorMessage = "";
|
|
147
|
+
}).catch((t) => {
|
|
148
|
+
console.error("Error getting chat UUID:", t), this.errorMessage = "Cannot connect to server. Please try again.";
|
|
149
|
+
}).finally(() => {
|
|
150
|
+
this.isLoading = !1;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
async sendMessage(t) {
|
|
154
|
+
this.isLoading = !0;
|
|
155
|
+
try {
|
|
156
|
+
const s = (await (await fetch(`/api/chat/${this.chatUuid}`, {
|
|
157
|
+
method: "POST",
|
|
158
|
+
headers: {
|
|
159
|
+
"Content-Type": "application/json"
|
|
160
|
+
},
|
|
161
|
+
body: JSON.stringify({ query: t })
|
|
162
|
+
})).json()).response;
|
|
163
|
+
this.messages.push({ type: "ai", content: s }), this.structureComponent = [];
|
|
164
|
+
const i = s.components ?? s;
|
|
165
|
+
Array.isArray(i) && (this.structureComponent = i.map((n) => (n.application_id = this.chatUuid, n))), this.structureComponent = k(this.structureComponent);
|
|
166
|
+
const a = this.structureComponent.find((n) => n.component_type === "vertical-container-block");
|
|
167
|
+
this.rootUUID = a.uuid, C(this.chatUuid, [...this.structureComponent]), requestAnimationFrame(() => {
|
|
168
|
+
this.preview = !0;
|
|
169
|
+
});
|
|
170
|
+
} catch (e) {
|
|
171
|
+
console.error("Error sending message:", e);
|
|
172
|
+
} finally {
|
|
173
|
+
this.isLoading = !1;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
handleSendMessage(t) {
|
|
177
|
+
const e = this.inputValue;
|
|
178
|
+
e.trim() && (this.sendMessage(e), this.inputValue = "");
|
|
179
|
+
}
|
|
180
|
+
handleInputChange(t) {
|
|
181
|
+
this.inputValue = t.detail.value;
|
|
182
|
+
}
|
|
183
|
+
handleKeyUp(t) {
|
|
184
|
+
t.key === "Enter" && this.handleSendMessage(t);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
o.styles = U;
|
|
188
|
+
r([
|
|
189
|
+
x({ type: Object })
|
|
190
|
+
], o.prototype, "component", 2);
|
|
191
|
+
r([
|
|
192
|
+
c()
|
|
193
|
+
], o.prototype, "preview", 2);
|
|
194
|
+
r([
|
|
195
|
+
c()
|
|
196
|
+
], o.prototype, "rootUUID", 2);
|
|
197
|
+
r([
|
|
198
|
+
c()
|
|
199
|
+
], o.prototype, "isChatBoxVisible", 2);
|
|
200
|
+
r([
|
|
201
|
+
c()
|
|
202
|
+
], o.prototype, "chatUuid", 2);
|
|
203
|
+
r([
|
|
204
|
+
c()
|
|
205
|
+
], o.prototype, "messages", 2);
|
|
206
|
+
r([
|
|
207
|
+
c()
|
|
208
|
+
], o.prototype, "errorMessage", 2);
|
|
209
|
+
r([
|
|
210
|
+
c()
|
|
211
|
+
], o.prototype, "inputValue", 2);
|
|
212
|
+
r([
|
|
213
|
+
c()
|
|
214
|
+
], o.prototype, "isLoading", 2);
|
|
215
|
+
o = r([
|
|
216
|
+
v("ai-chat-block")
|
|
217
|
+
], o);
|
|
218
|
+
export {
|
|
219
|
+
o as AiChat
|
|
220
|
+
};
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { styleMap } from 'lit/directives/style-map.js';
|
|
2
|
+
import { ae as BaseElementBlock } from './BaseElement-wyA58UxT.js';
|
|
3
|
+
import { css, html } from 'lit';
|
|
4
|
+
import { property, state, customElement } from 'lit/decorators.js';
|
|
5
|
+
import { v4 } from 'uuid';
|
|
6
|
+
import { b as addGeneratedComponents, a as addTempApplication } from './aitchat-Btz9TPEN.js';
|
|
7
|
+
|
|
8
|
+
const styles = css`
|
|
9
|
+
:host {
|
|
10
|
+
display:flex;
|
|
11
|
+
align-items:center;
|
|
12
|
+
}
|
|
13
|
+
.chat-input-container {
|
|
14
|
+
position: relative;
|
|
15
|
+
display: inline-block;
|
|
16
|
+
width: 100%;
|
|
17
|
+
}
|
|
18
|
+
.chat-input {
|
|
19
|
+
display: flex;
|
|
20
|
+
margin-top: 10px;
|
|
21
|
+
width: 100%;
|
|
22
|
+
}
|
|
23
|
+
.chat-input nr-input {
|
|
24
|
+
flex: 1;
|
|
25
|
+
margin-right: 10px;
|
|
26
|
+
}
|
|
27
|
+
.chat-messages {
|
|
28
|
+
margin-top: 10px;
|
|
29
|
+
max-height: 200px;
|
|
30
|
+
overflow-y: auto;
|
|
31
|
+
background-color: #f9f9f9;
|
|
32
|
+
border: 1px solid #ccc;
|
|
33
|
+
border-radius: 8px;
|
|
34
|
+
padding: 10px;
|
|
35
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
36
|
+
}
|
|
37
|
+
.chat-message {
|
|
38
|
+
border-radius: 16px;
|
|
39
|
+
padding: 8px 12px;
|
|
40
|
+
margin-bottom: 8px;
|
|
41
|
+
max-width: 80%;
|
|
42
|
+
word-wrap: break-word;
|
|
43
|
+
}
|
|
44
|
+
.ai-message {
|
|
45
|
+
background-color: #d1fae5;
|
|
46
|
+
align-self: flex-start;
|
|
47
|
+
}
|
|
48
|
+
.error-message {
|
|
49
|
+
color: red;
|
|
50
|
+
margin-top: 10px;
|
|
51
|
+
}
|
|
52
|
+
.loading-indicator {
|
|
53
|
+
margin-top: 10px;
|
|
54
|
+
font-size: 14px;
|
|
55
|
+
color: #555;
|
|
56
|
+
}
|
|
57
|
+
`;
|
|
58
|
+
|
|
59
|
+
function createChat() {
|
|
60
|
+
return fetch("/api/chat", {
|
|
61
|
+
method: "POST",
|
|
62
|
+
headers: {
|
|
63
|
+
"Content-Type": "application/json"
|
|
64
|
+
}
|
|
65
|
+
}).then((response) => {
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
68
|
+
}
|
|
69
|
+
return response.json();
|
|
70
|
+
}).then((data) => {
|
|
71
|
+
return data;
|
|
72
|
+
}).catch((error) => {
|
|
73
|
+
console.error("Error creating chat:", error);
|
|
74
|
+
throw error;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function replaceUUIDs(data) {
|
|
79
|
+
const uuidMapping = {};
|
|
80
|
+
data.forEach((item) => {
|
|
81
|
+
const newUUID = v4();
|
|
82
|
+
uuidMapping[item.uuid] = newUUID;
|
|
83
|
+
});
|
|
84
|
+
data.forEach((item) => {
|
|
85
|
+
if (uuidMapping[item.uuid]) {
|
|
86
|
+
item.uuid = uuidMapping[item.uuid];
|
|
87
|
+
}
|
|
88
|
+
if (item.childrenIds) {
|
|
89
|
+
item.childrenIds = item.childrenIds.map((childId) => {
|
|
90
|
+
return uuidMapping[childId] || childId;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
return data;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
var __defProp = Object.defineProperty;
|
|
98
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
99
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
100
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
101
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
102
|
+
if (decorator = decorators[i])
|
|
103
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
104
|
+
if (kind && result) __defProp(target, key, result);
|
|
105
|
+
return result;
|
|
106
|
+
};
|
|
107
|
+
try {
|
|
108
|
+
await import('@nuralyui/slider-input');
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.warn("[@nuralyui/slider-input] Package not found or failed to load.");
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
await import('@nuralyui/button');
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.warn("[@nuralyui/button] Package not found or failed to load.");
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
await import('@nuralyui/input');
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.warn("[@nuralyui/input] Package not found or failed to load.");
|
|
121
|
+
}
|
|
122
|
+
let AiChat = class extends BaseElementBlock {
|
|
123
|
+
constructor() {
|
|
124
|
+
super(...arguments);
|
|
125
|
+
this.preview = false;
|
|
126
|
+
this.rootUUID = "";
|
|
127
|
+
this.isChatBoxVisible = false;
|
|
128
|
+
this.chatUuid = "";
|
|
129
|
+
this.messages = [];
|
|
130
|
+
this.errorMessage = "";
|
|
131
|
+
this.inputValue = "";
|
|
132
|
+
this.isLoading = false;
|
|
133
|
+
}
|
|
134
|
+
connectedCallback() {
|
|
135
|
+
super.connectedCallback();
|
|
136
|
+
}
|
|
137
|
+
render() {
|
|
138
|
+
const aiChatStyle = this.component?.style || {};
|
|
139
|
+
return html`
|
|
140
|
+
<div class="chat-input-container" style=${styleMap({ ...aiChatStyle })}>
|
|
141
|
+
<nr-button @click=${this.toggleChatBox}>Ask AI</nr-button>
|
|
142
|
+
${this.isChatBoxVisible ? html`
|
|
143
|
+
<div class="chat-input">
|
|
144
|
+
<nr-input value=${this.inputValue} placeholder="Type your message" @valueChange=${this.handleInputChange} @keyup=${this.handleKeyUp} ></nr-input>
|
|
145
|
+
<nr-button @click=${this.handleSendMessage}>Send</nr-button>
|
|
146
|
+
</div>
|
|
147
|
+
${this.messages.length > 0 ? html`
|
|
148
|
+
<div class="chat-messages">
|
|
149
|
+
${this.preview ? html`<micro-app uuid=${this.chatUuid} componentToRenderUUID=${this.rootUUID}></micro-app>` : ""}
|
|
150
|
+
<nr-button @click=${() => addGeneratedComponents(this.structureComponent)}>Insert</nr-button>
|
|
151
|
+
</div>
|
|
152
|
+
` : ""}
|
|
153
|
+
${this.errorMessage ? html`<div class="error-message">${this.errorMessage}</div>` : ""}
|
|
154
|
+
${this.isLoading ? html`<div class="loading-indicator">Loading...</div>` : ""}
|
|
155
|
+
` : ""}
|
|
156
|
+
</div>
|
|
157
|
+
`;
|
|
158
|
+
}
|
|
159
|
+
async toggleChatBox() {
|
|
160
|
+
this.isChatBoxVisible = !this.isChatBoxVisible;
|
|
161
|
+
if (this.isChatBoxVisible) {
|
|
162
|
+
await this.getChatUuid();
|
|
163
|
+
} else {
|
|
164
|
+
this.errorMessage = "";
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async getChatUuid() {
|
|
168
|
+
this.isLoading = true;
|
|
169
|
+
createChat().then((data) => {
|
|
170
|
+
this.chatUuid = data.chat_id;
|
|
171
|
+
this.errorMessage = "";
|
|
172
|
+
}).catch((error) => {
|
|
173
|
+
console.error("Error getting chat UUID:", error);
|
|
174
|
+
this.errorMessage = "Cannot connect to server. Please try again.";
|
|
175
|
+
}).finally(() => {
|
|
176
|
+
this.isLoading = false;
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
async sendMessage(message) {
|
|
180
|
+
this.isLoading = true;
|
|
181
|
+
try {
|
|
182
|
+
const response = await fetch(`/api/chat/${this.chatUuid}`, {
|
|
183
|
+
method: "POST",
|
|
184
|
+
headers: {
|
|
185
|
+
"Content-Type": "application/json"
|
|
186
|
+
},
|
|
187
|
+
body: JSON.stringify({ query: message })
|
|
188
|
+
});
|
|
189
|
+
const aiResponse = (await response.json()).response;
|
|
190
|
+
this.messages.push({ type: "ai", content: aiResponse });
|
|
191
|
+
this.structureComponent = [];
|
|
192
|
+
const result = aiResponse.components ?? aiResponse;
|
|
193
|
+
if (Array.isArray(result)) {
|
|
194
|
+
this.structureComponent = result.map((component) => {
|
|
195
|
+
component.application_id = this.chatUuid;
|
|
196
|
+
return component;
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
this.structureComponent = replaceUUIDs(this.structureComponent);
|
|
200
|
+
const structureComponentRoot = this.structureComponent.find((component) => component.component_type === "vertical-container-block");
|
|
201
|
+
this.rootUUID = structureComponentRoot.uuid;
|
|
202
|
+
addTempApplication(this.chatUuid, [...this.structureComponent]);
|
|
203
|
+
requestAnimationFrame(() => {
|
|
204
|
+
this.preview = true;
|
|
205
|
+
});
|
|
206
|
+
} catch (error) {
|
|
207
|
+
console.error("Error sending message:", error);
|
|
208
|
+
} finally {
|
|
209
|
+
this.isLoading = false;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
handleSendMessage(event) {
|
|
213
|
+
const message = this.inputValue;
|
|
214
|
+
if (message.trim()) {
|
|
215
|
+
this.sendMessage(message);
|
|
216
|
+
this.inputValue = "";
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
handleInputChange(event) {
|
|
220
|
+
this.inputValue = event.detail.value;
|
|
221
|
+
}
|
|
222
|
+
handleKeyUp(event) {
|
|
223
|
+
if (event.key === "Enter") {
|
|
224
|
+
this.handleSendMessage(event);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
AiChat.styles = styles;
|
|
229
|
+
__decorateClass([
|
|
230
|
+
property({ type: Object })
|
|
231
|
+
], AiChat.prototype, "component", 2);
|
|
232
|
+
__decorateClass([
|
|
233
|
+
state()
|
|
234
|
+
], AiChat.prototype, "preview", 2);
|
|
235
|
+
__decorateClass([
|
|
236
|
+
state()
|
|
237
|
+
], AiChat.prototype, "rootUUID", 2);
|
|
238
|
+
__decorateClass([
|
|
239
|
+
state()
|
|
240
|
+
], AiChat.prototype, "isChatBoxVisible", 2);
|
|
241
|
+
__decorateClass([
|
|
242
|
+
state()
|
|
243
|
+
], AiChat.prototype, "chatUuid", 2);
|
|
244
|
+
__decorateClass([
|
|
245
|
+
state()
|
|
246
|
+
], AiChat.prototype, "messages", 2);
|
|
247
|
+
__decorateClass([
|
|
248
|
+
state()
|
|
249
|
+
], AiChat.prototype, "errorMessage", 2);
|
|
250
|
+
__decorateClass([
|
|
251
|
+
state()
|
|
252
|
+
], AiChat.prototype, "inputValue", 2);
|
|
253
|
+
__decorateClass([
|
|
254
|
+
state()
|
|
255
|
+
], AiChat.prototype, "isLoading", 2);
|
|
256
|
+
AiChat = __decorateClass([
|
|
257
|
+
customElement("ai-chat-block")
|
|
258
|
+
], AiChat);
|
|
259
|
+
|
|
260
|
+
export { AiChat };
|