@sparkvault/sdk-js 16.4.1 → 16.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -13
- package/dist/index.cjs +1075 -418
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +32 -4
- package/dist/index.mjs +1075 -418
- package/dist/index.mjs.map +1 -1
- package/dist/products/help-desk/form-attachments.d.ts +23 -6
- package/dist/products/help-desk/form-composer.d.ts +34 -0
- package/dist/products/help-desk/form-draft.d.ts +11 -2
- package/dist/products/help-desk/form-types.d.ts +29 -4
- package/dist/products/help-desk/form.d.ts +32 -9
- package/dist/products/help-desk/icons.d.ts +21 -0
- package/dist/products/help-desk/support-types.d.ts +2 -0
- package/dist/products/help-desk/support-view.d.ts +8 -2
- package/dist/products/help-desk/widget-identity.d.ts +1 -0
- package/dist/products/identity/renderer.d.ts +0 -7
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/dist/ui/live-region.d.ts +15 -0
- package/package.json +1 -1
- package/dist/products/help-desk/support-subject.d.ts +0 -7
package/dist/index.mjs
CHANGED
|
@@ -6937,6 +6937,50 @@ class OriginNotAllowedView {
|
|
|
6937
6937
|
}
|
|
6938
6938
|
}
|
|
6939
6939
|
|
|
6940
|
+
/**
|
|
6941
|
+
* How long a live region waits before it takes new words: long enough that
|
|
6942
|
+
* assistive technology has seen the change that prompted them, and hears the
|
|
6943
|
+
* region's own change as a change.
|
|
6944
|
+
*/
|
|
6945
|
+
const ANNOUNCE_DELAY_MS = 100;
|
|
6946
|
+
/**
|
|
6947
|
+
* A polite status region for words said as a view changes. It is placed
|
|
6948
|
+
* empty and kept, and every announcement waits a moment, so the words never
|
|
6949
|
+
* land in the same change as the region or the view that holds them: a
|
|
6950
|
+
* region created with its words already in it is often never announced.
|
|
6951
|
+
*/
|
|
6952
|
+
function createLiveRegion(className) {
|
|
6953
|
+
const element = document.createElement('div');
|
|
6954
|
+
element.className = className;
|
|
6955
|
+
element.setAttribute('role', 'status');
|
|
6956
|
+
element.setAttribute('aria-live', 'polite');
|
|
6957
|
+
element.setAttribute('aria-atomic', 'true');
|
|
6958
|
+
let timer = null;
|
|
6959
|
+
const cancel = () => {
|
|
6960
|
+
if (timer !== null)
|
|
6961
|
+
clearTimeout(timer);
|
|
6962
|
+
timer = null;
|
|
6963
|
+
};
|
|
6964
|
+
return {
|
|
6965
|
+
element,
|
|
6966
|
+
announce(words) {
|
|
6967
|
+
cancel();
|
|
6968
|
+
if (!words) {
|
|
6969
|
+
element.textContent = '';
|
|
6970
|
+
return;
|
|
6971
|
+
}
|
|
6972
|
+
timer = setTimeout(() => {
|
|
6973
|
+
timer = null;
|
|
6974
|
+
element.textContent = words;
|
|
6975
|
+
}, ANNOUNCE_DELAY_MS);
|
|
6976
|
+
},
|
|
6977
|
+
destroy() {
|
|
6978
|
+
cancel();
|
|
6979
|
+
element.remove();
|
|
6980
|
+
},
|
|
6981
|
+
};
|
|
6982
|
+
}
|
|
6983
|
+
|
|
6940
6984
|
/**
|
|
6941
6985
|
* Identity View Renderer
|
|
6942
6986
|
*
|
|
@@ -6965,12 +7009,6 @@ function blockedSignInMessage(companyName) {
|
|
|
6965
7009
|
: 'Sign-in is temporarily unavailable. Please contact the site owner for assistance.';
|
|
6966
7010
|
}
|
|
6967
7011
|
const BLOCKED_ERROR_CODES = new Set(IDENTITY_BLOCKED_ERROR_CODES);
|
|
6968
|
-
/**
|
|
6969
|
-
* How long the live region waits after a view is in place before it takes
|
|
6970
|
-
* the view's words: long enough that assistive technology has seen the
|
|
6971
|
-
* view's change and hears the region's as a change of its own.
|
|
6972
|
-
*/
|
|
6973
|
-
const STATUS_ANNOUNCE_DELAY_MS = 100;
|
|
6974
7012
|
const SPARKLINK_CSP_BLOCKED_ERROR = {
|
|
6975
7013
|
message: [
|
|
6976
7014
|
'Connection blocked by security policy.',
|
|
@@ -7017,11 +7055,8 @@ class IdentityRenderer {
|
|
|
7017
7055
|
this.untouchedStep = null;
|
|
7018
7056
|
// The page's one live region: placed beside the flow content when the
|
|
7019
7057
|
// container opens, empty, and kept across views, so the words a view
|
|
7020
|
-
// announces (View.announcement) land in a region already in the page
|
|
7021
|
-
// assistive technology hears change. A region created with its words already
|
|
7022
|
-
// in it is often never announced.
|
|
7058
|
+
// announces (View.announcement) land in a region already in the page.
|
|
7023
7059
|
this.statusRegion = null;
|
|
7024
|
-
this.statusTimer = null;
|
|
7025
7060
|
this.container = container;
|
|
7026
7061
|
this.api = api;
|
|
7027
7062
|
this.options = options;
|
|
@@ -7278,11 +7313,7 @@ class IdentityRenderer {
|
|
|
7278
7313
|
window.removeEventListener('pageshow', this.pageRestoreHandler);
|
|
7279
7314
|
this.pageRestoreHandler = null;
|
|
7280
7315
|
}
|
|
7281
|
-
|
|
7282
|
-
clearTimeout(this.statusTimer);
|
|
7283
|
-
this.statusTimer = null;
|
|
7284
|
-
}
|
|
7285
|
-
this.statusRegion?.remove();
|
|
7316
|
+
this.statusRegion?.destroy();
|
|
7286
7317
|
this.statusRegion = null;
|
|
7287
7318
|
this.cleanupSparkLink();
|
|
7288
7319
|
this.destroyCurrentView();
|
|
@@ -7527,7 +7558,7 @@ class IdentityRenderer {
|
|
|
7527
7558
|
this.container.setMinimalChrome(minimalChromeViews.includes(this.viewState.view));
|
|
7528
7559
|
const view = this.createViewForState(this.viewState);
|
|
7529
7560
|
this.currentView = view;
|
|
7530
|
-
this.announce(view.announcement ?? '');
|
|
7561
|
+
this.statusRegion?.announce(view.announcement ?? '');
|
|
7531
7562
|
const rendered = view.render();
|
|
7532
7563
|
// Each step enters with a calm fade + rise (see .sv-step-enter). The brand
|
|
7533
7564
|
// lockup and footer live outside `body`, so only the flow content moves.
|
|
@@ -7563,37 +7594,11 @@ class IdentityRenderer {
|
|
|
7563
7594
|
/** Place the empty live region beside the flow content, once per container. */
|
|
7564
7595
|
placeStatusRegion() {
|
|
7565
7596
|
const body = this.container.getBody();
|
|
7566
|
-
if (!body || this.statusRegion?.isConnected)
|
|
7567
|
-
return;
|
|
7568
|
-
const region = document.createElement('div');
|
|
7569
|
-
region.className = 'sv-sr-only';
|
|
7570
|
-
region.setAttribute('role', 'status');
|
|
7571
|
-
region.setAttribute('aria-live', 'polite');
|
|
7572
|
-
region.setAttribute('aria-atomic', 'true');
|
|
7573
|
-
body.insertAdjacentElement('beforebegin', region);
|
|
7574
|
-
this.statusRegion = region;
|
|
7575
|
-
}
|
|
7576
|
-
/**
|
|
7577
|
-
* Put `words` in the live region, a moment after the view that says them
|
|
7578
|
-
* is in place, so they never land in the same change as the region or the
|
|
7579
|
-
* view that holds them; empty words clear it at once.
|
|
7580
|
-
*/
|
|
7581
|
-
announce(words) {
|
|
7582
|
-
if (this.statusTimer !== null) {
|
|
7583
|
-
clearTimeout(this.statusTimer);
|
|
7584
|
-
this.statusTimer = null;
|
|
7585
|
-
}
|
|
7586
|
-
const region = this.statusRegion;
|
|
7587
|
-
if (!region)
|
|
7588
|
-
return;
|
|
7589
|
-
if (!words) {
|
|
7590
|
-
region.textContent = '';
|
|
7597
|
+
if (!body || this.statusRegion?.element.isConnected)
|
|
7591
7598
|
return;
|
|
7592
|
-
|
|
7593
|
-
this.
|
|
7594
|
-
|
|
7595
|
-
region.textContent = words;
|
|
7596
|
-
}, STATUS_ANNOUNCE_DELAY_MS);
|
|
7599
|
+
this.statusRegion?.destroy();
|
|
7600
|
+
this.statusRegion = createLiveRegion('sv-sr-only');
|
|
7601
|
+
body.insertAdjacentElement('beforebegin', this.statusRegion.element);
|
|
7597
7602
|
}
|
|
7598
7603
|
destroyCurrentView() {
|
|
7599
7604
|
if (this.currentView?.destroy) {
|
|
@@ -14331,15 +14336,16 @@ Array.from({ length: 1 << BRAND_BITS.size }, (_, mask) =>
|
|
|
14331
14336
|
* API prefix, team mail aliases, the attachment ceremony's steps, the
|
|
14332
14337
|
* question a customer's new request asks before it is discarded, session,
|
|
14333
14338
|
* sign-in code (its length, lifetime, sender, resend wait, countdown and
|
|
14334
|
-
* the code step's words),
|
|
14335
|
-
*
|
|
14336
|
-
* the operator
|
|
14337
|
-
*
|
|
14338
|
-
*
|
|
14339
|
-
*
|
|
14340
|
-
*
|
|
14341
|
-
* applies where
|
|
14342
|
-
*
|
|
14339
|
+
* the code step's words), merge and pending-attachment timings, hold
|
|
14340
|
+
* presets, tag and size limits, the operator display and desk mode choices,
|
|
14341
|
+
* the operator queue's views and orders, the reply review list's views and
|
|
14342
|
+
* states, the response-time histogram's bucket edges, the sections of a
|
|
14343
|
+
* desk's settings an address names, and the messages the widget's native
|
|
14344
|
+
* sign-in posts between the website and its first-party page live here for
|
|
14345
|
+
* the same reason. So do the one rule a tag is stored by (ticketTag), which
|
|
14346
|
+
* Core applies where it stores a tag and the console applies where one is
|
|
14347
|
+
* typed, and the one rule a typed or pasted sign-in code is read by
|
|
14348
|
+
* (helpDeskPinDigits), which every sign-in form applies. So
|
|
14343
14349
|
* does the one way a client names a message it sends (newMessageId), which
|
|
14344
14350
|
* the portal, the SDK and the console's composer each send their messages
|
|
14345
14351
|
* under, and the one rule that a message sent again is the same message
|
|
@@ -14364,6 +14370,22 @@ const HELP_DESK_CLOSE_REASONS = Object.freeze(['resolved', 'duplicate', 'spam'])
|
|
|
14364
14370
|
/** The close reasons an operator's status change names: a duplicate closes by merging it into the request it repeats. */
|
|
14365
14371
|
Object.freeze(HELP_DESK_CLOSE_REASONS.filter((reason) => reason !== 'duplicate'));
|
|
14366
14372
|
|
|
14373
|
+
/**
|
|
14374
|
+
* The messages the widget's native sign-in exchanges between the website's
|
|
14375
|
+
* window (the JS SDK's openWidgetIdentity) and the first-party page it opens
|
|
14376
|
+
* on auth.sv (Core's widget-identity-page.js), each posted to the other's
|
|
14377
|
+
* exact origin: the page asks its opener for the challenge's state (`ready`),
|
|
14378
|
+
* the opener answers its own popup alone (`state`), and the page reports the
|
|
14379
|
+
* sign-in's code or its cancellation (`result`). Every message names its
|
|
14380
|
+
* challenge, and the state is never in the page's URL or its server-rendered
|
|
14381
|
+
* context, so only the window that started a challenge can complete it.
|
|
14382
|
+
*/
|
|
14383
|
+
const HELP_DESK_WIDGET_IDENTITY_MESSAGES = Object.freeze({
|
|
14384
|
+
ready: 'sparkvault:help-desk:identity-ready',
|
|
14385
|
+
state: 'sparkvault:help-desk:identity-state',
|
|
14386
|
+
result: 'sparkvault:help-desk:identity'
|
|
14387
|
+
});
|
|
14388
|
+
|
|
14367
14389
|
/**
|
|
14368
14390
|
* Mail local parts no team may take as its alias: the role mailboxes RFC 2142
|
|
14369
14391
|
* names, the addresses mail systems and their operators keep for themselves,
|
|
@@ -17583,7 +17605,17 @@ function openWidgetIdentity(options, prepare, ready, redeem, deskId) {
|
|
|
17583
17605
|
if (!challenge || event.source !== popup || event.origin !== firstPartyOrigin)
|
|
17584
17606
|
return;
|
|
17585
17607
|
const data = event.data;
|
|
17586
|
-
if (!data || data.
|
|
17608
|
+
if (!data || data.challenge_id !== challenge.challenge_id)
|
|
17609
|
+
return;
|
|
17610
|
+
// The first-party page this window opened asks for the challenge's
|
|
17611
|
+
// state, without which Core takes none of its steps: only this popup,
|
|
17612
|
+
// at the first-party origin, is ever answered, so a sign-in link opened
|
|
17613
|
+
// in any other window or browser completes nothing.
|
|
17614
|
+
if (data.type === HELP_DESK_WIDGET_IDENTITY_MESSAGES.ready) {
|
|
17615
|
+
popup.postMessage({ type: HELP_DESK_WIDGET_IDENTITY_MESSAGES.state, challenge_id: challenge.challenge_id, state: challenge.state }, event.origin);
|
|
17616
|
+
return;
|
|
17617
|
+
}
|
|
17618
|
+
if (data.type !== HELP_DESK_WIDGET_IDENTITY_MESSAGES.result || data.state !== challenge.state)
|
|
17587
17619
|
return;
|
|
17588
17620
|
if (data.cancelled === true) {
|
|
17589
17621
|
cancel();
|
|
@@ -18235,16 +18267,16 @@ function injectHelpDeskFormStyles() {
|
|
|
18235
18267
|
.svhd-modal .svhd-container{max-width:none;border:0;border-radius:0;padding-top:8px}
|
|
18236
18268
|
.svhd-container{box-sizing:border-box;max-width:36rem;border:1px solid ${DS.slate200};border-radius:12px;background:${DS.white};color:${DS.slate900};font:400 15px/1.5 system-ui,sans-serif;padding:24px}
|
|
18237
18269
|
.svhd-container *{box-sizing:border-box}
|
|
18238
|
-
.svhd-container h2{font-size:22px;line-height:1.25;margin:0
|
|
18270
|
+
.svhd-container h2{font-size:22px;line-height:1.25;margin:0}
|
|
18271
|
+
.svhd-step-head h2:focus{outline:none}
|
|
18239
18272
|
.svhd-form{display:grid;gap:16px}
|
|
18240
18273
|
.svhd-field{display:grid;gap:6px}
|
|
18241
18274
|
.svhd-label{font-weight:600}
|
|
18242
18275
|
.svhd-input{width:100%;border:1px solid ${DS.slate300};border-radius:6px;padding:10px 12px;color:${DS.slate900};background:${DS.white};font:inherit;font-size:16px}
|
|
18243
18276
|
.svhd-input:focus-visible,.svhd-button:focus-visible,.svhd-link:focus-visible{outline:3px solid ${DS.action};outline-offset:2px}
|
|
18244
18277
|
.svhd-input:disabled{background:${DS.slate50}}
|
|
18245
|
-
.svhd-description{min-height:140px;resize:vertical}
|
|
18246
18278
|
.svhd-auth{display:grid;gap:16px;border:0;padding:0;margin:0}
|
|
18247
|
-
.svhd-form[hidden],.svhd-auth[hidden],.svhd-field[hidden],.svhd-field-error[hidden],.svhd-status[hidden],.svhd-link[hidden],.svhd-actions[hidden],.svhd-confirm[hidden]{display:none}
|
|
18279
|
+
.svhd-form[hidden],.svhd-step[hidden],.svhd-auth[hidden],.svhd-field[hidden],.svhd-field-error[hidden],.svhd-status[hidden],.svhd-link[hidden],.svhd-actions[hidden],.svhd-confirm[hidden],.svhd-widget-account[hidden],.svhd-text-button[hidden],.svhd-composer-drop[hidden],.svhd-attachment-chips[hidden]{display:none}
|
|
18248
18280
|
.svhd-actions{display:flex;align-items:center;gap:12px;flex-wrap:wrap}
|
|
18249
18281
|
.svhd-button{border:0;border-radius:6px;padding:10px 16px;min-height:44px;font:600 15px/1.5 system-ui,sans-serif;background:${DS.action};color:${DS.white};cursor:pointer}
|
|
18250
18282
|
.svhd-button:hover{background:${DS.actionHover}}
|
|
@@ -18262,14 +18294,53 @@ function injectHelpDeskFormStyles() {
|
|
|
18262
18294
|
.svhd-done-title:focus{outline:none}
|
|
18263
18295
|
.svhd-confirmation-message{white-space:pre-wrap;overflow-wrap:anywhere}
|
|
18264
18296
|
.svhd-link{display:inline-flex;align-items:center;justify-self:start;min-height:44px;color:${DS.action};text-decoration:underline}
|
|
18265
|
-
.svhd-
|
|
18266
|
-
.svhd-
|
|
18267
|
-
.svhd-
|
|
18268
|
-
.svhd-
|
|
18269
|
-
.svhd-
|
|
18270
|
-
.svhd-
|
|
18271
|
-
.svhd-
|
|
18272
|
-
.svhd-
|
|
18297
|
+
.svhd-hint{font-size:13px;color:${DS.slate600};margin:0}
|
|
18298
|
+
.svhd-step{display:grid;gap:16px;min-width:0}
|
|
18299
|
+
.svhd-step-head{display:grid;gap:4px;margin-bottom:4px}
|
|
18300
|
+
.svhd-step-label{margin:0;font-size:13px;font-weight:600;line-height:1.4;color:${DS.slate600}}
|
|
18301
|
+
.svhd-text-button{display:inline-flex;align-items:center;min-height:44px;padding:0 4px;border:0;border-radius:6px;background:transparent;color:${DS.action};font:inherit;font-size:14px;font-weight:600;text-decoration:underline;text-underline-offset:2px;cursor:pointer}
|
|
18302
|
+
.svhd-text-button:hover{color:${DS.actionHover}}
|
|
18303
|
+
.svhd-text-button:focus-visible{outline:3px solid ${DS.action};outline-offset:2px}
|
|
18304
|
+
.svhd-text-button:disabled{color:${DS.slate500};cursor:default}
|
|
18305
|
+
.svhd-widget-account{display:flex;align-items:center;flex-wrap:wrap;gap:0 16px;min-width:0}
|
|
18306
|
+
.svhd-posting-as{margin:0;color:${DS.slate600};font-size:14px;line-height:1.5;overflow-wrap:anywhere}
|
|
18307
|
+
.svhd-note{display:flex;align-items:flex-start;gap:10px;margin:0;padding:12px 14px;border:1px solid ${DS.slate200};border-radius:8px;background:${DS.slate50};color:${DS.slate900};font-size:14px;line-height:1.5}
|
|
18308
|
+
.svhd-step .svhd-note svg{display:block;width:18px;height:18px;flex:none;margin-top:2px;color:${DS.action}}
|
|
18309
|
+
.svhd-recap{display:flex;align-items:center;gap:12px;padding:6px 6px 6px 14px;border:1px solid ${DS.slate200};border-radius:8px}
|
|
18310
|
+
.svhd-recap-request{flex:1;min-width:0}
|
|
18311
|
+
.svhd-recap-label{display:block;color:${DS.slate600};font-size:12px;font-weight:600;line-height:1.4}
|
|
18312
|
+
.svhd-recap-text{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;margin:0;color:${DS.slate900};font-size:14px;line-height:1.5;overflow-wrap:anywhere}
|
|
18313
|
+
.svhd-recap .svhd-text-button{flex:none}
|
|
18314
|
+
/* The frame is the field: its ring shows wherever focus is inside it, and the text inside draws none of its own. */
|
|
18315
|
+
.svhd-composer{position:relative;display:flex;flex-direction:column;min-width:0;border:1px solid ${DS.slate300};border-radius:6px;background:${DS.white}}
|
|
18316
|
+
.svhd-composer:has(.svhd-composer-input:focus-visible){outline:3px solid ${DS.action};outline-offset:2px}
|
|
18317
|
+
@supports not selector(:has(*)){.svhd-composer:focus-within{outline:3px solid ${DS.action};outline-offset:2px}}
|
|
18318
|
+
.svhd-composer-dragging{border-style:dashed;border-color:${DS.action}}
|
|
18319
|
+
.svhd-composer-input{display:block;width:100%;min-height:140px;resize:vertical;border:0;border-radius:6px 6px 0 0;padding:10px 12px;background:transparent;color:${DS.slate900};font:inherit;font-size:16px}
|
|
18320
|
+
.svhd-composer-input:focus,.svhd-composer-input:focus-visible{outline:none}
|
|
18321
|
+
.svhd-composer-input:disabled{background:${DS.slate50}}
|
|
18322
|
+
.svhd-composer-drop{position:absolute;inset:0;z-index:1;display:flex;align-items:center;justify-content:center;margin:0;padding:12px;border-radius:5px;background:${DS.actionBg};color:${DS.action};font-weight:600;text-align:center;pointer-events:none}
|
|
18323
|
+
.svhd-composer-toolbar{display:flex;align-items:center;flex-wrap:wrap;gap:0 12px;padding:0 8px 0 4px;border-top:1px solid ${DS.slate200}}
|
|
18324
|
+
.svhd-composer-attach{display:inline-flex;align-items:center;gap:6px;min-height:44px;padding:0 8px;border:0;border-radius:6px;background:transparent;color:${DS.slate600};font:600 14px/1.4 system-ui,sans-serif;cursor:pointer}
|
|
18325
|
+
.svhd-composer-attach:hover{background:${DS.slate100};color:${DS.slate900}}
|
|
18326
|
+
.svhd-composer-attach:disabled{opacity:.6;cursor:default}
|
|
18327
|
+
.svhd-composer .svhd-composer-attach svg{display:block;width:18px;height:18px}
|
|
18328
|
+
.svhd-composer-hint{flex:1 1 160px;min-width:0;margin:0;padding:6px 0;font-size:12px;line-height:1.4;color:${DS.slate600}}
|
|
18329
|
+
.svhd-composer-notice{margin:0;font-size:14px}
|
|
18330
|
+
.svhd-attachment-chips{display:flex;flex-wrap:wrap;gap:8px;list-style:none;margin:0;padding:8px;border-top:1px solid ${DS.slate200}}
|
|
18331
|
+
.svhd-attachment-chips:empty{display:none}
|
|
18332
|
+
.svhd-attachment-chip{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:center;flex:0 1 280px;min-width:0;max-width:100%;padding:0 0 8px 10px;border:1px solid ${DS.slate200};border-radius:6px;background:${DS.slate50};font-size:13px;line-height:1.4}
|
|
18333
|
+
.svhd-attachment-name{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:600;color:${DS.slate900}}
|
|
18334
|
+
.svhd-attachment-status{grid-column:1;padding-right:8px;color:${DS.slate600};font-size:12px;overflow-wrap:anywhere}
|
|
18335
|
+
.svhd-attachment-status.svhd-error{color:${DS.error}}
|
|
18336
|
+
.svhd-attachment-progress{grid-column:1/-1;width:calc(100% - 10px);height:6px;margin-top:6px;accent-color:${DS.action}}
|
|
18337
|
+
.svhd-attachment-chip .svhd-attachment-remove{display:grid;place-items:center;width:44px;height:44px;min-height:44px;padding:0;border:0;border-radius:6px;background:transparent;color:${DS.slate600};cursor:pointer}
|
|
18338
|
+
.svhd-attachment-remove:hover{background:${DS.slate200};color:${DS.slate900}}
|
|
18339
|
+
.svhd-attachment-chip .svhd-attachment-remove svg{display:block;width:16px;height:16px}
|
|
18340
|
+
.svhd-attachment-chip .svhd-attachment-retry{grid-column:2;min-height:44px;padding:0 10px;border:0;border-radius:6px;background:transparent;color:${DS.action};font:600 13px/1.4 system-ui,sans-serif;text-decoration:underline;cursor:pointer}
|
|
18341
|
+
.svhd-composer button:focus-visible{outline:3px solid ${DS.action};outline-offset:-3px}
|
|
18342
|
+
.svhd-attachment-remove:disabled,.svhd-attachment-retry:disabled{opacity:.6;cursor:default}
|
|
18343
|
+
.svhd-live{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
|
|
18273
18344
|
.svhd-footer{margin-top:20px;font-size:12px;color:${DS.slate500}}
|
|
18274
18345
|
`;
|
|
18275
18346
|
document.head.appendChild(style);
|
|
@@ -18473,23 +18544,6 @@ function lastExtension(name) {
|
|
|
18473
18544
|
return shownExtension(closeUpSpaces(name));
|
|
18474
18545
|
}
|
|
18475
18546
|
|
|
18476
|
-
/**
|
|
18477
|
-
* The longest prefix of `text` within `maxLength` UTF-16 units that splits no
|
|
18478
|
-
* character.
|
|
18479
|
-
*
|
|
18480
|
-
* @param {string} text
|
|
18481
|
-
* @param {number} maxLength
|
|
18482
|
-
* @returns {string}
|
|
18483
|
-
*/
|
|
18484
|
-
function truncateToLength(text, maxLength) {
|
|
18485
|
-
let truncated = '';
|
|
18486
|
-
for (const character of text) {
|
|
18487
|
-
if (truncated.length + character.length > maxLength) break;
|
|
18488
|
-
truncated += character;
|
|
18489
|
-
}
|
|
18490
|
-
return truncated;
|
|
18491
|
-
}
|
|
18492
|
-
|
|
18493
18547
|
/**
|
|
18494
18548
|
* What a help-desk attachment may be named and what its first bytes may not
|
|
18495
18549
|
* be: the one list of the files a ticket accepts, beside the one list of
|
|
@@ -18788,6 +18842,15 @@ const ACCEPTED_ATTACHMENTS_COPY = acceptedKindsCopy(ACCEPTED_ATTACHMENT_KINDS);
|
|
|
18788
18842
|
const CUSTOMER_ATTACHMENTS_HINT =
|
|
18789
18843
|
`Add screenshots, documents or recordings. Up to ${MAX_ATTACHMENTS_PER_MESSAGE} files, ${formatBytes(CUSTOMER_ATTACHMENT_MAX_BYTES)} each.`;
|
|
18790
18844
|
|
|
18845
|
+
/**
|
|
18846
|
+
* What a customer reads at a desk that takes no files from its customers
|
|
18847
|
+
* (the desk lookup's `customer_can_attach_files` is false, the upload refusal
|
|
18848
|
+
* CUSTOMER_UPLOAD_REFUSALS.UPLOADS_OFF): the portal's refusal and its note on
|
|
18849
|
+
* the files an email left out, and the SDK's support form refusing a file
|
|
18850
|
+
* dropped, pasted or uploaded there.
|
|
18851
|
+
*/
|
|
18852
|
+
const NO_CUSTOMER_FILES_COPY = "This help desk doesn't take files from customers.";
|
|
18853
|
+
|
|
18791
18854
|
/**
|
|
18792
18855
|
* A file input's `accept`: every extension a ticket accepts
|
|
18793
18856
|
* (ACCEPTED_ATTACHMENT_EXTENSIONS), each with its dot, so the system's file
|
|
@@ -18835,7 +18898,56 @@ function refusalCopy(refusal, maxBytes) {
|
|
|
18835
18898
|
return REFUSAL_COPY[refusal] ?? "This file can't be attached.";
|
|
18836
18899
|
}
|
|
18837
18900
|
|
|
18838
|
-
|
|
18901
|
+
/**
|
|
18902
|
+
* The help desk's bare outline glyphs, shared by the support wizard and the
|
|
18903
|
+
* ticket form: stroked in `currentColor`, so the stylesheet that sizes them
|
|
18904
|
+
* also colors them, and hidden from assistive technology, since the control
|
|
18905
|
+
* that holds one names it.
|
|
18906
|
+
*/
|
|
18907
|
+
const PATHS = {
|
|
18908
|
+
back: 'm14.5 6-6 6 6 6',
|
|
18909
|
+
close: 'm6 6 12 12M18 6 6 18',
|
|
18910
|
+
external: 'M14 4h6v6m0-6L10 14M11 5H5a1 1 0 0 0-1 1v13a1 1 0 0 0 1 1h13a1 1 0 0 0 1-1v-6',
|
|
18911
|
+
check: 'm5 12 4 4L19 6',
|
|
18912
|
+
article: 'M14 3H6a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8Zm0 0v5h5M8 12h8M8 16h6',
|
|
18913
|
+
chevron: 'm9 6 6 6-6 6',
|
|
18914
|
+
thumbUp: 'M7 10v11H3V10Zm0 1 5-8c2 0 3 1 2 4l-1 3h6a2 2 0 0 1 2 2l-2 7a2 2 0 0 1-2 2H7',
|
|
18915
|
+
thumbDown: 'M7 14V3H3v11Zm0-1 5 8c2 0 3-1 2-4l-1-3h6a2 2 0 0 0 2-2l-2-7a2 2 0 0 0-2-2H7',
|
|
18916
|
+
paperclip: 'm21 11-8.6 8.6a5.5 5.5 0 0 1-7.8-7.8l8.6-8.6a3.7 3.7 0 0 1 5.2 5.2l-8.6 8.6a1.8 1.8 0 0 1-2.6-2.6L15 6.6',
|
|
18917
|
+
info: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18Zm0-10v5m0-8h.01',
|
|
18918
|
+
};
|
|
18919
|
+
function helpDeskIcon(name) {
|
|
18920
|
+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
18921
|
+
svg.setAttribute('viewBox', '0 0 24 24');
|
|
18922
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
18923
|
+
svg.setAttribute('focusable', 'false');
|
|
18924
|
+
svg.setAttribute('fill', 'none');
|
|
18925
|
+
svg.setAttribute('stroke', 'currentColor');
|
|
18926
|
+
svg.setAttribute('stroke-width', '1.7');
|
|
18927
|
+
svg.setAttribute('stroke-linecap', 'round');
|
|
18928
|
+
svg.setAttribute('stroke-linejoin', 'round');
|
|
18929
|
+
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
18930
|
+
path.setAttribute('d', PATHS[name]);
|
|
18931
|
+
svg.append(path);
|
|
18932
|
+
return svg;
|
|
18933
|
+
}
|
|
18934
|
+
|
|
18935
|
+
/** A refusal of files read under the composer, hidden until there is one. */
|
|
18936
|
+
function createNotice() {
|
|
18937
|
+
const notice = document.createElement('p');
|
|
18938
|
+
notice.className = 'svhd-composer-notice svhd-error';
|
|
18939
|
+
notice.hidden = true;
|
|
18940
|
+
return notice;
|
|
18941
|
+
}
|
|
18942
|
+
/** Show a notice's refusal, or hide it with null. It is an alert only while it shows, as a field's error is. */
|
|
18943
|
+
function setNotice(notice, text) {
|
|
18944
|
+
notice.textContent = text ?? '';
|
|
18945
|
+
notice.hidden = text === null;
|
|
18946
|
+
if (text === null)
|
|
18947
|
+
notice.removeAttribute('role');
|
|
18948
|
+
else
|
|
18949
|
+
notice.setAttribute('role', 'alert');
|
|
18950
|
+
}
|
|
18839
18951
|
/** A failed mint's quota/size refusal remains a visible file error, never a silently omitted file. */
|
|
18840
18952
|
function problem(error) {
|
|
18841
18953
|
if (error instanceof SparkVaultError) {
|
|
@@ -18847,7 +18959,7 @@ function problem(error) {
|
|
|
18847
18959
|
}
|
|
18848
18960
|
if (error.statusCode === 402) {
|
|
18849
18961
|
const reason = error.details?.reason;
|
|
18850
|
-
return { copy: reason === CUSTOMER_UPLOAD_REFUSALS.UPLOADS_OFF ?
|
|
18962
|
+
return { copy: reason === CUSTOMER_UPLOAD_REFUSALS.UPLOADS_OFF ? NO_CUSTOMER_FILES_COPY
|
|
18851
18963
|
: reason === CUSTOMER_UPLOAD_REFUSALS.ALLOWANCE_REACHED ? 'You have reached this help desk’s upload allowance.'
|
|
18852
18964
|
: 'This help desk cannot store more files right now.', retryable: false };
|
|
18853
18965
|
}
|
|
@@ -18857,48 +18969,58 @@ function problem(error) {
|
|
|
18857
18969
|
}
|
|
18858
18970
|
return { copy: 'This file could not be uploaded. Try again or remove it.', retryable: true };
|
|
18859
18971
|
}
|
|
18860
|
-
/**
|
|
18861
|
-
|
|
18862
|
-
|
|
18863
|
-
|
|
18864
|
-
|
|
18865
|
-
|
|
18866
|
-
label.textContent = 'Attachments';
|
|
18867
|
-
label.htmlFor = `${prefix}-attachments`;
|
|
18972
|
+
/**
|
|
18973
|
+
* The picker owns each file's transfer; it publishes only IDs whose Forge
|
|
18974
|
+
* receipt has confirmed storage. `onEntriesChange` hears each file the
|
|
18975
|
+
* customer adds or removes.
|
|
18976
|
+
*/
|
|
18977
|
+
function createFormAttachments(client, prefix, context, onEntriesChange) {
|
|
18868
18978
|
const input = document.createElement('input');
|
|
18869
18979
|
input.type = 'file';
|
|
18870
18980
|
input.name = 'attachments';
|
|
18871
|
-
input.id = label.htmlFor;
|
|
18872
18981
|
input.multiple = true;
|
|
18873
18982
|
input.accept = ATTACHMENT_INPUT_ACCEPT;
|
|
18874
|
-
input.
|
|
18983
|
+
input.hidden = true;
|
|
18984
|
+
input.tabIndex = -1;
|
|
18875
18985
|
const hint = document.createElement('p');
|
|
18876
18986
|
hint.id = `${prefix}-attachment-hint`;
|
|
18877
|
-
hint.className = 'svhd-
|
|
18987
|
+
hint.className = 'svhd-composer-hint';
|
|
18878
18988
|
hint.textContent = CUSTOMER_ATTACHMENTS_HINT;
|
|
18879
|
-
|
|
18880
|
-
|
|
18881
|
-
|
|
18882
|
-
|
|
18883
|
-
|
|
18989
|
+
const attach = document.createElement('button');
|
|
18990
|
+
attach.type = 'button';
|
|
18991
|
+
attach.className = 'svhd-composer-attach';
|
|
18992
|
+
attach.setAttribute('aria-label', 'Attach files');
|
|
18993
|
+
attach.setAttribute('aria-describedby', hint.id);
|
|
18994
|
+
const attachText = document.createElement('span');
|
|
18995
|
+
attachText.textContent = 'Attach';
|
|
18996
|
+
attach.append(helpDeskIcon('paperclip'), attachText);
|
|
18997
|
+
const toolbar = document.createElement('div');
|
|
18998
|
+
toolbar.className = 'svhd-composer-toolbar';
|
|
18999
|
+
toolbar.append(attach, hint, input);
|
|
19000
|
+
const notice = createNotice();
|
|
18884
19001
|
const list = document.createElement('ul');
|
|
18885
|
-
list.className = 'svhd-
|
|
18886
|
-
list.setAttribute('aria-label', '
|
|
18887
|
-
element.append(label, input, hint, notice, list);
|
|
19002
|
+
list.className = 'svhd-attachment-chips';
|
|
19003
|
+
list.setAttribute('aria-label', 'Attached files');
|
|
18888
19004
|
let entries = [];
|
|
18889
19005
|
let revision = 0;
|
|
18890
19006
|
let locked = false;
|
|
18891
19007
|
let pickingDisabled = false;
|
|
18892
19008
|
let destroyed = false;
|
|
18893
19009
|
const current = (entry, ownRevision) => !destroyed && revision === ownRevision && entries.includes(entry) && !entry.controller?.signal.aborted;
|
|
19010
|
+
function syncPicking() {
|
|
19011
|
+
attach.disabled = locked || pickingDisabled;
|
|
19012
|
+
input.disabled = locked || pickingDisabled;
|
|
19013
|
+
}
|
|
18894
19014
|
function controls(entry) {
|
|
18895
19015
|
entry.remove.disabled = locked;
|
|
18896
19016
|
entry.retry.disabled = locked || !!entry.operation;
|
|
18897
19017
|
}
|
|
18898
19018
|
function update(entry, state, text) {
|
|
18899
19019
|
entry.state = state;
|
|
19020
|
+
entry.row.dataset.state = state;
|
|
18900
19021
|
entry.status.textContent = text;
|
|
18901
19022
|
entry.status.classList.toggle('svhd-error', state === 'failed');
|
|
19023
|
+
entry.progress.hidden = state !== 'uploading';
|
|
18902
19024
|
entry.retry.hidden = !(entry.retryable && (state === 'failed' || state === 'received'));
|
|
18903
19025
|
entry.retry.textContent = state === 'received' ? 'Check upload' : 'Retry';
|
|
18904
19026
|
entry.retry.setAttribute('aria-label', `${state === 'received' ? 'Check upload' : 'Retry'} ${entry.file.name}`);
|
|
@@ -18938,7 +19060,7 @@ function createFormAttachments(client, prefix, context) {
|
|
|
18938
19060
|
if (!stillCurrent())
|
|
18939
19061
|
return;
|
|
18940
19062
|
if (!owner) {
|
|
18941
|
-
update(entry, 'queued', '
|
|
19063
|
+
update(entry, 'queued', 'Uploads when you send your request.');
|
|
18942
19064
|
return;
|
|
18943
19065
|
}
|
|
18944
19066
|
const options = {
|
|
@@ -19021,54 +19143,70 @@ function createFormAttachments(client, prefix, context) {
|
|
|
19021
19143
|
function remove(entry) {
|
|
19022
19144
|
if (locked)
|
|
19023
19145
|
return;
|
|
19146
|
+
// A keyboard removal keeps focus among the files, else on Attach.
|
|
19147
|
+
const refocus = document.activeElement === entry.remove;
|
|
19148
|
+
const index = entries.indexOf(entry);
|
|
19024
19149
|
entry.controller?.abort();
|
|
19025
19150
|
entries = entries.filter(candidate => candidate !== entry);
|
|
19026
19151
|
entry.row.remove();
|
|
19027
|
-
notice
|
|
19152
|
+
setNotice(notice, null);
|
|
19028
19153
|
void cancel(entry);
|
|
19154
|
+
onEntriesChange();
|
|
19155
|
+
if (refocus)
|
|
19156
|
+
(entries[Math.min(index, entries.length - 1)]?.remove ?? attach).focus();
|
|
19029
19157
|
}
|
|
19030
19158
|
function add(files) {
|
|
19031
19159
|
if (locked || pickingDisabled || destroyed)
|
|
19032
19160
|
return;
|
|
19033
19161
|
const incoming = Array.from(files);
|
|
19162
|
+
if (incoming.length === 0)
|
|
19163
|
+
return;
|
|
19034
19164
|
const room = Math.max(0, MAX_ATTACHMENTS_PER_MESSAGE - entries.length);
|
|
19035
|
-
notice
|
|
19036
|
-
notice.textContent = `You can attach up to ${MAX_ATTACHMENTS_PER_MESSAGE} files. Remove a file before adding another.`;
|
|
19165
|
+
setNotice(notice, incoming.length > room ? `You can attach up to ${MAX_ATTACHMENTS_PER_MESSAGE} files. Remove a file before adding another.` : null);
|
|
19037
19166
|
for (const file of incoming.slice(0, room)) {
|
|
19038
19167
|
const row = document.createElement('li');
|
|
19039
|
-
row.className = 'svhd-
|
|
19168
|
+
row.className = 'svhd-attachment-chip';
|
|
19040
19169
|
const filename = document.createElement('span');
|
|
19041
|
-
filename.className = 'svhd-
|
|
19170
|
+
filename.className = 'svhd-attachment-name';
|
|
19042
19171
|
filename.textContent = file.name;
|
|
19172
|
+
filename.title = file.name;
|
|
19043
19173
|
const status = document.createElement('span');
|
|
19174
|
+
status.className = 'svhd-attachment-status';
|
|
19044
19175
|
status.setAttribute('role', 'status');
|
|
19045
19176
|
status.setAttribute('aria-live', 'polite');
|
|
19046
|
-
const progress =
|
|
19177
|
+
const progress = document.createElement('progress');
|
|
19178
|
+
progress.className = 'svhd-attachment-progress';
|
|
19047
19179
|
progress.max = 100;
|
|
19048
19180
|
progress.value = 0;
|
|
19181
|
+
progress.hidden = true;
|
|
19049
19182
|
progress.setAttribute('aria-label', `Upload progress for ${file.name}`);
|
|
19050
19183
|
const removeButton = document.createElement('button');
|
|
19051
19184
|
removeButton.type = 'button';
|
|
19052
|
-
removeButton.className = 'svhd-
|
|
19053
|
-
removeButton.textContent = 'Remove';
|
|
19185
|
+
removeButton.className = 'svhd-attachment-remove';
|
|
19054
19186
|
removeButton.setAttribute('aria-label', `Remove ${file.name}`);
|
|
19187
|
+
removeButton.append(helpDeskIcon('close'));
|
|
19055
19188
|
const retry = document.createElement('button');
|
|
19056
19189
|
retry.type = 'button';
|
|
19057
|
-
retry.className = 'svhd-
|
|
19190
|
+
retry.className = 'svhd-attachment-retry';
|
|
19058
19191
|
retry.hidden = true;
|
|
19059
19192
|
const entry = { file, row, status, progress, remove: removeButton, retry, state: 'queued', retryable: false };
|
|
19060
19193
|
removeButton.onclick = () => remove(entry);
|
|
19061
19194
|
retry.onclick = () => { if (!locked && entry.retryable)
|
|
19062
19195
|
void run(entry); };
|
|
19063
|
-
row.append(filename,
|
|
19196
|
+
row.append(filename, removeButton, status, retry, progress);
|
|
19064
19197
|
list.append(row);
|
|
19065
19198
|
entries.push(entry);
|
|
19066
19199
|
void run(entry);
|
|
19067
19200
|
}
|
|
19201
|
+
if (room > 0)
|
|
19202
|
+
onEntriesChange();
|
|
19068
19203
|
}
|
|
19069
19204
|
const onChange = () => { if (input.files)
|
|
19070
19205
|
add(input.files); input.value = ''; };
|
|
19206
|
+
const onAttach = () => { if (!attach.disabled)
|
|
19207
|
+
input.click(); };
|
|
19071
19208
|
input.addEventListener('change', onChange);
|
|
19209
|
+
attach.addEventListener('click', onAttach);
|
|
19072
19210
|
function clear(preserveComplete = false) {
|
|
19073
19211
|
revision += 1;
|
|
19074
19212
|
const previous = entries;
|
|
@@ -19080,17 +19218,20 @@ function createFormAttachments(client, prefix, context) {
|
|
|
19080
19218
|
}
|
|
19081
19219
|
list.replaceChildren();
|
|
19082
19220
|
input.value = '';
|
|
19083
|
-
notice
|
|
19221
|
+
setNotice(notice, null);
|
|
19084
19222
|
}
|
|
19085
19223
|
return {
|
|
19086
|
-
|
|
19224
|
+
toolbar,
|
|
19225
|
+
list,
|
|
19226
|
+
notice,
|
|
19227
|
+
get accepting() { return !locked && !pickingDisabled && !destroyed; },
|
|
19087
19228
|
get attachmentIds() { return entries.filter(entry => entry.state === 'complete' && entry.attachmentId).map(entry => entry.attachmentId); },
|
|
19088
19229
|
get unresolved() { return entries.some(entry => entry.state !== 'complete'); },
|
|
19089
19230
|
get hasEntries() { return entries.length > 0; },
|
|
19090
|
-
|
|
19231
|
+
add,
|
|
19091
19232
|
async start() { await Promise.all(entries.map(entry => entry.operation ?? (entry.state === 'queued' ? run(entry) : Promise.resolve()))); },
|
|
19092
|
-
lock(value) { locked = value;
|
|
19093
|
-
disablePicking(value) { pickingDisabled = value;
|
|
19233
|
+
lock(value) { locked = value; syncPicking(); entries.forEach(controls); },
|
|
19234
|
+
disablePicking(value) { pickingDisabled = value; syncPicking(); },
|
|
19094
19235
|
renewSession(previousToken, nextToken) {
|
|
19095
19236
|
for (const entry of entries) {
|
|
19096
19237
|
if (entry.context?.expectedSessionToken === previousToken)
|
|
@@ -19098,11 +19239,175 @@ function createFormAttachments(client, prefix, context) {
|
|
|
19098
19239
|
}
|
|
19099
19240
|
},
|
|
19100
19241
|
clear,
|
|
19101
|
-
destroy(preserveComplete = false) {
|
|
19242
|
+
destroy(preserveComplete = false) {
|
|
19243
|
+
destroyed = true;
|
|
19244
|
+
clear(preserveComplete);
|
|
19245
|
+
input.removeEventListener('change', onChange);
|
|
19246
|
+
attach.removeEventListener('click', onAttach);
|
|
19247
|
+
},
|
|
19248
|
+
};
|
|
19249
|
+
}
|
|
19250
|
+
|
|
19251
|
+
const FOLDER_COPY = 'Folders can’t be attached. Add the files inside them instead.';
|
|
19252
|
+
function carriesFiles(event) {
|
|
19253
|
+
return Array.from(event.dataTransfer?.types ?? []).includes('Files');
|
|
19254
|
+
}
|
|
19255
|
+
/**
|
|
19256
|
+
* The details field as a composer. A file pasted into the summary or the
|
|
19257
|
+
* details, or dropped anywhere on the request step, joins the form's one
|
|
19258
|
+
* attachment pipeline (`attachments.add`), under the same limits and
|
|
19259
|
+
* refusals as a picked one; the drop target shows only over the composer. A
|
|
19260
|
+
* paste or drag of text alone stays the browser's. A file brought over the
|
|
19261
|
+
* form is never the browser's to open in place of the unsent request: on the
|
|
19262
|
+
* reply-to step, or while the form takes no files, it is refused outright,
|
|
19263
|
+
* and a desk that takes no files says so when the file is dropped.
|
|
19264
|
+
*/
|
|
19265
|
+
function createComposer(options) {
|
|
19266
|
+
const { form, summary, textarea, attachments, deskRefusesFiles, onRequestStep } = options;
|
|
19267
|
+
const frame = document.createElement('div');
|
|
19268
|
+
frame.className = 'svhd-composer';
|
|
19269
|
+
textarea.classList.add('svhd-composer-input');
|
|
19270
|
+
const drop = document.createElement('p');
|
|
19271
|
+
drop.className = 'svhd-composer-drop';
|
|
19272
|
+
drop.textContent = 'Drop the files to attach them.';
|
|
19273
|
+
drop.hidden = true;
|
|
19274
|
+
frame.append(textarea, drop);
|
|
19275
|
+
if (attachments)
|
|
19276
|
+
frame.append(attachments.toolbar, attachments.list);
|
|
19277
|
+
const notice = attachments?.notice ?? createNotice();
|
|
19278
|
+
const fields = [summary, textarea];
|
|
19279
|
+
let pastedImages = 0;
|
|
19280
|
+
function fileAction() {
|
|
19281
|
+
if (!onRequestStep())
|
|
19282
|
+
return 'none';
|
|
19283
|
+
if (attachments)
|
|
19284
|
+
return attachments.accepting ? 'attach' : 'none';
|
|
19285
|
+
return deskRefusesFiles ? 'refuse' : 'none';
|
|
19286
|
+
}
|
|
19287
|
+
function dragging(value) {
|
|
19288
|
+
frame.classList.toggle('svhd-composer-dragging', value);
|
|
19289
|
+
drop.hidden = !value;
|
|
19290
|
+
}
|
|
19291
|
+
function refuseFiles() {
|
|
19292
|
+
if (!notice.hidden && notice.textContent === NO_CUSTOMER_FILES_COPY)
|
|
19293
|
+
return;
|
|
19294
|
+
setNotice(notice, NO_CUSTOMER_FILES_COPY);
|
|
19295
|
+
}
|
|
19296
|
+
// A dropped folder arrives as a file that cannot be read, so it is left out,
|
|
19297
|
+
// and said so beside any refusal the files with it met.
|
|
19298
|
+
function attachDropped(transfer) {
|
|
19299
|
+
const files = [];
|
|
19300
|
+
let folders = 0;
|
|
19301
|
+
for (const item of Array.from(transfer.items)) {
|
|
19302
|
+
if (item.kind !== 'file')
|
|
19303
|
+
continue;
|
|
19304
|
+
if (item.webkitGetAsEntry()?.isDirectory) {
|
|
19305
|
+
folders += 1;
|
|
19306
|
+
continue;
|
|
19307
|
+
}
|
|
19308
|
+
const file = item.getAsFile();
|
|
19309
|
+
if (file)
|
|
19310
|
+
files.push(file);
|
|
19311
|
+
}
|
|
19312
|
+
if (files.length > 0)
|
|
19313
|
+
attachments?.add(files);
|
|
19314
|
+
if (folders > 0)
|
|
19315
|
+
setNotice(notice, files.length > 0 && !notice.hidden ? `${FOLDER_COPY} ${notice.textContent}` : FOLDER_COPY);
|
|
19316
|
+
}
|
|
19317
|
+
// A picture pasted from the clipboard is named "image.png" every time;
|
|
19318
|
+
// numbering the pastes tells their chips, and their Remove buttons, apart.
|
|
19319
|
+
function pastedName(file) {
|
|
19320
|
+
const extension = /^image\.(\w+)$/.exec(file.name)?.[1];
|
|
19321
|
+
if (extension === undefined)
|
|
19322
|
+
return file;
|
|
19323
|
+
pastedImages += 1;
|
|
19324
|
+
return new File([file], `Pasted image ${pastedImages}.${extension}`, { type: file.type, lastModified: file.lastModified });
|
|
19325
|
+
}
|
|
19326
|
+
// Cancelling dragenter and dragover keeps the browser from opening the file
|
|
19327
|
+
// in place of the page. A drop effect of none cancels the drop itself, so a
|
|
19328
|
+
// file the desk refuses keeps one to be refused in words when it lands.
|
|
19329
|
+
const onDragOver = (event) => {
|
|
19330
|
+
if (!carriesFiles(event))
|
|
19331
|
+
return;
|
|
19332
|
+
event.preventDefault();
|
|
19333
|
+
const action = fileAction();
|
|
19334
|
+
if (event.dataTransfer)
|
|
19335
|
+
event.dataTransfer.dropEffect = action === 'none' ? 'none' : 'copy';
|
|
19336
|
+
dragging(action === 'attach' && event.target instanceof Node && frame.contains(event.target));
|
|
19337
|
+
};
|
|
19338
|
+
const onDragLeave = (event) => {
|
|
19339
|
+
if (!(event.relatedTarget instanceof Node) || !frame.contains(event.relatedTarget))
|
|
19340
|
+
dragging(false);
|
|
19341
|
+
};
|
|
19342
|
+
const onDrop = (event) => {
|
|
19343
|
+
if (!carriesFiles(event))
|
|
19344
|
+
return;
|
|
19345
|
+
event.preventDefault();
|
|
19346
|
+
dragging(false);
|
|
19347
|
+
const action = fileAction();
|
|
19348
|
+
if (action === 'attach' && event.dataTransfer)
|
|
19349
|
+
attachDropped(event.dataTransfer);
|
|
19350
|
+
else if (action === 'refuse')
|
|
19351
|
+
refuseFiles();
|
|
19352
|
+
};
|
|
19353
|
+
// A paste that carries files is those files, and the text beside them is
|
|
19354
|
+
// only their names (a file copied in the system's file manager), so none of
|
|
19355
|
+
// it lands in the field. Office apps are the exception: copied cells or
|
|
19356
|
+
// paragraphs come as text and formatted text, with a picture of them as a
|
|
19357
|
+
// file, and that paste is the text.
|
|
19358
|
+
const onPaste = (event) => {
|
|
19359
|
+
const clipboard = event.clipboardData;
|
|
19360
|
+
if (!clipboard || clipboard.files.length === 0)
|
|
19361
|
+
return;
|
|
19362
|
+
if (Array.from(clipboard.types).includes('text/html') && clipboard.getData('text/plain'))
|
|
19363
|
+
return;
|
|
19364
|
+
const action = fileAction();
|
|
19365
|
+
if (action === 'none')
|
|
19366
|
+
return;
|
|
19367
|
+
event.preventDefault();
|
|
19368
|
+
if (action === 'attach')
|
|
19369
|
+
attachments?.add(Array.from(clipboard.files, pastedName));
|
|
19370
|
+
else
|
|
19371
|
+
refuseFiles();
|
|
19372
|
+
};
|
|
19373
|
+
const onInput = () => { if (!attachments)
|
|
19374
|
+
setNotice(notice, null); };
|
|
19375
|
+
form.addEventListener('dragenter', onDragOver);
|
|
19376
|
+
form.addEventListener('dragover', onDragOver);
|
|
19377
|
+
form.addEventListener('dragleave', onDragLeave);
|
|
19378
|
+
form.addEventListener('drop', onDrop);
|
|
19379
|
+
for (const field of fields) {
|
|
19380
|
+
field.addEventListener('paste', onPaste);
|
|
19381
|
+
field.addEventListener('input', onInput);
|
|
19382
|
+
}
|
|
19383
|
+
return {
|
|
19384
|
+
frame,
|
|
19385
|
+
notice,
|
|
19386
|
+
clearNotice: () => setNotice(notice, null),
|
|
19387
|
+
destroy() {
|
|
19388
|
+
form.removeEventListener('dragenter', onDragOver);
|
|
19389
|
+
form.removeEventListener('dragover', onDragOver);
|
|
19390
|
+
form.removeEventListener('dragleave', onDragLeave);
|
|
19391
|
+
form.removeEventListener('drop', onDrop);
|
|
19392
|
+
for (const field of fields) {
|
|
19393
|
+
field.removeEventListener('paste', onPaste);
|
|
19394
|
+
field.removeEventListener('input', onInput);
|
|
19395
|
+
}
|
|
19396
|
+
},
|
|
19102
19397
|
};
|
|
19103
19398
|
}
|
|
19104
19399
|
|
|
19105
19400
|
const TTL_MS = 30 * 60 * 1000;
|
|
19401
|
+
/** JSON writes one character of a field as up to six: a control character or lone surrogate becomes an escape like \u0001. */
|
|
19402
|
+
const MAX_ESCAPED_CHAR = 6;
|
|
19403
|
+
/** Room in a row for its keys, ids, timestamps, attachment list and article id. */
|
|
19404
|
+
const ROW_FRAME_CHARS = 8192;
|
|
19405
|
+
/** The longest row a writer can store with these fields, so a reader refuses only rows no writer made. */
|
|
19406
|
+
const maxRowChars = (bodies, subjects) => MAX_ESCAPED_CHAR * (bodies * MAX_BODY_BYTES + subjects * MAX_SUBJECT_LEN) + ROW_FRAME_CHARS;
|
|
19407
|
+
/** The question, the request's subject and description, and the question the request was filled from. */
|
|
19408
|
+
const MAX_ISSUE_ROW_CHARS = maxRowChars(3, 1);
|
|
19409
|
+
/** The request and the uncertain send, each with a subject and description. */
|
|
19410
|
+
const MAX_DRAFT_ROW_CHARS = maxRowChars(2, 2);
|
|
19106
19411
|
const storageKey = (deskId, requesterId) => isHelpDeskId(deskId) && isResourceIdOf('requester', requesterId) ? `sv-hd-draft:${deskId}:${requesterId}:new` : null;
|
|
19107
19412
|
const validBody = (value) => typeof value === 'string' && value.length <= MAX_BODY_BYTES && new TextEncoder().encode(value).length <= MAX_BODY_BYTES;
|
|
19108
19413
|
const validSubject = (value) => typeof value === 'string' && value.length <= MAX_SUBJECT_LEN;
|
|
@@ -19123,14 +19428,19 @@ function readSupportDraft(deskId) {
|
|
|
19123
19428
|
const raw = sessionStorage.getItem(`sv-hd-issue:${deskId}`);
|
|
19124
19429
|
if (!raw)
|
|
19125
19430
|
return null;
|
|
19126
|
-
if (raw.length >
|
|
19431
|
+
if (raw.length > MAX_ISSUE_ROW_CHARS)
|
|
19127
19432
|
throw new Error('Invalid issue');
|
|
19128
19433
|
const row = JSON.parse(raw);
|
|
19129
19434
|
if (row?.desk_id !== deskId || !validBody(row.issue) || !Number.isFinite(row.expires_at) ||
|
|
19130
19435
|
row.expires_at <= Date.now() || row.expires_at > Date.now() + TTL_MS ||
|
|
19131
19436
|
(row.composition !== undefined && (!validSubject(row.composition?.subject) || !validBody(row.composition?.body))))
|
|
19132
19437
|
throw new Error('Invalid issue');
|
|
19133
|
-
|
|
19438
|
+
if (row.composition === undefined)
|
|
19439
|
+
return { issue: row.issue };
|
|
19440
|
+
// The question a request was filled from only steers refilling it: one that
|
|
19441
|
+
// is not a question, or belongs to no request, is left out, never the row.
|
|
19442
|
+
return { issue: row.issue, composition: { subject: row.composition.subject, body: row.composition.body },
|
|
19443
|
+
...(validBody(row.composed_from) && { composedFrom: row.composed_from }) };
|
|
19134
19444
|
}
|
|
19135
19445
|
catch {
|
|
19136
19446
|
clearSupportIssue(deskId);
|
|
@@ -19138,25 +19448,34 @@ function readSupportDraft(deskId) {
|
|
|
19138
19448
|
}
|
|
19139
19449
|
}
|
|
19140
19450
|
function readSupportIssue(deskId) { return readSupportDraft(deskId)?.issue ?? null; }
|
|
19141
|
-
function readAnonymousFormDraft(deskId) {
|
|
19142
|
-
|
|
19451
|
+
function readAnonymousFormDraft(deskId) {
|
|
19452
|
+
const draft = readSupportDraft(deskId);
|
|
19453
|
+
return draft?.composition ? { ...draft.composition, composedFrom: draft.composedFrom ?? '' } : null;
|
|
19454
|
+
}
|
|
19455
|
+
function writeSupportDraft(deskId, draft) {
|
|
19143
19456
|
try {
|
|
19144
|
-
sessionStorage.setItem(`sv-hd-issue:${deskId}`, JSON.stringify({ desk_id: deskId, issue,
|
|
19145
|
-
...(composition && { composition }),
|
|
19457
|
+
sessionStorage.setItem(`sv-hd-issue:${deskId}`, JSON.stringify({ desk_id: deskId, issue: draft.issue,
|
|
19458
|
+
...(draft.composition && { composition: draft.composition }), ...(draft.composedFrom !== undefined && { composed_from: draft.composedFrom }),
|
|
19459
|
+
expires_at: Date.now() + TTL_MS }));
|
|
19146
19460
|
}
|
|
19147
19461
|
catch { /* The live wizard still keeps its composition in memory. */ }
|
|
19148
19462
|
}
|
|
19149
19463
|
function saveSupportIssue(deskId, issue) {
|
|
19150
19464
|
if (!isHelpDeskId(deskId) || !validBody(issue))
|
|
19151
19465
|
return;
|
|
19152
|
-
const
|
|
19153
|
-
if (!issue && !composition) {
|
|
19466
|
+
const draft = readSupportDraft(deskId);
|
|
19467
|
+
if (!issue && !draft?.composition) {
|
|
19154
19468
|
clearSupportIssue(deskId);
|
|
19155
19469
|
return;
|
|
19156
19470
|
}
|
|
19157
|
-
writeSupportDraft(deskId,
|
|
19471
|
+
writeSupportDraft(deskId, { ...draft, issue });
|
|
19158
19472
|
}
|
|
19159
|
-
|
|
19473
|
+
/**
|
|
19474
|
+
* Save a signed-out customer's request beside the tab's question, with the
|
|
19475
|
+
* question it was filled from when the support wizard filled it. A question
|
|
19476
|
+
* too long to keep is left out, so the request reads as the customer's own.
|
|
19477
|
+
*/
|
|
19478
|
+
function saveAnonymousFormDraft(deskId, composition, composedFrom) {
|
|
19160
19479
|
if (!isHelpDeskId(deskId) || !validSubject(composition.subject) || !validBody(composition.body))
|
|
19161
19480
|
return;
|
|
19162
19481
|
const issue = readSupportIssue(deskId) ?? '';
|
|
@@ -19164,7 +19483,7 @@ function saveAnonymousFormDraft(deskId, composition) {
|
|
|
19164
19483
|
clearSupportIssue(deskId);
|
|
19165
19484
|
return;
|
|
19166
19485
|
}
|
|
19167
|
-
writeSupportDraft(deskId, issue, { subject: composition.subject, body: composition.body });
|
|
19486
|
+
writeSupportDraft(deskId, { issue, composition: { subject: composition.subject, body: composition.body }, ...(validBody(composedFrom) && { composedFrom }) });
|
|
19168
19487
|
}
|
|
19169
19488
|
function removeFormDraft(deskId, requesterId) {
|
|
19170
19489
|
const key = storageKey(deskId, requesterId);
|
|
@@ -19182,7 +19501,7 @@ function readFormDraft(deskId, requesterId) {
|
|
|
19182
19501
|
const raw = sessionStorage.getItem(key);
|
|
19183
19502
|
if (!raw)
|
|
19184
19503
|
return null;
|
|
19185
|
-
if (raw.length >
|
|
19504
|
+
if (raw.length > MAX_DRAFT_ROW_CHARS)
|
|
19186
19505
|
throw new Error('Invalid draft');
|
|
19187
19506
|
const row = JSON.parse(raw);
|
|
19188
19507
|
const sent = row?.uncertain;
|
|
@@ -19231,9 +19550,47 @@ function unknownSubmissionOutcome(error) {
|
|
|
19231
19550
|
const status = error instanceof SparkVaultError ? error.statusCode : undefined;
|
|
19232
19551
|
return status === undefined || status < 400 || status === 408 || status >= 500;
|
|
19233
19552
|
}
|
|
19234
|
-
|
|
19235
|
-
|
|
19553
|
+
/**
|
|
19554
|
+
* A ticket's body: the details the customer wrote, or, when they wrote none,
|
|
19555
|
+
* the summary, since every ticket carries a message. The one place the two
|
|
19556
|
+
* fields become the body that is checked against the limit and sent.
|
|
19557
|
+
*/
|
|
19558
|
+
function ticketBody(summary, details) {
|
|
19559
|
+
return details.trim() ? details : summary;
|
|
19560
|
+
}
|
|
19561
|
+
/** The details field that gives a send's body back through `ticketBody`: empty when the body is its summary. */
|
|
19562
|
+
function detailsOf(submission) {
|
|
19563
|
+
return submission.body === submission.subject ? '' : submission.body;
|
|
19564
|
+
}
|
|
19565
|
+
/** A signed-in customer as the form names them: "Alex M." for Alex Morgan, a one-word name as it is, else their email. */
|
|
19566
|
+
function postingName(customer) {
|
|
19567
|
+
const words = (customer.display_name ?? '').trim().split(/\s+/).filter(Boolean);
|
|
19568
|
+
if (words.length === 0)
|
|
19569
|
+
return customer.email;
|
|
19570
|
+
if (words.length === 1)
|
|
19571
|
+
return words[0];
|
|
19572
|
+
return `${words[0]} ${Array.from(words[words.length - 1])[0]}.`;
|
|
19573
|
+
}
|
|
19574
|
+
function focusAtEnd(field, focusOptions) {
|
|
19575
|
+
field.focus(focusOptions);
|
|
19576
|
+
// An email field has no caret to place.
|
|
19577
|
+
if (field.type !== 'email')
|
|
19578
|
+
field.setSelectionRange(field.value.length, field.value.length);
|
|
19236
19579
|
}
|
|
19580
|
+
/** A button that reads as a link: an action beside text, never the step's own. */
|
|
19581
|
+
function textButton(text, action) {
|
|
19582
|
+
const button = document.createElement('button');
|
|
19583
|
+
button.type = 'button';
|
|
19584
|
+
button.className = 'svhd-text-button';
|
|
19585
|
+
button.textContent = text;
|
|
19586
|
+
button.addEventListener('click', action);
|
|
19587
|
+
return button;
|
|
19588
|
+
}
|
|
19589
|
+
const SIGN_IN_CANCELLED_COPY = 'Sign-in was cancelled. Your request is still here and hasn’t been sent.';
|
|
19590
|
+
const RECOVER_STATUS_COPY = 'Sign in again to recover your saved request.';
|
|
19591
|
+
const RECOVER_WEBSITE_COPY = 'Sign in to your website account again to recover your saved request.';
|
|
19592
|
+
const WEBSITE_SIGNED_OUT_COPY = 'You’re not signed in to the website. Sign in there, then choose Use website account again.';
|
|
19593
|
+
const RECOVER_NOTE_COPY = 'Sign in with the same email as before to recover your saved request.';
|
|
19237
19594
|
/** Host callback failures do not change a ticket's accepted or failed result. */
|
|
19238
19595
|
function notify$1(callback, value) {
|
|
19239
19596
|
try {
|
|
@@ -19261,6 +19618,22 @@ function edited(input, prefill) {
|
|
|
19261
19618
|
const text = input.value.trim();
|
|
19262
19619
|
return text !== '' && text !== prefill.trim();
|
|
19263
19620
|
}
|
|
19621
|
+
/**
|
|
19622
|
+
* The longest issue that fills the summary when contact starts. An issue this
|
|
19623
|
+
* short, on one line, already names the request; a longer one is the
|
|
19624
|
+
* customer's description, and cutting a summary from it would put words in
|
|
19625
|
+
* their mouth.
|
|
19626
|
+
*/
|
|
19627
|
+
const SUMMARY_PREFILL_MAX = 100;
|
|
19628
|
+
/** Whether trimmed text is one line of at most `max` characters. */
|
|
19629
|
+
function oneLine(text, max) {
|
|
19630
|
+
return text.length <= max && !/[\r\n]/.test(text);
|
|
19631
|
+
}
|
|
19632
|
+
/** What contact starts from: a short one-line issue as the summary; any other as the details, every character as written. */
|
|
19633
|
+
function composeIssue(issue) {
|
|
19634
|
+
const text = issue.trim();
|
|
19635
|
+
return oneLine(text, SUMMARY_PREFILL_MAX) ? { subject: text, body: '' } : { subject: '', body: issue };
|
|
19636
|
+
}
|
|
19264
19637
|
function companySignInUrl(value) {
|
|
19265
19638
|
try {
|
|
19266
19639
|
const url = new URL(value ?? '');
|
|
@@ -19280,24 +19653,54 @@ function companySignInUrl(value) {
|
|
|
19280
19653
|
* line carries the flow (a code sent, a send in progress or uncertain, a
|
|
19281
19654
|
* changed sign-in, a server error). Closing with unsent work asks first.
|
|
19282
19655
|
* A confirmed send replaces the form with its confirmation.
|
|
19656
|
+
*
|
|
19657
|
+
* The request is a summary and optional details, in a composer that also
|
|
19658
|
+
* takes files. A signed-out widget customer writes it as step 1 of 2; step 2
|
|
19659
|
+
* asks who the reply goes to and proves it in the native sign-in window.
|
|
19283
19660
|
*/
|
|
19284
19661
|
function mountHelpDeskForm(client, options) {
|
|
19285
19662
|
const target = resolveTarget(options.target);
|
|
19286
19663
|
injectHelpDeskFormStyles();
|
|
19664
|
+
const widget = options.widgetIdentity;
|
|
19287
19665
|
const shell = new InlineShell(target, {
|
|
19288
19666
|
containerClassName: 'svhd-container',
|
|
19289
19667
|
bodyClassName: 'svhd-body',
|
|
19290
|
-
|
|
19668
|
+
// The page that lays the support wizard out carries the attribution itself.
|
|
19669
|
+
footer: options.hostShowsAttribution ? null : createSecuredByFooter('svhd'),
|
|
19291
19670
|
});
|
|
19292
19671
|
const prefix = `svhd-${++formSequence}`;
|
|
19293
|
-
const heading = document.createElement('h2');
|
|
19294
|
-
heading.id = `${prefix}-heading`;
|
|
19295
|
-
heading.textContent = 'Contact support';
|
|
19296
19672
|
const form = document.createElement('form');
|
|
19297
19673
|
form.className = 'svhd-form';
|
|
19298
19674
|
form.noValidate = true;
|
|
19675
|
+
shell.body.append(form);
|
|
19676
|
+
/** A step's heading, which takes focus when the step is entered, under its "Step N of 2" label when it has one. */
|
|
19677
|
+
function stepHead(id, title, label) {
|
|
19678
|
+
const head = document.createElement('div');
|
|
19679
|
+
head.className = 'svhd-step-head';
|
|
19680
|
+
const stepLabel = label === null ? null : document.createElement('p');
|
|
19681
|
+
if (stepLabel) {
|
|
19682
|
+
stepLabel.className = 'svhd-step-label';
|
|
19683
|
+
stepLabel.textContent = label;
|
|
19684
|
+
head.append(stepLabel);
|
|
19685
|
+
}
|
|
19686
|
+
const stepHeading = document.createElement('h2');
|
|
19687
|
+
stepHeading.id = id;
|
|
19688
|
+
stepHeading.tabIndex = -1;
|
|
19689
|
+
stepHeading.textContent = title;
|
|
19690
|
+
head.append(stepHeading);
|
|
19691
|
+
return { head, heading: stepHeading, label: stepLabel };
|
|
19692
|
+
}
|
|
19693
|
+
function stepContainer(step) {
|
|
19694
|
+
const container = document.createElement('div');
|
|
19695
|
+
container.className = 'svhd-step';
|
|
19696
|
+
container.dataset.contactStep = step;
|
|
19697
|
+
return container;
|
|
19698
|
+
}
|
|
19699
|
+
const request = stepHead(`${prefix}-heading`, widget ? `Contact ${client.desk.organization_name || 'support'}` : 'Contact support', widget ? 'Step 1 of 2' : null);
|
|
19700
|
+
const heading = request.heading;
|
|
19299
19701
|
form.setAttribute('aria-labelledby', heading.id);
|
|
19300
|
-
|
|
19702
|
+
const details = stepContainer('details');
|
|
19703
|
+
details.append(request.head);
|
|
19301
19704
|
// A field's error is an alert only while it shows, so it is announced
|
|
19302
19705
|
// even when focus already sits on the field it names.
|
|
19303
19706
|
function setFieldError(entry, text) {
|
|
@@ -19329,10 +19732,11 @@ function mountHelpDeskForm(client, options) {
|
|
|
19329
19732
|
label.className = 'svhd-label';
|
|
19330
19733
|
label.htmlFor = `${prefix}-${name}`;
|
|
19331
19734
|
label.textContent = labelText;
|
|
19332
|
-
const input = textarea ?
|
|
19735
|
+
const input = textarea ? document.createElement('textarea') : document.createElement('input');
|
|
19333
19736
|
input.id = label.htmlFor;
|
|
19334
19737
|
input.name = name;
|
|
19335
|
-
|
|
19738
|
+
if (!textarea)
|
|
19739
|
+
input.className = 'svhd-input';
|
|
19336
19740
|
const error = document.createElement('p');
|
|
19337
19741
|
error.id = `${input.id}-error`;
|
|
19338
19742
|
error.className = 'svhd-field-error';
|
|
@@ -19342,19 +19746,23 @@ function mountHelpDeskForm(client, options) {
|
|
|
19342
19746
|
input.addEventListener('input', () => clearFieldError(created));
|
|
19343
19747
|
return created;
|
|
19344
19748
|
}
|
|
19345
|
-
const subject = field('
|
|
19346
|
-
const description = field('
|
|
19749
|
+
const subject = field('Summary', 'subject');
|
|
19750
|
+
const description = field('Additional details', 'description', true);
|
|
19347
19751
|
const email = field('Email address', 'email');
|
|
19348
19752
|
const code = field('Email code', 'code');
|
|
19349
19753
|
const name = field('Your name', 'display_name');
|
|
19350
19754
|
const firstName = field('First name', 'given_name');
|
|
19351
19755
|
const lastName = field('Last name (optional)', 'family_name');
|
|
19352
19756
|
const fields = [subject, description, email, code, name, firstName, lastName];
|
|
19353
|
-
//
|
|
19354
|
-
|
|
19757
|
+
// The support wizard's issue the form was last filled from, which either
|
|
19758
|
+
// field may hold; undefined for a form filled from the host's subject and body.
|
|
19759
|
+
let filledFrom = options.issue;
|
|
19760
|
+
/** What a field was filled with: text the customer did not write. */
|
|
19761
|
+
const filledWith = (key) => filledFrom ?? options[key] ?? '';
|
|
19762
|
+
const filled = filledFrom === undefined ? { subject: filledWith('subject'), body: filledWith('body') } : composeIssue(filledFrom);
|
|
19355
19763
|
subject.input.maxLength = MAX_SUBJECT_LEN;
|
|
19356
|
-
subject.input.value =
|
|
19357
|
-
description.input.value =
|
|
19764
|
+
subject.input.value = filled.subject;
|
|
19765
|
+
description.input.value = filled.body;
|
|
19358
19766
|
email.input.type = 'email';
|
|
19359
19767
|
email.input.autocomplete = 'email';
|
|
19360
19768
|
code.input.inputMode = 'numeric';
|
|
@@ -19366,7 +19774,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
19366
19774
|
lastName.input.maxLength = 100;
|
|
19367
19775
|
const codeHint = document.createElement('p');
|
|
19368
19776
|
codeHint.id = `${code.input.id}-hint`;
|
|
19369
|
-
codeHint.className = 'svhd-
|
|
19777
|
+
codeHint.className = 'svhd-hint';
|
|
19370
19778
|
codeHint.textContent = `It works for ${HELP_DESK_PIN_TTL_MINUTES} minutes. Not in your inbox? Look in spam for mail from ${client.desk.contact_email ?? helpDeskCodeSender(client.desk.sending_host)}.`;
|
|
19371
19779
|
code.input.setAttribute('aria-describedby', codeHint.id);
|
|
19372
19780
|
const resend = document.createElement('button');
|
|
@@ -19383,23 +19791,93 @@ function mountHelpDeskForm(client, options) {
|
|
|
19383
19791
|
code.wrapper.append(codeHint, codeLinks);
|
|
19384
19792
|
code.wrapper.hidden = true;
|
|
19385
19793
|
name.wrapper.hidden = true;
|
|
19794
|
+
subject.input.required = true;
|
|
19795
|
+
// Enter in the summary moves on to the details it leads into, never sends a request half written.
|
|
19796
|
+
subject.input.addEventListener('keydown', (event) => {
|
|
19797
|
+
if (event.key !== 'Enter' || event.isComposing || event.keyCode === 229)
|
|
19798
|
+
return;
|
|
19799
|
+
event.preventDefault();
|
|
19800
|
+
focusAtEnd(description.input);
|
|
19801
|
+
});
|
|
19802
|
+
const attachments = client.desk.customer_can_attach_files && options.attachments !== false
|
|
19803
|
+
? createFormAttachments(client, prefix, async () => {
|
|
19804
|
+
const ownGeneration = generation;
|
|
19805
|
+
const token = await tokenFor(ownGeneration);
|
|
19806
|
+
if (!token || !alive(ownGeneration))
|
|
19807
|
+
return null;
|
|
19808
|
+
const id = await ensureDraft(ownGeneration, token);
|
|
19809
|
+
if (!alive(ownGeneration))
|
|
19810
|
+
return null;
|
|
19811
|
+
return { draftId: id, expectedSessionToken: token };
|
|
19812
|
+
}, () => {
|
|
19813
|
+
if (attachments?.hasEntries)
|
|
19814
|
+
restoredFiles = false;
|
|
19815
|
+
persistDraft();
|
|
19816
|
+
syncLeaveGuard();
|
|
19817
|
+
})
|
|
19818
|
+
: undefined;
|
|
19819
|
+
const composer = createComposer({
|
|
19820
|
+
form, summary: subject.input, textarea: description.input, attachments,
|
|
19821
|
+
deskRefusesFiles: !client.desk.customer_can_attach_files, onRequestStep: () => step === 'details',
|
|
19822
|
+
});
|
|
19823
|
+
description.wrapper.classList.add('svhd-composer-field');
|
|
19824
|
+
description.wrapper.insertBefore(composer.frame, description.error);
|
|
19825
|
+
description.wrapper.insertBefore(composer.notice, description.error);
|
|
19826
|
+
details.append(subject.wrapper, description.wrapper);
|
|
19386
19827
|
const auth = document.createElement('fieldset');
|
|
19387
19828
|
auth.className = 'svhd-auth';
|
|
19388
19829
|
auth.hidden = true;
|
|
19389
|
-
auth.append(
|
|
19830
|
+
auth.append(code.wrapper, name.wrapper);
|
|
19390
19831
|
const widgetAccount = document.createElement('div');
|
|
19391
19832
|
widgetAccount.className = 'svhd-widget-account';
|
|
19392
|
-
let widgetCustomer =
|
|
19393
|
-
|
|
19394
|
-
|
|
19395
|
-
|
|
19396
|
-
|
|
19397
|
-
|
|
19833
|
+
let widgetCustomer = widget?.customer ?? null;
|
|
19834
|
+
// A desk that signs in with SparkVault Identity asks only the email: its sign-in window asks a missing name.
|
|
19835
|
+
const asksName = client.desk.auth_mode !== 'identity';
|
|
19836
|
+
const reply = widget ? stepHead(`${prefix}-reply-heading`, asksName ? 'Who should we reply to?' : 'Sign in to send your request', 'Step 2 of 2') : null;
|
|
19837
|
+
const identity = widget ? stepContainer('identity') : null;
|
|
19838
|
+
const recap = document.createElement('div');
|
|
19839
|
+
recap.className = 'svhd-recap';
|
|
19840
|
+
const recapText = document.createElement('p');
|
|
19841
|
+
recapText.className = 'svhd-recap-text';
|
|
19842
|
+
const editRequest = textButton('Edit', () => { if (!pending && !destroyed)
|
|
19843
|
+
enterStep('details'); });
|
|
19844
|
+
editRequest.setAttribute('aria-label', 'Edit your request');
|
|
19845
|
+
const noteText = document.createTextNode('');
|
|
19846
|
+
const unsentNote = asksName
|
|
19847
|
+
? 'Your request hasn’t been sent yet. Tell us who to reply to, then we’ll send it.'
|
|
19848
|
+
: 'Your request hasn’t been sent yet. Sign in so we know who to reply to, then we’ll send it.';
|
|
19849
|
+
const live = createLiveRegion('svhd-live');
|
|
19850
|
+
if (identity && reply) {
|
|
19398
19851
|
form.classList.add('svhd-widget-form');
|
|
19399
|
-
|
|
19400
|
-
|
|
19401
|
-
|
|
19402
|
-
|
|
19852
|
+
details.append(widgetAccount);
|
|
19853
|
+
identity.hidden = true;
|
|
19854
|
+
const note = document.createElement('p');
|
|
19855
|
+
note.className = 'svhd-note';
|
|
19856
|
+
note.dataset.unsentNote = '';
|
|
19857
|
+
note.append(helpDeskIcon('info'), noteText);
|
|
19858
|
+
const recapRequest = document.createElement('div');
|
|
19859
|
+
recapRequest.className = 'svhd-recap-request';
|
|
19860
|
+
const recapLabel = document.createElement('span');
|
|
19861
|
+
recapLabel.className = 'svhd-recap-label';
|
|
19862
|
+
recapLabel.textContent = 'Your request';
|
|
19863
|
+
recapRequest.append(recapLabel, recapText);
|
|
19864
|
+
recap.append(recapRequest, editRequest);
|
|
19865
|
+
const helper = document.createElement('p');
|
|
19866
|
+
helper.id = `${email.input.id}-help`;
|
|
19867
|
+
helper.className = 'svhd-hint';
|
|
19868
|
+
helper.textContent = asksName ? 'We’ll email you a code to confirm it’s you.' : 'You’ll confirm it’s you in a secure SparkVault window.';
|
|
19869
|
+
email.input.setAttribute('aria-describedby', helper.id);
|
|
19870
|
+
identity.append(reply.head, note, recap);
|
|
19871
|
+
if (asksName) {
|
|
19872
|
+
const names = document.createElement('div');
|
|
19873
|
+
names.className = 'svhd-widget-names';
|
|
19874
|
+
names.append(firstName.wrapper, lastName.wrapper);
|
|
19875
|
+
identity.append(names);
|
|
19876
|
+
}
|
|
19877
|
+
identity.append(email.wrapper, helper);
|
|
19878
|
+
}
|
|
19879
|
+
else
|
|
19880
|
+
auth.prepend(email.wrapper);
|
|
19403
19881
|
const status = document.createElement('p');
|
|
19404
19882
|
status.className = 'svhd-status';
|
|
19405
19883
|
status.setAttribute('role', 'status');
|
|
@@ -19419,13 +19897,15 @@ function mountHelpDeskForm(client, options) {
|
|
|
19419
19897
|
const send = document.createElement('button');
|
|
19420
19898
|
send.className = 'svhd-button';
|
|
19421
19899
|
send.type = 'submit';
|
|
19422
|
-
send.textContent = options.widgetIdentity ? widgetCustomer ? 'Send message' : 'Continue' : 'Send request';
|
|
19423
19900
|
const cancel = document.createElement('button');
|
|
19424
19901
|
cancel.className = 'svhd-button svhd-secondary';
|
|
19425
19902
|
cancel.type = 'button';
|
|
19426
19903
|
cancel.textContent = 'Cancel';
|
|
19427
19904
|
cancel.hidden = !options.onCancel;
|
|
19428
|
-
|
|
19905
|
+
const startNew = textButton('Start a new request', () => { if (!pending && !destroyed && recovery !== null)
|
|
19906
|
+
leaveRecovery(); });
|
|
19907
|
+
startNew.hidden = true;
|
|
19908
|
+
actions.append(send, startNew, cancel);
|
|
19429
19909
|
const confirm = document.createElement('div');
|
|
19430
19910
|
confirm.className = 'svhd-confirm';
|
|
19431
19911
|
confirm.setAttribute('role', 'group');
|
|
@@ -19451,8 +19931,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
19451
19931
|
discard.textContent = DISCARD_REQUEST_COPY.discard;
|
|
19452
19932
|
confirmActions.append(keepEditing, discard);
|
|
19453
19933
|
confirm.append(confirmTitle, confirmNote, confirmActions);
|
|
19454
|
-
form.append(
|
|
19934
|
+
form.append(details, ...(identity ? [identity] : []), auth, status, hosted, actions, confirm, live.element);
|
|
19455
19935
|
let state = 'editing';
|
|
19936
|
+
let step = 'details';
|
|
19937
|
+
let guardingLeave = false;
|
|
19456
19938
|
let destroyed = false;
|
|
19457
19939
|
let pending = false;
|
|
19458
19940
|
let completed = false;
|
|
@@ -19472,43 +19954,56 @@ function mountHelpDeskForm(client, options) {
|
|
|
19472
19954
|
let uncertainSubmission = null;
|
|
19473
19955
|
let sessionToken = null;
|
|
19474
19956
|
let sessionKnown = false;
|
|
19475
|
-
let attachments;
|
|
19476
19957
|
let submittedCode = null;
|
|
19477
19958
|
let resendAt = 0;
|
|
19478
19959
|
let resendTimer = null;
|
|
19479
19960
|
let confirmReturn = null;
|
|
19480
19961
|
let done = null;
|
|
19481
|
-
|
|
19962
|
+
// The verified customer whose saved request the form holds.
|
|
19963
|
+
let draftOwner = null;
|
|
19482
19964
|
let restoredDraft = false;
|
|
19483
19965
|
let restoredAnonymous = false;
|
|
19484
19966
|
let restoredFiles = false;
|
|
19485
|
-
|
|
19967
|
+
// How the customer whose saved request the form hides signed in, while it
|
|
19968
|
+
// waits for them to sign in again: that is the only way back to it.
|
|
19969
|
+
let recovery = null;
|
|
19970
|
+
// The website gave no account back when asked for the hidden request's customer.
|
|
19971
|
+
let websiteSignedOut = false;
|
|
19486
19972
|
function persistDraft() {
|
|
19487
19973
|
if (!options.persist || completed || destroyed)
|
|
19488
19974
|
return;
|
|
19489
|
-
if (!
|
|
19490
|
-
|
|
19491
|
-
|
|
19975
|
+
if (!draftOwner) {
|
|
19976
|
+
// The hidden request is a previous customer's; nothing is saved over it.
|
|
19977
|
+
if (recovery === null)
|
|
19978
|
+
saveAnonymousFormDraft(client.desk.desk_id, { subject: subject.input.value, body: description.input.value }, filledFrom);
|
|
19492
19979
|
return;
|
|
19493
19980
|
}
|
|
19494
|
-
saveFormDraft(client.desk.desk_id,
|
|
19981
|
+
saveFormDraft(client.desk.desk_id, draftOwner.requester_id, {
|
|
19495
19982
|
subject: subject.input.value, body: description.input.value, ticketId: draftId,
|
|
19496
19983
|
uncertain: uncertainSubmission, hadFiles: restoredFiles || attachments?.hasEntries === true,
|
|
19497
19984
|
});
|
|
19498
19985
|
}
|
|
19499
19986
|
function forgetDraft() {
|
|
19500
|
-
if (
|
|
19501
|
-
|
|
19502
|
-
|
|
19987
|
+
if (!options.persist)
|
|
19988
|
+
return;
|
|
19989
|
+
if (draftOwner)
|
|
19990
|
+
removeFormDraft(client.desk.desk_id, draftOwner.requester_id);
|
|
19991
|
+
else
|
|
19503
19992
|
clearSupportIssue(client.desk.desk_id);
|
|
19504
19993
|
}
|
|
19505
|
-
/**
|
|
19994
|
+
/**
|
|
19995
|
+
* The request is now this verified customer's, saved in this tab or not.
|
|
19996
|
+
* Only /me or the verified sign-in answer can select a saved requester's draft.
|
|
19997
|
+
*/
|
|
19506
19998
|
function restoreDraft(customer) {
|
|
19507
|
-
if (
|
|
19999
|
+
if (draftOwner?.requester_id === customer.requester_id)
|
|
20000
|
+
return false;
|
|
20001
|
+
draftOwner = customer;
|
|
20002
|
+
recovery = null;
|
|
20003
|
+
renderActions();
|
|
20004
|
+
if (!options.persist)
|
|
19508
20005
|
return false;
|
|
19509
|
-
|
|
19510
|
-
draftRequester = customer.requester_id;
|
|
19511
|
-
const saved = readFormDraft(client.desk.desk_id, draftRequester);
|
|
20006
|
+
const saved = readFormDraft(client.desk.desk_id, customer.requester_id);
|
|
19512
20007
|
clearSupportIssue(client.desk.desk_id);
|
|
19513
20008
|
if (!saved) {
|
|
19514
20009
|
persistDraft();
|
|
@@ -19517,12 +20012,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
19517
20012
|
restoredDraft = true;
|
|
19518
20013
|
restoredFiles = saved.hadFiles && !saved.uncertain;
|
|
19519
20014
|
subject.input.value = saved.uncertain?.subject ?? saved.subject;
|
|
19520
|
-
description.input.value = saved.uncertain
|
|
20015
|
+
description.input.value = saved.uncertain ? detailsOf(saved.uncertain) : saved.body;
|
|
19521
20016
|
draftId = saved.ticketId;
|
|
19522
20017
|
uncertainSubmission = saved.uncertain;
|
|
19523
|
-
|
|
19524
|
-
description.input.readOnly = uncertainSubmission !== null;
|
|
19525
|
-
send.textContent = uncertainSubmission ? 'Check submission' : options.widgetIdentity ? widgetCustomer ? 'Send message' : 'Continue' : 'Send request';
|
|
20018
|
+
send.textContent = idleLabel();
|
|
19526
20019
|
setState(uncertainSubmission ? 'uncertain' : 'editing');
|
|
19527
20020
|
message(uncertainSubmission
|
|
19528
20021
|
? 'Your original request is preserved. Check submission before starting another request.'
|
|
@@ -19534,55 +20027,136 @@ function mountHelpDeskForm(client, options) {
|
|
|
19534
20027
|
// An account switch must not turn an uncertain send into a fresh request.
|
|
19535
20028
|
return pending || uncertainSubmission !== null || completed ? null : { subject: subject.input.value, body: description.input.value };
|
|
19536
20029
|
}
|
|
20030
|
+
/** What the send button reads while nothing is in flight. */
|
|
20031
|
+
function idleLabel() {
|
|
20032
|
+
if (uncertainSubmission)
|
|
20033
|
+
return 'Check submission';
|
|
20034
|
+
if (challenge)
|
|
20035
|
+
return 'Verify and send request';
|
|
20036
|
+
if (recovery === 'external_sso' && widget)
|
|
20037
|
+
return 'Use website account';
|
|
20038
|
+
if (recovery !== null && step === 'details')
|
|
20039
|
+
return 'Sign in to recover request';
|
|
20040
|
+
return widget && !widgetCustomer ? 'Continue' : 'Send request';
|
|
20041
|
+
}
|
|
20042
|
+
/**
|
|
20043
|
+
* The signed-in widget customer writes and sends in one step, posting as
|
|
20044
|
+
* the account named under it; a signed-out one writes the request as step
|
|
20045
|
+
* 1 of 2. Either way the form shows the request.
|
|
20046
|
+
*/
|
|
19537
20047
|
function renderWidgetIdentity() {
|
|
19538
|
-
if (!
|
|
20048
|
+
if (!widget)
|
|
19539
20049
|
return;
|
|
19540
|
-
|
|
19541
|
-
|
|
19542
|
-
auth.hidden =
|
|
19543
|
-
email.wrapper.hidden = false;
|
|
20050
|
+
if (request.label)
|
|
20051
|
+
request.label.hidden = widgetCustomer !== null;
|
|
20052
|
+
auth.hidden = true;
|
|
19544
20053
|
code.wrapper.hidden = true;
|
|
19545
20054
|
name.wrapper.hidden = true;
|
|
20055
|
+
widgetAccount.replaceChildren();
|
|
20056
|
+
const free = () => !pending && !destroyed && uncertainSubmission === null && !completed;
|
|
19546
20057
|
if (widgetCustomer) {
|
|
19547
|
-
const
|
|
19548
|
-
|
|
19549
|
-
const
|
|
19550
|
-
|
|
19551
|
-
|
|
19552
|
-
|
|
19553
|
-
|
|
19554
|
-
|
|
19555
|
-
|
|
19556
|
-
change.className = 'svhd-widget-account-link';
|
|
19557
|
-
change.textContent = 'Not you?';
|
|
19558
|
-
change.addEventListener('click', () => {
|
|
19559
|
-
if (pending || destroyed || uncertainSubmission !== null || completed)
|
|
19560
|
-
return;
|
|
19561
|
-
options.widgetIdentity?.switchAccount(safeComposition());
|
|
19562
|
-
});
|
|
19563
|
-
widgetAccount.append(identity, change);
|
|
20058
|
+
const postingAs = document.createElement('p');
|
|
20059
|
+
postingAs.className = 'svhd-posting-as';
|
|
20060
|
+
const shown = postingName(widgetCustomer);
|
|
20061
|
+
// Not you? opens the sign-in window in this click: nothing may await before it.
|
|
20062
|
+
postingAs.append(`Posting as ${shown}${shown.endsWith('.') ? '' : '.'} `, textButton('Not you?', () => {
|
|
20063
|
+
if (free())
|
|
20064
|
+
widget.switchAccount(safeComposition());
|
|
20065
|
+
}));
|
|
20066
|
+
widgetAccount.append(postingAs);
|
|
19564
20067
|
}
|
|
19565
|
-
|
|
19566
|
-
|
|
19567
|
-
|
|
19568
|
-
|
|
19569
|
-
|
|
19570
|
-
}
|
|
19571
|
-
if (options.widgetIdentity.useWebsiteAccount) {
|
|
19572
|
-
const website = document.createElement('button');
|
|
19573
|
-
website.type = 'button';
|
|
19574
|
-
website.className = 'svhd-widget-account-link';
|
|
19575
|
-
website.textContent = 'Use website account';
|
|
19576
|
-
website.addEventListener('click', () => {
|
|
19577
|
-
if (!pending && !destroyed && uncertainSubmission === null && !completed)
|
|
19578
|
-
options.widgetIdentity?.useWebsiteAccount?.(safeComposition());
|
|
19579
|
-
});
|
|
19580
|
-
widgetAccount.append(website);
|
|
20068
|
+
if (widget.useWebsiteAccount && widget.offerWebsiteAccount) {
|
|
20069
|
+
widgetAccount.append(textButton('Use website account', () => {
|
|
20070
|
+
if (free())
|
|
20071
|
+
widget.useWebsiteAccount?.(safeComposition());
|
|
20072
|
+
}));
|
|
19581
20073
|
}
|
|
20074
|
+
setStep('details');
|
|
20075
|
+
}
|
|
20076
|
+
/**
|
|
20077
|
+
* The actions and notes for where the request is. While the form hides a
|
|
20078
|
+
* previous customer's saved request (`recovery`), nothing shows of it, nor
|
|
20079
|
+
* says it was not sent, since it may be a send whose answer was lost: the
|
|
20080
|
+
* request step's status line says how to get it back and the reply-to
|
|
20081
|
+
* step's note alone speaks there, Start a new request leaves it, and the
|
|
20082
|
+
* account row is away. A website-account customer's request comes back only
|
|
20083
|
+
* through that account, so Use website account is its one way on when the
|
|
20084
|
+
* website bridges one, and there is none when it does not.
|
|
20085
|
+
*/
|
|
20086
|
+
function renderActions() {
|
|
20087
|
+
send.textContent = idleLabel();
|
|
20088
|
+
send.hidden = recovery === 'external_sso' && widget !== undefined && !widget.useWebsiteAccount;
|
|
20089
|
+
startNew.hidden = recovery === null;
|
|
20090
|
+
widgetAccount.hidden = recovery !== null || widgetAccount.childElementCount === 0;
|
|
20091
|
+
recap.hidden = recovery !== null;
|
|
20092
|
+
noteText.data = recovery === 'identity' || recovery === 'email_pin' ? RECOVER_NOTE_COPY : unsentNote;
|
|
20093
|
+
if (recovery !== null)
|
|
20094
|
+
message(step === 'identity' ? '' : recoveryStatus());
|
|
20095
|
+
}
|
|
20096
|
+
/** What the request step's status line asks for while a saved request is hidden. */
|
|
20097
|
+
function recoveryStatus() {
|
|
20098
|
+
if (recovery !== 'external_sso')
|
|
20099
|
+
return RECOVER_STATUS_COPY;
|
|
20100
|
+
return websiteSignedOut ? WEBSITE_SIGNED_OUT_COPY : RECOVER_WEBSITE_COPY;
|
|
20101
|
+
}
|
|
20102
|
+
/** Start a new request in place of the hidden one, which stays saved for its customer. */
|
|
20103
|
+
function leaveRecovery() {
|
|
20104
|
+
recovery = null;
|
|
20105
|
+
disable(false);
|
|
20106
|
+
message('');
|
|
20107
|
+
// A question asked while the saved request was hidden fills the new one.
|
|
20108
|
+
widget?.followIssue();
|
|
20109
|
+
if (step === 'identity')
|
|
20110
|
+
enterStep('details');
|
|
20111
|
+
else {
|
|
20112
|
+
renderActions();
|
|
20113
|
+
options.onScreenChange?.();
|
|
20114
|
+
controller.focusEntry();
|
|
20115
|
+
}
|
|
20116
|
+
}
|
|
20117
|
+
/** Show one step, the request or who the reply goes to, without moving focus. */
|
|
20118
|
+
function setStep(next) {
|
|
20119
|
+
const changed = next !== step;
|
|
20120
|
+
step = next;
|
|
20121
|
+
details.hidden = next !== 'details';
|
|
20122
|
+
if (identity)
|
|
20123
|
+
identity.hidden = next !== 'identity';
|
|
20124
|
+
if (next === 'identity')
|
|
20125
|
+
recapText.textContent = subject.input.value.trim();
|
|
20126
|
+
renderActions();
|
|
20127
|
+
syncLeaveGuard();
|
|
20128
|
+
if (changed)
|
|
20129
|
+
options.onScreenChange?.();
|
|
20130
|
+
}
|
|
20131
|
+
/** The customer moves between the steps: the new step's heading takes focus and its place is announced. */
|
|
20132
|
+
function enterStep(next) {
|
|
20133
|
+
setStep(next);
|
|
20134
|
+
live.announce(next === 'identity' ? 'Step 2 of 2' : 'Step 1 of 2');
|
|
20135
|
+
(next === 'identity' && reply ? reply.heading : heading).focus();
|
|
20136
|
+
}
|
|
20137
|
+
// An inline wizard, on any host page that gives a `target`, asks before that
|
|
20138
|
+
// page unloads while the request holds unsent work: leaving would lose it.
|
|
20139
|
+
// The floating panel never holds the page.
|
|
20140
|
+
// Chrome and Edge below 119, inside the SDK's browser floor, ask only when
|
|
20141
|
+
// returnValue is set; preventDefault is the standard signal.
|
|
20142
|
+
const onBeforeUnload = (event) => {
|
|
20143
|
+
event.preventDefault();
|
|
20144
|
+
event.returnValue = '';
|
|
20145
|
+
};
|
|
20146
|
+
function syncLeaveGuard() {
|
|
20147
|
+
const needed = options.pageLayout === true && !destroyed && holdsUnsentWork();
|
|
20148
|
+
if (needed === guardingLeave)
|
|
20149
|
+
return;
|
|
20150
|
+
guardingLeave = needed;
|
|
20151
|
+
if (needed)
|
|
20152
|
+
window.addEventListener('beforeunload', onBeforeUnload);
|
|
20153
|
+
else
|
|
20154
|
+
window.removeEventListener('beforeunload', onBeforeUnload);
|
|
19582
20155
|
}
|
|
19583
20156
|
function setState(next) {
|
|
19584
20157
|
state = next;
|
|
19585
20158
|
persistDraft();
|
|
20159
|
+
syncLeaveGuard();
|
|
19586
20160
|
notify$1(options.onStateChange, next);
|
|
19587
20161
|
}
|
|
19588
20162
|
function message(text, isError = false) {
|
|
@@ -19609,13 +20183,22 @@ function mountHelpDeskForm(client, options) {
|
|
|
19609
20183
|
resendTimer = setInterval(renderResend, 1000);
|
|
19610
20184
|
renderResend();
|
|
19611
20185
|
}
|
|
20186
|
+
/**
|
|
20187
|
+
* Disable every control while `disabled`. The request stays read-only, and
|
|
20188
|
+
* takes no files, while a send is unanswered, its exact text kept for the
|
|
20189
|
+
* check, and while it hides a saved request, which signing in brings back
|
|
20190
|
+
* in place of anything written.
|
|
20191
|
+
*/
|
|
19612
20192
|
function disable(disabled) {
|
|
19613
|
-
for (const input of [subject.input, description.input, email.input, code.input, name.input, firstName.input, lastName.input, send, cancel, changeEmail])
|
|
20193
|
+
for (const input of [subject.input, description.input, email.input, code.input, name.input, firstName.input, lastName.input, send, cancel, changeEmail, editRequest, startNew])
|
|
19614
20194
|
input.disabled = disabled;
|
|
20195
|
+
const held = uncertainSubmission !== null || recovery !== null;
|
|
20196
|
+
subject.input.readOnly = held;
|
|
20197
|
+
description.input.readOnly = held;
|
|
19615
20198
|
for (const button of widgetAccount.querySelectorAll('button'))
|
|
19616
20199
|
button.disabled = disabled || uncertainSubmission !== null || completed;
|
|
19617
20200
|
renderResend();
|
|
19618
|
-
attachments?.disablePicking(disabled);
|
|
20201
|
+
attachments?.disablePicking(disabled || recovery !== null);
|
|
19619
20202
|
attachments?.lock(completed || uncertainSubmission !== null);
|
|
19620
20203
|
}
|
|
19621
20204
|
function clearCode() {
|
|
@@ -19644,8 +20227,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
19644
20227
|
? 'We may already have received this request. Closing now loses the way to check it.'
|
|
19645
20228
|
: DISCARD_REQUEST_COPY.note;
|
|
19646
20229
|
}
|
|
19647
|
-
/** The field of the step in view: the code, name or email the sign-in asks for, else the
|
|
20230
|
+
/** The field of the step in view: who the reply goes to, the code, name or email the sign-in asks for, else the summary. */
|
|
19648
20231
|
function stepField() {
|
|
20232
|
+
if (step === 'identity')
|
|
20233
|
+
return (asksName ? firstName : email).input;
|
|
19649
20234
|
const asked = auth.hidden ? undefined : [code, name, email].find((entry) => !entry.wrapper.hidden);
|
|
19650
20235
|
return (asked ?? subject).input;
|
|
19651
20236
|
}
|
|
@@ -19686,25 +20271,27 @@ function mountHelpDeskForm(client, options) {
|
|
|
19686
20271
|
}
|
|
19687
20272
|
/**
|
|
19688
20273
|
* Whether closing now would lose something: a send under way or
|
|
19689
|
-
* unanswered, a code step,
|
|
19690
|
-
*
|
|
19691
|
-
* no work of the customer's.
|
|
20274
|
+
* unanswered, a code step, a request moved on to who the reply goes to, or
|
|
20275
|
+
* text and files of the customer's own. The silent company sign-in the
|
|
20276
|
+
* form runs as it opens (`authenticating`) is no work of the customer's.
|
|
19692
20277
|
*/
|
|
19693
20278
|
function holdsUnsentWork() {
|
|
19694
20279
|
if (completed)
|
|
19695
20280
|
return false;
|
|
19696
|
-
return (pending && state !== 'authenticating') || uncertainSubmission !== null || challenge !== null
|
|
19697
|
-
|| edited(subject.input,
|
|
20281
|
+
return (pending && state !== 'authenticating') || uncertainSubmission !== null || challenge !== null || step === 'identity'
|
|
20282
|
+
|| edited(subject.input, filledWith('subject')) || edited(description.input, filledWith('body'))
|
|
19698
20283
|
|| attachments?.hasEntries === true;
|
|
19699
20284
|
}
|
|
19700
|
-
/**
|
|
20285
|
+
/**
|
|
20286
|
+
* The field a request the ticket write would refuse is refused under, with
|
|
20287
|
+
* what it reads there; null for one it takes. The body is `ticketBody`'s,
|
|
20288
|
+
* so a request of a summary alone always has one.
|
|
20289
|
+
*/
|
|
19701
20290
|
function refusal(subjectText, body) {
|
|
19702
20291
|
if (!subjectText)
|
|
19703
|
-
return [subject, 'Add a
|
|
20292
|
+
return [subject, 'Add a summary.'];
|
|
19704
20293
|
if (subjectText.length > MAX_SUBJECT_LEN)
|
|
19705
|
-
return [subject, `Keep the
|
|
19706
|
-
if (!body.trim())
|
|
19707
|
-
return [description, 'Describe what you need help with.'];
|
|
20294
|
+
return [subject, `Keep the summary to ${MAX_SUBJECT_LEN} characters.`];
|
|
19708
20295
|
// The limit counts UTF-8 bytes, so a message of fewer characters can be over it;
|
|
19709
20296
|
// a message of more UTF-16 units than that is over it without being encoded.
|
|
19710
20297
|
if (body.length > MAX_BODY_BYTES || new TextEncoder().encode(body).length > MAX_BODY_BYTES)
|
|
@@ -19773,7 +20360,8 @@ function mountHelpDeskForm(client, options) {
|
|
|
19773
20360
|
attachments?.clear(completed || uncertainSubmission !== null);
|
|
19774
20361
|
attachments?.lock(false);
|
|
19775
20362
|
if (attachments)
|
|
19776
|
-
attachments.
|
|
20363
|
+
attachments.list.hidden = false;
|
|
20364
|
+
composer.clearNotice();
|
|
19777
20365
|
subject.input.value = '';
|
|
19778
20366
|
description.input.value = '';
|
|
19779
20367
|
email.input.value = '';
|
|
@@ -19794,13 +20382,13 @@ function mountHelpDeskForm(client, options) {
|
|
|
19794
20382
|
draftId = null;
|
|
19795
20383
|
draftPromise = null;
|
|
19796
20384
|
uncertainSubmission = null;
|
|
19797
|
-
|
|
20385
|
+
recovery = null;
|
|
20386
|
+
websiteSignedOut = false;
|
|
19798
20387
|
restoredAnonymous = false;
|
|
19799
|
-
subject.input.readOnly = false;
|
|
19800
|
-
description.input.readOnly = false;
|
|
19801
20388
|
completed = false;
|
|
19802
|
-
send.textContent = 'Send request';
|
|
19803
20389
|
message('');
|
|
20390
|
+
renderActions();
|
|
20391
|
+
syncLeaveGuard();
|
|
19804
20392
|
}
|
|
19805
20393
|
function sessionChanged(change) {
|
|
19806
20394
|
if (destroyed)
|
|
@@ -19833,18 +20421,26 @@ function mountHelpDeskForm(client, options) {
|
|
|
19833
20421
|
// during a pending proof must not leave the previous composer visible.
|
|
19834
20422
|
subject.input.value = '';
|
|
19835
20423
|
description.input.value = '';
|
|
20424
|
+
recapText.textContent = '';
|
|
19836
20425
|
name.input.value = '';
|
|
19837
20426
|
email.input.value = '';
|
|
19838
20427
|
clearCode();
|
|
19839
20428
|
if (attachments)
|
|
19840
|
-
attachments.
|
|
20429
|
+
attachments.list.hidden = true;
|
|
19841
20430
|
return;
|
|
19842
20431
|
}
|
|
19843
20432
|
// Preserve the old request before hiding it. The next verified requester
|
|
19844
20433
|
// selects only their own storage key, including after a 401 and sign-in.
|
|
19845
20434
|
persistDraft();
|
|
19846
|
-
|
|
19847
|
-
|
|
20435
|
+
// A signed-in customer's request leaves view, saved or not, and with it the
|
|
20436
|
+
// question it was filled from: nothing the form holds may write it back.
|
|
20437
|
+
const hidesCustomer = draftOwner !== null;
|
|
20438
|
+
if (hidesCustomer && filledFrom !== undefined)
|
|
20439
|
+
filledFrom = '';
|
|
20440
|
+
// A saved request stays hidden for its customer, through any further change.
|
|
20441
|
+
const hidden = draftOwner === null ? recovery
|
|
20442
|
+
: options.persist && readFormDraft(client.desk.desk_id, draftOwner.requester_id) !== null ? draftOwner.assurance : null;
|
|
20443
|
+
draftOwner = null;
|
|
19848
20444
|
restoredDraft = false;
|
|
19849
20445
|
restoredFiles = false;
|
|
19850
20446
|
generation += 1;
|
|
@@ -19853,15 +20449,19 @@ function mountHelpDeskForm(client, options) {
|
|
|
19853
20449
|
if (options.widgetIdentity)
|
|
19854
20450
|
widgetCustomer = null;
|
|
19855
20451
|
clearComposer();
|
|
19856
|
-
|
|
20452
|
+
recovery = hidden;
|
|
19857
20453
|
disable(false);
|
|
19858
20454
|
setState('editing');
|
|
19859
|
-
|
|
19860
|
-
|
|
19861
|
-
|
|
19862
|
-
|
|
19863
|
-
else
|
|
20455
|
+
// The question that led here was the previous customer's too.
|
|
20456
|
+
if (hidesCustomer)
|
|
20457
|
+
widget?.forgetIssue();
|
|
20458
|
+
if (recovery === null)
|
|
19864
20459
|
message('Your sign-in changed. Start a new request for the current account.');
|
|
20460
|
+
else
|
|
20461
|
+
renderActions();
|
|
20462
|
+
// The request and its actions changed under the pointer: a press already
|
|
20463
|
+
// under way must not act on what replaced them.
|
|
20464
|
+
options.onScreenChange?.();
|
|
19865
20465
|
}
|
|
19866
20466
|
const unsubscribe = client.subscribeSession(sessionChanged);
|
|
19867
20467
|
const alive = (ownGeneration) => !destroyed && generation === ownGeneration;
|
|
@@ -19902,19 +20502,6 @@ function mountHelpDeskForm(client, options) {
|
|
|
19902
20502
|
}
|
|
19903
20503
|
return draftPromise;
|
|
19904
20504
|
}
|
|
19905
|
-
if (client.desk.customer_can_attach_files && options.attachments !== false) {
|
|
19906
|
-
attachments = createFormAttachments(client, prefix, async () => {
|
|
19907
|
-
const ownGeneration = generation;
|
|
19908
|
-
const token = await tokenFor(ownGeneration);
|
|
19909
|
-
if (!token || !alive(ownGeneration))
|
|
19910
|
-
return null;
|
|
19911
|
-
const id = await ensureDraft(ownGeneration, token);
|
|
19912
|
-
if (!alive(ownGeneration))
|
|
19913
|
-
return null;
|
|
19914
|
-
return { draftId: id, expectedSessionToken: token };
|
|
19915
|
-
});
|
|
19916
|
-
form.insertBefore(attachments.element, auth);
|
|
19917
|
-
}
|
|
19918
20505
|
function showEmail() {
|
|
19919
20506
|
auth.hidden = false;
|
|
19920
20507
|
email.wrapper.hidden = false;
|
|
@@ -19947,31 +20534,46 @@ function mountHelpDeskForm(client, options) {
|
|
|
19947
20534
|
// Sending (Enter in a field, a code's last digit) answers the discard
|
|
19948
20535
|
// question: the customer kept going.
|
|
19949
20536
|
closeConfirm(false);
|
|
20537
|
+
if (recovery === 'external_sso' && widget) {
|
|
20538
|
+
// Only the website account reaches a website-account customer's saved
|
|
20539
|
+
// request: a code or the secure window would sign in someone else.
|
|
20540
|
+
widget.useWebsiteAccount?.(null, true);
|
|
20541
|
+
return;
|
|
20542
|
+
}
|
|
19950
20543
|
for (const entry of fields)
|
|
19951
20544
|
clearFieldError(entry);
|
|
19952
20545
|
const recoveringSubmission = uncertainSubmission !== null;
|
|
19953
20546
|
const subjectText = uncertainSubmission?.subject ?? subject.input.value.trim();
|
|
19954
|
-
const
|
|
20547
|
+
const detailsText = uncertainSubmission ? detailsOf(uncertainSubmission) : description.input.value;
|
|
20548
|
+
const body = uncertainSubmission?.body ?? ticketBody(subjectText, detailsText);
|
|
19955
20549
|
if (uncertainSubmission) {
|
|
19956
20550
|
// Retrying recovers this exact request. A lost response must never make
|
|
19957
20551
|
// newly typed text appear to have been accepted as the earlier ticket.
|
|
19958
20552
|
subject.input.value = subjectText;
|
|
19959
|
-
description.input.value =
|
|
20553
|
+
description.input.value = detailsText;
|
|
19960
20554
|
}
|
|
19961
20555
|
const refused = refusal(subjectText, body);
|
|
19962
|
-
const recoveringAfterSignIn =
|
|
20556
|
+
const recoveringAfterSignIn = recovery !== null;
|
|
19963
20557
|
if (refused && !recoveringAfterSignIn) {
|
|
19964
20558
|
const [entry, text] = refused;
|
|
20559
|
+
if (step !== 'details')
|
|
20560
|
+
setStep('details');
|
|
19965
20561
|
setFieldError(entry, text);
|
|
19966
20562
|
entry.input.focus();
|
|
19967
20563
|
return;
|
|
19968
20564
|
}
|
|
19969
20565
|
let widgetSignIn;
|
|
19970
|
-
if (
|
|
19971
|
-
|
|
19972
|
-
|
|
20566
|
+
if (widget && !widgetCustomer) {
|
|
20567
|
+
// The request is written; who the reply goes to is the next step, and
|
|
20568
|
+
// nothing reaches the network before it.
|
|
20569
|
+
if (step === 'details') {
|
|
20570
|
+
enterStep('identity');
|
|
20571
|
+
return;
|
|
20572
|
+
}
|
|
20573
|
+
const givenName = asksName ? firstName.input.value.trim() : '';
|
|
20574
|
+
const familyName = asksName ? lastName.input.value.trim() : '';
|
|
19973
20575
|
const emailAddress = email.input.value.trim();
|
|
19974
|
-
const invalid = !givenName ? firstName : !email.input.validity.valid || !emailAddress ? email : null;
|
|
20576
|
+
const invalid = asksName && !givenName ? firstName : !email.input.validity.valid || !emailAddress ? email : null;
|
|
19975
20577
|
if (invalid) {
|
|
19976
20578
|
setFieldError(invalid, invalid === email ? 'Enter your email address.' : 'Enter your first name.');
|
|
19977
20579
|
invalid.input.focus();
|
|
@@ -19980,7 +20582,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
19980
20582
|
// Invoke in the original submit gesture, before any awaited token read:
|
|
19981
20583
|
// the Identity adapter can open its native window without a popup block.
|
|
19982
20584
|
try {
|
|
19983
|
-
widgetSignIn =
|
|
20585
|
+
widgetSignIn = widget.signIn(asksName ? { email: emailAddress, givenName, familyName } : { email: emailAddress });
|
|
19984
20586
|
}
|
|
19985
20587
|
catch (failure) {
|
|
19986
20588
|
const error = failure instanceof Error ? failure : new Error('Sign-in could not be opened.');
|
|
@@ -19997,12 +20599,13 @@ function mountHelpDeskForm(client, options) {
|
|
|
19997
20599
|
pending = true;
|
|
19998
20600
|
disable(true);
|
|
19999
20601
|
message('');
|
|
20602
|
+
syncLeaveGuard();
|
|
20000
20603
|
try {
|
|
20001
20604
|
if (widgetSignIn) {
|
|
20002
20605
|
authenticating = true;
|
|
20003
20606
|
authNotification = false;
|
|
20004
20607
|
setState('authenticating');
|
|
20005
|
-
message('
|
|
20608
|
+
message('Finish signing in in the secure window.');
|
|
20006
20609
|
}
|
|
20007
20610
|
let token = await tokenFor(ownGeneration);
|
|
20008
20611
|
if (!alive(ownGeneration))
|
|
@@ -20028,10 +20631,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
20028
20631
|
sessionKnown = true;
|
|
20029
20632
|
authenticating = false;
|
|
20030
20633
|
if (attachments)
|
|
20031
|
-
attachments.
|
|
20634
|
+
attachments.list.hidden = false;
|
|
20032
20635
|
subject.input.value = subjectText;
|
|
20033
|
-
description.input.value =
|
|
20034
|
-
if (
|
|
20636
|
+
description.input.value = detailsText;
|
|
20637
|
+
if (widget && session) {
|
|
20035
20638
|
widgetCustomer = session.customer;
|
|
20036
20639
|
renderWidgetIdentity();
|
|
20037
20640
|
message('');
|
|
@@ -20047,7 +20650,8 @@ function mountHelpDeskForm(client, options) {
|
|
|
20047
20650
|
if (!alive(ownGeneration))
|
|
20048
20651
|
return;
|
|
20049
20652
|
if (!token) {
|
|
20050
|
-
|
|
20653
|
+
// A website-account customer's saved request never comes back through an emailed code.
|
|
20654
|
+
if (recovery === 'external_sso' || (client.desk.auth_mode !== 'email_pin' && !(client.desk.auth_mode === 'external_sso' && client.desk.external_identity?.guest_email === true))) {
|
|
20051
20655
|
showHosted();
|
|
20052
20656
|
return;
|
|
20053
20657
|
}
|
|
@@ -20091,10 +20695,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
20091
20695
|
sessionKnown = true;
|
|
20092
20696
|
authenticating = false;
|
|
20093
20697
|
if (attachments)
|
|
20094
|
-
attachments.
|
|
20698
|
+
attachments.list.hidden = false;
|
|
20095
20699
|
dropChallenge();
|
|
20096
20700
|
subject.input.value = subjectText;
|
|
20097
|
-
description.input.value =
|
|
20701
|
+
description.input.value = detailsText;
|
|
20098
20702
|
notify$1(options.onSession, verified);
|
|
20099
20703
|
}
|
|
20100
20704
|
if (!token || !alive(ownGeneration))
|
|
@@ -20122,7 +20726,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20122
20726
|
email.wrapper.hidden = true;
|
|
20123
20727
|
code.wrapper.hidden = true;
|
|
20124
20728
|
name.wrapper.hidden = false;
|
|
20125
|
-
send.textContent =
|
|
20729
|
+
send.textContent = idleLabel();
|
|
20126
20730
|
setState('editing');
|
|
20127
20731
|
setFieldError(name, 'Add your name before sending your request.');
|
|
20128
20732
|
focusAfter = name.input;
|
|
@@ -20144,7 +20748,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20144
20748
|
setState('submitting');
|
|
20145
20749
|
if (!alive(ownGeneration))
|
|
20146
20750
|
return;
|
|
20147
|
-
send.textContent =
|
|
20751
|
+
send.textContent = 'Sending request';
|
|
20148
20752
|
if (!uncertainSubmission) {
|
|
20149
20753
|
const id = await ensureDraft(ownGeneration, token);
|
|
20150
20754
|
if (!alive(ownGeneration) || !(await tokenFor(ownGeneration)))
|
|
@@ -20187,14 +20791,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
20187
20791
|
const draftExpired = ticketAttempted && error instanceof SparkVaultError
|
|
20188
20792
|
&& (error.serviceCode === 'DRAFT_EXPIRED' || error.code === 'DRAFT_EXPIRED');
|
|
20189
20793
|
if (uncertainSubmission && !draftExpired && (!ticketAttempted || recoveringSubmission || unknownSubmissionOutcome(error))) {
|
|
20190
|
-
subject.input.readOnly = true;
|
|
20191
|
-
description.input.readOnly = true;
|
|
20192
20794
|
message('We could not confirm whether your request was sent. Check submission to recover it. Your original text is kept unchanged.', true);
|
|
20193
20795
|
}
|
|
20194
20796
|
else {
|
|
20195
20797
|
uncertainSubmission = null;
|
|
20196
|
-
subject.input.readOnly = false;
|
|
20197
|
-
description.input.readOnly = false;
|
|
20198
20798
|
if (draftExpired) {
|
|
20199
20799
|
draftId = null;
|
|
20200
20800
|
draftPromise = null;
|
|
@@ -20205,6 +20805,13 @@ function mountHelpDeskForm(client, options) {
|
|
|
20205
20805
|
setFieldError(code, HELP_DESK_CODE_STEP_COPY.codeRefused);
|
|
20206
20806
|
focusAfter = code.input;
|
|
20207
20807
|
}
|
|
20808
|
+
else if (widgetSignIn && error instanceof SparkVaultError && error.code === 'user_cancelled') {
|
|
20809
|
+
// The request stays on who the reply goes to, ready to sign in again;
|
|
20810
|
+
// a hidden saved request is not here to speak of, so its note alone stays.
|
|
20811
|
+
if (recovery === null)
|
|
20812
|
+
message(SIGN_IN_CANCELLED_COPY);
|
|
20813
|
+
focusAfter = send;
|
|
20814
|
+
}
|
|
20208
20815
|
else {
|
|
20209
20816
|
message(draftExpired ? 'Your saved draft expired. Your text is kept. Choose your files again before sending.' : error.message, true);
|
|
20210
20817
|
}
|
|
@@ -20212,7 +20819,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20212
20819
|
setState(uncertainSubmission ? 'uncertain' : challenge ? 'verifying' : 'editing');
|
|
20213
20820
|
if (!alive(ownGeneration))
|
|
20214
20821
|
return;
|
|
20215
|
-
send.textContent =
|
|
20822
|
+
send.textContent = idleLabel();
|
|
20216
20823
|
notify$1(options.onError, error);
|
|
20217
20824
|
}
|
|
20218
20825
|
finally {
|
|
@@ -20220,6 +20827,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20220
20827
|
authenticating = false;
|
|
20221
20828
|
pending = false;
|
|
20222
20829
|
disable(completed);
|
|
20830
|
+
syncLeaveGuard();
|
|
20223
20831
|
focusSettled();
|
|
20224
20832
|
}
|
|
20225
20833
|
}
|
|
@@ -20292,6 +20900,8 @@ function mountHelpDeskForm(client, options) {
|
|
|
20292
20900
|
generation += 1;
|
|
20293
20901
|
stopResendCountdown();
|
|
20294
20902
|
attachments?.destroy(completed || uncertainSubmission !== null);
|
|
20903
|
+
composer.destroy();
|
|
20904
|
+
live.destroy();
|
|
20295
20905
|
unsubscribe();
|
|
20296
20906
|
form.removeEventListener('submit', onSubmit);
|
|
20297
20907
|
shell.destroy();
|
|
@@ -20316,24 +20926,50 @@ function mountHelpDeskForm(client, options) {
|
|
|
20316
20926
|
subject.input.value = composition.subject;
|
|
20317
20927
|
description.input.value = composition.body;
|
|
20318
20928
|
persistDraft();
|
|
20929
|
+
syncLeaveGuard();
|
|
20319
20930
|
},
|
|
20320
|
-
refill(
|
|
20321
|
-
if (destroyed || restoredDraft || safeComposition() === null)
|
|
20931
|
+
refill(issue) {
|
|
20932
|
+
if (destroyed || restoredDraft || recovery !== null || safeComposition() === null)
|
|
20322
20933
|
return false;
|
|
20934
|
+
const own = { subject: edited(subject.input, filledWith('subject')), body: edited(description.input, filledWith('body')) };
|
|
20935
|
+
const text = issue.trim();
|
|
20936
|
+
const placed = !own.subject && !own.body ? composeIssue(issue) : { subject: oneLine(text, MAX_SUBJECT_LEN) ? text : '', body: issue };
|
|
20323
20937
|
for (const [entry, key] of [[subject, 'subject'], [description, 'body']]) {
|
|
20324
|
-
if (
|
|
20325
|
-
|
|
20326
|
-
|
|
20327
|
-
|
|
20328
|
-
prefill[key] = composition[key];
|
|
20938
|
+
if (own[key])
|
|
20939
|
+
continue;
|
|
20940
|
+
entry.input.value = placed[key];
|
|
20941
|
+
clearFieldError(entry);
|
|
20329
20942
|
}
|
|
20943
|
+
filledFrom = issue;
|
|
20944
|
+
if (step === 'identity')
|
|
20945
|
+
recapText.textContent = subject.input.value.trim();
|
|
20330
20946
|
persistDraft();
|
|
20947
|
+
syncLeaveGuard();
|
|
20331
20948
|
return true;
|
|
20332
20949
|
},
|
|
20333
20950
|
resumeAfterAccess() {
|
|
20334
20951
|
if (!destroyed && !pending && !completed && uncertainSubmission === null)
|
|
20335
20952
|
message('');
|
|
20336
20953
|
},
|
|
20954
|
+
returnToRequest() {
|
|
20955
|
+
if (destroyed || step !== 'identity')
|
|
20956
|
+
return false;
|
|
20957
|
+
// While the sign-in window is open the request stays where it is.
|
|
20958
|
+
if (!pending)
|
|
20959
|
+
enterStep('details');
|
|
20960
|
+
return true;
|
|
20961
|
+
},
|
|
20962
|
+
focusEntry(focusOptions) {
|
|
20963
|
+
if (destroyed || form.hidden)
|
|
20964
|
+
return false;
|
|
20965
|
+
const asked = stepField();
|
|
20966
|
+
const entry = asked === subject.input && subject.input.value.trim() ? description.input : asked;
|
|
20967
|
+
if (entry.disabled || entry.readOnly)
|
|
20968
|
+
(step === 'identity' && reply ? reply.heading : heading).focus(focusOptions);
|
|
20969
|
+
else
|
|
20970
|
+
focusAtEnd(entry, focusOptions);
|
|
20971
|
+
return true;
|
|
20972
|
+
},
|
|
20337
20973
|
requestDismiss() {
|
|
20338
20974
|
if (destroyed)
|
|
20339
20975
|
return;
|
|
@@ -20367,18 +21003,28 @@ function mountHelpDeskForm(client, options) {
|
|
|
20367
21003
|
keepEditing.addEventListener('click', () => closeConfirm(true));
|
|
20368
21004
|
discard.addEventListener('click', dismiss);
|
|
20369
21005
|
form.addEventListener('submit', onSubmit);
|
|
20370
|
-
form.addEventListener('input',
|
|
20371
|
-
form.addEventListener('change', () => {
|
|
20372
|
-
if (attachments?.hasEntries)
|
|
20373
|
-
restoredFiles = false;
|
|
21006
|
+
form.addEventListener('input', () => {
|
|
20374
21007
|
persistDraft();
|
|
21008
|
+
syncLeaveGuard();
|
|
20375
21009
|
});
|
|
21010
|
+
send.textContent = idleLabel();
|
|
20376
21011
|
renderWidgetIdentity();
|
|
21012
|
+
// A signed-out widget customer starts on step 1 of 2 with focus in the request.
|
|
21013
|
+
if (widget && !widgetCustomer)
|
|
21014
|
+
live.announce('Step 1 of 2');
|
|
20377
21015
|
if (options.widgetIdentity?.customer) {
|
|
20378
21016
|
restoreDraft(options.widgetIdentity.customer);
|
|
20379
21017
|
disable(false);
|
|
20380
21018
|
}
|
|
20381
|
-
else if (
|
|
21019
|
+
else if (widget?.recovering) {
|
|
21020
|
+
recovery = 'external_sso';
|
|
21021
|
+
websiteSignedOut = widget.recovering.websiteSignedOut;
|
|
21022
|
+
disable(false);
|
|
21023
|
+
renderActions();
|
|
21024
|
+
}
|
|
21025
|
+
else if (options.persist && filledFrom === undefined) {
|
|
21026
|
+
// The support wizard hands a composition it carries to restoreComposition;
|
|
21027
|
+
// a form of the host's own restores the one saved before a reload.
|
|
20382
21028
|
const saved = readAnonymousFormDraft(client.desk.desk_id);
|
|
20383
21029
|
if (saved) {
|
|
20384
21030
|
subject.input.value = saved.subject;
|
|
@@ -20386,6 +21032,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20386
21032
|
restoredAnonymous = true;
|
|
20387
21033
|
}
|
|
20388
21034
|
}
|
|
21035
|
+
syncLeaveGuard();
|
|
20389
21036
|
notify$1(options.onStateChange, state);
|
|
20390
21037
|
// Native company identity starts as the form opens, never from a Connect,
|
|
20391
21038
|
// Allow, verification or submit gesture. Guest email is explicit desk policy.
|
|
@@ -22613,58 +23260,6 @@ function createSupportLauncher(options, open) {
|
|
|
22613
23260
|
};
|
|
22614
23261
|
}
|
|
22615
23262
|
|
|
22616
|
-
/** A title written with a period: in "Dear Mr. Smith," that period ends no sentence. */
|
|
22617
|
-
const HONORIFIC = String.raw `(?:Mr|Mrs|Ms|Mx|Dr|Prof)\.`;
|
|
22618
|
-
/**
|
|
22619
|
-
* Where a sentence ends: after a period, exclamation or question mark that
|
|
22620
|
-
* whitespace follows. An honorific's period is matched first, whole, and left
|
|
22621
|
-
* as it is.
|
|
22622
|
-
*/
|
|
22623
|
-
const SENTENCE_END = new RegExp(String.raw `\b${HONORIFIC}(?=\s)|([.!?])(?=\s)`, 'g');
|
|
22624
|
-
/** The word a greeting opens with, whole: "Hi", "Hello", "Good morning", "Morning". */
|
|
22625
|
-
const SALUTATION = /^(?:hi|hello|hey|hiya|howdy|greetings|dear|good\s+day|(?:good\s+)?(?:morning|afternoon|evening))(?!\p{L})/iu;
|
|
22626
|
-
/** The few words greetings use for whom they address. */
|
|
22627
|
-
const ADDRESS_WORDS = 'again|there|team|all|everyone|everybody|folks|guys|support|customer|service|sir|madam|or|and';
|
|
22628
|
-
/**
|
|
22629
|
-
* What may follow the salutation in a greeting: up to four words of address,
|
|
22630
|
-
* each an honorific, a name or one of the few words greetings use, in lower
|
|
22631
|
-
* case or capitals ("Mr. Smith", "Privacy Bee team", "there", "AGAIN", "Sir
|
|
22632
|
-
* or Madam"), then anything but letters and digits: punctuation, symbols and
|
|
22633
|
-
* emoji. The words of an issue ("Hi, I can't sign in", "Hey refund please",
|
|
22634
|
-
* "HELLO I CANT LOGIN") are none of these, so a sentence holding them is the
|
|
22635
|
-
* issue. A name is a capital and lowercase letters, again for each capital of
|
|
22636
|
-
* one like PayPal or McKenzie, so a word in capitals is shouted, not a name.
|
|
22637
|
-
* Case-sensitive, so that case tells a name: a case-insensitive \p{Lu} matches
|
|
22638
|
-
* every letter. A name's apostrophes and hyphens only join letters, so a word
|
|
22639
|
-
* of address ends in a letter or an honorific's period, and the closing run
|
|
22640
|
-
* never competes with it for more than that one period; that keeps the read
|
|
22641
|
-
* linear.
|
|
22642
|
-
*/
|
|
22643
|
-
const ADDRESS = new RegExp(String.raw `^(?:[\s,/&]+(?:${HONORIFIC}|${ADDRESS_WORDS}|${ADDRESS_WORDS.toUpperCase()}|\p{Lu}\p{Ll}*(?:\p{Lu}\p{Ll}+)*(?:['\u2019-]\p{L}+)*)){0,4}[^\p{L}\p{N}]*$`, 'u');
|
|
22644
|
-
const TO_WHOM = /^to\s+whom\s+it\s+may\s+concern[^\p{L}\p{N}]*$/iu;
|
|
22645
|
-
const LETTER = /\p{L}/u;
|
|
22646
|
-
/** A line or sentence that only greets: "Hi there,", "Good morning team!", "Dear Sir or Madam,", "To whom it may concern:". */
|
|
22647
|
-
function isGreeting(sentence) {
|
|
22648
|
-
const salutation = SALUTATION.exec(sentence);
|
|
22649
|
-
return salutation ? ADDRESS.test(sentence.slice(salutation[0].length)) : TO_WHOM.test(sentence);
|
|
22650
|
-
}
|
|
22651
|
-
/**
|
|
22652
|
-
* The subject a support issue prefills: its first line or sentence that holds
|
|
22653
|
-
* a word and says more than a greeting (its first one when none does),
|
|
22654
|
-
* shortened at a word boundary with an ellipsis to fit MAX_SUBJECT_LEN. The
|
|
22655
|
-
* message carries the whole issue, so the subject only needs to name it.
|
|
22656
|
-
*/
|
|
22657
|
-
function issueSubject(issue) {
|
|
22658
|
-
const sentences = issue.replace(SENTENCE_END, (match, end) => end ? `${end}\n` : match)
|
|
22659
|
-
.split('\n').map((sentence) => sentence.trim()).filter(Boolean);
|
|
22660
|
-
const subject = sentences.find((sentence) => LETTER.test(sentence) && !isGreeting(sentence)) ?? sentences[0] ?? '';
|
|
22661
|
-
if (subject.length <= MAX_SUBJECT_LEN)
|
|
22662
|
-
return subject;
|
|
22663
|
-
const kept = truncateToLength(subject, MAX_SUBJECT_LEN - 1);
|
|
22664
|
-
const atWord = /\s/u.test(subject.charAt(kept.length)) ? kept : kept.replace(/\s+\S*$/u, '');
|
|
22665
|
-
return `${atWord.trimEnd()}…`;
|
|
22666
|
-
}
|
|
22667
|
-
|
|
22668
23263
|
/** The support journey's only skin. Customer content stays in the product register. */
|
|
22669
23264
|
function injectHelpDeskSupportStyles() {
|
|
22670
23265
|
if (document.getElementById('sparkvault-help-desk-support-styles'))
|
|
@@ -22790,11 +23385,10 @@ function injectHelpDeskSupportStyles() {
|
|
|
22790
23385
|
.svhs-unlock-form{margin:0}
|
|
22791
23386
|
.svhs-contact-target>.svhd-container{display:flex;flex:1;flex-direction:column;min-height:100%;max-width:none;padding:24px;border:0;border-radius:0;box-shadow:none;background:transparent}
|
|
22792
23387
|
.svhs-contact-target .svhd-body{display:flex;flex:1;flex-direction:column;min-height:0}
|
|
22793
|
-
.svhs-contact-target .svhd-container h2{
|
|
23388
|
+
.svhs-contact-target .svhd-container h2{font-size:22px;line-height:1.25;letter-spacing:-.6px;overflow-wrap:anywhere}
|
|
22794
23389
|
.svhs-contact-target .svhd-form{gap:16px}
|
|
22795
23390
|
.svhs-contact-target .svhd-label{font-size:13px;line-height:1.5}
|
|
22796
23391
|
.svhs-contact-target .svhd-input{font-size:16px;line-height:1.5}
|
|
22797
|
-
.svhs-contact-target .svhd-description{min-height:138px}
|
|
22798
23392
|
.svhs-contact-target .svhd-actions{gap:10px}
|
|
22799
23393
|
.svhs-contact-target .svhd-button:not(.svhd-secondary){background:var(--hd-accent,${DS.action});color:var(--hd-on-accent,${DS.white})}
|
|
22800
23394
|
.svhs-contact-target .svhd-button:not(.svhd-secondary):hover{background:var(--hd-accent-hover,${DS.actionHover})}
|
|
@@ -22802,18 +23396,19 @@ function injectHelpDeskSupportStyles() {
|
|
|
22802
23396
|
.svhs-contact-target .svhd-actions>.svhd-button:first-child{flex:1}
|
|
22803
23397
|
.svhs-contact-target .svhd-status{font-size:14px}
|
|
22804
23398
|
.svhs-contact-target .svhd-auth{gap:14px}
|
|
22805
|
-
.svhs-contact-target .svhd-
|
|
22806
|
-
.svhs-contact-target .svhd-
|
|
22807
|
-
.svhs-contact-target .svhd-
|
|
22808
|
-
.svhs-contact-target .svhd-
|
|
22809
|
-
.svhs-
|
|
22810
|
-
.svhs-
|
|
22811
|
-
.svhs-contact-target .svhd-widget-account-link:focus-visible{outline:2px solid var(--hd-focus,var(--hd-accent-ink,${DS.action}));outline-offset:3px}
|
|
22812
|
-
.svhs-contact-target .svhd-widget-account-link:disabled{cursor:progress;color:${DS.slate500}}
|
|
23399
|
+
.svhs-contact-target .svhd-text-button{color:var(--hd-accent-ink,${DS.action})}
|
|
23400
|
+
.svhs-contact-target .svhd-text-button:disabled{color:${DS.slate500}}
|
|
23401
|
+
.svhs-contact-target .svhd-composer:has(.svhd-composer-input:focus-visible){outline:2px solid var(--hd-focus,var(--hd-accent-ink,${DS.action}));outline-offset:3px}
|
|
23402
|
+
@supports not selector(:has(*)){.svhs-contact-target .svhd-composer:focus-within{outline:2px solid var(--hd-focus,var(--hd-accent-ink,${DS.action}));outline-offset:3px}}
|
|
23403
|
+
.svhs-panel .svhd-composer-input:focus-visible{outline:none}
|
|
23404
|
+
.svhs-panel .svhd-composer button:focus-visible{outline-offset:-2px}
|
|
22813
23405
|
.svhs-contact-target .svhd-widget-names{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:12px}
|
|
22814
23406
|
.svhs-contact-target .svhd-widget-form{display:flex;flex:1;flex-direction:column;gap:16px}
|
|
22815
|
-
|
|
22816
|
-
.svhs-contact-target .svhd-widget-
|
|
23407
|
+
/* The request fills the panel: the details step, and in it the composer and its text, take the height the fields leave. */
|
|
23408
|
+
.svhs-contact-target .svhd-widget-form>[data-contact-step=details]{display:flex;flex:1;flex-direction:column;gap:16px}
|
|
23409
|
+
.svhs-contact-target .svhd-widget-form .svhd-composer-field{display:flex;flex:1;flex-direction:column;gap:6px;min-height:164px}
|
|
23410
|
+
.svhs-contact-target .svhd-widget-form .svhd-composer{flex:1}
|
|
23411
|
+
.svhs-contact-target .svhd-widget-form .svhd-composer-input{flex:1;min-height:120px}
|
|
22817
23412
|
.svhs-contact-target .svhd-widget-form>.svhd-actions{position:sticky;bottom:0;z-index:1;margin:auto -24px 0;padding:16px 24px 0;border-top:1px solid ${DS.slate100};background:${DS.white}}
|
|
22818
23413
|
.svhs-contact-target .svhd-widget-form>.svhd-actions>.svhd-secondary{display:none}
|
|
22819
23414
|
.svhs-contact-target .svhd-widget-form .svhd-actions>.svhd-button{font-size:14px}
|
|
@@ -22826,7 +23421,6 @@ function injectHelpDeskSupportStyles() {
|
|
|
22826
23421
|
.svhs-ticket-link{display:inline-flex;align-items:center;min-height:44px;margin:0 0 10px;color:var(--hd-accent-ink,${DS.action});font-size:14px;font-weight:600;text-decoration:underline}
|
|
22827
23422
|
.svhs-receipt-note{white-space:pre-wrap;overflow-wrap:anywhere}
|
|
22828
23423
|
.svhs-receipt-actions{display:flex;flex-direction:column;align-items:center;gap:4px}
|
|
22829
|
-
.svhs-live{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
|
|
22830
23424
|
.svhs-toast{box-sizing:border-box;position:fixed;right:24px;bottom:calc(96px + var(--svhs-toast-offset,0px) + env(safe-area-inset-bottom));z-index:2147482901;display:flex;align-items:center;gap:10px;max-width:calc(100vw - 36px);padding:14px 18px;border:1px solid transparent;border-radius:8px;background:${DS.slate900};color:${DS.white};box-shadow:${DS.shadowPopover};font:400 14px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',sans-serif;overflow-wrap:anywhere}
|
|
22831
23425
|
.svhs-toast svg{width:18px;height:18px;flex:none;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round}
|
|
22832
23426
|
.svhs-overlay{position:fixed;inset:0;z-index:2147482900;display:flex;background:${DS.white};padding:0;overflow:hidden}
|
|
@@ -22861,7 +23455,6 @@ function injectHelpDeskSupportStyles() {
|
|
|
22861
23455
|
.svhs-feedback-actions{margin-top:30px}
|
|
22862
23456
|
.svhs-feedback-actions .svhs-primary,.svhs-feedback-actions .svhs-secondary{min-height:48px}
|
|
22863
23457
|
.svhs-contact-scroll{padding:0}
|
|
22864
|
-
.svhs-contact-target .svhd-description{min-height:160px}
|
|
22865
23458
|
.svhs-contact-target>.svhd-container{padding:24px}
|
|
22866
23459
|
.svhs-contact-target .svhd-widget-form>.svhd-actions{padding-bottom:env(safe-area-inset-bottom)}
|
|
22867
23460
|
.svhs-receipt-scroll{padding-top:58px}
|
|
@@ -23227,24 +23820,6 @@ function button(className, text, action) {
|
|
|
23227
23820
|
node.addEventListener('click', action);
|
|
23228
23821
|
return node;
|
|
23229
23822
|
}
|
|
23230
|
-
function icon(name) {
|
|
23231
|
-
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
23232
|
-
svg.setAttribute('viewBox', '0 0 24 24');
|
|
23233
|
-
svg.setAttribute('aria-hidden', 'true');
|
|
23234
|
-
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
23235
|
-
path.setAttribute('d', {
|
|
23236
|
-
back: 'm14.5 6-6 6 6 6',
|
|
23237
|
-
close: 'm6 6 12 12M18 6 6 18',
|
|
23238
|
-
external: 'M14 4h6v6m0-6L10 14M11 5H5a1 1 0 0 0-1 1v13a1 1 0 0 0 1 1h13a1 1 0 0 0 1-1v-6',
|
|
23239
|
-
check: 'm5 12 4 4L19 6',
|
|
23240
|
-
article: 'M14 3H6a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8Zm0 0v5h5M8 12h8M8 16h6',
|
|
23241
|
-
chevron: 'm9 6 6 6-6 6',
|
|
23242
|
-
thumbUp: 'M7 10v11H3V10Zm0 1 5-8c2 0 3 1 2 4l-1 3h6a2 2 0 0 1 2 2l-2 7a2 2 0 0 1-2 2H7',
|
|
23243
|
-
thumbDown: 'M7 14V3H3v11Zm0-1 5 8c2 0 3-1 2-4l-1-3h6a2 2 0 0 0 2-2l-2-7a2 2 0 0 0-2-2H7',
|
|
23244
|
-
}[name]);
|
|
23245
|
-
svg.append(path);
|
|
23246
|
-
return svg;
|
|
23247
|
-
}
|
|
23248
23823
|
function httpUrl(value, base = window.location.href) {
|
|
23249
23824
|
if (!value)
|
|
23250
23825
|
return null;
|
|
@@ -23303,7 +23878,6 @@ class SupportView {
|
|
|
23303
23878
|
this.receiptCopy = element('p', 'svhs-copy');
|
|
23304
23879
|
this.receiptTicket = element('a', 'svhs-ticket-link');
|
|
23305
23880
|
this.receiptMessage = element('p', 'svhs-copy svhs-receipt-note');
|
|
23306
|
-
this.live = element('div', 'svhs-live');
|
|
23307
23881
|
this.identityNotice = element('div', 'svhs-identity-notice');
|
|
23308
23882
|
this.onMediaChange = () => this.syncPresentation();
|
|
23309
23883
|
this.onViewportChange = () => this.syncViewport();
|
|
@@ -23316,6 +23890,24 @@ class SupportView {
|
|
|
23316
23890
|
this.ticketGateSignature = '';
|
|
23317
23891
|
this.toastCleanups = new Set();
|
|
23318
23892
|
this.destroyed = false;
|
|
23893
|
+
// A multi-click that began before the screen changed (the panel opening, a
|
|
23894
|
+
// new stage or article, a new contact form, its step, or its request and
|
|
23895
|
+
// actions changing in place), wherever its first press
|
|
23896
|
+
// was, lands its later presses on a screen the customer has not seen yet:
|
|
23897
|
+
// they neither take focus there nor reach what is under them. A press in the
|
|
23898
|
+
// panel that starts anew, or a key press, acts as usual.
|
|
23899
|
+
this.screenChanges = 0;
|
|
23900
|
+
this.pressedAt = 0;
|
|
23901
|
+
this.onPress = (event) => {
|
|
23902
|
+
if (event.detail <= 1) {
|
|
23903
|
+
this.pressedAt = this.screenChanges;
|
|
23904
|
+
return;
|
|
23905
|
+
}
|
|
23906
|
+
if (this.screenChanges === this.pressedAt)
|
|
23907
|
+
return;
|
|
23908
|
+
event.preventDefault();
|
|
23909
|
+
event.stopPropagation();
|
|
23910
|
+
};
|
|
23319
23911
|
injectHelpDeskSupportStyles();
|
|
23320
23912
|
this.phoneHistory = !target && actions.onBrowserBack && actions.onBrowserForward ? new SupportPhoneHistory({
|
|
23321
23913
|
onBack: () => this.actions.onBrowserBack?.(),
|
|
@@ -23328,20 +23920,20 @@ class SupportView {
|
|
|
23328
23920
|
this.panel.hidden = true;
|
|
23329
23921
|
this.panel.setAttribute('aria-labelledby', `${this.prefix}-name`);
|
|
23330
23922
|
this.deskName.id = `${this.prefix}-name`;
|
|
23331
|
-
this.
|
|
23332
|
-
this.
|
|
23923
|
+
this.panel.addEventListener('mousedown', this.onPress, true);
|
|
23924
|
+
this.panel.addEventListener('click', this.onPress, true);
|
|
23333
23925
|
const toolbar = element('header', 'svhs-toolbar');
|
|
23334
23926
|
this.toolbar = toolbar;
|
|
23335
23927
|
this.back = button('svhs-back', 'Back', () => this.actions.onBack());
|
|
23336
|
-
this.back.prepend(
|
|
23928
|
+
this.back.prepend(helpDeskIcon('back'));
|
|
23337
23929
|
this.close = button('svhs-icon-button', '', () => this.actions.onClose());
|
|
23338
23930
|
this.close.setAttribute('aria-label', 'Close support');
|
|
23339
|
-
this.close.append(
|
|
23931
|
+
this.close.append(helpDeskIcon('close'));
|
|
23340
23932
|
this.external.setAttribute('aria-label', 'Open article in a new tab');
|
|
23341
23933
|
this.external.title = 'Open article in a new tab';
|
|
23342
23934
|
this.external.target = '_blank';
|
|
23343
23935
|
this.external.rel = 'noopener noreferrer';
|
|
23344
|
-
this.external.append(
|
|
23936
|
+
this.external.append(helpDeskIcon('external'));
|
|
23345
23937
|
const toolbarActions = element('div', 'svhs-toolbar-actions');
|
|
23346
23938
|
toolbarActions.append(this.external);
|
|
23347
23939
|
if (!target)
|
|
@@ -23415,9 +24007,9 @@ class SupportView {
|
|
|
23415
24007
|
const readerActions = element('div', 'svhs-reader-actions');
|
|
23416
24008
|
const yes = button('svhs-primary', 'Yes', () => { if (this.state?.article && !this.state.busy && !this.state.error)
|
|
23417
24009
|
this.actions.onAnswered(); });
|
|
23418
|
-
yes.prepend(
|
|
24010
|
+
yes.prepend(helpDeskIcon('thumbUp'));
|
|
23419
24011
|
const no = button('svhs-text-button', 'No, create a ticket', () => this.actions.onContact('article_not_answered'));
|
|
23420
|
-
no.prepend(
|
|
24012
|
+
no.prepend(helpDeskIcon('thumbDown'));
|
|
23421
24013
|
readerActions.append(yes, no);
|
|
23422
24014
|
this.articleFooter.append(element('span', 'svhs-article-question', 'Did this resolve your question?'), readerActions);
|
|
23423
24015
|
this.screens.get('article').append(this.articleFooter);
|
|
@@ -23459,7 +24051,7 @@ class SupportView {
|
|
|
23459
24051
|
contact.append(this.contactTarget);
|
|
23460
24052
|
const receipt = this.screen('receipt', 'Message sent');
|
|
23461
24053
|
receipt.classList.add('svhs-receipt-scroll');
|
|
23462
|
-
const receiptMark =
|
|
24054
|
+
const receiptMark = helpDeskIcon('check');
|
|
23463
24055
|
receiptMark.classList.add('svhs-receipt-mark');
|
|
23464
24056
|
receipt.prepend(receiptMark);
|
|
23465
24057
|
this.receiptTicket.target = '_blank';
|
|
@@ -23470,7 +24062,6 @@ class SupportView {
|
|
|
23470
24062
|
if (!target)
|
|
23471
24063
|
receiptFooter.append(button('svhs-secondary svhs-full', 'Done', () => this.actions.onClose()));
|
|
23472
24064
|
receiptFooter.append(this.restart);
|
|
23473
|
-
this.panel.append(this.live);
|
|
23474
24065
|
this.media = typeof window.matchMedia === 'function' ? window.matchMedia('(max-width:640px)') : null;
|
|
23475
24066
|
if (!target) {
|
|
23476
24067
|
this.media?.addEventListener('change', this.onMediaChange);
|
|
@@ -23559,24 +24150,34 @@ class SupportView {
|
|
|
23559
24150
|
if (!next.visible)
|
|
23560
24151
|
return;
|
|
23561
24152
|
if (!previous?.visible || previous.stage !== next.stage || previous.article?.id !== next.article?.id) {
|
|
24153
|
+
// A new screen, however it opened: from a press in the panel, the
|
|
24154
|
+
// launcher or a host link.
|
|
24155
|
+
this.screenChanges += 1;
|
|
23562
24156
|
this.restoreScroll(next);
|
|
23563
24157
|
this.focusCurrent();
|
|
23564
24158
|
}
|
|
23565
24159
|
}
|
|
24160
|
+
/** A new contact form, or one whose controls changed in place: a change of screen, as a new stage is. */
|
|
24161
|
+
contactScreenChanged() {
|
|
24162
|
+
this.screenChanges += 1;
|
|
24163
|
+
}
|
|
23566
24164
|
/** Programmatic close invalidates Forward restoration even after neutral Back. */
|
|
23567
24165
|
deactivateHistory() {
|
|
23568
24166
|
this.phoneHistory?.deactivate();
|
|
23569
24167
|
}
|
|
23570
|
-
/** Focus the shared form after its controller has mounted it. */
|
|
24168
|
+
/** Focus the shared form where the customer goes on, else its heading, after its controller has mounted it. */
|
|
23571
24169
|
focusContact() {
|
|
23572
24170
|
if (this.destroyed || !this.state?.visible || this.state.stage !== 'contact')
|
|
23573
24171
|
return;
|
|
23574
24172
|
const heading = this.contactTarget.querySelector('h1,h2,h3');
|
|
23575
24173
|
this.contactTitle.hidden = Boolean(heading);
|
|
23576
24174
|
this.contactTitle.parentElement.hidden = this.contactTitle.hidden && this.contactStatus.hidden && this.contactError.hidden && this.sourceArticle.hidden;
|
|
24175
|
+
const focusOptions = { preventScroll: !this.target };
|
|
24176
|
+
if (!this.contactTarget.hidden && this.actions.onFocusContact?.(focusOptions))
|
|
24177
|
+
return;
|
|
23577
24178
|
const target = heading ?? this.contactTarget;
|
|
23578
24179
|
target.tabIndex = -1;
|
|
23579
|
-
target.focus(
|
|
24180
|
+
target.focus(focusOptions);
|
|
23580
24181
|
}
|
|
23581
24182
|
/** Hydrate only the current reader's matching authorized publication assets. */
|
|
23582
24183
|
setArticleAsset(path, blobUrl) {
|
|
@@ -23627,7 +24228,7 @@ class SupportView {
|
|
|
23627
24228
|
const toast = element('div', 'svhs-toast');
|
|
23628
24229
|
toast.setAttribute('role', 'status');
|
|
23629
24230
|
toast.setAttribute('aria-atomic', 'true');
|
|
23630
|
-
toast.append(
|
|
24231
|
+
toast.append(helpDeskIcon('check'), document.createTextNode(message));
|
|
23631
24232
|
document.body.append(toast);
|
|
23632
24233
|
const arrange = () => {
|
|
23633
24234
|
let offset = 0;
|
|
@@ -23678,6 +24279,8 @@ class SupportView {
|
|
|
23678
24279
|
return;
|
|
23679
24280
|
this.destroyed = true;
|
|
23680
24281
|
this.phoneHistory?.destroy();
|
|
24282
|
+
this.panel.removeEventListener('mousedown', this.onPress, true);
|
|
24283
|
+
this.panel.removeEventListener('click', this.onPress, true);
|
|
23681
24284
|
document.removeEventListener('keydown', this.onKeydown);
|
|
23682
24285
|
this.media?.removeEventListener('change', this.onMediaChange);
|
|
23683
24286
|
window.visualViewport?.removeEventListener('resize', this.onViewportChange);
|
|
@@ -23748,9 +24351,9 @@ class SupportView {
|
|
|
23748
24351
|
copy.append(element('span', 'svhs-result-excerpt', result.summary));
|
|
23749
24352
|
if (result.category)
|
|
23750
24353
|
copy.append(element('span', 'svhs-result-category', result.category));
|
|
23751
|
-
const documentIcon =
|
|
24354
|
+
const documentIcon = helpDeskIcon('article');
|
|
23752
24355
|
documentIcon.classList.add('svhs-result-icon');
|
|
23753
|
-
const chevron =
|
|
24356
|
+
const chevron = helpDeskIcon('chevron');
|
|
23754
24357
|
chevron.classList.add('svhs-result-chevron');
|
|
23755
24358
|
open.append(documentIcon, copy, chevron);
|
|
23756
24359
|
item.append(open);
|
|
@@ -24122,8 +24725,6 @@ class SupportView {
|
|
|
24122
24725
|
}
|
|
24123
24726
|
}
|
|
24124
24727
|
|
|
24125
|
-
/** What contact starts from: the issue's subject and, as the message, every character of the issue. */
|
|
24126
|
-
function composeIssue(issue) { return { subject: issueSubject(issue), body: issue }; }
|
|
24127
24728
|
function notify(callback, value) {
|
|
24128
24729
|
try {
|
|
24129
24730
|
void Promise.resolve(callback?.(value)).catch(() => undefined);
|
|
@@ -24149,10 +24750,14 @@ function createHelpDeskSupport(config, options) {
|
|
|
24149
24750
|
// only while it is the current sequence, so whatever supersedes it frees it.
|
|
24150
24751
|
let contactOpening = null;
|
|
24151
24752
|
let pendingComposition = null;
|
|
24152
|
-
//
|
|
24153
|
-
//
|
|
24154
|
-
|
|
24155
|
-
//
|
|
24753
|
+
// A website-account customer's saved request the next form keeps hidden,
|
|
24754
|
+
// asked for through the website account, which may give no account back.
|
|
24755
|
+
let pendingRecovery = null;
|
|
24756
|
+
// The issue, as written, that the held composition (the mounted form, the one
|
|
24757
|
+
// a re-authorized form will take, or the one saved before a reload) was last
|
|
24758
|
+
// filled from: '' for one filled from none. A form taking that composition is
|
|
24759
|
+
// filled from it too, so the text it carries is the customer's own, or not,
|
|
24760
|
+
// as it was in the form it came from.
|
|
24156
24761
|
let composedFrom = '';
|
|
24157
24762
|
let nativeIdentity = null;
|
|
24158
24763
|
let switchedAccount = false;
|
|
@@ -24186,6 +24791,9 @@ function createHelpDeskSupport(config, options) {
|
|
|
24186
24791
|
onBack: () => {
|
|
24187
24792
|
if (destroyed || state.navigationLocked || state.identityPending)
|
|
24188
24793
|
return;
|
|
24794
|
+
// On who the reply goes to, Back returns to the request it is for.
|
|
24795
|
+
if (state.stage === 'contact' && !state.ticketAccessRequired && contact?.returnToRequest())
|
|
24796
|
+
return;
|
|
24189
24797
|
// A held form shows at once while contact still checks access behind it,
|
|
24190
24798
|
// so a contact opening in flight is cancelled even when nothing is busy.
|
|
24191
24799
|
if (state.busy || contactOpening === sequence)
|
|
@@ -24232,6 +24840,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24232
24840
|
onUnlock: (password) => { void unlock(password); },
|
|
24233
24841
|
onUnlockTicketAccess: (password) => { void unlockTicketAccess(password); },
|
|
24234
24842
|
onCancelIdentity: () => nativeIdentity?.abort(),
|
|
24843
|
+
onFocusContact: (focusOptions) => contact?.focusEntry(focusOptions) ?? false,
|
|
24235
24844
|
onBrowserBack: minimize,
|
|
24236
24845
|
onBrowserForward: () => update({ visible: true }),
|
|
24237
24846
|
}, options.target === undefined ? undefined : resolveTarget(options.target));
|
|
@@ -24311,7 +24920,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24311
24920
|
const saved = readFormDraft(active.desk.desk_id, customer.requester_id);
|
|
24312
24921
|
const composition = readAnonymousFormDraft(active.desk.desk_id);
|
|
24313
24922
|
if ((saved || composition) && !state.issue) {
|
|
24314
|
-
update({ issue: saved
|
|
24923
|
+
update({ issue: saved ? ticketBody(saved.subject, saved.body) : readSupportIssue(active.desk.desk_id) ?? '' });
|
|
24315
24924
|
await showContact('direct');
|
|
24316
24925
|
}
|
|
24317
24926
|
else if (!state.issue)
|
|
@@ -24390,6 +24999,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24390
24999
|
results = [];
|
|
24391
25000
|
requestedArticle = null;
|
|
24392
25001
|
pendingComposition = null;
|
|
25002
|
+
pendingRecovery = null;
|
|
24393
25003
|
feedbackSequence += 1;
|
|
24394
25004
|
sourceArticleId = undefined;
|
|
24395
25005
|
if (options.persist && client)
|
|
@@ -24550,18 +25160,28 @@ function createHelpDeskSupport(config, options) {
|
|
|
24550
25160
|
notify(options.onError, error);
|
|
24551
25161
|
}
|
|
24552
25162
|
}
|
|
24553
|
-
|
|
25163
|
+
/** Mount the contact form filled from `composedFrom`, then put a composition carried from an earlier form in it. */
|
|
25164
|
+
function mountContact(carried, customer) {
|
|
24554
25165
|
if (!client || destroyed)
|
|
24555
25166
|
return;
|
|
24556
25167
|
contactCustomer = customer;
|
|
25168
|
+
// A customer the website gave back sees their own saved request; none keeps it hidden.
|
|
25169
|
+
const recovering = customer ? null : pendingRecovery;
|
|
25170
|
+
pendingRecovery = null;
|
|
24557
25171
|
let activeAttempt = null;
|
|
25172
|
+
// A ticket carries the attempt the form opened under only while it is still
|
|
25173
|
+
// the journey's: recovery drops it with the previous customer's question.
|
|
25174
|
+
const formAttempt = attempt;
|
|
25175
|
+
const bridged = Boolean(options.getSessionToken || options.getIdentityAssertion || options.identityEndpoint);
|
|
24558
25176
|
contact = mountHelpDeskForm(client, {
|
|
24559
25177
|
target: view.contactTarget,
|
|
24560
|
-
// Filled
|
|
25178
|
+
// Filled from the issue its composition came from, so text the customer
|
|
24561
25179
|
// wrote in an earlier form and carried here stays their own.
|
|
24562
|
-
|
|
25180
|
+
issue: composedFrom,
|
|
24563
25181
|
attachments: options.attachments,
|
|
24564
25182
|
persist: options.persist,
|
|
25183
|
+
pageLayout: options.target !== undefined,
|
|
25184
|
+
hostShowsAttribution: options.hostShowsAttribution === true,
|
|
24565
25185
|
onSession: (session) => {
|
|
24566
25186
|
anonymous = false;
|
|
24567
25187
|
if (options.persist)
|
|
@@ -24572,9 +25192,14 @@ function createHelpDeskSupport(config, options) {
|
|
|
24572
25192
|
customer,
|
|
24573
25193
|
signIn: (input) => signIn(input).then((session) => { contactCustomer = session.customer; return session; }),
|
|
24574
25194
|
switchAccount: (safe) => { void switchAccount(safe); },
|
|
24575
|
-
...(
|
|
25195
|
+
...(bridged && { useWebsiteAccount: (safe, recover) => { void useWebsiteAccount(safe, recover); } }),
|
|
25196
|
+
offerWebsiteAccount: switchedAccount,
|
|
25197
|
+
forgetIssue,
|
|
25198
|
+
followIssue,
|
|
25199
|
+
...(recovering && { recovering }),
|
|
24576
25200
|
},
|
|
24577
|
-
|
|
25201
|
+
onScreenChange: () => view.contactScreenChanged(),
|
|
25202
|
+
assistanceContext: () => (attempt === formAttempt ? activeAttempt?.ticketContext() : undefined),
|
|
24578
25203
|
sourceArticleId: () => sourceArticleId,
|
|
24579
25204
|
onError: (error) => {
|
|
24580
25205
|
notify(options.onError, error);
|
|
@@ -24593,11 +25218,14 @@ function createHelpDeskSupport(config, options) {
|
|
|
24593
25218
|
onSuccess: (ticket) => receipt(ticket),
|
|
24594
25219
|
onStateChange: (next) => update({ navigationLocked: ['authenticating', 'submitting', 'uncertain'].includes(next) }),
|
|
24595
25220
|
});
|
|
24596
|
-
|
|
24597
|
-
|
|
25221
|
+
// A form in place of another can put a different control under the pointer.
|
|
25222
|
+
view.contactScreenChanged();
|
|
25223
|
+
if (carried)
|
|
25224
|
+
contact.restoreComposition(carried);
|
|
25225
|
+
// A carried composition was filled from the issue as it read then.
|
|
24598
25226
|
followIssue();
|
|
24599
25227
|
const activeForm = contact;
|
|
24600
|
-
void
|
|
25228
|
+
void formAttempt?.then((active) => {
|
|
24601
25229
|
// Keep the mutable callback small: an analytics response arriving late
|
|
24602
25230
|
// must not delay contact, authentication or ticket submission.
|
|
24603
25231
|
if (contact === activeForm && active)
|
|
@@ -24613,10 +25241,30 @@ function createHelpDeskSupport(config, options) {
|
|
|
24613
25241
|
*/
|
|
24614
25242
|
function followIssue() {
|
|
24615
25243
|
const issue = state.issue.trim();
|
|
24616
|
-
if (!contact || !issue || issue === composedFrom)
|
|
25244
|
+
if (!contact || !issue || issue === composedFrom.trim())
|
|
24617
25245
|
return;
|
|
24618
|
-
if (contact.refill(
|
|
24619
|
-
composedFrom = issue;
|
|
25246
|
+
if (contact.refill(state.issue))
|
|
25247
|
+
composedFrom = state.issue;
|
|
25248
|
+
}
|
|
25249
|
+
/**
|
|
25250
|
+
* Forget the question of a customer whose request just left the contact
|
|
25251
|
+
* form: it, and the answers and article it led to, are theirs, in view and
|
|
25252
|
+
* in this tab's storage. The visitor is unknown again until one signs in,
|
|
25253
|
+
* so the tab keeps their next question as any signed-out visitor's.
|
|
25254
|
+
*/
|
|
25255
|
+
function forgetIssue() {
|
|
25256
|
+
cancelArticleAssets?.();
|
|
25257
|
+
cancelArticleAssets = null;
|
|
25258
|
+
kbConfig = null;
|
|
25259
|
+
results = [];
|
|
25260
|
+
requestedArticle = null;
|
|
25261
|
+
attempt = null;
|
|
25262
|
+
sourceArticleId = undefined;
|
|
25263
|
+
composedFrom = '';
|
|
25264
|
+
anonymous = true;
|
|
25265
|
+
if (options.persist && client)
|
|
25266
|
+
clearSupportIssue(client.desk.desk_id);
|
|
25267
|
+
update({ issue: '', results: [], article: undefined, articleUrl: undefined, kbState: undefined, sourceArticle: undefined });
|
|
24620
25268
|
}
|
|
24621
25269
|
async function showContact(reason) {
|
|
24622
25270
|
if (destroyed || contactOpening === sequence)
|
|
@@ -24663,12 +25311,16 @@ function createHelpDeskSupport(config, options) {
|
|
|
24663
25311
|
return;
|
|
24664
25312
|
update({ busy: false, ticketAccessRequired: false, ticketAccessMode: undefined });
|
|
24665
25313
|
anonymous = !customer;
|
|
24666
|
-
|
|
25314
|
+
// A composition saved before a reload goes on from the issue it was filled
|
|
25315
|
+
// from; with none carried, the form fills itself from the issue as written.
|
|
25316
|
+
const saved = pendingComposition === null && options.persist ? readAnonymousFormDraft(active.desk.desk_id) : null;
|
|
25317
|
+
if (saved)
|
|
25318
|
+
composedFrom = saved.composedFrom;
|
|
25319
|
+
else if (pendingComposition === null)
|
|
25320
|
+
composedFrom = state.issue;
|
|
24667
25321
|
if (customer && options.persist)
|
|
24668
25322
|
clearSupportIssue(active.desk.desk_id);
|
|
24669
|
-
|
|
24670
|
-
composedFrom = state.issue.trim();
|
|
24671
|
-
mountContact(composition, customer);
|
|
25323
|
+
mountContact(pendingComposition ?? saved, customer);
|
|
24672
25324
|
pendingComposition = null;
|
|
24673
25325
|
}
|
|
24674
25326
|
catch (value) {
|
|
@@ -24732,6 +25384,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24732
25384
|
cancelArticleAssets?.();
|
|
24733
25385
|
cancelArticleAssets = null;
|
|
24734
25386
|
pendingComposition = composition ?? { subject: '', body: '' };
|
|
25387
|
+
pendingRecovery = null;
|
|
24735
25388
|
kb?.clearAccess();
|
|
24736
25389
|
kbConfig = null;
|
|
24737
25390
|
results = [];
|
|
@@ -24771,7 +25424,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24771
25424
|
await showContact('direct');
|
|
24772
25425
|
}
|
|
24773
25426
|
}
|
|
24774
|
-
async function useWebsiteAccount(composition) {
|
|
25427
|
+
async function useWebsiteAccount(composition, recovering = false) {
|
|
24775
25428
|
if (!client || destroyed || state.navigationLocked)
|
|
24776
25429
|
return;
|
|
24777
25430
|
const ownSequence = ++sequence;
|
|
@@ -24780,6 +25433,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24780
25433
|
cancelArticleAssets?.();
|
|
24781
25434
|
cancelArticleAssets = null;
|
|
24782
25435
|
pendingComposition = composition ?? { subject: '', body: '' };
|
|
25436
|
+
pendingRecovery = recovering ? { websiteSignedOut: true } : null;
|
|
24783
25437
|
kb?.clearAccess();
|
|
24784
25438
|
kbConfig = null;
|
|
24785
25439
|
results = [];
|
|
@@ -24800,6 +25454,9 @@ function createHelpDeskSupport(config, options) {
|
|
|
24800
25454
|
return;
|
|
24801
25455
|
const error = failure(value);
|
|
24802
25456
|
update({ busy: false, error: error.message });
|
|
25457
|
+
// The website was not reached, so it is not known to have no account.
|
|
25458
|
+
if (pendingRecovery)
|
|
25459
|
+
pendingRecovery = { websiteSignedOut: false };
|
|
24803
25460
|
if (client.hasTicketAccess) {
|
|
24804
25461
|
mountContact(composition ?? { subject: '', body: '' }, null);
|
|
24805
25462
|
pendingComposition = null;
|
|
@@ -29614,7 +30271,7 @@ class SparkVault {
|
|
|
29614
30271
|
}
|
|
29615
30272
|
/** Get the SDK version */
|
|
29616
30273
|
static get version() {
|
|
29617
|
-
return '16.
|
|
30274
|
+
return '16.5.1';
|
|
29618
30275
|
}
|
|
29619
30276
|
}
|
|
29620
30277
|
if (typeof window !== 'undefined') {
|