create-heresay 0.2.10 → 0.2.12

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.
@@ -3,17 +3,45 @@
3
3
  *
4
4
  * <script src="https://<sdk-host>/sdk.js" data-key="pk_..." defer></script>
5
5
  *
6
- * Optional attributes: data-version, data-user-id, data-user-label, data-position ("left"),
7
- * data-intro ("auto": introduce the button a few seconds after the first page load),
8
- * data-accent ("#0f766e"; a hex colour, to match the host app. Defaults to Heresay peacock).
6
+ * The defaults are the recommended setup; every attribute below is optional. The full list, with
7
+ * what each is for, is public/guides/customize-web.md.
8
+ *
9
+ * Who and what: data-version, data-user-id, data-user-label, data-user-email
10
+ * Button: data-position right (default) | left | top-right | top-left | center
11
+ * data-offset "20" or "x,y" in px from the edges
12
+ * data-button always (default) | none (open it from the app's own menu)
13
+ * | desktop (not on phones) | scroll (after the first scroll)
14
+ * data-label the button text, default "Report"
15
+ * data-style pill (default) | icon | tab
16
+ * data-size regular (default) | small | large
17
+ * data-fill neutral (default) | accent
18
+ * data-shadow soft (default) | none | strong
19
+ * data-hide-on "/checkout,/login": paths where the button stays hidden
20
+ * Look: data-accent "#0f766e"; a hex colour. The logo follows it too, unless
21
+ * data-mark="heresay" keeps the Heresay teal.
22
+ * data-theme auto (default, follows the device) | light | dark
23
+ * data-font system (default) | inherit (the page's font)
24
+ * Words: data-lang the page's <html lang> (default) | auto (the browser) | en | fr | ta | hi
25
+ * data-placeholder, data-thanks, data-types ("broken,confusing,improvement,idea")
26
+ * Panel: data-panel corner (default) | sheet | center
27
+ * data-width regular (default) | narrow | wide
28
+ * data-backdrop dim (default) | clear | blur
29
+ * data-preferences show (default) | hide
30
+ * data-intro "auto": introduce the button a few seconds after the first load
9
31
  * Optional calls, any time after the script runs:
10
32
  * Feedback.identify({ id, label, email }) who is signed in; then nobody is asked their name
11
33
  * Feedback.setVersion("1.4.0")
12
34
  * Feedback.setScreen("Checkout") for apps whose URL does not change per screen
13
- * Feedback.open()
14
- * Feedback.introduce() once per device: a bubble saying the Report button is there
35
+ * Feedback.open({ type, text }) type and text optional: starts a report already filled in
36
+ * Feedback.on("sent", fn) fn({ id, type }) after each report is sent; returns an off()
37
+ * Feedback.introduce({ title, body }) once per device: a bubble saying the button is there
38
+ * data-preview for the dashboard's designer: nothing is sent or stored
15
39
  * Feedback.openPreferences() a note about their setup, and a name and email if not signed in
16
40
  *
41
+ * Not configurable, on purpose: the Heresay mark on the button, the report types' names (they set
42
+ * the priority), the "Your reports" tab (reporters read why a report was declined), and the
43
+ * "Powered by Heresay" line, so people can tell the app uses an outside tool.
44
+ *
17
45
  * No account, no cookies. The reporter is a random per-device id kept in localStorage, and
18
46
  * that id is also what lets them see what happened to their own reports. Their preferences are
19
47
  * kept on the device too, and sent with each report only if they filled them in.
@@ -31,6 +59,204 @@
31
59
  var API = (script.getAttribute('data-api') || new URL(script.src, location.href).origin + '/v1').replace(/\/+$/, '');
32
60
  if (!KEY) { console.warn('[feedback] missing data-key on the sdk.js script tag'); return; }
33
61
 
62
+ function attr(n) { var v = script.getAttribute('data-' + n); return v == null ? '' : String(v).trim(); }
63
+ /** One of the allowed values, lower-cased, or the default. Anything else is ignored. */
64
+ function pick(n, allowed, dflt) { var v = attr(n).toLowerCase(); return allowed.indexOf(v) >= 0 ? v : dflt; }
65
+ /** Plain text from an attribute or a call, trimmed and cut to a length. Only ever set as text. */
66
+ function words(v, max) { v = v == null ? '' : String(v).replace(/\s+/g, ' ').trim(); return v ? v.slice(0, max) : null; }
67
+
68
+ var HERESAY_URL = 'https://sibhimanyu.github.io/heresay/';
69
+ // data-preview: the dashboard's designer shows the real widget with nothing sent or stored.
70
+ var PREVIEW = script.hasAttribute('data-preview');
71
+
72
+ // ---- words -----------------------------------------------------------------------------
73
+
74
+ var STR = {
75
+ en: {
76
+ report: 'Report', reportAria: 'Report a problem',
77
+ update: 'Report a problem. {n} of your reports have an update',
78
+ close: 'Close', dialog: 'Feedback',
79
+ tabNew: 'Report', tabMine: 'Your reports', tabPrefs: 'Preferences',
80
+ what: 'What is it?', whatHappened: 'What happened?', ph: 'What happened, or what would you change?',
81
+ send: 'Send', sending: 'Sending…',
82
+ pickType: 'Pick what kind of report this is.', sayWhat: 'Say what happened.', cantSend: 'Could not send. Try again.',
83
+ attachedPrefs: 'This page, the app version and your preferences are attached.',
84
+ attached: 'This page and the app version are attached.',
85
+ types: {
86
+ broken: ['Broken', 'Something does not work'],
87
+ confusing: ['Confusing', 'I could not tell how to do something'],
88
+ improvement: ['Could be better', 'It works, but it could be better'],
89
+ idea: ['Idea', 'Something that does not exist yet'],
90
+ },
91
+ status: { open: 'Waiting for the developer', accepted: 'Accepted, being worked on', fixed: 'Fixed', declined: 'Declined' },
92
+ optional: '(optional)', yourName: 'Your name', email: 'Email',
93
+ emailHint: 'Only if you are happy for the team to reply to you.',
94
+ setup: 'About your setup', setupHint: 'Sent with every report, so you only say it once.',
95
+ setupPh: 'For example: I use a screen reader, or I am usually on slow Wi-Fi.',
96
+ signedAs: 'Signed in as {who}', yourAccount: 'your account',
97
+ seesReply: '{email}. The team sees this with each report and can reply.',
98
+ sees: 'The team sees this with each report.',
99
+ badEmail: 'That email does not look right.', saved: 'Saved on this device.',
100
+ clear: 'Clear all', save: 'Save',
101
+ kept: 'Kept in this browser and sent only with reports you choose to send.',
102
+ none: 'Nothing sent from this device yet.', why: 'Why: ',
103
+ introAria: 'About the Report button', introTitle: 'Help make this app better',
104
+ introBody: 'Use {label} any time to share an idea or tell the team what you would change. A real person reads every report, and you will see what happens to yours right here.',
105
+ got: 'Got it', tryIt: 'Try it',
106
+ sentTo: 'Sent to this app’s team', powered: 'Powered by Heresay',
107
+ },
108
+ fr: {
109
+ report: 'Signaler', reportAria: 'Signaler un problème',
110
+ update: 'Signaler un problème. {n} de vos signalements ont du nouveau',
111
+ close: 'Fermer', dialog: 'Signalement',
112
+ tabNew: 'Signaler', tabMine: 'Vos signalements', tabPrefs: 'Préférences',
113
+ what: 'De quoi s’agit-il ?', whatHappened: 'Que s’est-il passé ?', ph: 'Que s’est-il passé, ou que changeriez-vous ?',
114
+ send: 'Envoyer', sending: 'Envoi…',
115
+ pickType: 'Choisissez le type de signalement.', sayWhat: 'Dites ce qui s’est passé.', cantSend: 'Envoi impossible. Réessayez.',
116
+ attachedPrefs: 'Cette page, la version de l’app et vos préférences sont jointes.',
117
+ attached: 'Cette page et la version de l’app sont jointes.',
118
+ types: {
119
+ broken: ['Cassé', 'Quelque chose ne marche pas'],
120
+ confusing: ['Déroutant', 'Je ne voyais pas comment faire'],
121
+ improvement: ['Pourrait être mieux', 'Ça marche, mais ça pourrait être mieux'],
122
+ idea: ['Idée', 'Quelque chose qui n’existe pas encore'],
123
+ },
124
+ status: { open: 'En attente de l’équipe', accepted: 'Accepté, en cours', fixed: 'Corrigé', declined: 'Refusé' },
125
+ optional: '(facultatif)', yourName: 'Votre nom', email: 'E-mail',
126
+ emailHint: 'Seulement si vous acceptez que l’équipe vous réponde.',
127
+ setup: 'Votre configuration', setupHint: 'Envoyé avec chaque signalement, pour ne le dire qu’une fois.',
128
+ setupPh: 'Par exemple : j’utilise un lecteur d’écran, ou mon Wi-Fi est souvent lent.',
129
+ signedAs: 'Connecté en tant que {who}', yourAccount: 'votre compte',
130
+ seesReply: '{email}. L’équipe le voit avec chaque signalement et peut vous répondre.',
131
+ sees: 'L’équipe le voit avec chaque signalement.',
132
+ badEmail: 'Cette adresse e-mail ne semble pas correcte.', saved: 'Enregistré sur cet appareil.',
133
+ clear: 'Tout effacer', save: 'Enregistrer',
134
+ kept: 'Conservé dans ce navigateur, et envoyé seulement avec les signalements que vous envoyez.',
135
+ none: 'Aucun signalement envoyé depuis cet appareil.', why: 'Pourquoi : ',
136
+ introAria: 'À propos du bouton Signaler', introTitle: 'Aidez à améliorer cette app',
137
+ introBody: 'Utilisez {label} à tout moment pour partager une idée ou dire à l’équipe ce que vous changeriez. Une vraie personne lit chaque signalement, et vous verrez ici ce qu’il devient.',
138
+ got: 'Compris', tryIt: 'Essayer',
139
+ sentTo: 'Envoyé à l’équipe de cette app', powered: 'Propulsé par Heresay',
140
+ },
141
+ ta: {
142
+ report: 'தெரிவி', reportAria: 'சிக்கலைத் தெரிவிக்கவும்',
143
+ update: 'சிக்கலைத் தெரிவிக்கவும். உங்கள் {n} புகார்களில் புதிய தகவல் உள்ளது',
144
+ close: 'மூடு', dialog: 'கருத்து',
145
+ tabNew: 'தெரிவி', tabMine: 'உங்கள் புகார்கள்', tabPrefs: 'விருப்பங்கள்',
146
+ what: 'இது என்ன வகை?', whatHappened: 'என்ன நடந்தது?', ph: 'என்ன நடந்தது, அல்லது எதை மாற்ற விரும்புகிறீர்கள்?',
147
+ send: 'அனுப்பு', sending: 'அனுப்புகிறது…',
148
+ pickType: 'இது எந்த வகைப் புகார் என்பதைத் தேர்ந்தெடுக்கவும்.', sayWhat: 'என்ன நடந்தது என்று சொல்லுங்கள்.', cantSend: 'அனுப்ப முடியவில்லை. மீண்டும் முயலவும்.',
149
+ attachedPrefs: 'இந்தப் பக்கம், ஆப் பதிப்பு மற்றும் உங்கள் விருப்பங்கள் இணைக்கப்படும்.',
150
+ attached: 'இந்தப் பக்கமும் ஆப் பதிப்பும் இணைக்கப்படும்.',
151
+ types: {
152
+ broken: ['வேலை செய்யவில்லை', 'ஏதோ ஒன்று சரியாக இயங்கவில்லை'],
153
+ confusing: ['குழப்பமாக உள்ளது', 'எப்படிச் செய்வது என்று புரியவில்லை'],
154
+ improvement: ['இன்னும் சிறப்பாக்கலாம்', 'வேலை செய்கிறது, ஆனால் மேம்படுத்தலாம்'],
155
+ idea: ['யோசனை', 'இன்னும் இல்லாத ஒன்று'],
156
+ },
157
+ status: { open: 'டெவலப்பருக்காகக் காத்திருக்கிறது', accepted: 'ஏற்கப்பட்டது, வேலை நடக்கிறது', fixed: 'சரிசெய்யப்பட்டது', declined: 'நிராகரிக்கப்பட்டது' },
158
+ optional: '(விருப்பத்தேர்வு)', yourName: 'உங்கள் பெயர்', email: 'மின்னஞ்சல்',
159
+ emailHint: 'குழு உங்களுக்குப் பதில் அனுப்பலாம் என்றால் மட்டும்.',
160
+ setup: 'உங்கள் அமைப்பு பற்றி', setupHint: 'ஒவ்வொரு புகாருடனும் அனுப்பப்படும், எனவே ஒருமுறை சொன்னால் போதும்.',
161
+ setupPh: 'உதாரணமாக: நான் ஸ்கிரீன் ரீடர் பயன்படுத்துகிறேன், அல்லது என் Wi-Fi பெரும்பாலும் மெதுவாக இருக்கும்.',
162
+ signedAs: '{who} ஆக உள்நுழைந்துள்ளீர்கள்', yourAccount: 'உங்கள் கணக்கு',
163
+ seesReply: '{email}. ஒவ்வொரு புகாருடனும் குழு இதைப் பார்க்கும், பதிலும் அனுப்பலாம்.',
164
+ sees: 'ஒவ்வொரு புகாருடனும் குழு இதைப் பார்க்கும்.',
165
+ badEmail: 'இந்த மின்னஞ்சல் சரியாகத் தெரியவில்லை.', saved: 'இந்தச் சாதனத்தில் சேமிக்கப்பட்டது.',
166
+ clear: 'அனைத்தையும் அழி', save: 'சேமி',
167
+ kept: 'இந்த உலாவியில் வைக்கப்படும்; நீங்கள் அனுப்பும் புகார்களுடன் மட்டுமே அனுப்பப்படும்.',
168
+ none: 'இந்தச் சாதனத்திலிருந்து இன்னும் எதுவும் அனுப்பப்படவில்லை.', why: 'காரணம்: ',
169
+ introAria: 'தெரிவி பொத்தான் பற்றி', introTitle: 'இந்த ஆப்பை இன்னும் சிறப்பாக்க உதவுங்கள்',
170
+ introBody: 'ஒரு யோசனையைப் பகிர அல்லது நீங்கள் எதை மாற்ற விரும்புகிறீர்கள் என்று குழுவிடம் சொல்ல, எப்போது வேண்டுமானாலும் {label} ஐப் பயன்படுத்துங்கள். ஒவ்வொரு கருத்தையும் ஒருவர் படிக்கிறார்; உங்களுடையதற்கு என்ன ஆனது என்பதை இங்கேயே பார்க்கலாம்.',
171
+ got: 'சரி', tryIt: 'முயன்று பாருங்கள்',
172
+ sentTo: 'இந்த ஆப்பின் குழுவுக்கு அனுப்பப்படும்', powered: 'Heresay மூலம் இயங்குகிறது',
173
+ },
174
+ hi: {
175
+ report: 'रिपोर्ट करें', reportAria: 'समस्या की रिपोर्ट करें',
176
+ update: 'समस्या की रिपोर्ट करें। आपकी {n} रिपोर्ट में नई जानकारी है',
177
+ close: 'बंद करें', dialog: 'फ़ीडबैक',
178
+ tabNew: 'रिपोर्ट', tabMine: 'आपकी रिपोर्ट', tabPrefs: 'प्राथमिकताएँ',
179
+ what: 'यह क्या है?', whatHappened: 'क्या हुआ?', ph: 'क्या हुआ, या आप क्या बदलना चाहेंगे?',
180
+ send: 'भेजें', sending: 'भेजा जा रहा है…',
181
+ pickType: 'चुनें कि यह किस तरह की रिपोर्ट है।', sayWhat: 'बताइए क्या हुआ।', cantSend: 'भेजा नहीं जा सका। फिर से कोशिश करें।',
182
+ attachedPrefs: 'यह पेज, ऐप का वर्शन और आपकी प्राथमिकताएँ साथ भेजी जाती हैं।',
183
+ attached: 'यह पेज और ऐप का वर्शन साथ भेजे जाते हैं।',
184
+ types: {
185
+ broken: ['टूटा हुआ', 'कुछ काम नहीं कर रहा'],
186
+ confusing: ['उलझन भरा', 'समझ नहीं आया कि कैसे करें'],
187
+ improvement: ['बेहतर हो सकता है', 'काम करता है, पर बेहतर हो सकता है'],
188
+ idea: ['सुझाव', 'कुछ ऐसा जो अभी नहीं है'],
189
+ },
190
+ status: { open: 'डेवलपर का इंतज़ार', accepted: 'स्वीकार, इस पर काम चल रहा है', fixed: 'ठीक हो गया', declined: 'अस्वीकार' },
191
+ optional: '(वैकल्पिक)', yourName: 'आपका नाम', email: 'ईमेल',
192
+ emailHint: 'सिर्फ़ तब, जब आप चाहते हैं कि टीम आपको जवाब दे।',
193
+ setup: 'आपके सेटअप के बारे में', setupHint: 'हर रिपोर्ट के साथ भेजा जाता है, ताकि आपको एक ही बार बताना पड़े।',
194
+ setupPh: 'जैसे: स्क्रीन रीडर के साथ इस्तेमाल, या अक्सर धीमा Wi-Fi।',
195
+ signedAs: '{who} के रूप में साइन इन', yourAccount: 'आपका खाता',
196
+ seesReply: '{email}. टीम हर रिपोर्ट के साथ इसे देखती है और जवाब दे सकती है।',
197
+ sees: 'टीम हर रिपोर्ट के साथ इसे देखती है।',
198
+ badEmail: 'यह ईमेल सही नहीं लग रहा।', saved: 'इस डिवाइस पर सेव हो गया।',
199
+ clear: 'सब हटाएँ', save: 'सेव करें',
200
+ kept: 'इसी ब्राउज़र में रखा जाता है, और सिर्फ़ आपकी भेजी रिपोर्ट के साथ जाता है।',
201
+ none: 'इस डिवाइस से अभी तक कुछ नहीं भेजा गया।', why: 'वजह: ',
202
+ introAria: 'रिपोर्ट बटन के बारे में', introTitle: 'इस ऐप को और बेहतर बनाने में मदद करें',
203
+ introBody: 'कोई आइडिया बताने या टीम को यह बताने के लिए कि आप क्या बदलना चाहेंगे, कभी भी {label} का इस्तेमाल करें। हर रिपोर्ट कोई इंसान पढ़ता है, और आपकी रिपोर्ट का क्या हुआ, यह आप यहीं देखेंगे।',
204
+ got: 'ठीक है', tryIt: 'आज़माएँ',
205
+ sentTo: 'इस ऐप की टीम को भेजा जाता है', powered: 'Heresay द्वारा संचालित',
206
+ },
207
+ };
208
+ /** The page's own language by default, so the widget speaks like the app around it. */
209
+ function language() {
210
+ var want = attr('lang').toLowerCase();
211
+ var tries = want === 'auto' ? (navigator.languages || [navigator.language || ''])
212
+ : [want || document.documentElement.getAttribute('lang') || ''];
213
+ for (var i = 0; i < tries.length; i++) {
214
+ var code = String(tries[i] || '').toLowerCase().slice(0, 2);
215
+ if (STR[code]) return code;
216
+ }
217
+ return 'en';
218
+ }
219
+ var LANG = language();
220
+ var S = STR[LANG];
221
+ function fmt(s, o) { return s.replace(/\{(\w+)\}/g, function (_, k) { return o[k]; }); }
222
+
223
+ // ---- the developer's choices -----------------------------------------------------------
224
+
225
+ /** Where the button sits is the developer's choice (data-position), not the reporter's. */
226
+ var POS = ({
227
+ left: ['l', 'b'], 'bottom-left': ['l', 'b'], 'top-right': ['r', 't'], 'top-left': ['l', 't'],
228
+ center: ['c', 'b'], 'bottom-center': ['c', 'b'],
229
+ })[attr('position').toLowerCase()] || ['r', 'b'];
230
+ var STYLE = pick('style', ['pill', 'icon', 'tab'], 'pill');
231
+ if (STYLE === 'tab' && POS[0] === 'c') POS = ['r', 'b'];
232
+ var LEFT = POS[0] === 'l';
233
+ var OFFSET = (function () {
234
+ var m = /^(\d{1,4})(?:\s*,\s*(\d{1,4}))?$/.exec(attr('offset'));
235
+ var clamp = function (n) { return Math.min(400, +n); };
236
+ return m ? [clamp(m[1]), clamp(m[2] != null ? m[2] : m[1])] : [20, 20];
237
+ })();
238
+ var BUTTON = pick('button', ['always', 'none', 'desktop', 'scroll'], 'always');
239
+ var SIZE = pick('size', ['regular', 'small', 'large'], 'regular');
240
+ var LABEL = words(attr('label'), 40) || S.report;
241
+ var HIDE_ON = attr('hide-on').split(',').map(function (p) { return p.trim().replace(/\/+$/, ''); })
242
+ .filter(function (p) { return p.charAt(0) === '/'; });
243
+ var PANEL = pick('panel', ['corner', 'sheet', 'center'], 'corner');
244
+ var WIDTH = ({ narrow: 320, wide: 460 })[attr('width').toLowerCase()] || 380;
245
+ var BACKDROP = pick('backdrop', ['dim', 'clear', 'blur'], 'dim');
246
+ var PREFS_TAB = pick('preferences', ['show', 'hide'], 'show') === 'show';
247
+ var PLACEHOLDER = words(attr('placeholder'), 120) || S.ph;
248
+ var THANKS = words(attr('thanks'), 160);
249
+
250
+ var TYPES = ['broken', 'confusing', 'improvement', 'idea'].map(function (id) {
251
+ return { id: id, label: S.types[id][0], hint: S.types[id][1] };
252
+ });
253
+ /** The types the reporter can pick. Names and priorities never change; a developer can only leave some out. */
254
+ var OFFERED = (function () {
255
+ var want = attr('types').toLowerCase().split(',').map(function (s) { return s.trim(); });
256
+ var some = TYPES.filter(function (t) { return want.indexOf(t.id) >= 0; });
257
+ return some.length ? some : TYPES;
258
+ })();
259
+
34
260
  var state = {
35
261
  version: script.getAttribute('data-version') || null,
36
262
  userId: script.getAttribute('data-user-id') || null,
@@ -38,27 +264,17 @@
38
264
  userEmail: script.getAttribute('data-user-email') || null,
39
265
  screen: null,
40
266
  type: null,
267
+ draft: '',
268
+ justSent: false,
41
269
  reports: [],
42
270
  };
43
-
44
- var TYPES = [
45
- { id: 'broken', label: 'Broken', hint: 'Something does not work' },
46
- { id: 'confusing', label: 'Confusing', hint: 'I could not tell how to do something' },
47
- { id: 'improvement', label: 'Could be better', hint: 'It works, but it could be better' },
48
- { id: 'idea', label: 'Idea', hint: 'Something that does not exist yet' },
49
- ];
50
- var STATUS = {
51
- open: 'Waiting for the developer',
52
- accepted: 'Accepted, being worked on',
53
- fixed: 'Fixed',
54
- declined: 'Declined',
55
- };
271
+ var listeners = [];
56
272
 
57
273
  // ---- storage ---------------------------------------------------------------------------
58
274
 
59
275
  var mem = {};
60
- function load(k) { try { return localStorage.getItem(k); } catch (e) { return mem[k] || null; } }
61
- function save(k, v) { try { localStorage.setItem(k, v); } catch (e) { mem[k] = v; } }
276
+ function load(k) { if (PREVIEW) return mem[k] || null; try { return localStorage.getItem(k); } catch (e) { return mem[k] || null; } }
277
+ function save(k, v) { if (PREVIEW) { mem[k] = v; return; } try { localStorage.setItem(k, v); } catch (e) { mem[k] = v; } }
62
278
 
63
279
  function deviceId() {
64
280
  var id = load('fbsdk.device');
@@ -103,8 +319,6 @@
103
319
  var r = { name: mine && p.name || null, email: mine && p.email || null, note: p.note || null };
104
320
  return r.name || r.email || r.note ? r : null;
105
321
  }
106
- /** Where the button sits is the developer's choice (data-position), not the reporter's. */
107
- var LEFT = script.getAttribute('data-position') === 'left';
108
322
 
109
323
  // ---- context ---------------------------------------------------------------------------
110
324
 
@@ -194,6 +408,7 @@
194
408
  }
195
409
 
196
410
  function send(type, text) {
411
+ if (PREVIEW) return Promise.resolve({ report: { id: 'preview', type: type, text: text, status: 'open', created_at: new Date().toISOString() } });
197
412
  // text/plain keeps this a "simple" request: no CORS preflight round trip.
198
413
  return fetch(API + '/reports', {
199
414
  method: 'POST',
@@ -203,6 +418,7 @@
203
418
  }
204
419
 
205
420
  function refresh() {
421
+ if (PREVIEW) return Promise.resolve();
206
422
  return fetch(API + '/reports/mine', {
207
423
  method: 'POST',
208
424
  headers: { 'content-type': 'text/plain;charset=UTF-8' },
@@ -217,34 +433,70 @@
217
433
 
218
434
  // ---- ui --------------------------------------------------------------------------------
219
435
 
436
+ var DARK = '--fb-bg:#16181d;--fb-fg:#eceef1;--fb-mute:#9aa1ad;--fb-line:#2c313a;--fb-acc:#2dd4bf;--fb-acc-fg:#0b1f1d;--fb-bad:#f2b8b5;--fb-mark:#2dd4bf';
437
+ var THEME = pick('theme', ['auto', 'light', 'dark'], 'auto');
438
+ var FAB_H = { small: 40, regular: 48, large: 58 }[SIZE];
439
+
220
440
  var CSS = [
221
- ':host{all:initial;--fb-bg:#fff;--fb-fg:#15171c;--fb-mute:#5b6472;--fb-line:#e3e6ea;--fb-acc:#0f766e;--fb-acc-fg:#fff;--fb-bad:#b42318;--fb-mark:#0b5e57;',
441
+ ':host{all:initial;--fb-bg:#fff;--fb-fg:#15171c;--fb-mute:#5b6472;--fb-line:#e3e6ea;--fb-acc:#0f766e;--fb-acc-fg:#fff;--fb-bad:#b42318;--fb-mark:#0b5e57;--fb-eye:#fff;',
442
+ '--fb-x:' + OFFSET[0] + 'px;--fb-y:' + OFFSET[1] + 'px;--fb-h:' + FAB_H + 'px;--fb-w:' + WIDTH + 'px;',
222
443
  'font:14px/1.45 system-ui,-apple-system,"Segoe UI",sans-serif;color:var(--fb-fg)}',
223
- '@media (prefers-color-scheme:dark){:host{--fb-bg:#16181d;--fb-fg:#eceef1;--fb-mute:#9aa1ad;--fb-line:#2c313a;--fb-acc:#2dd4bf;--fb-acc-fg:#0b1f1d;--fb-bad:#f2b8b5;--fb-mark:#2dd4bf}}',
444
+ THEME === 'dark' ? ':host{' + DARK + '}' : THEME === 'light' ? '' : '@media (prefers-color-scheme:dark){:host{' + DARK + '}}',
445
+ pick('font', ['system', 'inherit'], 'system') === 'inherit' ? ':host{font-family:inherit}' : '',
224
446
  '*{box-sizing:border-box;font:inherit;color:inherit}',
225
- '.fab{position:fixed;bottom:20px;right:20px;z-index:2147483000;display:flex;align-items:center;gap:6px;',
447
+ '[hidden]{display:none!important}',
448
+
449
+ // the button
450
+ '.fab{position:fixed;z-index:2147483000;display:flex;align-items:center;gap:6px;',
226
451
  'padding:9px 14px;border-radius:999px;border:1px solid var(--fb-line);background:var(--fb-bg);color:var(--fb-fg);',
227
- 'box-shadow:0 4px 14px rgba(0,0,0,.18);cursor:pointer;font-weight:600}',
228
- '.fab.left{right:auto;left:20px}',
229
- '.intro{position:fixed;bottom:72px;right:20px;z-index:2147483000;width:min(300px,calc(100vw - 40px));padding:14px 16px;',
452
+ 'box-shadow:0 4px 14px rgba(0,0,0,.18);cursor:pointer;font-weight:600;white-space:nowrap}',
453
+ '.fab.r{right:var(--fb-x)}.fab.l{left:var(--fb-x)}.fab.c{left:50%;transform:translateX(-50%)}',
454
+ '.fab.b{bottom:var(--fb-y)}.fab.t{top:var(--fb-y)}',
455
+ '.fab.sz-small{padding:6px 10px;font-size:12.5px}.fab.sz-small svg{width:14px;height:14px}',
456
+ '.fab.sz-large{padding:12px 18px;font-size:16px}.fab.sz-large svg{width:22px;height:22px}',
457
+ '.fab.st-icon{padding:10px;border-radius:50%}.fab.st-icon.sz-small{padding:7px}.fab.st-icon.sz-large{padding:13px}',
458
+ '.fab.st-icon .lbl{display:none}',
459
+ '.fab.st-tab{writing-mode:vertical-rl;top:50%;bottom:auto;transform:translateY(-50%);padding:14px 8px;right:0;border-radius:10px 0 0 10px;border-right:0}',
460
+ '.fab.st-tab.l{left:0;right:auto;border-radius:0 10px 10px 0;border-left:0;border-right:1px solid var(--fb-line)}',
461
+ '.fab.st-tab .mark{display:none}',
462
+ '.fab.sh-none{box-shadow:none}.fab.sh-strong{box-shadow:0 10px 30px rgba(0,0,0,.35)}',
463
+ '.fab.fill{background:var(--fb-acc);color:var(--fb-acc-fg);border-color:var(--fb-acc)}',
464
+ '.fab.fill .mark{color:var(--fb-acc-fg)}.fab.fill .eye{fill:var(--fb-acc)}.fab.fill .dot{background:var(--fb-acc-fg)}',
465
+ '@media (max-width:640px){.fab.desktop{display:none}}',
466
+
467
+ // the introduction
468
+ '.intro{position:fixed;z-index:2147483000;width:min(300px,calc(100vw - 40px));padding:14px 16px;',
230
469
  'background:var(--fb-bg);border:1px solid var(--fb-line);border-radius:14px;box-shadow:0 12px 32px rgba(0,0,0,.22);animation:fb-in .25s ease-out}',
231
- '.intro.left{right:auto;left:20px}',
470
+ '.intro.r{right:var(--fb-x)}.intro.l{left:var(--fb-x)}.intro.c{left:50%;margin-left:min(-150px,calc(20px - 50vw))}',
471
+ '.intro.b{bottom:calc(var(--fb-y) + var(--fb-h) + 8px)}.intro.t{top:calc(var(--fb-y) + var(--fb-h) + 8px)}',
232
472
  '.intro:after{content:"";position:absolute;bottom:-7px;right:36px;width:12px;height:12px;background:var(--fb-bg);',
233
473
  'border-right:1px solid var(--fb-line);border-bottom:1px solid var(--fb-line);transform:rotate(45deg)}',
234
- '.intro.left:after{right:auto;left:36px}',
474
+ '.intro.st-icon:after{right:calc(var(--fb-h) / 2 - 6px)}.intro.st-icon.l:after{left:calc(var(--fb-h) / 2 - 6px)}.intro.l:after{right:auto;left:36px}.intro.c:after{right:auto;left:calc(50% - 6px)}',
475
+ '.intro.t:after{bottom:auto;top:-7px;transform:rotate(225deg)}',
476
+ '.intro.side{top:50%;bottom:auto;transform:translateY(-50%);animation:none}.intro.side.r{right:56px}.intro.side.l{left:56px}.intro.side:after{display:none}',
235
477
  '.intro b{display:block;margin-bottom:4px;font-weight:700}',
236
478
  '.intro p{margin:0 0 12px;color:var(--fb-mute);font-size:13px}',
237
479
  '.intro .row{margin-top:0;justify-content:flex-end}',
480
+ '.intro .by{margin-top:12px;padding-top:8px}',
238
481
  '@keyframes fb-in{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}',
239
482
  '@media (prefers-reduced-motion:reduce){.intro{animation:none}}',
240
- '.mark{display:inline-flex;color:var(--fb-mark)}.mark svg{display:block}',
483
+ '.mark{display:inline-flex;color:var(--fb-mark)}.mark svg{display:block}.eye{fill:var(--fb-eye)}',
241
484
  '.dot{width:8px;height:8px;border-radius:50%;background:var(--fb-acc)}',
485
+
486
+ // the panel
242
487
  '.scrim{position:fixed;inset:0;z-index:2147483001;background:rgba(0,0,0,.35);display:flex;align-items:flex-end;justify-content:flex-end;padding:16px}',
243
- '.scrim.left{justify-content:flex-start}',
244
- '.panel{width:min(380px,100%);max-height:min(560px,calc(100vh - 32px));overflow:auto;background:var(--fb-bg);',
245
- 'border:1px solid var(--fb-line);border-radius:14px;box-shadow:0 12px 40px rgba(0,0,0,.3);padding:16px}',
488
+ '.scrim.l{justify-content:flex-start}.scrim.c{justify-content:center}.scrim.t{align-items:flex-start}.scrim.side{align-items:center}',
489
+ '.scrim.center{align-items:center;justify-content:center}',
490
+ '.scrim.sheet{padding:0;align-items:stretch}',
491
+ '.scrim.clear{background:none}',
492
+ '.scrim.blur{background:rgba(0,0,0,.18);-webkit-backdrop-filter:blur(4px);backdrop-filter:blur(4px)}',
493
+ '.panel{width:min(var(--fb-w),100%);max-height:min(600px,calc(100vh - 32px));overflow:auto;background:var(--fb-bg);',
494
+ 'border:1px solid var(--fb-line);border-radius:14px;box-shadow:0 12px 40px rgba(0,0,0,.3);padding:16px;display:flex;flex-direction:column}',
495
+ '.sheet .panel{max-height:none;height:100%;border-radius:0;border-width:0 0 0 1px}',
496
+ '.sheet.l .panel{border-width:0 1px 0 0}',
497
+ '.main{flex:1}',
246
498
  '.head{display:flex;justify-content:space-between;align-items:center;margin-bottom:12px}',
247
- '.tabs{display:flex;gap:4px}',
499
+ '.tabs{display:flex;gap:4px;flex-wrap:wrap}',
248
500
  '.tab{border:0;background:none;padding:6px 10px;border-radius:8px;cursor:pointer;color:var(--fb-mute);font-weight:600}',
249
501
  '.tab[aria-selected=true]{background:var(--fb-line);color:var(--fb-fg)}',
250
502
  '.x{border:0;background:none;cursor:pointer;font-size:20px;line-height:1;padding:4px 8px;color:var(--fb-mute)}',
@@ -256,7 +508,7 @@
256
508
  '.type[aria-pressed=true]{border-color:var(--fb-acc);box-shadow:inset 0 0 0 1px var(--fb-acc)}',
257
509
  'textarea{width:100%;min-height:96px;resize:vertical;padding:10px;border:1px solid var(--fb-line);border-radius:10px;background:none}',
258
510
  'input[type=text],input[type=email]{width:100%;padding:9px 10px;border:1px solid var(--fb-line);border-radius:10px;background:none}',
259
- 'textarea:focus,input:focus,.type:focus-visible,button:focus-visible{outline:2px solid var(--fb-acc);outline-offset:1px}',
511
+ 'textarea:focus,input:focus,.type:focus-visible,button:focus-visible,a:focus-visible{outline:2px solid var(--fb-acc);outline-offset:1px}',
260
512
  '.field{display:block;margin:0 0 12px}',
261
513
  '.field>span{display:block;font-weight:600;margin-bottom:4px}',
262
514
  '.field>span i{font-style:normal;font-weight:400;color:var(--fb-mute)}',
@@ -271,6 +523,7 @@
271
523
  '.send{padding:9px 16px;border:0;border-radius:10px;background:var(--fb-acc);color:var(--fb-acc-fg);font-weight:600;cursor:pointer}',
272
524
  '.send[disabled]{opacity:.5;cursor:default}',
273
525
  '.err{color:var(--fb-bad);font-size:13px;margin-top:8px}',
526
+ '.thanks{padding:10px 12px;margin:0 0 8px;border-radius:10px;background:var(--fb-line)}',
274
527
  '.item{border-top:1px solid var(--fb-line);padding:10px 0}',
275
528
  '.item:first-child{border-top:0}',
276
529
  '.status{font-size:12px;font-weight:600}',
@@ -278,13 +531,20 @@
278
531
  '.reason{margin-top:4px;padding:8px;border-radius:8px;background:var(--fb-line);font-size:13px}',
279
532
  '.text{margin:2px 0;white-space:pre-wrap;word-break:break-word}',
280
533
  '.empty{color:var(--fb-mute);padding:12px 0}',
534
+ // Always shown: people should be able to tell this is an outside tool, and who reads it.
535
+ '.by{display:flex;justify-content:space-between;align-items:center;gap:8px;margin-top:14px;padding-top:10px;',
536
+ 'border-top:1px solid var(--fb-line);font-size:11.5px;color:var(--fb-mute)}',
537
+ '.by a{display:inline-flex;align-items:center;gap:4px;margin-left:auto;color:inherit;text-decoration:none;font-weight:600;white-space:nowrap}',
538
+ '.by a:hover{text-decoration:underline}.by .mark svg{width:13px;height:13px}',
281
539
  ].join('');
282
540
 
283
541
  /**
284
542
  * The host app's own accent, if it gave one. Only a plain hex colour is accepted, so the
285
543
  * attribute cannot inject CSS. The text on top of it is whichever of white or ink reads better.
544
+ * The logo follows the accent too (data-mark="heresay" keeps the teal), in each theme only
545
+ * where it stays visible against the button.
286
546
  */
287
- function accentCss(v) {
547
+ function accentCss(v, keepMark, theme) {
288
548
  var m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec((v || '').trim());
289
549
  if (!m) return '';
290
550
  var hex = m[1].length === 3 ? m[1].replace(/(.)/g, '$1$1') : m[1];
@@ -294,9 +554,16 @@
294
554
  });
295
555
  var L = 0.2126 * lin[0] + 0.7152 * lin[1] + 0.0722 * lin[2];
296
556
  var fg = (1.05 / (L + 0.05)) >= ((L + 0.05) / 0.0598) ? '#fff' : '#15171c';
297
- return ':host{--fb-acc:#' + hex + ';--fb-acc-fg:' + fg + '}';
557
+ var css = ':host{--fb-acc:#' + hex + ';--fb-acc-fg:' + fg + '}';
558
+ if (keepMark) return css;
559
+ var onLight = 1.05 / (L + 0.05) >= 3, onDark = (L + 0.05) / (0.0098 + 0.05) >= 3; // #16181d
560
+ var mark = ':host{--fb-mark:#' + hex + '}';
561
+ if (theme === 'dark') return css + (onDark ? mark : '');
562
+ if (theme === 'light') return css + (onLight ? mark : '');
563
+ return css + (onLight ? '@media (prefers-color-scheme:light){' + mark + '}' : '') +
564
+ (onDark ? '@media (prefers-color-scheme:dark){' + mark + '}' : '');
298
565
  }
299
- CSS += accentCss(script.getAttribute('data-accent'));
566
+ CSS += accentCss(attr('accent'), pick('mark', ['accent', 'heresay'], 'accent') === 'heresay', THEME);
300
567
 
301
568
  var host = document.createElement('div');
302
569
  host.setAttribute('data-feedback-sdk', '');
@@ -320,32 +587,71 @@
320
587
  function markEl() {
321
588
  var s = document.createElement('span');
322
589
  s.className = 'mark';
323
- s.innerHTML = '<svg viewBox="0 0 200 200" width="18" height="18" aria-hidden="true"><path d="M174 100L177 105L180 110L181 116L180 121L178 126L174 131L169 134L164 137L159 139L154 141L149 143L146 146L143 149L141 154L139 159L137 164L134 169L131 174L126 178L121 180L116 181L110 180L105 177L100 174L95 170L91 167L87 164L83 163L79 162L74 162L69 163L63 164L57 164L51 164L46 162L41 159L38 154L36 149L36 143L36 137L37 131L38 126L38 121L37 117L36 113L33 109L30 105L26 100L23 95L20 90L19 84L20 79L22 74L26 69L31 66L36 63L41 61L46 59L51 57L54 54L57 51L59 46L61 41L63 36L66 31L69 26L74 22L79 20L84 19L90 20L95 23L100 26L105 30L109 33L113 36L117 37L121 38L126 38L131 37L137 36L143 36L149 36L154 38L159 41L162 46L164 51L164 57L164 63L163 69L162 74L162 79L163 83L164 87L167 91L170 95Z" fill="currentColor"/><path d="M-13 12 C-13 -8 -2 -24 17 -32 L20 -25 C8 -18 2 -9 3 -1 A13 13 0 1 1 -13 12 Z" fill="#fff" transform="translate(80 106) rotate(-24) scale(1.25)"/><path d="M-13 12 C-13 -8 -2 -24 17 -32 L20 -25 C8 -18 2 -9 3 -1 A13 13 0 1 1 -13 12 Z" fill="#fff" transform="translate(124 101) rotate(-24) scale(1.25)"/></svg>';
590
+ s.innerHTML = '<svg viewBox="0 0 200 200" width="18" height="18" aria-hidden="true"><path d="M174 100L177 105L180 110L181 116L180 121L178 126L174 131L169 134L164 137L159 139L154 141L149 143L146 146L143 149L141 154L139 159L137 164L134 169L131 174L126 178L121 180L116 181L110 180L105 177L100 174L95 170L91 167L87 164L83 163L79 162L74 162L69 163L63 164L57 164L51 164L46 162L41 159L38 154L36 149L36 143L36 137L37 131L38 126L38 121L37 117L36 113L33 109L30 105L26 100L23 95L20 90L19 84L20 79L22 74L26 69L31 66L36 63L41 61L46 59L51 57L54 54L57 51L59 46L61 41L63 36L66 31L69 26L74 22L79 20L84 19L90 20L95 23L100 26L105 30L109 33L113 36L117 37L121 38L126 38L131 37L137 36L143 36L149 36L154 38L159 41L162 46L164 51L164 57L164 63L163 69L162 74L162 79L163 83L164 87L167 91L170 95Z" fill="currentColor"/><path class="eye" d="M-13 12 C-13 -8 -2 -24 17 -32 L20 -25 C8 -18 2 -9 3 -1 A13 13 0 1 1 -13 12 Z" transform="translate(80 106) rotate(-24) scale(1.25)"/><path class="eye" d="M-13 12 C-13 -8 -2 -24 17 -32 L20 -25 C8 -18 2 -9 3 -1 A13 13 0 1 1 -13 12 Z" transform="translate(124 101) rotate(-24) scale(1.25)"/></svg>';
324
591
  return s;
325
592
  }
593
+
594
+ /** "Powered by Heresay", on every view. Not configurable. */
595
+ function byline(sentTo) {
596
+ return el('div', { class: 'by' }, [
597
+ sentTo ? el('span', { text: S.sentTo }) : null,
598
+ el('a', { href: HERESAY_URL, target: '_blank', rel: 'noopener' }, [markEl(), document.createTextNode(S.powered)]),
599
+ ]);
600
+ }
601
+
602
+ var PLACE = POS.join(' ') + (STYLE === 'tab' ? ' side' : '');
326
603
  var fabDot = el('span', { class: 'dot', hidden: '' });
327
604
  var fab = el('button', {
328
- class: 'fab' + (LEFT ? ' left' : ''),
329
- type: 'button', 'aria-haspopup': 'dialog', onclick: function () { open(); },
330
- }, [markEl(), el('span', { text: 'Report' }), fabDot]);
331
- root.appendChild(fab);
605
+ class: ['fab', PLACE, 'st-' + STYLE, 'sz-' + SIZE, 'sh-' + pick('shadow', ['soft', 'none', 'strong'], 'soft'),
606
+ pick('fill', ['neutral', 'accent'], 'neutral') === 'accent' ? 'fill' : '', BUTTON === 'desktop' ? 'desktop' : ''].join(' '),
607
+ type: 'button', 'aria-haspopup': 'dialog', title: S.reportAria + ' · ' + S.powered,
608
+ onclick: function () { open(); },
609
+ }, [markEl(), el('span', { class: 'lbl', text: LABEL }), fabDot]);
610
+ if (BUTTON !== 'none') root.appendChild(fab);
611
+
612
+ // The button can wait for the first scroll. On a page that never scrolls, it shows after 10s.
613
+ var revealed = BUTTON !== 'scroll';
614
+ function reveal() { if (revealed) return; revealed = true; placeFab(); }
615
+ if (!revealed) {
616
+ ['scroll', 'wheel', 'touchmove'].forEach(function (e) { window.addEventListener(e, reveal, { passive: true, once: true }); });
617
+ setTimeout(reveal, 10000);
618
+ }
619
+ /** Hidden on the paths the developer listed: that path, or anything under it. */
620
+ function hiddenHere() {
621
+ var p = location.pathname.replace(/\/+$/, '');
622
+ return HIDE_ON.some(function (h) { return p === h || p.indexOf(h + '/') === 0; });
623
+ }
624
+ var lastPath = null;
625
+ function placeFab() {
626
+ lastPath = location.pathname;
627
+ var off = !revealed || hiddenHere();
628
+ if (off) fab.setAttribute('hidden', ''); else fab.removeAttribute('hidden');
629
+ if (off && bubble) { bubble.remove(); bubble = null; }
630
+ }
631
+ /** Can the reporter see the button right now? The introduction points at it. */
632
+ function fabShowing() {
633
+ return BUTTON !== 'none' && fab.isConnected && !fab.hasAttribute('hidden') && getComputedStyle(fab).display !== 'none';
634
+ }
635
+ // Single-page apps change the path without reloading; check cheaply, only when paths are listed.
636
+ if (HIDE_ON.length) setInterval(function () { if (location.pathname !== lastPath) placeFab(); }, 500);
332
637
 
333
638
  var scrim = null, view = 'new', listBox = null, lastFocus = null;
334
639
 
335
640
  function renderBadge() {
336
641
  var n = unseen();
337
642
  if (n) fabDot.removeAttribute('hidden'); else fabDot.setAttribute('hidden', '');
338
- fab.setAttribute('aria-label', n ? 'Report a problem. ' + n + ' of your reports have an update' : 'Report a problem');
643
+ fab.setAttribute('aria-label', n ? fmt(S.update, { n: n }) : S.reportAria);
339
644
  }
340
-
341
645
  renderBadge();
342
646
 
343
647
  function open(which) {
344
- if (scrim || dead) return;
648
+ if (dead) return;
649
+ if (scrim) { if (which) { view = which; renderPanel(); } return; }
345
650
  if (bubble) { bubble.remove(); bubble = null; }
346
651
  lastFocus = document.activeElement;
347
652
  view = which || (unseen() ? 'mine' : 'new');
348
- scrim = el('div', { class: 'scrim' + (LEFT ? ' left' : ''), onclick: function (e) { if (e.target === scrim) close(); } });
653
+ var cls = PANEL === 'center' ? 'center' : PLACE + (PANEL === 'sheet' ? ' sheet' : '');
654
+ scrim = el('div', { class: 'scrim ' + cls + ' ' + BACKDROP, onclick: function (e) { if (e.target === scrim) close(); } });
349
655
  scrim.addEventListener('keydown', function (e) { if (e.key === 'Escape') close(); });
350
656
  root.appendChild(scrim);
351
657
  renderPanel();
@@ -358,38 +664,43 @@
358
664
  scrim.remove();
359
665
  scrim = null;
360
666
  listBox = null;
667
+ state.justSent = false;
361
668
  renderBadge();
362
669
  if (lastFocus && lastFocus.focus) lastFocus.focus();
363
670
  }
364
671
 
365
672
  function renderPanel() {
366
673
  scrim.textContent = '';
674
+ if (view === 'prefs' && !PREFS_TAB) view = 'new';
367
675
  var tab = function (id, label) {
368
676
  return el('button', {
369
677
  class: 'tab', type: 'button', role: 'tab', 'aria-selected': String(view === id),
370
- onclick: function () { if (view === 'mine') markSeen(); view = id; renderPanel(); },
678
+ onclick: function () { if (view === 'mine') markSeen(); state.justSent = false; view = id; renderPanel(); },
371
679
  }, [document.createTextNode(label)]);
372
680
  };
373
- var panel = el('div', { class: 'panel', role: 'dialog', 'aria-modal': 'true', 'aria-label': 'Feedback' }, [
681
+ var panel = el('div', { class: 'panel', role: 'dialog', 'aria-modal': 'true', 'aria-label': S.dialog }, [
374
682
  el('div', { class: 'head' }, [
375
- el('div', { class: 'tabs', role: 'tablist' }, [tab('new', 'Report'), tab('mine', 'Your reports'), tab('prefs', 'Preferences')]),
376
- el('button', { class: 'x', type: 'button', 'aria-label': 'Close', text: '×', onclick: close }),
683
+ el('div', { class: 'tabs', role: 'tablist' }, [tab('new', S.tabNew), tab('mine', S.tabMine), PREFS_TAB ? tab('prefs', S.tabPrefs) : null]),
684
+ el('button', { class: 'x', type: 'button', 'aria-label': S.close, text: '×', onclick: close }),
377
685
  ]),
378
- view === 'new' ? formView() : view === 'prefs' ? prefsView() : listView(),
686
+ el('div', { class: 'main' }, [view === 'new' ? formView() : view === 'prefs' ? prefsView() : listView()]),
687
+ byline(view === 'new'),
379
688
  ]);
380
689
  scrim.appendChild(panel);
381
- var first = panel.querySelector(view === 'new' ? '.type' : view === 'prefs' ? 'input,textarea' : '.tab[aria-selected=true]');
690
+ var first = panel.querySelector(view === 'new' ? (state.type ? 'textarea' : '.type') : view === 'prefs' ? 'input,textarea' : '.tab[aria-selected=true]');
382
691
  if (first) first.focus();
383
692
  }
384
693
 
385
694
  function formView() {
386
695
  var err = el('div', { class: 'err', role: 'alert' });
387
696
  var text = el('textarea', {
388
- 'aria-label': 'What happened?', maxlength: '2000',
389
- placeholder: 'What happened, or what would you change?',
697
+ 'aria-label': S.whatHappened, maxlength: '2000',
698
+ placeholder: PLACEHOLDER,
699
+ oninput: function () { state.draft = text.value; },
390
700
  });
391
- var sendBtn = el('button', { class: 'send', type: 'submit', text: 'Send' });
392
- var types = TYPES.map(function (t) {
701
+ text.value = state.draft;
702
+ var sendBtn = el('button', { class: 'send', type: 'submit', text: S.send });
703
+ var types = OFFERED.map(function (t) {
393
704
  return el('button', {
394
705
  class: 'type', type: 'button', 'aria-pressed': String(state.type === t.id), 'data-type': t.id,
395
706
  onclick: function () {
@@ -403,29 +714,31 @@
403
714
  onsubmit: function (e) {
404
715
  e.preventDefault();
405
716
  err.textContent = '';
406
- if (!state.type) { err.textContent = 'Pick what kind of report this is.'; return; }
407
- if (!text.value.trim()) { err.textContent = 'Say what happened.'; text.focus(); return; }
717
+ if (!state.type) { err.textContent = S.pickType; return; }
718
+ if (!text.value.trim()) { err.textContent = S.sayWhat; text.focus(); return; }
408
719
  sendBtn.disabled = true;
409
- sendBtn.textContent = 'Sending…';
410
- send(state.type, text.value.trim()).then(function (b) {
720
+ sendBtn.textContent = S.sending;
721
+ var type = state.type;
722
+ send(type, text.value.trim()).then(function (b) {
411
723
  state.type = null;
724
+ state.draft = '';
412
725
  state.reports = [b.report].concat(state.reports);
413
726
  markSeen();
727
+ state.justSent = true;
414
728
  view = 'mine';
415
729
  renderPanel();
730
+ listeners.forEach(function (fn) { try { fn({ id: b.report && b.report.id, type: type }); } catch (x) { console.error(x); } });
416
731
  }).catch(function (x) {
417
- err.textContent = x.message || 'Could not send. Try again.';
732
+ err.textContent = x.message || S.cantSend;
418
733
  sendBtn.disabled = false;
419
- sendBtn.textContent = 'Send';
734
+ sendBtn.textContent = S.send;
420
735
  });
421
736
  },
422
737
  }, [
423
- el('fieldset', {}, [el('legend', { text: 'What is it?' })].concat(types)),
738
+ el('fieldset', {}, [el('legend', { text: S.what })].concat(types)),
424
739
  text,
425
740
  el('div', { class: 'row' }, [
426
- el('span', { class: 'small', text: reporter()
427
- ? 'This page, the app version and your preferences are attached.'
428
- : 'This page and the app version are attached.' }),
741
+ el('span', { class: 'small', text: reporter() ? S.attachedPrefs : S.attached }),
429
742
  sendBtn,
430
743
  ]),
431
744
  err,
@@ -439,29 +752,28 @@
439
752
  var status = el('span', { class: 'small', role: 'status' });
440
753
  var field = function (label, input, hint) {
441
754
  return el('label', { class: 'field' }, [
442
- el('span', {}, [document.createTextNode(label + ' '), el('i', { text: '(optional)' })]),
755
+ el('span', {}, [document.createTextNode(label + ' '), el('i', { text: S.optional })]),
443
756
  input, hint ? el('span', { class: 'hint', text: hint }) : null,
444
757
  ]);
445
758
  };
446
759
  var name = el('input', { type: 'text', maxlength: '80', autocomplete: 'name' });
447
760
  var email = el('input', { type: 'email', maxlength: '200', autocomplete: 'email' });
448
- var note = el('textarea', { maxlength: '500', placeholder: 'For example: I use a screen reader, or I am usually on slow Wi-Fi.' });
761
+ var note = el('textarea', { maxlength: '500', placeholder: S.setupPh });
449
762
  name.value = p.name || ''; email.value = p.email || ''; note.value = p.note || '';
450
763
  var err = el('div', { class: 'err', role: 'alert' });
451
764
 
452
765
  // Signed in: the app already told the team who this is. Say so, and ask nothing twice.
453
766
  var who = null;
454
767
  if (signedIn) {
455
- var shown = state.userLabel || state.userEmail || 'your account';
768
+ var shown = state.userLabel || state.userEmail || S.yourAccount;
456
769
  var initials = (state.userLabel || state.userEmail || '?').split(/[\s@.]+/).filter(Boolean).slice(0, 2)
457
770
  .map(function (w) { return w[0].toUpperCase(); }).join('');
458
771
  who = el('div', { class: 'who' }, [
459
772
  el('span', { class: 'avatar', 'aria-hidden': 'true', text: initials }),
460
773
  el('div', {}, [
461
- el('b', { text: 'Signed in as ' + shown }),
774
+ el('b', { text: fmt(S.signedAs, { who: shown }) }),
462
775
  el('span', { class: 'small', text: state.userEmail && state.userLabel
463
- ? state.userEmail + '. The team sees this with each report and can reply.'
464
- : 'The team sees this with each report.' }),
776
+ ? fmt(S.seesReply, { email: state.userEmail }) : S.sees }),
465
777
  ]),
466
778
  ]);
467
779
  }
@@ -472,25 +784,25 @@
472
784
  e.preventDefault();
473
785
  err.textContent = '';
474
786
  var em = email.value.trim();
475
- if (!signedIn && em && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(em)) { err.textContent = 'That email does not look right.'; email.focus(); return; }
787
+ if (!signedIn && em && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(em)) { err.textContent = S.badEmail; email.focus(); return; }
476
788
  savePrefs(signedIn ? { name: p.name, email: p.email, note: note.value.trim() }
477
789
  : { name: name.value.trim(), email: em, note: note.value.trim() });
478
- status.textContent = 'Saved on this device.';
790
+ status.textContent = S.saved;
479
791
  },
480
792
  }, [
481
793
  who,
482
- signedIn ? null : field('Your name', name),
483
- signedIn ? null : field('Email', email, 'Only if you are happy for the team to reply to you.'),
484
- field('About your setup', note, 'Sent with every report, so you only say it once.'),
794
+ signedIn ? null : field(S.yourName, name),
795
+ signedIn ? null : field(S.email, email, S.emailHint),
796
+ field(S.setup, note, S.setupHint),
485
797
  el('div', { class: 'row' }, [
486
- el('button', { class: 'link', type: 'button', text: 'Clear all', onclick: function () {
798
+ el('button', { class: 'link', type: 'button', text: S.clear, onclick: function () {
487
799
  savePrefs({});
488
800
  renderPanel();
489
801
  } }),
490
- el('span', {}, [status, document.createTextNode(' '), el('button', { class: 'send', type: 'submit', text: 'Save' })]),
802
+ el('span', {}, [status, document.createTextNode(' '), el('button', { class: 'send', type: 'submit', text: S.save })]),
491
803
  ]),
492
804
  err,
493
- el('p', { class: 'small', text: 'Kept in this browser and sent only with reports you choose to send.' }),
805
+ el('p', { class: 'small', text: S.kept }),
494
806
  ]);
495
807
  }
496
808
 
@@ -503,8 +815,9 @@
503
815
  function renderList() {
504
816
  if (!listBox) return;
505
817
  listBox.textContent = '';
818
+ if (state.justSent && THANKS) listBox.appendChild(el('div', { class: 'thanks', role: 'status', text: THANKS }));
506
819
  if (!state.reports.length) {
507
- listBox.appendChild(el('div', { class: 'empty', text: 'Nothing sent from this device yet.' }));
820
+ listBox.appendChild(el('div', { class: 'empty', text: S.none }));
508
821
  return;
509
822
  }
510
823
  var s = seen();
@@ -512,11 +825,11 @@
512
825
  var label = (TYPES.filter(function (t) { return t.id === r.type; })[0] || {}).label || r.type;
513
826
  var fresh = r.status !== 'open' && s[r.id] !== r.status;
514
827
  listBox.appendChild(el('div', { class: 'item' }, [
515
- el('div', { class: 'status ' + r.status, text: (fresh ? '● ' : '') + STATUS[r.status] }),
828
+ el('div', { class: 'status ' + r.status, text: (fresh ? '● ' : '') + (S.status[r.status] || r.status) }),
516
829
  el('div', { class: 'text', text: r.text }),
517
- el('div', { class: 'small', text: label + ' · ' + new Date(r.created_at).toLocaleDateString() }),
830
+ el('div', { class: 'small', text: label + ' · ' + new Date(r.created_at).toLocaleDateString(LANG) }),
518
831
  r.status === 'declined' && r.decline_reason
519
- ? el('div', { class: 'reason', text: 'Why: ' + r.decline_reason }) : null,
832
+ ? el('div', { class: 'reason', text: S.why + r.decline_reason }) : null,
520
833
  r.status === 'fixed' && r.fix_note
521
834
  ? el('div', { class: 'reason', text: r.fix_note }) : null,
522
835
  ]));
@@ -527,19 +840,25 @@
527
840
 
528
841
  // People can't use a button they never noticed. Once per device and app, a bubble says what it
529
842
  // is for. The host app picks the moment (introduce()), or data-intro="auto" does it on load.
843
+ // With no button on screen (data-button="none", a hidden path, a phone in desktop mode) there
844
+ // is nothing to point at, so it does nothing; the app tells people about its own menu item.
530
845
  var INTRO_KEY = 'fbsdk.introduced.' + KEY;
531
846
  var bubble = null;
532
- function introduce() {
533
- if (dead || bubble || scrim || load(INTRO_KEY)) return false;
847
+ function introduce(o) {
848
+ o = o || {};
849
+ if (!revealed && !hiddenHere()) reveal();
850
+ if (dead || bubble || scrim || load(INTRO_KEY) || !fabShowing()) return false;
534
851
  save(INTRO_KEY, new Date().toISOString());
535
852
  var done = function () { if (bubble) { bubble.remove(); bubble = null; } };
536
- bubble = el('div', { class: 'intro' + (LEFT ? ' left' : ''), role: 'dialog', 'aria-label': 'About the Report button' }, [
537
- el('b', { text: 'Something not right? Tell the team.' }),
538
- el('p', { text: 'Use Report to say what is broken, confusing or could be better. A person reads every report, and you will see what happens to yours right here.' }),
853
+ var label = LABEL === S.report ? LABEL : '“' + LABEL + '”';
854
+ bubble = el('div', { class: 'intro ' + PLACE + ' st-' + STYLE, role: 'dialog', 'aria-label': S.introAria }, [
855
+ el('b', { text: words(o.title, 80) || S.introTitle }),
856
+ el('p', { text: words(o.body, 280) || fmt(S.introBody, { label: label }) }),
539
857
  el('div', { class: 'row' }, [
540
- el('button', { class: 'link', type: 'button', text: 'Got it', onclick: done }),
541
- el('button', { class: 'send', type: 'button', text: 'Try it', onclick: function () { done(); open('new'); } }),
858
+ el('button', { class: 'link', type: 'button', text: S.got, onclick: done }),
859
+ el('button', { class: 'send', type: 'button', text: S.tryIt, onclick: function () { done(); open('new'); } }),
542
860
  ]),
861
+ byline(false),
543
862
  ]);
544
863
  bubble.addEventListener('keydown', function (e) { if (e.key === 'Escape') done(); });
545
864
  root.appendChild(bubble);
@@ -549,8 +868,9 @@
549
868
  function mount() {
550
869
  if (dead) return;
551
870
  if (!host.isConnected) document.body.appendChild(host);
871
+ placeFab();
552
872
  refresh();
553
- if (script.getAttribute('data-intro') === 'auto') setTimeout(introduce, 3000);
873
+ if (attr('intro') === 'auto') setTimeout(introduce, 3000);
554
874
  }
555
875
  if (document.body) mount(); else document.addEventListener('DOMContentLoaded', mount);
556
876
 
@@ -565,10 +885,22 @@
565
885
  },
566
886
  setVersion: function (v) { state.version = v != null ? String(v) : null; },
567
887
  setScreen: function (s) { state.screen = s != null ? String(s) : null; },
568
- open: function () { open('new'); },
569
- openPreferences: function () { open('prefs'); },
888
+ /** Open the report form. { type, text } fill it in; the reporter still reviews and sends. */
889
+ open: function (o) {
890
+ o = o || {};
891
+ if (OFFERED.some(function (t) { return t.id === o.type; })) state.type = o.type;
892
+ if (o.text != null) state.draft = String(o.text).slice(0, 2000);
893
+ open('new');
894
+ },
895
+ openPreferences: function () { if (PREFS_TAB) open('prefs'); },
570
896
  /** Show the one-time introduction now. False if it was already shown on this device. */
571
- introduce: function () { return introduce(); },
897
+ introduce: function (o) { return introduce(o); },
898
+ /** on('sent', fn): fn({ id, type }) after each report is sent. Returns a function that stops it. */
899
+ on: function (event, fn) {
900
+ if (event !== 'sent' || typeof fn !== 'function') return function () {};
901
+ listeners.push(fn);
902
+ return function () { listeners = listeners.filter(function (f) { return f !== fn; }); };
903
+ },
572
904
  close: close,
573
905
  };
574
906
  })();