@nuraly/runtime 0.1.9 → 0.1.10
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/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-DP3ZdLL3.js +220 -0
- package/dist/AIChat-km1IYaR-.js +260 -0
- package/dist/Badge-BR94MUt5.js +48 -0
- package/dist/Badge-DzNZFKtC.js +70 -0
- package/dist/{BaseElement-BNBn_IJk.js → BaseElement-pS6m_x6Q.js} +153 -24
- package/dist/Button-BHAN7npC.js +92 -0
- package/dist/Button-DCqgsxrL.js +80 -0
- package/dist/Card-B70c8NFb.js +150 -0
- package/dist/Card-DhOCsGKC.js +120 -0
- package/dist/Checkbox-BZTcPwew.js +59 -0
- package/dist/Checkbox-LYTIBAUV.js +65 -0
- package/dist/Code-BWbiciC8.js +123 -0
- package/dist/Code-Ds0vFclr.js +109 -0
- package/dist/{CodeEditor-B1gNuvPb.js → CodeEditor-ChuFC0ex.js} +22 -22
- package/dist/Col-B_wpWUcU.js +217 -0
- package/dist/Col-DYs8_65c.js +193 -0
- package/dist/Collapse-4kxbQ74u.js +74 -0
- package/dist/Collapse-Dkw6Ner6.js +96 -0
- package/dist/Collections-BSF-PqBz.js +122 -0
- package/dist/Collections-D5rwMFbv.js +151 -0
- package/dist/Container-DMNh5U4Y.js +204 -0
- package/dist/DatePicker-BmEOONiA.js +99 -0
- package/dist/DatePicker-VuUroOT4.js +80 -0
- package/dist/Divider-BfxR3rVl.js +86 -0
- package/dist/Divider-etMTYU3d.js +106 -0
- package/dist/Document-CHBcJciR.js +74 -0
- package/dist/Document-Cj-TmjAf.js +90 -0
- package/dist/Dropdown-BRtHvDa3.js +133 -0
- package/dist/Dropdown-C47Y11dj.js +112 -0
- package/dist/EmbedURL-BwbJRnY1.js +142 -0
- package/dist/EmbedURL-Ci5X1vQG.js +114 -0
- package/dist/FileUpload-BBgPcRag.js +54 -0
- package/dist/FileUpload-BgkhxtNe.js +47 -0
- package/dist/Form-BLq6U3In.js +339 -0
- package/dist/Form-E6zXqgsm.js +286 -0
- package/dist/Icon-CcLuhz6B.js +64 -0
- package/dist/Icon-_UiLblGb.js +74 -0
- package/dist/Image-B_VERIvH.js +111 -0
- package/dist/Image-hI8kIx8U.js +93 -0
- package/dist/Link-BVTo43Cc.js +76 -0
- package/dist/Link-xSrPxOLt.js +95 -0
- package/dist/Menu-CembLIjO.js +83 -0
- package/dist/Menu-D9ZjIOMg.js +73 -0
- package/dist/MicroApp-DI1kQwJk.js +100 -0
- package/dist/MicroApp-DJw57sLE.js +75 -0
- package/dist/NumberInput-DftAAKEs.js +84 -0
- package/dist/NumberInput-eOAk0-fb.js +95 -0
- package/dist/Panel-Bso5fv4i.js +127 -0
- package/dist/Panel-CwzW9iuA.js +161 -0
- package/dist/Radio-button-Sii5iveh.js +71 -0
- package/dist/Radio-button-YXsVqipQ.js +53 -0
- package/dist/RefComponent-Bwk_I0mK.js +79 -0
- package/dist/RefComponent-ZxafRVhZ.js +96 -0
- package/dist/RichText-CgYXXC_a.js +485 -0
- package/dist/RichText-DV46U7fI.js +449 -0
- package/dist/Row-Bb95f5DI.js +229 -0
- package/dist/Row-Dmd_61mR.js +202 -0
- package/dist/Select-Cma8JHAj.js +77 -0
- package/dist/Select-DqA08VYb.js +87 -0
- package/dist/Slider-B2_Qecjz.js +74 -0
- package/dist/Slider-DVY0N2YX.js +55 -0
- package/dist/Table-0WjrBnz-.js +159 -0
- package/dist/Table-dEma50kw.js +184 -0
- package/dist/Tabs-BDKEv1jn.js +131 -0
- package/dist/Tabs-Cvt3Q8vx.js +116 -0
- package/dist/Tag-BcZvQkE_.js +47 -0
- package/dist/Tag-DMZ0mu8y.js +61 -0
- package/dist/TextInput-KI6r9xET.js +193 -0
- package/dist/TextInput-hxK-HhJi.js +148 -0
- package/dist/TextLabel-DkV26yaL.js +102 -0
- package/dist/Textarea-Bzs3jSUm.js +117 -0
- package/dist/Textarea-CwK3SYbz.js +83 -0
- package/dist/Video-C4uBWCBb.js +100 -0
- package/dist/Video-CL1lgcvB.js +120 -0
- package/dist/aitchat-DjX5s7_8.js +23 -0
- package/dist/colorpicker-B-KETfWw.js +64 -0
- package/dist/colorpicker-DhB0AygJ.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-CV7QbFJv.js} +1 -1
- package/dist/{freemarker2-CYRLpyjt.js → freemarker2-CqQxSEZa.js} +1 -1
- package/dist/{handlebars-R8Efxi60.js → handlebars-a71LdN7X.js} +1 -1
- package/dist/{html-czhjovcp.js → html-D8UaB7IC.js} +1 -1
- package/dist/{htmlMode-DpyKDYYs.js → htmlMode-CqWQMFWX.js} +1 -1
- package/dist/iconbutton-DfnrRmmB.js +69 -0
- package/dist/iconbutton-DvIQHV8o.js +53 -0
- package/dist/{javascript-DwqkMEdb.js → javascript-D_jGqcRD.js} +1 -1
- package/dist/{jsonMode-Cmxxe0W9.js → jsonMode-C3-m5xts.js} +1 -1
- package/dist/{liquid-2spuEcBh.js → liquid-DLwYj6Te.js} +1 -1
- package/dist/{mdx-BjBXyEeR.js → mdx-DhYjhxkW.js} +1 -1
- package/dist/micro-app-entry-DiNqE6xi.js +12042 -0
- package/dist/micro-app.bundle.js +1 -1
- package/dist/micro-app.js +6 -4969
- package/dist/{python-DLI1ji08.js → python-B-WcGqFq.js} +1 -1
- package/dist/{razor-oAnIJsrL.js → razor-JGACy1mz.js} +1 -1
- package/dist/runtime.js +4 -2
- package/dist/{tsMode-D_PMsbjK.js → tsMode-lzBM1oT2.js} +1 -1
- package/dist/{typescript-Bu3ZbtQI.js → typescript-CuL5pdO2.js} +1 -1
- package/dist/{xml-CNSSkPqy.js → xml-D1tacAKD.js} +1 -1
- package/dist/{yaml-5RF_PGNe.js → yaml-CjPB1g7v.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
|
@@ -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-DiNqE6xi.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-pS6m_x6Q.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-DjX5s7_8.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 };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { B as v, n as $, o as w, b as H, i as V, c, t as y } from "./micro-app-entry-DiNqE6xi.js";
|
|
2
|
+
var P = Object.defineProperty, g = Object.getOwnPropertyDescriptor, a = (n, e, s, o) => {
|
|
3
|
+
for (var t = o > 1 ? void 0 : o ? g(e, s) : e, i = n.length - 1, l; i >= 0; i--)
|
|
4
|
+
(l = n[i]) && (t = (o ? l(e, s, t) : l(t)) || t);
|
|
5
|
+
return o && t && P(e, s, t), t;
|
|
6
|
+
};
|
|
7
|
+
try {
|
|
8
|
+
await import("@nuralyui/badge");
|
|
9
|
+
} catch {
|
|
10
|
+
console.warn("[@nuralyui/badge] Package not found or failed to load.");
|
|
11
|
+
}
|
|
12
|
+
let u = class extends v {
|
|
13
|
+
renderComponent() {
|
|
14
|
+
const n = this.component?.style || {}, e = this.component?.input?.count?.value ?? this.inputHandlersValue?.count, s = this.component?.input?.text?.value || this.inputHandlersValue?.text || "", o = this.component?.input?.dot?.value ?? this.inputHandlersValue?.dot ?? !1, t = this.component?.input?.showZero?.value ?? this.inputHandlersValue?.showZero ?? !1, i = this.component?.input?.overflowCount?.value || this.inputHandlersValue?.overflowCount || 99, l = this.component?.input?.size?.value || this.inputHandlersValue?.size || "default", f = this.component?.input?.color?.value || this.inputHandlersValue?.color, h = this.component?.input?.status?.value || this.inputHandlersValue?.status, d = this.component?.input?.ribbon?.value || this.inputHandlersValue?.ribbon, b = this.component?.input?.ribbonPlacement?.value || this.inputHandlersValue?.ribbonPlacement || "end", r = this.component?.input?.offsetX?.value || this.inputHandlersValue?.offsetX, p = this.component?.input?.offsetY?.value || this.inputHandlersValue?.offsetY, m = r || p ? [r || 0, p || 0] : void 0;
|
|
15
|
+
return H`
|
|
16
|
+
<nr-badge
|
|
17
|
+
${$(this.inputRef)}
|
|
18
|
+
style=${w(n)}
|
|
19
|
+
.count=${e}
|
|
20
|
+
.text=${s}
|
|
21
|
+
.size=${l}
|
|
22
|
+
.color=${f}
|
|
23
|
+
.status=${h}
|
|
24
|
+
.ribbon=${d}
|
|
25
|
+
.ribbonPlacement=${b}
|
|
26
|
+
.overflowCount=${i}
|
|
27
|
+
.offset=${m}
|
|
28
|
+
?dot=${o}
|
|
29
|
+
?showZero=${t}
|
|
30
|
+
>
|
|
31
|
+
<slot></slot>
|
|
32
|
+
</nr-badge>
|
|
33
|
+
`;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
u.styles = [V``];
|
|
37
|
+
a([
|
|
38
|
+
c({ type: Object })
|
|
39
|
+
], u.prototype, "component", 2);
|
|
40
|
+
a([
|
|
41
|
+
c({ type: Object })
|
|
42
|
+
], u.prototype, "item", 2);
|
|
43
|
+
u = a([
|
|
44
|
+
y("badge-block")
|
|
45
|
+
], u);
|
|
46
|
+
export {
|
|
47
|
+
u as BadgeBlock
|
|
48
|
+
};
|