@zoho_apptics/apptics-js-sdk 2.0.0-beta.2 → 2.0.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/CHANGELOG.md +47 -0
- package/README.md +229 -174
- package/dist/apptics-pn-sw.js +3 -0
- package/dist/apptics-pn-sw.js.map +1 -0
- package/dist/apptics.esm.min.js +2 -2
- package/dist/apptics.esm.min.js.map +1 -1
- package/dist/apptics.min.js +2 -2
- package/dist/apptics.min.js.map +1 -1
- package/dist/chunks/batch-Axq9sTzR.min.js +3 -0
- package/dist/chunks/batch-Axq9sTzR.min.js.map +1 -0
- package/dist/chunks/lifecycle-Cvg78jN_.min.js +3 -0
- package/dist/chunks/lifecycle-Cvg78jN_.min.js.map +1 -0
- package/dist/chunks/send-DBpesydB.min.js +3 -0
- package/dist/chunks/send-DBpesydB.min.js.map +1 -0
- package/dist/chunks/transport-B21X39p4.min.js +3 -0
- package/dist/chunks/transport-B21X39p4.min.js.map +1 -0
- package/dist/cjs/core/attempts.js +1 -1
- package/dist/cjs/core/batch.js +4 -3
- package/dist/cjs/core/consent.d.ts +9 -6
- package/dist/cjs/core/consent.js +63 -10
- package/dist/cjs/core/console-call.d.ts +23 -0
- package/dist/cjs/core/console-call.js +63 -0
- package/dist/cjs/core/constants.d.ts +44 -0
- package/dist/cjs/core/constants.js +55 -1
- package/dist/cjs/core/db.js +31 -7
- package/dist/cjs/core/debug.d.ts +6 -4
- package/dist/cjs/core/debug.js +36 -12
- package/dist/cjs/core/env.js +1 -1
- package/dist/cjs/core/framework-id.d.ts +1 -1
- package/dist/cjs/core/framework-id.js +3 -3
- package/dist/cjs/core/guard.js +19 -4
- package/dist/cjs/core/hooks.d.ts +25 -1
- package/dist/cjs/core/hooks.js +11 -1
- package/dist/cjs/core/locks.js +1 -1
- package/dist/cjs/core/logger.js +1 -1
- package/dist/cjs/core/shield.d.ts +31 -0
- package/dist/cjs/core/shield.js +129 -0
- package/dist/cjs/core/state.d.ts +5 -1
- package/dist/cjs/core/state.js +3 -1
- package/dist/cjs/core/storage.d.ts +7 -0
- package/dist/cjs/core/storage.js +28 -6
- package/dist/cjs/core/stylesheet.js +1 -1
- package/dist/cjs/core/transport.d.ts +15 -4
- package/dist/cjs/core/transport.js +63 -13
- package/dist/cjs/core/utils.js +1 -1
- package/dist/cjs/core/validate.js +6 -5
- package/dist/cjs/device/appversion.js +1 -1
- package/dist/cjs/device/index.js +63 -15
- package/dist/cjs/engagement/api-rules.js +1 -1
- package/dist/cjs/engagement/auto-api.js +4 -3
- package/dist/cjs/engagement/auto-screen.js +10 -6
- package/dist/cjs/engagement/defined-events.d.ts +2 -3
- package/dist/cjs/engagement/defined-events.js +10 -16
- package/dist/cjs/engagement/send.js +1 -1
- package/dist/cjs/engagement/session.js +77 -37
- package/dist/cjs/engagement/track.js +9 -6
- package/dist/cjs/errors/send.js +1 -1
- package/dist/cjs/errors/track.js +3 -2
- package/dist/cjs/feedback/controls.d.ts +30 -4
- package/dist/cjs/feedback/controls.js +237 -51
- package/dist/cjs/feedback/i18n/index.d.ts +31 -0
- package/dist/cjs/feedback/i18n/index.js +187 -0
- package/dist/cjs/feedback/i18n/strings.d.ts +9 -0
- package/dist/cjs/feedback/i18n/strings.js +8 -0
- package/dist/cjs/feedback/index.js +1 -1
- package/dist/cjs/feedback/logs.js +5 -4
- package/dist/cjs/feedback/quartz.js +5 -2
- package/dist/cjs/feedback/send.d.ts +4 -1
- package/dist/cjs/feedback/send.js +56 -15
- package/dist/cjs/feedback/styles.js +2 -2
- package/dist/cjs/feedback/template.d.ts +4 -2
- package/dist/cjs/feedback/template.js +67 -46
- package/dist/cjs/feedback/ui.d.ts +40 -4
- package/dist/cjs/feedback/ui.js +208 -89
- package/dist/cjs/heatmap/send.js +1 -1
- package/dist/cjs/heatmap/track.js +13 -9
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/lifecycle.js +119 -72
- package/dist/cjs/pushnotification/display.d.ts +65 -0
- package/dist/cjs/pushnotification/display.js +112 -0
- package/dist/cjs/pushnotification/index.d.ts +20 -0
- package/dist/cjs/pushnotification/index.js +96 -0
- package/dist/cjs/pushnotification/kept-opens.d.ts +23 -0
- package/dist/cjs/pushnotification/kept-opens.js +64 -0
- package/dist/cjs/pushnotification/notify.d.ts +45 -0
- package/dist/cjs/pushnotification/notify.js +476 -0
- package/dist/cjs/pushnotification/payload.d.ts +65 -0
- package/dist/cjs/pushnotification/payload.js +279 -0
- package/dist/cjs/pushnotification/session.d.ts +46 -0
- package/dist/cjs/pushnotification/session.js +413 -0
- package/dist/cjs/pushnotification/stats.d.ts +45 -0
- package/dist/cjs/pushnotification/stats.js +244 -0
- package/dist/cjs/pushnotification/wms.d.ts +30 -0
- package/dist/cjs/pushnotification/wms.js +374 -0
- package/dist/cjs/remoteconfig/country.js +1 -1
- package/dist/cjs/remoteconfig/custom.js +4 -3
- package/dist/cjs/remoteconfig/evaluate.js +1 -1
- package/dist/cjs/remoteconfig/fetch.js +27 -8
- package/dist/cjs/remoteconfig/index.d.ts +1 -6
- package/dist/cjs/remoteconfig/index.js +4 -28
- package/dist/cjs/remoteconfig/store.js +1 -1
- package/dist/cjs/remoteconfig/tz-countries.js +1 -1
- package/dist/cjs/remotelog/callsite.js +1 -1
- package/dist/cjs/remotelog/gate.js +1 -1
- package/dist/cjs/remotelog/logger.js +1 -1
- package/dist/cjs/remotelog/send.js +5 -4
- package/dist/cjs/remotelogger/index.js +1 -1
- package/dist/cjs/scheduler.js +11 -5
- package/dist/cjs/sw/apptics-pn-sw.d.ts +83 -0
- package/dist/cjs/sw/timers.d.ts +44 -0
- package/dist/cjs/types.d.ts +31 -15
- package/dist/cjs/user/index.d.ts +7 -0
- package/dist/cjs/user/index.js +25 -7
- package/dist/esm/core/attempts.js +1 -1
- package/dist/esm/core/batch.js +4 -3
- package/dist/esm/core/consent.d.ts +9 -6
- package/dist/esm/core/consent.js +67 -16
- package/dist/esm/core/console-call.d.ts +23 -0
- package/dist/esm/core/console-call.js +60 -0
- package/dist/esm/core/constants.d.ts +44 -0
- package/dist/esm/core/constants.js +52 -2
- package/dist/esm/core/db.js +31 -7
- package/dist/esm/core/debug.d.ts +6 -4
- package/dist/esm/core/debug.js +37 -13
- package/dist/esm/core/env.js +1 -1
- package/dist/esm/core/framework-id.d.ts +1 -1
- package/dist/esm/core/framework-id.js +3 -3
- package/dist/esm/core/guard.js +19 -4
- package/dist/esm/core/hooks.d.ts +25 -1
- package/dist/esm/core/hooks.js +11 -1
- package/dist/esm/core/locks.js +1 -1
- package/dist/esm/core/logger.js +1 -1
- package/dist/esm/core/shield.d.ts +31 -0
- package/dist/esm/core/shield.js +119 -0
- package/dist/esm/core/state.d.ts +5 -1
- package/dist/esm/core/state.js +3 -1
- package/dist/esm/core/storage.d.ts +7 -0
- package/dist/esm/core/storage.js +28 -8
- package/dist/esm/core/stylesheet.js +1 -1
- package/dist/esm/core/transport.d.ts +15 -4
- package/dist/esm/core/transport.js +64 -16
- package/dist/esm/core/utils.js +1 -1
- package/dist/esm/core/validate.js +6 -5
- package/dist/esm/device/appversion.js +1 -1
- package/dist/esm/device/index.js +67 -19
- package/dist/esm/engagement/api-rules.js +1 -1
- package/dist/esm/engagement/auto-api.js +4 -3
- package/dist/esm/engagement/auto-screen.js +10 -6
- package/dist/esm/engagement/defined-events.d.ts +2 -3
- package/dist/esm/engagement/defined-events.js +10 -16
- package/dist/esm/engagement/send.js +1 -1
- package/dist/esm/engagement/session.js +77 -37
- package/dist/esm/engagement/track.js +9 -6
- package/dist/esm/errors/send.js +1 -1
- package/dist/esm/errors/track.js +3 -2
- package/dist/esm/feedback/controls.d.ts +30 -4
- package/dist/esm/feedback/controls.js +234 -52
- package/dist/esm/feedback/i18n/index.d.ts +31 -0
- package/dist/esm/feedback/i18n/index.js +178 -0
- package/dist/esm/feedback/i18n/strings.d.ts +9 -0
- package/dist/esm/feedback/i18n/strings.js +4 -0
- package/dist/esm/feedback/index.js +1 -1
- package/dist/esm/feedback/logs.js +5 -4
- package/dist/esm/feedback/quartz.js +5 -2
- package/dist/esm/feedback/send.d.ts +4 -1
- package/dist/esm/feedback/send.js +56 -16
- package/dist/esm/feedback/styles.js +2 -2
- package/dist/esm/feedback/template.d.ts +4 -2
- package/dist/esm/feedback/template.js +67 -46
- package/dist/esm/feedback/ui.d.ts +40 -4
- package/dist/esm/feedback/ui.js +210 -91
- package/dist/esm/heatmap/send.js +1 -1
- package/dist/esm/heatmap/track.js +13 -9
- package/dist/esm/index.js +2 -2
- package/dist/esm/lifecycle.js +120 -73
- package/dist/esm/pushnotification/display.d.ts +65 -0
- package/dist/esm/pushnotification/display.js +95 -0
- package/dist/esm/pushnotification/index.d.ts +20 -0
- package/dist/esm/pushnotification/index.js +91 -0
- package/dist/esm/pushnotification/kept-opens.d.ts +23 -0
- package/dist/esm/pushnotification/kept-opens.js +62 -0
- package/dist/esm/pushnotification/notify.d.ts +45 -0
- package/dist/esm/pushnotification/notify.js +469 -0
- package/dist/esm/pushnotification/payload.d.ts +65 -0
- package/dist/esm/pushnotification/payload.js +272 -0
- package/dist/esm/pushnotification/session.d.ts +46 -0
- package/dist/esm/pushnotification/session.js +402 -0
- package/dist/esm/pushnotification/stats.d.ts +45 -0
- package/dist/esm/pushnotification/stats.js +238 -0
- package/dist/esm/pushnotification/wms.d.ts +30 -0
- package/dist/esm/pushnotification/wms.js +368 -0
- package/dist/esm/remoteconfig/country.js +1 -1
- package/dist/esm/remoteconfig/custom.js +4 -3
- package/dist/esm/remoteconfig/evaluate.js +1 -1
- package/dist/esm/remoteconfig/fetch.js +27 -8
- package/dist/esm/remoteconfig/index.d.ts +1 -6
- package/dist/esm/remoteconfig/index.js +4 -28
- package/dist/esm/remoteconfig/store.js +1 -1
- package/dist/esm/remoteconfig/tz-countries.js +1 -1
- package/dist/esm/remotelog/callsite.js +1 -1
- package/dist/esm/remotelog/gate.js +1 -1
- package/dist/esm/remotelog/logger.js +1 -1
- package/dist/esm/remotelog/send.js +5 -4
- package/dist/esm/remotelogger/index.js +1 -1
- package/dist/esm/scheduler.js +11 -5
- package/dist/esm/sw/apptics-pn-sw.d.ts +83 -0
- package/dist/esm/sw/timers.d.ts +44 -0
- package/dist/esm/types.d.ts +31 -15
- package/dist/esm/user/index.d.ts +7 -0
- package/dist/esm/user/index.js +26 -9
- package/dist/feedback.esm.min.js +2 -2
- package/dist/feedback.esm.min.js.map +1 -1
- package/dist/pushnotification.esm.min.js +3 -0
- package/dist/pushnotification.esm.min.js.map +1 -0
- package/dist/remoteconfig.esm.min.js +2 -2
- package/dist/remoteconfig.esm.min.js.map +1 -1
- package/dist/remotelogger.esm.min.js +2 -2
- package/dist/remotelogger.esm.min.js.map +1 -1
- package/package.json +15 -2
- package/dist/chunks/lifecycle-C6m1W7jo.min.js +0 -3
- package/dist/chunks/lifecycle-C6m1W7jo.min.js.map +0 -1
- package/dist/chunks/send-CgUO82ne.min.js +0 -3
- package/dist/chunks/send-CgUO82ne.min.js.map +0 -1
|
@@ -12,6 +12,21 @@ export declare const logChoice: {
|
|
|
12
12
|
includeLog?: boolean;
|
|
13
13
|
includeDyninfo?: boolean;
|
|
14
14
|
};
|
|
15
|
+
/** The entry the user picker has selected, for the same form rebuilt in another language. */
|
|
16
|
+
export declare function pickedUser(): string;
|
|
17
|
+
/** What the data viewer shows, while it is open: the same form rebuilt in another language shows it again. */
|
|
18
|
+
export interface ViewerShown {
|
|
19
|
+
titleKey: string;
|
|
20
|
+
content: string;
|
|
21
|
+
}
|
|
22
|
+
/** The viewer's title key and content while it is open, else null. */
|
|
23
|
+
export declare function shownViewer(): ViewerShown | null;
|
|
24
|
+
/** What a form rebuilt in another language keeps of the switches and the viewer. Unset decides as a new form does. */
|
|
25
|
+
export interface LogKeep {
|
|
26
|
+
includeLog?: boolean;
|
|
27
|
+
includeDyninfo?: boolean;
|
|
28
|
+
viewer?: ViewerShown | null;
|
|
29
|
+
}
|
|
15
30
|
/**
|
|
16
31
|
* Who a sendFeedback() report, made without the form, is attributed to: nobody when `anonymous`,
|
|
17
32
|
* else the user AppticsUser.setUser set (or the active registered one, status 1). Returns a function
|
|
@@ -20,15 +35,26 @@ export declare const logChoice: {
|
|
|
20
35
|
export declare function chooseUserForSend(anonymous: boolean): () => void;
|
|
21
36
|
/**
|
|
22
37
|
* The "User" dropdown above the description. It lists Anonymous plus every registered user, and
|
|
23
|
-
* starts on the active one (status 1) unless the caller asked for anonymous
|
|
38
|
+
* starts on the active one (status 1) unless the caller asked for anonymous; `keep`, the entry a
|
|
39
|
+
* form rebuilt in another language had selected, wins over both while it is still listed.
|
|
40
|
+
*/
|
|
41
|
+
export declare function wireUserPicker(modal: HTMLElement, forceAnonymous: boolean, keep?: string): void;
|
|
42
|
+
/** A language's own name, its label without the English name in brackets: Deutsch, Español – México. */
|
|
43
|
+
export declare function ownName(label: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* The language dropdown in the header. It lists every language the form has, English first, each
|
|
46
|
+
* by its own name; picking one is remembered for the next form and hands over to `picked`, which
|
|
47
|
+
* builds this one again in it. Built as the user picker is, and closed the same way (focusout, so
|
|
48
|
+
* it works in a shadow root), with the keys a listbox takes: arrows to move, Enter or Space to
|
|
49
|
+
* pick, Escape to close.
|
|
24
50
|
*/
|
|
25
|
-
export declare function
|
|
51
|
+
export declare function wireLangPicker(modal: HTMLElement, picked: () => void): void;
|
|
26
52
|
/**
|
|
27
53
|
* The two "Include …" switches and the viewer behind their View links. A row is shown only when
|
|
28
54
|
* there is something to include, and is then on by default, so a submission carries what the app
|
|
29
|
-
* recorded unless the user turns it off.
|
|
55
|
+
* recorded unless the user turns it off. `keep` is what a form rebuilt in another language had.
|
|
30
56
|
*/
|
|
31
|
-
export declare function wireLogControls(modal: HTMLElement, opts: Dict): void;
|
|
57
|
+
export declare function wireLogControls(modal: HTMLElement, opts: Dict, keep?: LogKeep): void;
|
|
32
58
|
/**
|
|
33
59
|
* Drags the dialog by its header. The right/bottom placement from the stylesheet is converted to
|
|
34
60
|
* an explicit left/top on the first drag, so the offsets have something to add to, and the box is
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
/*! @zoho_apptics/apptics-js-sdk v2.0.0
|
|
1
|
+
/*! @zoho_apptics/apptics-js-sdk v2.0.0 | (c) Zoho Corporation Private Limited | see LICENSE */
|
|
2
2
|
import { Console } from '../core/logger.js';
|
|
3
3
|
import { hooks } from '../core/hooks.js';
|
|
4
4
|
import { user_defaults } from '../core/storage.js';
|
|
5
5
|
import { isEmpty } from '../core/utils.js';
|
|
6
6
|
import { _ZAP } from '../core/state.js';
|
|
7
7
|
import { hasLogLines, hasDiagnostics, logText, diagnosticsText } from './logs.js';
|
|
8
|
+
import { shield, quietly } from '../core/shield.js';
|
|
9
|
+
import { feedbackLocale, FEEDBACK_LOCALES, getLocale, setFeedbackLocale } from './i18n/index.js';
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* The three controls at the top and bottom of the feedback form: the user picker, the
|
|
@@ -14,11 +16,21 @@ import { hasLogLines, hasDiagnostics, logText, diagnosticsText } from './logs.js
|
|
|
14
16
|
* control can be wired (and read back) on its own.
|
|
15
17
|
*/
|
|
16
18
|
const ANONYMOUS = 'anonymous'; // no i18n
|
|
17
|
-
const ANONYMOUS_LABEL = 'Anonymous'; // no i18n
|
|
18
19
|
/** Read by core/transport when it builds the feedback request's parameters. */
|
|
19
20
|
const userChoice = { anonymous: true, userid: '', groupid: '' }; // no i18n
|
|
20
21
|
/** Whether the next submission carries the stored logs and diagnostics. Unset means "decide from what is stored". */
|
|
21
22
|
const logChoice = {};
|
|
23
|
+
/** The picker's selected entry: 'anonymous' or a user's address. Read when the form is rebuilt in another language. */
|
|
24
|
+
var pickedValue = ANONYMOUS;
|
|
25
|
+
/** The entry the user picker has selected, for the same form rebuilt in another language. */
|
|
26
|
+
function pickedUser() {
|
|
27
|
+
return pickedValue;
|
|
28
|
+
}
|
|
29
|
+
var viewerShown = null;
|
|
30
|
+
/** The viewer's title key and content while it is open, else null. */
|
|
31
|
+
function shownViewer() {
|
|
32
|
+
return viewerShown;
|
|
33
|
+
}
|
|
22
34
|
function resetUserChoice() {
|
|
23
35
|
userChoice.anonymous = true;
|
|
24
36
|
userChoice.userid = ''; // no i18n
|
|
@@ -57,8 +69,9 @@ function storedUsers() {
|
|
|
57
69
|
var users = user_defaults.item('users'); // no i18n
|
|
58
70
|
return Array.isArray(users) ? users : [];
|
|
59
71
|
}
|
|
72
|
+
/** The picker's entries: Anonymous, named by its key, then each address as it is. */
|
|
60
73
|
function pickerItems(users) {
|
|
61
|
-
var items = [{ value: ANONYMOUS, label:
|
|
74
|
+
var items = [{ value: ANONYMOUS, label: '', key: 'fdk.user.anonymous' }]; // no i18n
|
|
62
75
|
var seen = {};
|
|
63
76
|
users.forEach(function (user) {
|
|
64
77
|
var mam = user && user.mam;
|
|
@@ -88,9 +101,10 @@ function tickIcon() {
|
|
|
88
101
|
}
|
|
89
102
|
/**
|
|
90
103
|
* The "User" dropdown above the description. It lists Anonymous plus every registered user, and
|
|
91
|
-
* starts on the active one (status 1) unless the caller asked for anonymous
|
|
104
|
+
* starts on the active one (status 1) unless the caller asked for anonymous; `keep`, the entry a
|
|
105
|
+
* form rebuilt in another language had selected, wins over both while it is still listed.
|
|
92
106
|
*/
|
|
93
|
-
function wireUserPicker(modal, forceAnonymous) {
|
|
107
|
+
function wireUserPicker(modal, forceAnonymous, keep) {
|
|
94
108
|
var trigger = modal.querySelector('#zasdkEmailTrigger'); // no i18n
|
|
95
109
|
var panel = modal.querySelector('#zasdkEmailPanel'); // no i18n
|
|
96
110
|
var label = modal.querySelector('#zasdkEmailLabel'); // no i18n
|
|
@@ -103,6 +117,7 @@ function wireUserPicker(modal, forceAnonymous) {
|
|
|
103
117
|
var items = pickerItems(users);
|
|
104
118
|
var selected = ANONYMOUS;
|
|
105
119
|
resetUserChoice();
|
|
120
|
+
pickedValue = ANONYMOUS;
|
|
106
121
|
if (!forceAnonymous) {
|
|
107
122
|
var active = null;
|
|
108
123
|
users.forEach(function (user) {
|
|
@@ -114,8 +129,12 @@ function wireUserPicker(modal, forceAnonymous) {
|
|
|
114
129
|
select(String(active.mam));
|
|
115
130
|
}
|
|
116
131
|
}
|
|
132
|
+
if (keep !== undefined && items.some(function (item) { return item.value === keep; })) {
|
|
133
|
+
select(keep);
|
|
134
|
+
}
|
|
117
135
|
function select(value) {
|
|
118
136
|
selected = value;
|
|
137
|
+
pickedValue = value;
|
|
119
138
|
userChoice.anonymous = value === ANONYMOUS;
|
|
120
139
|
var matched = null;
|
|
121
140
|
if (!userChoice.anonymous) {
|
|
@@ -127,7 +146,7 @@ function wireUserPicker(modal, forceAnonymous) {
|
|
|
127
146
|
}
|
|
128
147
|
userChoice.userid = matched ? String(matched.userid || '') : ''; // no i18n
|
|
129
148
|
userChoice.groupid = matched ? String(matched.groupid || '') : ''; // no i18n
|
|
130
|
-
label.textContent = userChoice.anonymous ?
|
|
149
|
+
label.textContent = userChoice.anonymous ? getLocale('fdk.user.anonymous') : value; // no i18n
|
|
131
150
|
render();
|
|
132
151
|
}
|
|
133
152
|
function render() {
|
|
@@ -135,7 +154,7 @@ function wireUserPicker(modal, forceAnonymous) {
|
|
|
135
154
|
if (items.length === 0) {
|
|
136
155
|
var empty = document.createElement('div'); // no i18n
|
|
137
156
|
empty.className = 'zasdk-select-empty'; // no i18n
|
|
138
|
-
empty.textContent = '
|
|
157
|
+
empty.textContent = getLocale('fdk.user.none'); // no i18n
|
|
139
158
|
list.appendChild(empty);
|
|
140
159
|
return;
|
|
141
160
|
}
|
|
@@ -145,7 +164,7 @@ function wireUserPicker(modal, forceAnonymous) {
|
|
|
145
164
|
option.className = 'zasdk-select-option' + (isSelected ? ' zasdk-option-selected' : ''); // no i18n
|
|
146
165
|
option.setAttribute('data-value', item.value); // no i18n
|
|
147
166
|
var text = document.createElement('span'); // no i18n
|
|
148
|
-
text.textContent = item.label;
|
|
167
|
+
text.textContent = item.key ? getLocale(item.key) : item.label;
|
|
149
168
|
option.appendChild(text);
|
|
150
169
|
if (isSelected) {
|
|
151
170
|
option.appendChild(tickIcon());
|
|
@@ -153,49 +172,200 @@ function wireUserPicker(modal, forceAnonymous) {
|
|
|
153
172
|
list.appendChild(option);
|
|
154
173
|
});
|
|
155
174
|
}
|
|
156
|
-
trigger.addEventListener('click', function (event) {
|
|
175
|
+
trigger.addEventListener('click', shield('AppticsFeedback', function (event) {
|
|
157
176
|
event.stopPropagation();
|
|
158
177
|
var open = panel.style.display !== 'none'; // no i18n
|
|
159
178
|
panel.style.display = open ? 'none' : 'block'; // no i18n
|
|
160
179
|
if (!open) {
|
|
161
180
|
render();
|
|
162
181
|
}
|
|
163
|
-
});
|
|
164
|
-
list.addEventListener('click', function (event) {
|
|
182
|
+
}));
|
|
183
|
+
list.addEventListener('click', shield('AppticsFeedback', function (event) {
|
|
165
184
|
var option = event.target.closest('.zasdk-select-option'); // no i18n
|
|
166
185
|
if (!option) {
|
|
167
186
|
return;
|
|
168
187
|
}
|
|
169
188
|
select(String(option.getAttribute('data-value'))); // no i18n
|
|
170
189
|
panel.style.display = 'none'; // no i18n
|
|
171
|
-
});
|
|
190
|
+
}));
|
|
172
191
|
// closing on focusout rather than a document click keeps it working inside a shadow root
|
|
173
192
|
dropdown.setAttribute('tabindex', '0'); // no i18n
|
|
174
|
-
dropdown.addEventListener('focusout', function (event) {
|
|
193
|
+
dropdown.addEventListener('focusout', shield('AppticsFeedback', function (event) {
|
|
175
194
|
if (!dropdown.contains(event.relatedTarget)) {
|
|
176
195
|
panel.style.display = 'none'; // no i18n
|
|
177
196
|
}
|
|
178
|
-
});
|
|
197
|
+
}));
|
|
179
198
|
render();
|
|
180
199
|
}
|
|
181
|
-
/**
|
|
182
|
-
function
|
|
200
|
+
/** A language's own name, its label without the English name in brackets: Deutsch, Español – México. */
|
|
201
|
+
function ownName(label) {
|
|
202
|
+
var cut = label.indexOf(' ('); // no i18n
|
|
203
|
+
return cut === -1 ? label : label.slice(0, cut);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* The language dropdown in the header. It lists every language the form has, English first, each
|
|
207
|
+
* by its own name; picking one is remembered for the next form and hands over to `picked`, which
|
|
208
|
+
* builds this one again in it. Built as the user picker is, and closed the same way (focusout, so
|
|
209
|
+
* it works in a shadow root), with the keys a listbox takes: arrows to move, Enter or Space to
|
|
210
|
+
* pick, Escape to close.
|
|
211
|
+
*/
|
|
212
|
+
function wireLangPicker(modal, picked) {
|
|
213
|
+
var dropdown = modal.querySelector('#zasdkLangDropdown'); // no i18n
|
|
214
|
+
var trigger = modal.querySelector('#zasdkLangTrigger'); // no i18n
|
|
215
|
+
var panel = modal.querySelector('#zasdkLangPanel'); // no i18n
|
|
216
|
+
var list = modal.querySelector('#zasdkLangList'); // no i18n
|
|
217
|
+
if (!dropdown || !trigger || !panel || !list) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
var label = modal.querySelector('#zasdkLangLabel'); // no i18n
|
|
221
|
+
var current = feedbackLocale();
|
|
222
|
+
FEEDBACK_LOCALES.forEach(function (locale) {
|
|
223
|
+
if (label && locale.code === current) {
|
|
224
|
+
label.textContent = ownName(locale.label);
|
|
225
|
+
// the trigger cuts a long name such as "Português – Portugal" short; hovering shows it whole
|
|
226
|
+
label.title = label.textContent;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
function isOpen() {
|
|
230
|
+
return panel.style.display !== 'none'; // no i18n
|
|
231
|
+
}
|
|
232
|
+
function options() {
|
|
233
|
+
return Array.prototype.slice.call(list.querySelectorAll('[role="option"]')); // no i18n
|
|
234
|
+
}
|
|
235
|
+
function render() {
|
|
236
|
+
var current = feedbackLocale();
|
|
237
|
+
list.innerHTML = ''; // no i18n
|
|
238
|
+
FEEDBACK_LOCALES.forEach(function (locale) {
|
|
239
|
+
var on = locale.code === current;
|
|
240
|
+
var option = document.createElement('li'); // no i18n
|
|
241
|
+
option.className = 'zasdk-select-option' + (on ? ' zasdk-option-selected' : ''); // no i18n
|
|
242
|
+
option.setAttribute('role', 'option'); // no i18n
|
|
243
|
+
option.setAttribute('tabindex', '-1'); // no i18n
|
|
244
|
+
option.setAttribute('data-value', locale.code); // no i18n
|
|
245
|
+
option.setAttribute('aria-selected', on ? 'true' : 'false'); // no i18n
|
|
246
|
+
// each name in its own language, so a screen reader says it as it is written
|
|
247
|
+
option.setAttribute('lang', locale.bcp47); // no i18n
|
|
248
|
+
var text = document.createElement('span'); // no i18n
|
|
249
|
+
text.textContent = locale.label;
|
|
250
|
+
option.appendChild(text);
|
|
251
|
+
if (on) {
|
|
252
|
+
option.appendChild(tickIcon());
|
|
253
|
+
}
|
|
254
|
+
list.appendChild(option);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function open() {
|
|
258
|
+
render();
|
|
259
|
+
panel.style.display = 'block'; // no i18n
|
|
260
|
+
trigger.setAttribute('aria-expanded', 'true'); // no i18n
|
|
261
|
+
var current = list.querySelector('[aria-selected="true"]') || options()[0]; // no i18n
|
|
262
|
+
if (current) {
|
|
263
|
+
try {
|
|
264
|
+
current.focus({ preventScroll: false });
|
|
265
|
+
}
|
|
266
|
+
catch (err) { /* focus is a courtesy */ }
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
function close(focusTrigger) {
|
|
270
|
+
panel.style.display = 'none'; // no i18n
|
|
271
|
+
trigger.setAttribute('aria-expanded', 'false'); // no i18n
|
|
272
|
+
if (focusTrigger) {
|
|
273
|
+
try {
|
|
274
|
+
trigger.focus();
|
|
275
|
+
}
|
|
276
|
+
catch (err) { /* focus is a courtesy */ }
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function pick(code) {
|
|
280
|
+
close(false);
|
|
281
|
+
if (code === feedbackLocale()) {
|
|
282
|
+
try {
|
|
283
|
+
trigger.focus();
|
|
284
|
+
}
|
|
285
|
+
catch (err) { /* focus is a courtesy */ }
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
setFeedbackLocale(code);
|
|
289
|
+
picked();
|
|
290
|
+
}
|
|
291
|
+
// macOS Safari and Firefox do not focus a button on mousedown, so focus would fall to the body,
|
|
292
|
+
// focusout would close the list, and the click would then open it again; keeping focus where it
|
|
293
|
+
// is lets the click alone decide. Keyboard use (Enter, Space, arrows) does not go through mousedown.
|
|
294
|
+
trigger.addEventListener('mousedown', function (event) {
|
|
295
|
+
event.preventDefault();
|
|
296
|
+
});
|
|
297
|
+
trigger.addEventListener('click', shield('AppticsFeedback', function (event) {
|
|
298
|
+
event.stopPropagation();
|
|
299
|
+
if (isOpen()) {
|
|
300
|
+
close(true);
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
open();
|
|
304
|
+
}
|
|
305
|
+
}));
|
|
306
|
+
list.addEventListener('click', shield('AppticsFeedback', function (event) {
|
|
307
|
+
var option = event.target.closest('[role="option"]'); // no i18n
|
|
308
|
+
if (option) {
|
|
309
|
+
pick(String(option.getAttribute('data-value'))); // no i18n
|
|
310
|
+
}
|
|
311
|
+
}));
|
|
312
|
+
dropdown.addEventListener('keydown', shield('AppticsFeedback', function (event) {
|
|
313
|
+
var key = event.key;
|
|
314
|
+
if (!isOpen()) {
|
|
315
|
+
if (event.target === trigger && (key === 'ArrowDown' || key === 'ArrowUp')) { // no i18n
|
|
316
|
+
event.preventDefault();
|
|
317
|
+
open();
|
|
318
|
+
}
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
var all = options();
|
|
322
|
+
// the key's target is the focused option; document.activeElement would be a shadow host
|
|
323
|
+
var at = all.indexOf(event.target);
|
|
324
|
+
if (key === 'Escape') { // no i18n
|
|
325
|
+
// closes the list only: the form's own Escape, on the document, never hears it
|
|
326
|
+
event.preventDefault();
|
|
327
|
+
event.stopPropagation();
|
|
328
|
+
close(true);
|
|
329
|
+
}
|
|
330
|
+
else if (key === 'ArrowDown' || key === 'ArrowUp' || key === 'Home' || key === 'End') { // no i18n
|
|
331
|
+
event.preventDefault();
|
|
332
|
+
var next = key === 'Home' ? 0 : key === 'End' ? all.length - 1 // no i18n
|
|
333
|
+
: Math.max(0, Math.min(all.length - 1, at + (key === 'ArrowDown' ? 1 : -1))); // no i18n
|
|
334
|
+
if (all[next]) {
|
|
335
|
+
all[next].focus();
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
else if ((key === 'Enter' || key === ' ') && at !== -1) { // no i18n
|
|
339
|
+
event.preventDefault();
|
|
340
|
+
pick(String(all[at].getAttribute('data-value'))); // no i18n
|
|
341
|
+
}
|
|
342
|
+
}));
|
|
343
|
+
dropdown.addEventListener('focusout', shield('AppticsFeedback', function (event) {
|
|
344
|
+
if (!dropdown.contains(event.relatedTarget)) {
|
|
345
|
+
close(false);
|
|
346
|
+
}
|
|
347
|
+
}));
|
|
348
|
+
}
|
|
349
|
+
/** Shows `content` in the viewer panel over the form, under the title `titleKey` names. */
|
|
350
|
+
function openViewer(modal, titleKey, content) {
|
|
183
351
|
var viewer = modal.querySelector('#zasdkDataViewer'); // no i18n
|
|
184
352
|
var viewerTitle = modal.querySelector('#zasdkViewerTitle'); // no i18n
|
|
185
353
|
var viewerContent = modal.querySelector('#zasdkViewerContent'); // no i18n
|
|
186
354
|
if (!viewer || !viewerTitle || !viewerContent) {
|
|
187
355
|
return;
|
|
188
356
|
}
|
|
189
|
-
viewerTitle.textContent =
|
|
190
|
-
|
|
357
|
+
viewerTitle.textContent = getLocale(titleKey);
|
|
358
|
+
// the logs and diagnostics are data, shown as they are; only the empty note is the form's
|
|
359
|
+
viewerContent.textContent = content ? content : getLocale('fdk.viewer.empty'); // no i18n
|
|
191
360
|
viewer.style.display = 'flex'; // no i18n
|
|
361
|
+
viewerShown = { titleKey: titleKey, content: content };
|
|
192
362
|
}
|
|
193
363
|
/**
|
|
194
364
|
* The two "Include …" switches and the viewer behind their View links. A row is shown only when
|
|
195
365
|
* there is something to include, and is then on by default, so a submission carries what the app
|
|
196
|
-
* recorded unless the user turns it off.
|
|
366
|
+
* recorded unless the user turns it off. `keep` is what a form rebuilt in another language had.
|
|
197
367
|
*/
|
|
198
|
-
function wireLogControls(modal, opts) {
|
|
368
|
+
function wireLogControls(modal, opts, keep) {
|
|
199
369
|
var logToggle = modal.querySelector('#zasdkIncludeLogToggle'); // no i18n
|
|
200
370
|
var diagToggle = modal.querySelector('#zasdkIncludeDiagToggle'); // no i18n
|
|
201
371
|
var section = modal.querySelector('.zasdk-toggles-section'); // no i18n
|
|
@@ -209,8 +379,18 @@ function wireLogControls(modal, opts) {
|
|
|
209
379
|
}
|
|
210
380
|
var logRow = logToggle.closest('.zasdk-toggle-row'); // no i18n
|
|
211
381
|
var diagRow = diagToggle.closest('.zasdk-toggle-row'); // no i18n
|
|
212
|
-
|
|
213
|
-
logChoice.
|
|
382
|
+
var kept = keep || {};
|
|
383
|
+
logChoice.includeLog = typeof kept.includeLog === 'boolean' ? kept.includeLog : opts.includeLog === true ? true : undefined; // no i18n
|
|
384
|
+
logChoice.includeDyninfo = typeof kept.includeDyninfo === 'boolean' ? kept.includeDyninfo : opts.includeDyninfo === true ? true : undefined; // no i18n
|
|
385
|
+
// a rebuilt form shows the switches as the user left them from the start, not once the reads are back
|
|
386
|
+
if (typeof kept.includeLog === 'boolean')
|
|
387
|
+
logToggle.checked = kept.includeLog; // no i18n
|
|
388
|
+
if (typeof kept.includeDyninfo === 'boolean')
|
|
389
|
+
diagToggle.checked = kept.includeDyninfo; // no i18n
|
|
390
|
+
viewerShown = null;
|
|
391
|
+
if (kept.viewer) {
|
|
392
|
+
openViewer(modal, kept.viewer.titleKey, kept.viewer.content);
|
|
393
|
+
}
|
|
214
394
|
// hidden until the reads come back, so an empty section never flashes into view
|
|
215
395
|
section.style.display = 'none'; // no i18n
|
|
216
396
|
Promise.all([hasLogLines(), hasDiagnostics()]).then(function ([anyLogs, anyDiagnostics]) {
|
|
@@ -221,38 +401,39 @@ function wireLogControls(modal, opts) {
|
|
|
221
401
|
if (separator)
|
|
222
402
|
separator.style.display = anyLogs && anyDiagnostics ? '' : 'none'; // no i18n
|
|
223
403
|
section.style.display = anyLogs || anyDiagnostics ? '' : 'none'; // no i18n
|
|
224
|
-
// on when there is data, unless the caller
|
|
225
|
-
logToggle.checked = opts.includeLog === true || anyLogs;
|
|
226
|
-
diagToggle.checked = opts.includeDyninfo === true || anyDiagnostics;
|
|
404
|
+
// on when there is data, unless the caller, or the user before a language was picked, decided
|
|
405
|
+
logToggle.checked = typeof kept.includeLog === 'boolean' ? kept.includeLog : opts.includeLog === true || anyLogs; // no i18n
|
|
406
|
+
diagToggle.checked = typeof kept.includeDyninfo === 'boolean' ? kept.includeDyninfo : opts.includeDyninfo === true || anyDiagnostics; // no i18n
|
|
227
407
|
logChoice.includeLog = logToggle.checked;
|
|
228
408
|
logChoice.includeDyninfo = diagToggle.checked;
|
|
229
409
|
}).catch(function (err) {
|
|
230
410
|
Console.warn('apptics: could not read the stored logs: ' + String(err)); // no i18n
|
|
231
411
|
});
|
|
232
|
-
logToggle.addEventListener('change', function () {
|
|
412
|
+
logToggle.addEventListener('change', shield('AppticsFeedback', function () {
|
|
233
413
|
logChoice.includeLog = logToggle.checked;
|
|
234
|
-
});
|
|
235
|
-
diagToggle.addEventListener('change', function () {
|
|
414
|
+
}));
|
|
415
|
+
diagToggle.addEventListener('change', shield('AppticsFeedback', function () {
|
|
236
416
|
logChoice.includeDyninfo = diagToggle.checked;
|
|
237
|
-
});
|
|
417
|
+
}));
|
|
238
418
|
if (viewLogs) {
|
|
239
|
-
viewLogs.addEventListener('click', function () {
|
|
240
|
-
logText().then(function (text) {
|
|
241
|
-
openViewer(modal, '
|
|
242
|
-
});
|
|
243
|
-
});
|
|
419
|
+
viewLogs.addEventListener('click', shield('AppticsFeedback', function () {
|
|
420
|
+
quietly('AppticsFeedback', logText().then(function (text) {
|
|
421
|
+
openViewer(modal, 'fdk.viewer.logs', text); // no i18n
|
|
422
|
+
}));
|
|
423
|
+
}));
|
|
244
424
|
}
|
|
245
425
|
if (viewDiag) {
|
|
246
|
-
viewDiag.addEventListener('click', function () {
|
|
247
|
-
diagnosticsText().then(function (text) {
|
|
248
|
-
openViewer(modal, '
|
|
249
|
-
});
|
|
250
|
-
});
|
|
426
|
+
viewDiag.addEventListener('click', shield('AppticsFeedback', function () {
|
|
427
|
+
quietly('AppticsFeedback', diagnosticsText().then(function (text) {
|
|
428
|
+
openViewer(modal, 'fdk.viewer.diag', text); // no i18n
|
|
429
|
+
}));
|
|
430
|
+
}));
|
|
251
431
|
}
|
|
252
432
|
if (viewerClose && viewer) {
|
|
253
|
-
viewerClose.addEventListener('click', function () {
|
|
433
|
+
viewerClose.addEventListener('click', shield('AppticsFeedback', function () {
|
|
254
434
|
viewer.style.display = 'none'; // no i18n
|
|
255
|
-
|
|
435
|
+
viewerShown = null;
|
|
436
|
+
}));
|
|
256
437
|
}
|
|
257
438
|
}
|
|
258
439
|
/**
|
|
@@ -266,8 +447,8 @@ function wireDrag(box) {
|
|
|
266
447
|
return;
|
|
267
448
|
}
|
|
268
449
|
makeDraggable(box, header, function (target) {
|
|
269
|
-
// the close button
|
|
270
|
-
return !!target.closest('.zasdk-close'); // no i18n
|
|
450
|
+
// the close button and the language dropdown are not drag handles
|
|
451
|
+
return !!target.closest('.zasdk-close, .zasdk-lang-slot'); // no i18n
|
|
271
452
|
});
|
|
272
453
|
}
|
|
273
454
|
/** Where the recording timer was last dragged to, so the next recording's timer starts there. */
|
|
@@ -298,7 +479,7 @@ function placeAt(box, left, top) {
|
|
|
298
479
|
*/
|
|
299
480
|
function makeDraggable(box, handle, skip, moved) {
|
|
300
481
|
var startX = 0, startY = 0, boxLeft = 0, boxTop = 0, dragging = false, dragged = false;
|
|
301
|
-
handle.addEventListener('pointerdown', function (event) {
|
|
482
|
+
handle.addEventListener('pointerdown', shield('AppticsFeedback', function (event) {
|
|
302
483
|
if (event.button !== 0 || (skip && skip(event.target))) {
|
|
303
484
|
return;
|
|
304
485
|
}
|
|
@@ -317,8 +498,8 @@ function makeDraggable(box, handle, skip, moved) {
|
|
|
317
498
|
}
|
|
318
499
|
catch (err) { /* a pointer already released */ }
|
|
319
500
|
event.preventDefault();
|
|
320
|
-
});
|
|
321
|
-
handle.addEventListener('pointermove', function (event) {
|
|
501
|
+
}));
|
|
502
|
+
handle.addEventListener('pointermove', shield('AppticsFeedback', function (event) {
|
|
322
503
|
if (!dragging) {
|
|
323
504
|
return;
|
|
324
505
|
}
|
|
@@ -328,7 +509,7 @@ function makeDraggable(box, handle, skip, moved) {
|
|
|
328
509
|
}
|
|
329
510
|
dragged = true;
|
|
330
511
|
placeAt(box, boxLeft + dx, boxTop + dy);
|
|
331
|
-
});
|
|
512
|
+
}));
|
|
332
513
|
function stop() {
|
|
333
514
|
if (!dragging) {
|
|
334
515
|
return;
|
|
@@ -339,19 +520,20 @@ function makeDraggable(box, handle, skip, moved) {
|
|
|
339
520
|
moved(parseInt(box.style.left, 10), parseInt(box.style.top, 10));
|
|
340
521
|
}
|
|
341
522
|
}
|
|
342
|
-
|
|
343
|
-
handle.addEventListener('
|
|
344
|
-
|
|
523
|
+
var onStop = shield('AppticsFeedback', stop); // no i18n
|
|
524
|
+
handle.addEventListener('pointerup', onStop); // no i18n
|
|
525
|
+
handle.addEventListener('pointercancel', onStop); // no i18n
|
|
526
|
+
box.addEventListener('click', shield('AppticsFeedback', function (event) {
|
|
345
527
|
if (dragged) {
|
|
346
528
|
dragged = false;
|
|
347
529
|
event.stopImmediatePropagation();
|
|
348
530
|
event.preventDefault();
|
|
349
531
|
}
|
|
350
|
-
}, true);
|
|
532
|
+
}), true);
|
|
351
533
|
}
|
|
352
534
|
// core/transport asks for the picked user when it builds the feedback request's parameters
|
|
353
535
|
hooks.feedbackUser = function () {
|
|
354
536
|
return userChoice.anonymous || isEmpty(userChoice.userid) ? null : userChoice;
|
|
355
537
|
};
|
|
356
538
|
|
|
357
|
-
export { chooseUserForSend, logChoice, userChoice, wireDrag, wireLogControls, wireTimerDrag, wireUserPicker };
|
|
539
|
+
export { chooseUserForSend, logChoice, ownName, pickedUser, shownViewer, userChoice, wireDrag, wireLangPicker, wireLogControls, wireTimerDrag, wireUserPicker };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The feedback form's languages: the dropdown's text (own name, then the English name) and the
|
|
3
|
+
* BCP 47 tag the form root gets as its lang. English comes first and is the fallback for every key.
|
|
4
|
+
*/
|
|
5
|
+
export declare const FEEDBACK_LOCALES: readonly {
|
|
6
|
+
code: string;
|
|
7
|
+
label: string;
|
|
8
|
+
bcp47: string;
|
|
9
|
+
}[];
|
|
10
|
+
/** The locale for the browser's language preferences: the first that matches, else English. */
|
|
11
|
+
export declare function matchLocale(preferences: readonly string[]): string;
|
|
12
|
+
/** The stored pick if there is one, else what the browser asks for, else English. */
|
|
13
|
+
export declare function feedbackLocale(): string;
|
|
14
|
+
/** Remembers the language the user picked; a code the form doesn't have is ignored. */
|
|
15
|
+
export declare function setFeedbackLocale(code: string): void;
|
|
16
|
+
/** What fills a text's $1, $2...: a list, or one value on its own, as UI 2.0's getLocale takes them. */
|
|
17
|
+
export type LocaleParams = readonly (string | number)[] | string | number | null;
|
|
18
|
+
/**
|
|
19
|
+
* The text for a key in the form's language, else in English, else the key, with $1, $2... filled
|
|
20
|
+
* from params: UI 2.0's getLocale, so a key reads the same in both. getLocale('fdk.size.used', ['2 KB', '10 MB']).
|
|
21
|
+
*/
|
|
22
|
+
export declare function getLocale(key: string, params?: LocaleParams): string;
|
|
23
|
+
/**
|
|
24
|
+
* The English text for a key, whatever the form shows: for the errors a developer reads, which stay
|
|
25
|
+
* in English as the console warnings do, though they say what the form says.
|
|
26
|
+
*/
|
|
27
|
+
export declare function english(key: string, params?: LocaleParams): string;
|
|
28
|
+
/** The BCP 47 tag of the current language, for the form root's lang. */
|
|
29
|
+
export declare function feedbackLang(): string;
|
|
30
|
+
/** A count's text: the key's .one form for 1, its .other form for everything else. */
|
|
31
|
+
export declare function plural(count: number, key: string): string;
|