@ourroadmaps/web-sdk 0.3.0
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/README.md +314 -0
- package/dist/chunk-4DE2IREA.cjs +9 -0
- package/dist/chunk-4DE2IREA.cjs.map +1 -0
- package/dist/chunk-KGQKTDB4.cjs +537 -0
- package/dist/chunk-KGQKTDB4.cjs.map +1 -0
- package/dist/chunk-MKPDPQXT.js +534 -0
- package/dist/chunk-MKPDPQXT.js.map +1 -0
- package/dist/chunk-V6TY7KAL.js +7 -0
- package/dist/chunk-V6TY7KAL.js.map +1 -0
- package/dist/chunk-XFAAEDJK.js +1251 -0
- package/dist/chunk-XFAAEDJK.js.map +1 -0
- package/dist/chunk-ZPPQHIRO.cjs +1254 -0
- package/dist/chunk-ZPPQHIRO.cjs.map +1 -0
- package/dist/feedback/index.cjs +13 -0
- package/dist/feedback/index.cjs.map +1 -0
- package/dist/feedback/index.d.cts +20 -0
- package/dist/feedback/index.d.ts +20 -0
- package/dist/feedback/index.js +4 -0
- package/dist/feedback/index.js.map +1 -0
- package/dist/feedback.global.js +389 -0
- package/dist/feedback.global.js.map +1 -0
- package/dist/index.cjs +64 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/overlay/index.cjs +17 -0
- package/dist/overlay/index.cjs.map +1 -0
- package/dist/overlay/index.d.cts +205 -0
- package/dist/overlay/index.d.ts +205 -0
- package/dist/overlay/index.js +4 -0
- package/dist/overlay/index.js.map +1 -0
- package/dist/overlay.global.js +123 -0
- package/dist/overlay.global.js.map +1 -0
- package/dist/types-CEewztln.d.cts +11 -0
- package/dist/types-CEewztln.d.ts +11 -0
- package/package.json +60 -0
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
import { __publicField } from './chunk-V6TY7KAL.js';
|
|
2
|
+
|
|
3
|
+
// src/feedback/api.ts
|
|
4
|
+
var API_URL = (() => {
|
|
5
|
+
if (typeof import.meta !== "undefined" && import.meta.env?.VITE_API_URL) {
|
|
6
|
+
return import.meta.env.VITE_API_URL;
|
|
7
|
+
}
|
|
8
|
+
return "https://api.ourroadmaps.com";
|
|
9
|
+
})();
|
|
10
|
+
async function submitFeedback(apiKey, content) {
|
|
11
|
+
const title = content.slice(0, 100).trim() || "Feedback";
|
|
12
|
+
const response = await fetch(`${API_URL}/v1/ideas`, {
|
|
13
|
+
method: "POST",
|
|
14
|
+
headers: {
|
|
15
|
+
Authorization: `Bearer ${apiKey}`,
|
|
16
|
+
"Content-Type": "application/json"
|
|
17
|
+
},
|
|
18
|
+
body: JSON.stringify({
|
|
19
|
+
title,
|
|
20
|
+
description: content,
|
|
21
|
+
source: "feedback-widget"
|
|
22
|
+
})
|
|
23
|
+
});
|
|
24
|
+
if (!response.ok) {
|
|
25
|
+
const error = await response.json().catch(() => ({
|
|
26
|
+
error: "Request failed"
|
|
27
|
+
}));
|
|
28
|
+
throw new Error(error.message || error.error || "Failed to submit feedback");
|
|
29
|
+
}
|
|
30
|
+
return response.json();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/feedback/icons.ts
|
|
34
|
+
var ICONS = {
|
|
35
|
+
lightbulb: `<svg viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
|
|
36
|
+
<path d="M9 21c0 .55.45 1 1 1h4c.55 0 1-.45 1-1v-1H9v1zm3-19C8.14 2 5 5.14 5 9c0 2.38 1.19 4.47 3 5.74V17c0 .55.45 1 1 1h6c.55 0 1-.45 1-1v-2.26c1.81-1.27 3-3.36 3-5.74 0-3.86-3.14-7-7-7zm2.85 11.1l-.85.6V16h-4v-2.3l-.85-.6A4.997 4.997 0 0 1 7 9c0-2.76 2.24-5 5-5s5 2.24 5 5c0 1.63-.8 3.16-2.15 4.1z"/>
|
|
37
|
+
</svg>`,
|
|
38
|
+
close: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" xmlns="http://www.w3.org/2000/svg">
|
|
39
|
+
<path d="M18 6L6 18M6 6l12 12"/>
|
|
40
|
+
</svg>`,
|
|
41
|
+
send: `<svg viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
|
|
42
|
+
<path d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"/>
|
|
43
|
+
</svg>`,
|
|
44
|
+
check: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" xmlns="http://www.w3.org/2000/svg">
|
|
45
|
+
<path d="M20 6L9 17l-5-5"/>
|
|
46
|
+
</svg>`
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// src/feedback/styles.ts
|
|
50
|
+
var WIDGET_STYLES = `
|
|
51
|
+
:host {
|
|
52
|
+
--or-primary: #2563eb;
|
|
53
|
+
--or-primary-hover: #1d4ed8;
|
|
54
|
+
--or-success: #10b981;
|
|
55
|
+
--or-error: #ef4444;
|
|
56
|
+
--or-text: #1f2937;
|
|
57
|
+
--or-text-muted: #6b7280;
|
|
58
|
+
--or-bg: #ffffff;
|
|
59
|
+
--or-border: #e5e7eb;
|
|
60
|
+
--or-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
|
|
61
|
+
|
|
62
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
63
|
+
font-size: 14px;
|
|
64
|
+
line-height: 1.5;
|
|
65
|
+
color: var(--or-text);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
* {
|
|
69
|
+
box-sizing: border-box;
|
|
70
|
+
margin: 0;
|
|
71
|
+
padding: 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.trigger {
|
|
75
|
+
position: fixed;
|
|
76
|
+
bottom: 20px;
|
|
77
|
+
right: 20px;
|
|
78
|
+
width: 48px;
|
|
79
|
+
height: 48px;
|
|
80
|
+
border-radius: 50%;
|
|
81
|
+
background: var(--or-primary);
|
|
82
|
+
border: none;
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
display: flex;
|
|
85
|
+
align-items: center;
|
|
86
|
+
justify-content: center;
|
|
87
|
+
box-shadow: var(--or-shadow);
|
|
88
|
+
transition: transform 0.15s ease, background-color 0.15s ease;
|
|
89
|
+
z-index: 2147483647;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.trigger:hover {
|
|
93
|
+
background: var(--or-primary-hover);
|
|
94
|
+
transform: scale(1.05);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.trigger svg {
|
|
98
|
+
width: 24px;
|
|
99
|
+
height: 24px;
|
|
100
|
+
fill: white;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.trigger.hidden {
|
|
104
|
+
display: none;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.panel {
|
|
108
|
+
position: fixed;
|
|
109
|
+
bottom: 80px;
|
|
110
|
+
right: 20px;
|
|
111
|
+
width: 320px;
|
|
112
|
+
background: var(--or-bg);
|
|
113
|
+
border-radius: 12px;
|
|
114
|
+
box-shadow: var(--or-shadow);
|
|
115
|
+
display: none;
|
|
116
|
+
flex-direction: column;
|
|
117
|
+
overflow: hidden;
|
|
118
|
+
z-index: 2147483647;
|
|
119
|
+
animation: slideIn 0.15s ease;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.panel.open {
|
|
123
|
+
display: flex;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@keyframes slideIn {
|
|
127
|
+
from {
|
|
128
|
+
opacity: 0;
|
|
129
|
+
transform: translateY(10px) scale(0.95);
|
|
130
|
+
}
|
|
131
|
+
to {
|
|
132
|
+
opacity: 1;
|
|
133
|
+
transform: translateY(0) scale(1);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.panel-header {
|
|
138
|
+
display: flex;
|
|
139
|
+
align-items: center;
|
|
140
|
+
justify-content: space-between;
|
|
141
|
+
padding: 12px 16px;
|
|
142
|
+
border-bottom: 1px solid var(--or-border);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.panel-title {
|
|
146
|
+
font-weight: 600;
|
|
147
|
+
font-size: 14px;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.close-btn {
|
|
151
|
+
width: 28px;
|
|
152
|
+
height: 28px;
|
|
153
|
+
border: none;
|
|
154
|
+
background: transparent;
|
|
155
|
+
cursor: pointer;
|
|
156
|
+
border-radius: 6px;
|
|
157
|
+
display: flex;
|
|
158
|
+
align-items: center;
|
|
159
|
+
justify-content: center;
|
|
160
|
+
color: var(--or-text-muted);
|
|
161
|
+
transition: background-color 0.15s ease;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.close-btn:hover {
|
|
165
|
+
background: var(--or-border);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.panel-body {
|
|
169
|
+
padding: 16px;
|
|
170
|
+
display: flex;
|
|
171
|
+
flex-direction: column;
|
|
172
|
+
gap: 12px;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.error-banner {
|
|
176
|
+
background: #fef2f2;
|
|
177
|
+
border: 1px solid #fecaca;
|
|
178
|
+
border-radius: 8px;
|
|
179
|
+
padding: 12px;
|
|
180
|
+
display: none;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.error-banner.visible {
|
|
184
|
+
display: block;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.error-text {
|
|
188
|
+
color: var(--or-error);
|
|
189
|
+
font-size: 13px;
|
|
190
|
+
margin-bottom: 8px;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.retry-btn {
|
|
194
|
+
background: transparent;
|
|
195
|
+
border: 1px solid var(--or-error);
|
|
196
|
+
color: var(--or-error);
|
|
197
|
+
padding: 4px 12px;
|
|
198
|
+
border-radius: 6px;
|
|
199
|
+
font-size: 13px;
|
|
200
|
+
cursor: pointer;
|
|
201
|
+
transition: background-color 0.15s ease;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.retry-btn:hover {
|
|
205
|
+
background: #fef2f2;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
textarea {
|
|
209
|
+
width: 100%;
|
|
210
|
+
min-height: 80px;
|
|
211
|
+
max-height: 200px;
|
|
212
|
+
padding: 12px;
|
|
213
|
+
border: 1px solid var(--or-border);
|
|
214
|
+
border-radius: 8px;
|
|
215
|
+
resize: none;
|
|
216
|
+
font-family: inherit;
|
|
217
|
+
font-size: 14px;
|
|
218
|
+
line-height: 1.5;
|
|
219
|
+
outline: none;
|
|
220
|
+
transition: border-color 0.15s ease;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
textarea:focus {
|
|
224
|
+
border-color: var(--or-primary);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
textarea:disabled {
|
|
228
|
+
background: #f9fafb;
|
|
229
|
+
cursor: not-allowed;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
.panel-footer {
|
|
233
|
+
display: flex;
|
|
234
|
+
align-items: center;
|
|
235
|
+
justify-content: space-between;
|
|
236
|
+
padding: 12px 16px;
|
|
237
|
+
border-top: 1px solid var(--or-border);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.hint {
|
|
241
|
+
font-size: 12px;
|
|
242
|
+
color: var(--or-text-muted);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.hint kbd {
|
|
246
|
+
background: #f3f4f6;
|
|
247
|
+
padding: 2px 6px;
|
|
248
|
+
border-radius: 4px;
|
|
249
|
+
font-family: inherit;
|
|
250
|
+
font-size: 11px;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
.submit-btn {
|
|
254
|
+
display: flex;
|
|
255
|
+
align-items: center;
|
|
256
|
+
gap: 6px;
|
|
257
|
+
padding: 8px 16px;
|
|
258
|
+
background: var(--or-primary);
|
|
259
|
+
color: white;
|
|
260
|
+
border: none;
|
|
261
|
+
border-radius: 8px;
|
|
262
|
+
font-size: 14px;
|
|
263
|
+
font-weight: 500;
|
|
264
|
+
cursor: pointer;
|
|
265
|
+
transition: background-color 0.15s ease;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.submit-btn:hover:not(:disabled) {
|
|
269
|
+
background: var(--or-primary-hover);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
.submit-btn:disabled {
|
|
273
|
+
opacity: 0.6;
|
|
274
|
+
cursor: not-allowed;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
.submit-btn svg {
|
|
278
|
+
width: 16px;
|
|
279
|
+
height: 16px;
|
|
280
|
+
fill: currentColor;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.spinner {
|
|
284
|
+
width: 16px;
|
|
285
|
+
height: 16px;
|
|
286
|
+
border: 2px solid transparent;
|
|
287
|
+
border-top-color: currentColor;
|
|
288
|
+
border-radius: 50%;
|
|
289
|
+
animation: spin 0.6s linear infinite;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
@keyframes spin {
|
|
293
|
+
to { transform: rotate(360deg); }
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
.success-content {
|
|
297
|
+
display: none;
|
|
298
|
+
flex-direction: column;
|
|
299
|
+
align-items: center;
|
|
300
|
+
justify-content: center;
|
|
301
|
+
padding: 32px 16px;
|
|
302
|
+
text-align: center;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
.success-content.visible {
|
|
306
|
+
display: flex;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
.success-icon {
|
|
310
|
+
width: 48px;
|
|
311
|
+
height: 48px;
|
|
312
|
+
background: #d1fae5;
|
|
313
|
+
border-radius: 50%;
|
|
314
|
+
display: flex;
|
|
315
|
+
align-items: center;
|
|
316
|
+
justify-content: center;
|
|
317
|
+
margin-bottom: 12px;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
.success-icon svg {
|
|
321
|
+
width: 24px;
|
|
322
|
+
height: 24px;
|
|
323
|
+
stroke: var(--or-success);
|
|
324
|
+
fill: none;
|
|
325
|
+
stroke-width: 3;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
.success-title {
|
|
329
|
+
font-weight: 600;
|
|
330
|
+
font-size: 16px;
|
|
331
|
+
margin-bottom: 4px;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
.success-subtitle {
|
|
335
|
+
color: var(--or-text-muted);
|
|
336
|
+
font-size: 13px;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
.form-content {
|
|
340
|
+
display: flex;
|
|
341
|
+
flex-direction: column;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
.form-content.hidden {
|
|
345
|
+
display: none;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/* Mobile bottom sheet */
|
|
349
|
+
@media (max-width: 640px) {
|
|
350
|
+
.panel {
|
|
351
|
+
bottom: 0;
|
|
352
|
+
right: 0;
|
|
353
|
+
left: 0;
|
|
354
|
+
width: 100%;
|
|
355
|
+
border-radius: 16px 16px 0 0;
|
|
356
|
+
animation: slideUp 0.2s ease;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
@keyframes slideUp {
|
|
360
|
+
from {
|
|
361
|
+
opacity: 0;
|
|
362
|
+
transform: translateY(100%);
|
|
363
|
+
}
|
|
364
|
+
to {
|
|
365
|
+
opacity: 1;
|
|
366
|
+
transform: translateY(0);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
.panel::before {
|
|
371
|
+
content: '';
|
|
372
|
+
display: block;
|
|
373
|
+
width: 36px;
|
|
374
|
+
height: 4px;
|
|
375
|
+
background: var(--or-border);
|
|
376
|
+
border-radius: 2px;
|
|
377
|
+
margin: 8px auto;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
.trigger {
|
|
381
|
+
bottom: 16px;
|
|
382
|
+
right: 16px;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
`;
|
|
386
|
+
|
|
387
|
+
// src/feedback/Feedback.ts
|
|
388
|
+
var Feedback = class {
|
|
389
|
+
constructor(config) {
|
|
390
|
+
__publicField(this, "config");
|
|
391
|
+
__publicField(this, "root", null);
|
|
392
|
+
__publicField(this, "shadow", null);
|
|
393
|
+
__publicField(this, "store", {
|
|
394
|
+
state: "closed",
|
|
395
|
+
content: "",
|
|
396
|
+
error: null
|
|
397
|
+
});
|
|
398
|
+
this.config = config;
|
|
399
|
+
}
|
|
400
|
+
mount() {
|
|
401
|
+
if (this.root) return;
|
|
402
|
+
this.root = document.createElement("div");
|
|
403
|
+
this.root.id = "ourroadmaps-widget-root";
|
|
404
|
+
document.body.appendChild(this.root);
|
|
405
|
+
this.shadow = this.root.attachShadow({ mode: "open" });
|
|
406
|
+
this.render();
|
|
407
|
+
this.attachEventListeners();
|
|
408
|
+
}
|
|
409
|
+
unmount() {
|
|
410
|
+
if (this.root) {
|
|
411
|
+
this.root.remove();
|
|
412
|
+
this.root = null;
|
|
413
|
+
this.shadow = null;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
setState(partial) {
|
|
417
|
+
this.store = { ...this.store, ...partial };
|
|
418
|
+
this.render();
|
|
419
|
+
}
|
|
420
|
+
render() {
|
|
421
|
+
if (!this.shadow) return;
|
|
422
|
+
const { state, content, error } = this.store;
|
|
423
|
+
const isOpen = state !== "closed";
|
|
424
|
+
const isSubmitting = state === "submitting";
|
|
425
|
+
const isSuccess = state === "success";
|
|
426
|
+
const isError = state === "error";
|
|
427
|
+
this.shadow.innerHTML = `
|
|
428
|
+
<style>${WIDGET_STYLES}</style>
|
|
429
|
+
|
|
430
|
+
<button class="trigger ${isOpen ? "hidden" : ""}" aria-label="Open feedback">
|
|
431
|
+
${ICONS.lightbulb}
|
|
432
|
+
</button>
|
|
433
|
+
|
|
434
|
+
<div class="panel ${isOpen ? "open" : ""}" role="dialog" aria-label="Share feedback">
|
|
435
|
+
<div class="panel-header">
|
|
436
|
+
<span class="panel-title">Share feedback</span>
|
|
437
|
+
<button class="close-btn" aria-label="Close">
|
|
438
|
+
${ICONS.close}
|
|
439
|
+
</button>
|
|
440
|
+
</div>
|
|
441
|
+
|
|
442
|
+
<div class="success-content ${isSuccess ? "visible" : ""}">
|
|
443
|
+
<div class="success-icon">
|
|
444
|
+
${ICONS.check}
|
|
445
|
+
</div>
|
|
446
|
+
<div class="success-title">Feedback sent!</div>
|
|
447
|
+
<div class="success-subtitle">Thanks for sharing your thoughts.</div>
|
|
448
|
+
</div>
|
|
449
|
+
|
|
450
|
+
<div class="form-content ${isSuccess ? "hidden" : ""}">
|
|
451
|
+
<div class="panel-body">
|
|
452
|
+
<div class="error-banner ${isError ? "visible" : ""}">
|
|
453
|
+
<div class="error-text">${error || "Couldn't save. Your note is preserved."}</div>
|
|
454
|
+
<button class="retry-btn">Try again</button>
|
|
455
|
+
</div>
|
|
456
|
+
<textarea
|
|
457
|
+
placeholder="What's on your mind?"
|
|
458
|
+
${isSubmitting ? "disabled" : ""}
|
|
459
|
+
>${content}</textarea>
|
|
460
|
+
</div>
|
|
461
|
+
|
|
462
|
+
<div class="panel-footer">
|
|
463
|
+
<span class="hint"><kbd>\u2318</kbd> <kbd>\u21B5</kbd> to send</span>
|
|
464
|
+
<button class="submit-btn" ${isSubmitting || !content.trim() ? "disabled" : ""}>
|
|
465
|
+
${isSubmitting ? '<span class="spinner"></span>' : ICONS.send}
|
|
466
|
+
${isSubmitting ? "Sending..." : "Send"}
|
|
467
|
+
</button>
|
|
468
|
+
</div>
|
|
469
|
+
</div>
|
|
470
|
+
</div>
|
|
471
|
+
`;
|
|
472
|
+
}
|
|
473
|
+
attachEventListeners() {
|
|
474
|
+
if (!this.shadow) return;
|
|
475
|
+
this.shadow.addEventListener("click", (e) => {
|
|
476
|
+
const target = e.target;
|
|
477
|
+
if (target.closest(".trigger")) {
|
|
478
|
+
this.open();
|
|
479
|
+
} else if (target.closest(".close-btn")) {
|
|
480
|
+
this.close();
|
|
481
|
+
} else if (target.closest(".submit-btn")) {
|
|
482
|
+
this.submit();
|
|
483
|
+
} else if (target.closest(".retry-btn")) {
|
|
484
|
+
this.submit();
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
this.shadow.addEventListener("input", (e) => {
|
|
488
|
+
const target = e.target;
|
|
489
|
+
if (target.tagName === "TEXTAREA") {
|
|
490
|
+
this.setState({ content: target.value, error: null, state: "open" });
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
this.shadow.addEventListener("keydown", (e) => {
|
|
494
|
+
const ke = e;
|
|
495
|
+
if (ke.key === "Escape") {
|
|
496
|
+
this.close();
|
|
497
|
+
} else if ((ke.metaKey || ke.ctrlKey) && ke.key === "Enter") {
|
|
498
|
+
this.submit();
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
document.addEventListener("click", (e) => {
|
|
502
|
+
if (this.store.state !== "closed" && this.root && !this.root.contains(e.target)) {
|
|
503
|
+
this.close();
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
open() {
|
|
508
|
+
this.setState({ state: "open" });
|
|
509
|
+
setTimeout(() => {
|
|
510
|
+
const textarea = this.shadow?.querySelector("textarea");
|
|
511
|
+
textarea?.focus();
|
|
512
|
+
}, 50);
|
|
513
|
+
}
|
|
514
|
+
close() {
|
|
515
|
+
this.setState({ state: "closed", error: null });
|
|
516
|
+
}
|
|
517
|
+
async submit() {
|
|
518
|
+
const { content } = this.store;
|
|
519
|
+
if (!content.trim()) return;
|
|
520
|
+
this.setState({ state: "submitting", error: null });
|
|
521
|
+
try {
|
|
522
|
+
await submitFeedback(this.config.apiKey, content);
|
|
523
|
+
this.setState({ state: "success", content: "" });
|
|
524
|
+
setTimeout(() => this.close(), 1500);
|
|
525
|
+
} catch (err) {
|
|
526
|
+
const message = err instanceof Error ? err.message : "Failed to submit";
|
|
527
|
+
this.setState({ state: "error", error: message });
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
export { Feedback };
|
|
533
|
+
//# sourceMappingURL=chunk-MKPDPQXT.js.map
|
|
534
|
+
//# sourceMappingURL=chunk-MKPDPQXT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/feedback/api.ts","../src/feedback/icons.ts","../src/feedback/styles.ts","../src/feedback/Feedback.ts"],"names":[],"mappings":";;;AAGA,IAAM,WAAW,MAAM;AAErB,EAAA,IAAI,OAAO,MAAA,CAAA,IAAA,KAAgB,WAAA,IAAe,MAAA,CAAA,IAAA,CAAY,KAAK,YAAA,EAAc;AACvE,IAAA,OAAO,YAAY,GAAA,CAAI,YAAA;AAAA,EACzB;AACA,EAAA,OAAO,6BAAA;AACT,CAAA,GAAG;AAEH,eAAsB,cAAA,CAAe,QAAgB,OAAA,EAAuC;AAC1F,EAAA,MAAM,QAAQ,OAAA,CAAQ,KAAA,CAAM,GAAG,GAAG,CAAA,CAAE,MAAK,IAAK,UAAA;AAE9C,EAAA,MAAM,QAAA,GAAW,MAAM,KAAA,CAAM,CAAA,EAAG,OAAO,CAAA,SAAA,CAAA,EAAa;AAAA,IAClD,MAAA,EAAQ,MAAA;AAAA,IACR,OAAA,EAAS;AAAA,MACP,aAAA,EAAe,UAAU,MAAM,CAAA,CAAA;AAAA,MAC/B,cAAA,EAAgB;AAAA,KAClB;AAAA,IACA,IAAA,EAAM,KAAK,SAAA,CAAU;AAAA,MACnB,KAAA;AAAA,MACA,WAAA,EAAa,OAAA;AAAA,MACb,MAAA,EAAQ;AAAA,KACT;AAAA,GACF,CAAA;AAED,EAAA,IAAI,CAAC,SAAS,EAAA,EAAI;AAChB,IAAA,MAAM,QAAkB,MAAM,QAAA,CAAS,IAAA,EAAK,CAAE,MAAM,OAAO;AAAA,MACzD,KAAA,EAAO;AAAA,KACT,CAAE,CAAA;AACF,IAAA,MAAM,IAAI,KAAA,CAAM,KAAA,CAAM,OAAA,IAAW,KAAA,CAAM,SA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AA,EACF;AACF","file":"chunk-MKPDPQXT.js","sourcesContent":["import type { ApiError, ApiResponse } from './types'\n\n// Default to production, override with env var for local dev\nconst API_URL = (() => {\n // Vite dev mode\n if (typeof import.meta !== 'undefined' && import.meta.env?.VITE_API_URL) {\n return import.meta.env.VITE_API_URL\n }\n return 'https://api.ourroadmaps.com'\n})()\n\nexport async function submitFeedback(apiKey: string, content: string): Promise<ApiResponse> {\n const title = content.slice(0, 100).trim() || 'Feedback'\n\n const response = await fetch(`${API_URL}/v1/ideas`, {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${apiKey}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n title,\n description: content,\n source: 'feedback-widget',\n }),\n })\n\n if (!response.ok) {\n const error: ApiError = await response.json().catch(() => ({\n error: 'Request failed',\n }))\n throw new Error(error.message || error.error || 'Failed to submit feedback')\n }\n\n return response.json()\n}\n","export const ICONS = {\n lightbulb: `<svg viewBox=\"0 0 24 24\" fill=\"currentColor\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M9 21c0 .55.45 1 1 1h4c.55 0 1-.45 1-1v-1H9v1zm3-19C8.14 2 5 5.14 5 9c0 2.38 1.19 4.47 3 5.74V17c0 .55.45 1 1 1h6c.55 0 1-.45 1-1v-2.26c1.81-1.27 3-3.36 3-5.74 0-3.86-3.14-7-7-7zm2.85 11.1l-.85.6V16h-4v-2.3l-.85-.6A4.997 4.997 0 0 1 7 9c0-2.76 2.24-5 5-5s5 2.24 5 5c0 1.63-.8 3.16-2.15 4.1z\"/>\n </svg>`,\n\n close: `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M18 6L6 18M6 6l12 12\"/>\n </svg>`,\n\n send: `<svg viewBox=\"0 0 24 24\" fill=\"currentColor\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M2.01 21L23 12 2.01 3 2 10l15 2-15 2z\"/>\n </svg>`,\n\n check: `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20 6L9 17l-5-5\"/>\n </svg>`,\n}\n","export const WIDGET_STYLES = `\n :host {\n --or-primary: #2563eb;\n --or-primary-hover: #1d4ed8;\n --or-success: #10b981;\n --or-error: #ef4444;\n --or-text: #1f2937;\n --or-text-muted: #6b7280;\n --or-bg: #ffffff;\n --or-border: #e5e7eb;\n --or-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);\n\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n font-size: 14px;\n line-height: 1.5;\n color: var(--or-text);\n }\n\n * {\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n }\n\n .trigger {\n position: fixed;\n bottom: 20px;\n right: 20px;\n width: 48px;\n height: 48px;\n border-radius: 50%;\n background: var(--or-primary);\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n box-shadow: var(--or-shadow);\n transition: transform 0.15s ease, background-color 0.15s ease;\n z-index: 2147483647;\n }\n\n .trigger:hover {\n background: var(--or-primary-hover);\n transform: scale(1.05);\n }\n\n .trigger svg {\n width: 24px;\n height: 24px;\n fill: white;\n }\n\n .trigger.hidden {\n display: none;\n }\n\n .panel {\n position: fixed;\n bottom: 80px;\n right: 20px;\n width: 320px;\n background: var(--or-bg);\n border-radius: 12px;\n box-shadow: var(--or-shadow);\n display: none;\n flex-direction: column;\n overflow: hidden;\n z-index: 2147483647;\n animation: slideIn 0.15s ease;\n }\n\n .panel.open {\n display: flex;\n }\n\n @keyframes slideIn {\n from {\n opacity: 0;\n transform: translateY(10px) scale(0.95);\n }\n to {\n opacity: 1;\n transform: translateY(0) scale(1);\n }\n }\n\n .panel-header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 12px 16px;\n border-bottom: 1px solid var(--or-border);\n }\n\n .panel-title {\n font-weight: 600;\n font-size: 14px;\n }\n\n .close-btn {\n width: 28px;\n height: 28px;\n border: none;\n background: transparent;\n cursor: pointer;\n border-radius: 6px;\n display: flex;\n align-items: center;\n justify-content: center;\n color: var(--or-text-muted);\n transition: background-color 0.15s ease;\n }\n\n .close-btn:hover {\n background: var(--or-border);\n }\n\n .panel-body {\n padding: 16px;\n display: flex;\n flex-direction: column;\n gap: 12px;\n }\n\n .error-banner {\n background: #fef2f2;\n border: 1px solid #fecaca;\n border-radius: 8px;\n padding: 12px;\n display: none;\n }\n\n .error-banner.visible {\n display: block;\n }\n\n .error-text {\n color: var(--or-error);\n font-size: 13px;\n margin-bottom: 8px;\n }\n\n .retry-btn {\n background: transparent;\n border: 1px solid var(--or-error);\n color: var(--or-error);\n padding: 4px 12px;\n border-radius: 6px;\n font-size: 13px;\n cursor: pointer;\n transition: background-color 0.15s ease;\n }\n\n .retry-btn:hover {\n background: #fef2f2;\n }\n\n textarea {\n width: 100%;\n min-height: 80px;\n max-height: 200px;\n padding: 12px;\n border: 1px solid var(--or-border);\n border-radius: 8px;\n resize: none;\n font-family: inherit;\n font-size: 14px;\n line-height: 1.5;\n outline: none;\n transition: border-color 0.15s ease;\n }\n\n textarea:focus {\n border-color: var(--or-primary);\n }\n\n textarea:disabled {\n background: #f9fafb;\n cursor: not-allowed;\n }\n\n .panel-footer {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 12px 16px;\n border-top: 1px solid var(--or-border);\n }\n\n .hint {\n font-size: 12px;\n color: var(--or-text-muted);\n }\n\n .hint kbd {\n background: #f3f4f6;\n padding: 2px 6px;\n border-radius: 4px;\n font-family: inherit;\n font-size: 11px;\n }\n\n .submit-btn {\n display: flex;\n align-items: center;\n gap: 6px;\n padding: 8px 16px;\n background: var(--or-primary);\n color: white;\n border: none;\n border-radius: 8px;\n font-size: 14px;\n font-weight: 500;\n cursor: pointer;\n transition: background-color 0.15s ease;\n }\n\n .submit-btn:hover:not(:disabled) {\n background: var(--or-primary-hover);\n }\n\n .submit-btn:disabled {\n opacity: 0.6;\n cursor: not-allowed;\n }\n\n .submit-btn svg {\n width: 16px;\n height: 16px;\n fill: currentColor;\n }\n\n .spinner {\n width: 16px;\n height: 16px;\n border: 2px solid transparent;\n border-top-color: currentColor;\n border-radius: 50%;\n animation: spin 0.6s linear infinite;\n }\n\n @keyframes spin {\n to { transform: rotate(360deg); }\n }\n\n .success-content {\n display: none;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n padding: 32px 16px;\n text-align: center;\n }\n\n .success-content.visible {\n display: flex;\n }\n\n .success-icon {\n width: 48px;\n height: 48px;\n background: #d1fae5;\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n margin-bottom: 12px;\n }\n\n .success-icon svg {\n width: 24px;\n height: 24px;\n stroke: var(--or-success);\n fill: none;\n stroke-width: 3;\n }\n\n .success-title {\n font-weight: 600;\n font-size: 16px;\n margin-bottom: 4px;\n }\n\n .success-subtitle {\n color: var(--or-text-muted);\n font-size: 13px;\n }\n\n .form-content {\n display: flex;\n flex-direction: column;\n }\n\n .form-content.hidden {\n display: none;\n }\n\n /* Mobile bottom sheet */\n @media (max-width: 640px) {\n .panel {\n bottom: 0;\n right: 0;\n left: 0;\n width: 100%;\n border-radius: 16px 16px 0 0;\n animation: slideUp 0.2s ease;\n }\n\n @keyframes slideUp {\n from {\n opacity: 0;\n transform: translateY(100%);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n }\n\n .panel::before {\n content: '';\n display: block;\n width: 36px;\n height: 4px;\n background: var(--or-border);\n border-radius: 2px;\n margin: 8px auto;\n }\n\n .trigger {\n bottom: 16px;\n right: 16px;\n }\n }\n`\n","import { submitFeedback } from './api'\nimport { ICONS } from './icons'\nimport { WIDGET_STYLES } from './styles'\nimport type { WidgetConfig, WidgetStore } from './types'\n\nexport class Feedback {\n private config: WidgetConfig\n private root: HTMLElement | null = null\n private shadow: ShadowRoot | null = null\n private store: WidgetStore = {\n state: 'closed',\n content: '',\n error: null,\n }\n\n constructor(config: WidgetConfig) {\n this.config = config\n }\n\n mount(): void {\n if (this.root) return\n\n this.root = document.createElement('div')\n this.root.id = 'ourroadmaps-widget-root'\n document.body.appendChild(this.root)\n\n this.shadow = this.root.attachShadow({ mode: 'open' })\n this.render()\n this.attachEventListeners()\n }\n\n unmount(): void {\n if (this.root) {\n this.root.remove()\n this.root = null\n this.shadow = null\n }\n }\n\n private setState(partial: Partial<WidgetStore>): void {\n this.store = { ...this.store, ...partial }\n this.render()\n }\n\n private render(): void {\n if (!this.shadow) return\n\n const { state, content, error } = this.store\n const isOpen = state !== 'closed'\n const isSubmitting = state === 'submitting'\n const isSuccess = state === 'success'\n const isError = state === 'error'\n\n this.shadow.innerHTML = `\n <style>${WIDGET_STYLES}</style>\n\n <button class=\"trigger ${isOpen ? 'hidden' : ''}\" aria-label=\"Open feedback\">\n ${ICONS.lightbulb}\n </button>\n\n <div class=\"panel ${isOpen ? 'open' : ''}\" role=\"dialog\" aria-label=\"Share feedback\">\n <div class=\"panel-header\">\n <span class=\"panel-title\">Share feedback</span>\n <button class=\"close-btn\" aria-label=\"Close\">\n ${ICONS.close}\n </button>\n </div>\n\n <div class=\"success-content ${isSuccess ? 'visible' : ''}\">\n <div class=\"success-icon\">\n ${ICONS.check}\n </div>\n <div class=\"success-title\">Feedback sent!</div>\n <div class=\"success-subtitle\">Thanks for sharing your thoughts.</div>\n </div>\n\n <div class=\"form-content ${isSuccess ? 'hidden' : ''}\">\n <div class=\"panel-body\">\n <div class=\"error-banner ${isError ? 'visible' : ''}\">\n <div class=\"error-text\">${error || \"Couldn't save. Your note is preserved.\"}</div>\n <button class=\"retry-btn\">Try again</button>\n </div>\n <textarea\n placeholder=\"What's on your mind?\"\n ${isSubmitting ? 'disabled' : ''}\n >${content}</textarea>\n </div>\n\n <div class=\"panel-footer\">\n <span class=\"hint\"><kbd>⌘</kbd> <kbd>↵</kbd> to send</span>\n <button class=\"submit-btn\" ${isSubmitting || !content.trim() ? 'disabled' : ''}>\n ${isSubmitting ? '<span class=\"spinner\"></span>' : ICONS.send}\n ${isSubmitting ? 'Sending...' : 'Send'}\n </button>\n </div>\n </div>\n </div>\n `\n }\n\n private attachEventListeners(): void {\n if (!this.shadow) return\n\n this.shadow.addEventListener('click', (e) => {\n const target = e.target as HTMLElement\n\n if (target.closest('.trigger')) {\n this.open()\n } else if (target.closest('.close-btn')) {\n this.close()\n } else if (target.closest('.submit-btn')) {\n this.submit()\n } else if (target.closest('.retry-btn')) {\n this.submit()\n }\n })\n\n this.shadow.addEventListener('input', (e) => {\n const target = e.target as HTMLTextAreaElement\n if (target.tagName === 'TEXTAREA') {\n this.setState({ content: target.value, error: null, state: 'open' })\n }\n })\n\n this.shadow.addEventListener('keydown', (e) => {\n const ke = e as KeyboardEvent\n if (ke.key === 'Escape') {\n this.close()\n } else if ((ke.metaKey || ke.ctrlKey) && ke.key === 'Enter') {\n this.submit()\n }\n })\n\n document.addEventListener('click', (e) => {\n if (this.store.state !== 'closed' && this.root && !this.root.contains(e.target as Node)) {\n this.close()\n }\n })\n }\n\n private open(): void {\n this.setState({ state: 'open' })\n setTimeout(() => {\n const textarea = this.shadow?.querySelector('textarea')\n textarea?.focus()\n }, 50)\n }\n\n private close(): void {\n this.setState({ state: 'closed', error: null })\n }\n\n private async submit(): Promise<void> {\n const { content } = this.store\n if (!content.trim()) return\n\n this.setState({ state: 'submitting', error: null })\n\n try {\n await submitFeedback(this.config.apiKey, content)\n this.setState({ state: 'success', content: '' })\n setTimeout(() => this.close(), 1500)\n } catch (err) {\n const message = err instanceof Error ? err.message : 'Failed to submit'\n this.setState({ state: 'error', error: message })\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
export { __publicField };
|
|
6
|
+
//# sourceMappingURL=chunk-V6TY7KAL.js.map
|
|
7
|
+
//# sourceMappingURL=chunk-V6TY7KAL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-V6TY7KAL.js"}
|