appscms-tools-theme 5.1.8 → 5.1.9

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.
@@ -0,0 +1,309 @@
1
+ // Auto-generated JS for Amazon Product Description Generator
2
+ document.addEventListener("DOMContentLoaded", function () {
3
+ const form = document.getElementById("contentToolForm");
4
+ const tool = "amazon_product_description_generator";
5
+
6
+ // Wait for Quill to be initialized
7
+ let quill;
8
+ const checkQuill = setInterval(() => {
9
+ if (window.quill) {
10
+ quill = window.quill;
11
+ clearInterval(checkQuill);
12
+ }
13
+ }, 100);
14
+
15
+ let input0 = form.querySelector('[name="input0"]');
16
+ let input1 = form.querySelector('[name="input1"]');
17
+ let language = form.querySelector('[name="language"]');
18
+ let tone = form.querySelector('[name="tone"]');
19
+
20
+ form.addEventListener("submit", async function (e) {
21
+ e.preventDefault();
22
+
23
+ // Check if Quill is available
24
+ if (!quill) {
25
+ console.error("Quill editor not found");
26
+ return;
27
+ }
28
+
29
+ // Show loading state
30
+ const submitButton = form.querySelector('button[type="submit"]');
31
+ const originalText = submitButton ? submitButton.textContent : "";
32
+ if (submitButton) {
33
+ submitButton.textContent = "Generating...";
34
+ submitButton.disabled = true;
35
+ }
36
+
37
+ const options = {};
38
+
39
+ options["product_name"] = input0.value;
40
+ options["key_features"] = input1.value;
41
+ options["language"] = language.value;
42
+ options["tone"] = tone.value;
43
+
44
+ const body = {
45
+ tool: tool,
46
+ llm: "gemini",
47
+ model_name: "gemini-2.0-flash",
48
+ options: options,
49
+ };
50
+
51
+ try {
52
+ const response = await fetch(
53
+ "http://localhost:8000/api/v1/ecommerce-tools/amazon-product-description-generator",
54
+ {
55
+ method: "POST",
56
+ headers: {
57
+ "Content-Type": "application/json",
58
+ },
59
+ body: JSON.stringify(body),
60
+ }
61
+ );
62
+
63
+ const data = await response.json();
64
+
65
+ if (data.result) {
66
+ // Clear the editor first
67
+ quill.setText("");
68
+
69
+ // Parse and render markdown content
70
+ renderMarkdownToQuill(data.result, quill);
71
+
72
+ console.log("✅ Content generated successfully");
73
+ } else {
74
+ quill.setText("No output received from server.");
75
+ }
76
+ } catch (err) {
77
+ console.error("❌ API Error:", err);
78
+ quill.setText("Error: " + err.message);
79
+ } finally {
80
+ // Reset button state
81
+ if (submitButton) {
82
+ submitButton.textContent = originalText;
83
+ submitButton.disabled = false;
84
+ }
85
+ }
86
+ });
87
+ });
88
+
89
+ // Function to render markdown content to Quill editor
90
+ function renderMarkdownToQuill(markdownText, quill) {
91
+ // Clear editor
92
+ quill.setText("");
93
+
94
+ let index = 0;
95
+ const lines = markdownText.split("\n");
96
+
97
+ lines.forEach((line, lineIndex) => {
98
+ if (line.trim() === "") {
99
+ // Empty line - add line break
100
+ if (lineIndex < lines.length - 1) {
101
+ quill.insertText(index, "\n");
102
+ index += 1;
103
+ }
104
+ return;
105
+ }
106
+
107
+ // Handle different markdown patterns
108
+ if (line.startsWith("**") && line.endsWith("**") && line.length > 4) {
109
+ // Bold text (like **Product Title:** or **Key Features:**)
110
+ const text = line.replace(/^\*\*(.*?)\*\*$/, "$1");
111
+ quill.insertText(index, text, { bold: true });
112
+ index += text.length;
113
+ } else if (line.includes("**")) {
114
+ // Mixed bold and normal text (like **Product Title:** Coffee Mug)
115
+ const parts = line.split("**");
116
+ for (let i = 0; i < parts.length; i++) {
117
+ if (parts[i]) {
118
+ if (i % 2 === 1) {
119
+ // Odd index = bold text
120
+ quill.insertText(index, parts[i], { bold: true });
121
+ index += parts[i].length;
122
+ } else {
123
+ // Even index = normal text
124
+ quill.insertText(index, parts[i]);
125
+ index += parts[i].length;
126
+ }
127
+ }
128
+ }
129
+ } else if (line.startsWith("- ")) {
130
+ // Bullet points
131
+ const text = line.substring(2); // Remove '- '
132
+ quill.insertText(index, "• " + text);
133
+ index += text.length + 2;
134
+ } else if (line.match(/^\d+\.\s/)) {
135
+ // Numbered lists
136
+ const match = line.match(/^(\d+\.\s)(.*)$/);
137
+ if (match) {
138
+ const number = match[1];
139
+ const content = match[2];
140
+
141
+ // Insert number in bold
142
+ quill.insertText(index, number, { bold: true });
143
+ index += number.length;
144
+
145
+ // Insert content in normal text
146
+ quill.insertText(index, content);
147
+ index += content.length;
148
+ } else {
149
+ quill.insertText(index, line);
150
+ index += line.length;
151
+ }
152
+ } else if (line.startsWith("### ")) {
153
+ // Headers (H3)
154
+ const text = line.substring(4);
155
+ quill.insertText(index, text, { bold: true });
156
+ index += text.length;
157
+ } else if (line.startsWith("## ")) {
158
+ // Headers (H2)
159
+ const text = line.substring(3);
160
+ quill.insertText(index, text, { bold: true, size: "large" });
161
+ index += text.length;
162
+ } else if (line.startsWith("# ")) {
163
+ // Headers (H1)
164
+ const text = line.substring(2);
165
+ quill.insertText(index, text, { bold: true, size: "huge" });
166
+ index += text.length;
167
+ } else if (line.startsWith("*") && line.endsWith("*") && line.length > 2) {
168
+ // Italic text
169
+ const text = line.replace(/^\*(.*?)\*$/, "$1");
170
+ quill.insertText(index, text, { italic: true });
171
+ index += text.length;
172
+ } else {
173
+ // Normal text
174
+ quill.insertText(index, line);
175
+ index += line.length;
176
+ }
177
+
178
+ // Add line break if not the last line
179
+ if (lineIndex < lines.length - 1) {
180
+ quill.insertText(index, "\n");
181
+ index += 1;
182
+ }
183
+ });
184
+ }
185
+
186
+ // Alternative function using marked.js if available
187
+ function renderMarkdownToQuillWithMarked(markdownText, quill) {
188
+ if (typeof marked !== "undefined") {
189
+ try {
190
+ // Convert markdown to HTML
191
+ const html = marked.parse(markdownText);
192
+
193
+ // Create a temporary div to parse HTML
194
+ const tempDiv = document.createElement("div");
195
+ tempDiv.innerHTML = html;
196
+
197
+ // Clear editor
198
+ quill.setText("");
199
+
200
+ let index = 0;
201
+
202
+ // Process each child element
203
+ tempDiv.childNodes.forEach((node) => {
204
+ if (node.nodeType === Node.TEXT_NODE) {
205
+ const text = node.textContent.trim();
206
+ if (text) {
207
+ quill.insertText(index, text);
208
+ index += text.length;
209
+ }
210
+ } else if (node.nodeType === Node.ELEMENT_NODE) {
211
+ switch (node.tagName.toLowerCase()) {
212
+ case "h1":
213
+ quill.insertText(index, node.textContent, {
214
+ bold: true,
215
+ size: "huge",
216
+ });
217
+ index += node.textContent.length;
218
+ break;
219
+ case "h2":
220
+ quill.insertText(index, node.textContent, {
221
+ bold: true,
222
+ size: "large",
223
+ });
224
+ index += node.textContent.length;
225
+ break;
226
+ case "h3":
227
+ case "h4":
228
+ case "h5":
229
+ case "h6":
230
+ quill.insertText(index, node.textContent, { bold: true });
231
+ index += node.textContent.length;
232
+ break;
233
+ case "strong":
234
+ case "b":
235
+ quill.insertText(index, node.textContent, { bold: true });
236
+ index += node.textContent.length;
237
+ break;
238
+ case "em":
239
+ case "i":
240
+ quill.insertText(index, node.textContent, { italic: true });
241
+ index += node.textContent.length;
242
+ break;
243
+ case "ul":
244
+ node.querySelectorAll("li").forEach((li) => {
245
+ quill.insertText(index, "• " + li.textContent + "\n");
246
+ index += li.textContent.length + 3;
247
+ });
248
+ break;
249
+ case "ol":
250
+ node.querySelectorAll("li").forEach((li, i) => {
251
+ const number = `${i + 1}. `;
252
+ quill.insertText(index, number, { bold: true });
253
+ index += number.length;
254
+ quill.insertText(index, li.textContent + "\n");
255
+ index += li.textContent.length + 1;
256
+ });
257
+ break;
258
+ case "p":
259
+ const pText = node.textContent.trim();
260
+ if (pText) {
261
+ quill.insertText(index, pText + "\n");
262
+ index += pText.length + 1;
263
+ }
264
+ break;
265
+ case "br":
266
+ quill.insertText(index, "\n");
267
+ index += 1;
268
+ break;
269
+ default:
270
+ const defaultText = node.textContent.trim();
271
+ if (defaultText) {
272
+ quill.insertText(index, defaultText);
273
+ index += defaultText.length;
274
+ }
275
+ }
276
+ }
277
+ });
278
+
279
+ // Add final formatting cleanup
280
+ if (index > 0) {
281
+ quill.insertText(index, "\n");
282
+ }
283
+ } catch (error) {
284
+ console.error("Error parsing markdown with marked.js:", error);
285
+ // Fallback to basic markdown parsing
286
+ renderMarkdownToQuill(markdownText, quill);
287
+ }
288
+ } else {
289
+ // Fallback to basic markdown parsing
290
+ renderMarkdownToQuill(markdownText, quill);
291
+ }
292
+ }
293
+
294
+ // Enhanced function that tries marked.js first, then falls back to basic parsing
295
+ function renderContentToQuill(content, quill) {
296
+ // Try to detect if content is markdown
297
+ const hasMarkdownPatterns = /\*\*|\*|#{1,6}\s|^\s*[-*+]\s|^\s*\d+\.\s/m.test(
298
+ content
299
+ );
300
+
301
+ if (hasMarkdownPatterns && typeof marked !== "undefined") {
302
+ renderMarkdownToQuillWithMarked(content, quill);
303
+ } else if (hasMarkdownPatterns) {
304
+ renderMarkdownToQuill(content, quill);
305
+ } else {
306
+ // Plain text
307
+ quill.setText(content);
308
+ }
309
+ }
@@ -0,0 +1,127 @@
1
+ // Auto-generated JS for Brand Name Generator
2
+ document.addEventListener("DOMContentLoaded", function () {
3
+ const form = document.getElementById("contentToolForm");
4
+ const tool = "brand_name_generator";
5
+
6
+ // Wait for Quill to be initialized
7
+ let quill;
8
+ const checkQuill = setInterval(() => {
9
+ if (window.quill) {
10
+ quill = window.quill;
11
+ clearInterval(checkQuill);
12
+ }
13
+ }, 100);
14
+
15
+ let input0 = form.querySelector('[name="input0"]');
16
+ let language = form.querySelector('[name="language"]');
17
+ let tone = form.querySelector('[name="tone"]');
18
+
19
+ form.addEventListener("submit", async function (e) {
20
+ e.preventDefault();
21
+
22
+ // Check if Quill is available
23
+ if (!quill) {
24
+ console.error("Quill editor not found");
25
+ return;
26
+ }
27
+
28
+ // Show loading state
29
+ const submitButton = form.querySelector('button[type="submit"]');
30
+ const originalText = submitButton ? submitButton.textContent : '';
31
+ if (submitButton) {
32
+ submitButton.textContent = 'Generating...';
33
+ submitButton.disabled = true;
34
+ }
35
+
36
+ const options = {};
37
+
38
+ options["input[0]"] = input0.value;
39
+ options["language"] = language.value;
40
+ options["tone"] = tone.value;
41
+
42
+ const body = {
43
+ tool: tool,
44
+ llm: "gemini",
45
+ model_name: "gemini-2.0-flash",
46
+ options: options
47
+ };
48
+
49
+ try {
50
+ const response = await fetch("http://localhost:8000/api/v1/name-and-title-tools/brand-name-generator", {
51
+ method: "POST",
52
+ headers: {
53
+ "Content-Type": "application/json"
54
+ },
55
+ body: JSON.stringify(body)
56
+ });
57
+
58
+ const data = await response.json();
59
+
60
+ if (data.result) {
61
+ // Clear the editor first
62
+ quill.setText('');
63
+
64
+ // Insert the content as plain text first
65
+ quill.insertText(0, data.result);
66
+
67
+ // Format the content for better readability
68
+ const content = quill.getText();
69
+ quill.setText('');
70
+
71
+ // Parse and format the content
72
+ const lines = content.split('\n');
73
+ let index = 0;
74
+
75
+ lines.forEach((line, i) => {
76
+ if (line.trim()) {
77
+ // Check if line starts with a number (like "1. ", "2. ", etc.)
78
+ const isNumberedItem = /^\d+\./.test(line.trim());
79
+
80
+ if (isNumberedItem) {
81
+ // Split the numbered item into number and content
82
+ const parts = line.trim().split(/^(\d+\.)\s*/);
83
+ if (parts.length >= 3) {
84
+ const number = parts[1];
85
+ const content = parts[2];
86
+
87
+ // Insert number in bold
88
+ quill.insertText(index, number + ' ', { 'bold': true });
89
+ index += number.length + 1;
90
+
91
+ // Insert content in normal text
92
+ quill.insertText(index, content);
93
+ index += content.length;
94
+ } else {
95
+ quill.insertText(index, line);
96
+ index += line.length;
97
+ }
98
+ } else {
99
+ // Regular text
100
+ quill.insertText(index, line);
101
+ index += line.length;
102
+ }
103
+
104
+ // Add line break if not the last line
105
+ if (i < lines.length - 1) {
106
+ quill.insertText(index, '\n');
107
+ index += 1;
108
+ }
109
+ }
110
+ });
111
+
112
+ console.log("✅ Content generated successfully");
113
+ } else {
114
+ quill.setText("No output received from server.");
115
+ }
116
+ } catch (err) {
117
+ console.error("❌ API Error:", err);
118
+ quill.setText("Error: " + err.message);
119
+ } finally {
120
+ // Reset button state
121
+ if (submitButton) {
122
+ submitButton.textContent = originalText;
123
+ submitButton.disabled = false;
124
+ }
125
+ }
126
+ });
127
+ });