@sparkvault/sdk-js 16.4.1 → 16.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -13
- package/dist/index.cjs +1038 -408
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +31 -4
- package/dist/index.mjs +1038 -408
- 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/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)
|
|
7597
|
+
if (!body || this.statusRegion?.element.isConnected)
|
|
7588
7598
|
return;
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
}
|
|
7593
|
-
this.statusTimer = setTimeout(() => {
|
|
7594
|
-
this.statusTimer = null;
|
|
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) {
|
|
@@ -18235,16 +18240,16 @@ function injectHelpDeskFormStyles() {
|
|
|
18235
18240
|
.svhd-modal .svhd-container{max-width:none;border:0;border-radius:0;padding-top:8px}
|
|
18236
18241
|
.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
18242
|
.svhd-container *{box-sizing:border-box}
|
|
18238
|
-
.svhd-container h2{font-size:22px;line-height:1.25;margin:0
|
|
18243
|
+
.svhd-container h2{font-size:22px;line-height:1.25;margin:0}
|
|
18244
|
+
.svhd-step-head h2:focus{outline:none}
|
|
18239
18245
|
.svhd-form{display:grid;gap:16px}
|
|
18240
18246
|
.svhd-field{display:grid;gap:6px}
|
|
18241
18247
|
.svhd-label{font-weight:600}
|
|
18242
18248
|
.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
18249
|
.svhd-input:focus-visible,.svhd-button:focus-visible,.svhd-link:focus-visible{outline:3px solid ${DS.action};outline-offset:2px}
|
|
18244
18250
|
.svhd-input:disabled{background:${DS.slate50}}
|
|
18245
|
-
.svhd-description{min-height:140px;resize:vertical}
|
|
18246
18251
|
.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}
|
|
18252
|
+
.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
18253
|
.svhd-actions{display:flex;align-items:center;gap:12px;flex-wrap:wrap}
|
|
18249
18254
|
.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
18255
|
.svhd-button:hover{background:${DS.actionHover}}
|
|
@@ -18262,14 +18267,53 @@ function injectHelpDeskFormStyles() {
|
|
|
18262
18267
|
.svhd-done-title:focus{outline:none}
|
|
18263
18268
|
.svhd-confirmation-message{white-space:pre-wrap;overflow-wrap:anywhere}
|
|
18264
18269
|
.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-
|
|
18270
|
+
.svhd-hint{font-size:13px;color:${DS.slate600};margin:0}
|
|
18271
|
+
.svhd-step{display:grid;gap:16px;min-width:0}
|
|
18272
|
+
.svhd-step-head{display:grid;gap:4px;margin-bottom:4px}
|
|
18273
|
+
.svhd-step-label{margin:0;font-size:13px;font-weight:600;line-height:1.4;color:${DS.slate600}}
|
|
18274
|
+
.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}
|
|
18275
|
+
.svhd-text-button:hover{color:${DS.actionHover}}
|
|
18276
|
+
.svhd-text-button:focus-visible{outline:3px solid ${DS.action};outline-offset:2px}
|
|
18277
|
+
.svhd-text-button:disabled{color:${DS.slate500};cursor:default}
|
|
18278
|
+
.svhd-widget-account{display:flex;align-items:center;flex-wrap:wrap;gap:0 16px;min-width:0}
|
|
18279
|
+
.svhd-posting-as{margin:0;color:${DS.slate600};font-size:14px;line-height:1.5;overflow-wrap:anywhere}
|
|
18280
|
+
.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}
|
|
18281
|
+
.svhd-step .svhd-note svg{display:block;width:18px;height:18px;flex:none;margin-top:2px;color:${DS.action}}
|
|
18282
|
+
.svhd-recap{display:flex;align-items:center;gap:12px;padding:6px 6px 6px 14px;border:1px solid ${DS.slate200};border-radius:8px}
|
|
18283
|
+
.svhd-recap-request{flex:1;min-width:0}
|
|
18284
|
+
.svhd-recap-label{display:block;color:${DS.slate600};font-size:12px;font-weight:600;line-height:1.4}
|
|
18285
|
+
.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}
|
|
18286
|
+
.svhd-recap .svhd-text-button{flex:none}
|
|
18287
|
+
/* The frame is the field: its ring shows wherever focus is inside it, and the text inside draws none of its own. */
|
|
18288
|
+
.svhd-composer{position:relative;display:flex;flex-direction:column;min-width:0;border:1px solid ${DS.slate300};border-radius:6px;background:${DS.white}}
|
|
18289
|
+
.svhd-composer:has(.svhd-composer-input:focus-visible){outline:3px solid ${DS.action};outline-offset:2px}
|
|
18290
|
+
@supports not selector(:has(*)){.svhd-composer:focus-within{outline:3px solid ${DS.action};outline-offset:2px}}
|
|
18291
|
+
.svhd-composer-dragging{border-style:dashed;border-color:${DS.action}}
|
|
18292
|
+
.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}
|
|
18293
|
+
.svhd-composer-input:focus,.svhd-composer-input:focus-visible{outline:none}
|
|
18294
|
+
.svhd-composer-input:disabled{background:${DS.slate50}}
|
|
18295
|
+
.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}
|
|
18296
|
+
.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}}
|
|
18297
|
+
.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}
|
|
18298
|
+
.svhd-composer-attach:hover{background:${DS.slate100};color:${DS.slate900}}
|
|
18299
|
+
.svhd-composer-attach:disabled{opacity:.6;cursor:default}
|
|
18300
|
+
.svhd-composer .svhd-composer-attach svg{display:block;width:18px;height:18px}
|
|
18301
|
+
.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}}
|
|
18302
|
+
.svhd-composer-notice{margin:0;font-size:14px}
|
|
18303
|
+
.svhd-attachment-chips{display:flex;flex-wrap:wrap;gap:8px;list-style:none;margin:0;padding:8px;border-top:1px solid ${DS.slate200}}
|
|
18304
|
+
.svhd-attachment-chips:empty{display:none}
|
|
18305
|
+
.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}
|
|
18306
|
+
.svhd-attachment-name{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:600;color:${DS.slate900}}
|
|
18307
|
+
.svhd-attachment-status{grid-column:1;padding-right:8px;color:${DS.slate600};font-size:12px;overflow-wrap:anywhere}
|
|
18308
|
+
.svhd-attachment-status.svhd-error{color:${DS.error}}
|
|
18309
|
+
.svhd-attachment-progress{grid-column:1/-1;width:calc(100% - 10px);height:6px;margin-top:6px;accent-color:${DS.action}}
|
|
18310
|
+
.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}
|
|
18311
|
+
.svhd-attachment-remove:hover{background:${DS.slate200};color:${DS.slate900}}
|
|
18312
|
+
.svhd-attachment-chip .svhd-attachment-remove svg{display:block;width:16px;height:16px}
|
|
18313
|
+
.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}
|
|
18314
|
+
.svhd-composer button:focus-visible{outline:3px solid ${DS.action};outline-offset:-3px}
|
|
18315
|
+
.svhd-attachment-remove:disabled,.svhd-attachment-retry:disabled{opacity:.6;cursor:default}
|
|
18316
|
+
.svhd-live{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
|
|
18273
18317
|
.svhd-footer{margin-top:20px;font-size:12px;color:${DS.slate500}}
|
|
18274
18318
|
`;
|
|
18275
18319
|
document.head.appendChild(style);
|
|
@@ -18473,23 +18517,6 @@ function lastExtension(name) {
|
|
|
18473
18517
|
return shownExtension(closeUpSpaces(name));
|
|
18474
18518
|
}
|
|
18475
18519
|
|
|
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
18520
|
/**
|
|
18494
18521
|
* What a help-desk attachment may be named and what its first bytes may not
|
|
18495
18522
|
* be: the one list of the files a ticket accepts, beside the one list of
|
|
@@ -18788,6 +18815,15 @@ const ACCEPTED_ATTACHMENTS_COPY = acceptedKindsCopy(ACCEPTED_ATTACHMENT_KINDS);
|
|
|
18788
18815
|
const CUSTOMER_ATTACHMENTS_HINT =
|
|
18789
18816
|
`Add screenshots, documents or recordings. Up to ${MAX_ATTACHMENTS_PER_MESSAGE} files, ${formatBytes(CUSTOMER_ATTACHMENT_MAX_BYTES)} each.`;
|
|
18790
18817
|
|
|
18818
|
+
/**
|
|
18819
|
+
* What a customer reads at a desk that takes no files from its customers
|
|
18820
|
+
* (the desk lookup's `customer_can_attach_files` is false, the upload refusal
|
|
18821
|
+
* CUSTOMER_UPLOAD_REFUSALS.UPLOADS_OFF): the portal's refusal and its note on
|
|
18822
|
+
* the files an email left out, and the SDK's support form refusing a file
|
|
18823
|
+
* dropped, pasted or uploaded there.
|
|
18824
|
+
*/
|
|
18825
|
+
const NO_CUSTOMER_FILES_COPY = "This help desk doesn't take files from customers.";
|
|
18826
|
+
|
|
18791
18827
|
/**
|
|
18792
18828
|
* A file input's `accept`: every extension a ticket accepts
|
|
18793
18829
|
* (ACCEPTED_ATTACHMENT_EXTENSIONS), each with its dot, so the system's file
|
|
@@ -18835,7 +18871,56 @@ function refusalCopy(refusal, maxBytes) {
|
|
|
18835
18871
|
return REFUSAL_COPY[refusal] ?? "This file can't be attached.";
|
|
18836
18872
|
}
|
|
18837
18873
|
|
|
18838
|
-
|
|
18874
|
+
/**
|
|
18875
|
+
* The help desk's bare outline glyphs, shared by the support wizard and the
|
|
18876
|
+
* ticket form: stroked in `currentColor`, so the stylesheet that sizes them
|
|
18877
|
+
* also colors them, and hidden from assistive technology, since the control
|
|
18878
|
+
* that holds one names it.
|
|
18879
|
+
*/
|
|
18880
|
+
const PATHS = {
|
|
18881
|
+
back: 'm14.5 6-6 6 6 6',
|
|
18882
|
+
close: 'm6 6 12 12M18 6 6 18',
|
|
18883
|
+
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',
|
|
18884
|
+
check: 'm5 12 4 4L19 6',
|
|
18885
|
+
article: 'M14 3H6a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8Zm0 0v5h5M8 12h8M8 16h6',
|
|
18886
|
+
chevron: 'm9 6 6 6-6 6',
|
|
18887
|
+
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',
|
|
18888
|
+
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',
|
|
18889
|
+
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',
|
|
18890
|
+
info: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18Zm0-10v5m0-8h.01',
|
|
18891
|
+
};
|
|
18892
|
+
function helpDeskIcon(name) {
|
|
18893
|
+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
18894
|
+
svg.setAttribute('viewBox', '0 0 24 24');
|
|
18895
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
18896
|
+
svg.setAttribute('focusable', 'false');
|
|
18897
|
+
svg.setAttribute('fill', 'none');
|
|
18898
|
+
svg.setAttribute('stroke', 'currentColor');
|
|
18899
|
+
svg.setAttribute('stroke-width', '1.7');
|
|
18900
|
+
svg.setAttribute('stroke-linecap', 'round');
|
|
18901
|
+
svg.setAttribute('stroke-linejoin', 'round');
|
|
18902
|
+
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
18903
|
+
path.setAttribute('d', PATHS[name]);
|
|
18904
|
+
svg.append(path);
|
|
18905
|
+
return svg;
|
|
18906
|
+
}
|
|
18907
|
+
|
|
18908
|
+
/** A refusal of files read under the composer, hidden until there is one. */
|
|
18909
|
+
function createNotice() {
|
|
18910
|
+
const notice = document.createElement('p');
|
|
18911
|
+
notice.className = 'svhd-composer-notice svhd-error';
|
|
18912
|
+
notice.hidden = true;
|
|
18913
|
+
return notice;
|
|
18914
|
+
}
|
|
18915
|
+
/** Show a notice's refusal, or hide it with null. It is an alert only while it shows, as a field's error is. */
|
|
18916
|
+
function setNotice(notice, text) {
|
|
18917
|
+
notice.textContent = text ?? '';
|
|
18918
|
+
notice.hidden = text === null;
|
|
18919
|
+
if (text === null)
|
|
18920
|
+
notice.removeAttribute('role');
|
|
18921
|
+
else
|
|
18922
|
+
notice.setAttribute('role', 'alert');
|
|
18923
|
+
}
|
|
18839
18924
|
/** A failed mint's quota/size refusal remains a visible file error, never a silently omitted file. */
|
|
18840
18925
|
function problem(error) {
|
|
18841
18926
|
if (error instanceof SparkVaultError) {
|
|
@@ -18847,7 +18932,7 @@ function problem(error) {
|
|
|
18847
18932
|
}
|
|
18848
18933
|
if (error.statusCode === 402) {
|
|
18849
18934
|
const reason = error.details?.reason;
|
|
18850
|
-
return { copy: reason === CUSTOMER_UPLOAD_REFUSALS.UPLOADS_OFF ?
|
|
18935
|
+
return { copy: reason === CUSTOMER_UPLOAD_REFUSALS.UPLOADS_OFF ? NO_CUSTOMER_FILES_COPY
|
|
18851
18936
|
: reason === CUSTOMER_UPLOAD_REFUSALS.ALLOWANCE_REACHED ? 'You have reached this help desk’s upload allowance.'
|
|
18852
18937
|
: 'This help desk cannot store more files right now.', retryable: false };
|
|
18853
18938
|
}
|
|
@@ -18857,48 +18942,58 @@ function problem(error) {
|
|
|
18857
18942
|
}
|
|
18858
18943
|
return { copy: 'This file could not be uploaded. Try again or remove it.', retryable: true };
|
|
18859
18944
|
}
|
|
18860
|
-
/**
|
|
18861
|
-
|
|
18862
|
-
|
|
18863
|
-
|
|
18864
|
-
|
|
18865
|
-
|
|
18866
|
-
label.textContent = 'Attachments';
|
|
18867
|
-
label.htmlFor = `${prefix}-attachments`;
|
|
18945
|
+
/**
|
|
18946
|
+
* The picker owns each file's transfer; it publishes only IDs whose Forge
|
|
18947
|
+
* receipt has confirmed storage. `onEntriesChange` hears each file the
|
|
18948
|
+
* customer adds or removes.
|
|
18949
|
+
*/
|
|
18950
|
+
function createFormAttachments(client, prefix, context, onEntriesChange) {
|
|
18868
18951
|
const input = document.createElement('input');
|
|
18869
18952
|
input.type = 'file';
|
|
18870
18953
|
input.name = 'attachments';
|
|
18871
|
-
input.id = label.htmlFor;
|
|
18872
18954
|
input.multiple = true;
|
|
18873
18955
|
input.accept = ATTACHMENT_INPUT_ACCEPT;
|
|
18874
|
-
input.
|
|
18956
|
+
input.hidden = true;
|
|
18957
|
+
input.tabIndex = -1;
|
|
18875
18958
|
const hint = document.createElement('p');
|
|
18876
18959
|
hint.id = `${prefix}-attachment-hint`;
|
|
18877
|
-
hint.className = 'svhd-
|
|
18960
|
+
hint.className = 'svhd-composer-hint';
|
|
18878
18961
|
hint.textContent = CUSTOMER_ATTACHMENTS_HINT;
|
|
18879
|
-
|
|
18880
|
-
|
|
18881
|
-
|
|
18882
|
-
|
|
18883
|
-
|
|
18962
|
+
const attach = document.createElement('button');
|
|
18963
|
+
attach.type = 'button';
|
|
18964
|
+
attach.className = 'svhd-composer-attach';
|
|
18965
|
+
attach.setAttribute('aria-label', 'Attach files');
|
|
18966
|
+
attach.setAttribute('aria-describedby', hint.id);
|
|
18967
|
+
const attachText = document.createElement('span');
|
|
18968
|
+
attachText.textContent = 'Attach';
|
|
18969
|
+
attach.append(helpDeskIcon('paperclip'), attachText);
|
|
18970
|
+
const toolbar = document.createElement('div');
|
|
18971
|
+
toolbar.className = 'svhd-composer-toolbar';
|
|
18972
|
+
toolbar.append(attach, hint, input);
|
|
18973
|
+
const notice = createNotice();
|
|
18884
18974
|
const list = document.createElement('ul');
|
|
18885
|
-
list.className = 'svhd-
|
|
18886
|
-
list.setAttribute('aria-label', '
|
|
18887
|
-
element.append(label, input, hint, notice, list);
|
|
18975
|
+
list.className = 'svhd-attachment-chips';
|
|
18976
|
+
list.setAttribute('aria-label', 'Attached files');
|
|
18888
18977
|
let entries = [];
|
|
18889
18978
|
let revision = 0;
|
|
18890
18979
|
let locked = false;
|
|
18891
18980
|
let pickingDisabled = false;
|
|
18892
18981
|
let destroyed = false;
|
|
18893
18982
|
const current = (entry, ownRevision) => !destroyed && revision === ownRevision && entries.includes(entry) && !entry.controller?.signal.aborted;
|
|
18983
|
+
function syncPicking() {
|
|
18984
|
+
attach.disabled = locked || pickingDisabled;
|
|
18985
|
+
input.disabled = locked || pickingDisabled;
|
|
18986
|
+
}
|
|
18894
18987
|
function controls(entry) {
|
|
18895
18988
|
entry.remove.disabled = locked;
|
|
18896
18989
|
entry.retry.disabled = locked || !!entry.operation;
|
|
18897
18990
|
}
|
|
18898
18991
|
function update(entry, state, text) {
|
|
18899
18992
|
entry.state = state;
|
|
18993
|
+
entry.row.dataset.state = state;
|
|
18900
18994
|
entry.status.textContent = text;
|
|
18901
18995
|
entry.status.classList.toggle('svhd-error', state === 'failed');
|
|
18996
|
+
entry.progress.hidden = state !== 'uploading';
|
|
18902
18997
|
entry.retry.hidden = !(entry.retryable && (state === 'failed' || state === 'received'));
|
|
18903
18998
|
entry.retry.textContent = state === 'received' ? 'Check upload' : 'Retry';
|
|
18904
18999
|
entry.retry.setAttribute('aria-label', `${state === 'received' ? 'Check upload' : 'Retry'} ${entry.file.name}`);
|
|
@@ -18938,7 +19033,7 @@ function createFormAttachments(client, prefix, context) {
|
|
|
18938
19033
|
if (!stillCurrent())
|
|
18939
19034
|
return;
|
|
18940
19035
|
if (!owner) {
|
|
18941
|
-
update(entry, 'queued', '
|
|
19036
|
+
update(entry, 'queued', 'Uploads when you send your request.');
|
|
18942
19037
|
return;
|
|
18943
19038
|
}
|
|
18944
19039
|
const options = {
|
|
@@ -19021,54 +19116,70 @@ function createFormAttachments(client, prefix, context) {
|
|
|
19021
19116
|
function remove(entry) {
|
|
19022
19117
|
if (locked)
|
|
19023
19118
|
return;
|
|
19119
|
+
// A keyboard removal keeps focus among the files, else on Attach.
|
|
19120
|
+
const refocus = document.activeElement === entry.remove;
|
|
19121
|
+
const index = entries.indexOf(entry);
|
|
19024
19122
|
entry.controller?.abort();
|
|
19025
19123
|
entries = entries.filter(candidate => candidate !== entry);
|
|
19026
19124
|
entry.row.remove();
|
|
19027
|
-
notice
|
|
19125
|
+
setNotice(notice, null);
|
|
19028
19126
|
void cancel(entry);
|
|
19127
|
+
onEntriesChange();
|
|
19128
|
+
if (refocus)
|
|
19129
|
+
(entries[Math.min(index, entries.length - 1)]?.remove ?? attach).focus();
|
|
19029
19130
|
}
|
|
19030
19131
|
function add(files) {
|
|
19031
19132
|
if (locked || pickingDisabled || destroyed)
|
|
19032
19133
|
return;
|
|
19033
19134
|
const incoming = Array.from(files);
|
|
19135
|
+
if (incoming.length === 0)
|
|
19136
|
+
return;
|
|
19034
19137
|
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.`;
|
|
19138
|
+
setNotice(notice, incoming.length > room ? `You can attach up to ${MAX_ATTACHMENTS_PER_MESSAGE} files. Remove a file before adding another.` : null);
|
|
19037
19139
|
for (const file of incoming.slice(0, room)) {
|
|
19038
19140
|
const row = document.createElement('li');
|
|
19039
|
-
row.className = 'svhd-
|
|
19141
|
+
row.className = 'svhd-attachment-chip';
|
|
19040
19142
|
const filename = document.createElement('span');
|
|
19041
|
-
filename.className = 'svhd-
|
|
19143
|
+
filename.className = 'svhd-attachment-name';
|
|
19042
19144
|
filename.textContent = file.name;
|
|
19145
|
+
filename.title = file.name;
|
|
19043
19146
|
const status = document.createElement('span');
|
|
19147
|
+
status.className = 'svhd-attachment-status';
|
|
19044
19148
|
status.setAttribute('role', 'status');
|
|
19045
19149
|
status.setAttribute('aria-live', 'polite');
|
|
19046
|
-
const progress =
|
|
19150
|
+
const progress = document.createElement('progress');
|
|
19151
|
+
progress.className = 'svhd-attachment-progress';
|
|
19047
19152
|
progress.max = 100;
|
|
19048
19153
|
progress.value = 0;
|
|
19154
|
+
progress.hidden = true;
|
|
19049
19155
|
progress.setAttribute('aria-label', `Upload progress for ${file.name}`);
|
|
19050
19156
|
const removeButton = document.createElement('button');
|
|
19051
19157
|
removeButton.type = 'button';
|
|
19052
|
-
removeButton.className = 'svhd-
|
|
19053
|
-
removeButton.textContent = 'Remove';
|
|
19158
|
+
removeButton.className = 'svhd-attachment-remove';
|
|
19054
19159
|
removeButton.setAttribute('aria-label', `Remove ${file.name}`);
|
|
19160
|
+
removeButton.append(helpDeskIcon('close'));
|
|
19055
19161
|
const retry = document.createElement('button');
|
|
19056
19162
|
retry.type = 'button';
|
|
19057
|
-
retry.className = 'svhd-
|
|
19163
|
+
retry.className = 'svhd-attachment-retry';
|
|
19058
19164
|
retry.hidden = true;
|
|
19059
19165
|
const entry = { file, row, status, progress, remove: removeButton, retry, state: 'queued', retryable: false };
|
|
19060
19166
|
removeButton.onclick = () => remove(entry);
|
|
19061
19167
|
retry.onclick = () => { if (!locked && entry.retryable)
|
|
19062
19168
|
void run(entry); };
|
|
19063
|
-
row.append(filename,
|
|
19169
|
+
row.append(filename, removeButton, status, retry, progress);
|
|
19064
19170
|
list.append(row);
|
|
19065
19171
|
entries.push(entry);
|
|
19066
19172
|
void run(entry);
|
|
19067
19173
|
}
|
|
19174
|
+
if (room > 0)
|
|
19175
|
+
onEntriesChange();
|
|
19068
19176
|
}
|
|
19069
19177
|
const onChange = () => { if (input.files)
|
|
19070
19178
|
add(input.files); input.value = ''; };
|
|
19179
|
+
const onAttach = () => { if (!attach.disabled)
|
|
19180
|
+
input.click(); };
|
|
19071
19181
|
input.addEventListener('change', onChange);
|
|
19182
|
+
attach.addEventListener('click', onAttach);
|
|
19072
19183
|
function clear(preserveComplete = false) {
|
|
19073
19184
|
revision += 1;
|
|
19074
19185
|
const previous = entries;
|
|
@@ -19080,17 +19191,20 @@ function createFormAttachments(client, prefix, context) {
|
|
|
19080
19191
|
}
|
|
19081
19192
|
list.replaceChildren();
|
|
19082
19193
|
input.value = '';
|
|
19083
|
-
notice
|
|
19194
|
+
setNotice(notice, null);
|
|
19084
19195
|
}
|
|
19085
19196
|
return {
|
|
19086
|
-
|
|
19197
|
+
toolbar,
|
|
19198
|
+
list,
|
|
19199
|
+
notice,
|
|
19200
|
+
get accepting() { return !locked && !pickingDisabled && !destroyed; },
|
|
19087
19201
|
get attachmentIds() { return entries.filter(entry => entry.state === 'complete' && entry.attachmentId).map(entry => entry.attachmentId); },
|
|
19088
19202
|
get unresolved() { return entries.some(entry => entry.state !== 'complete'); },
|
|
19089
19203
|
get hasEntries() { return entries.length > 0; },
|
|
19090
|
-
|
|
19204
|
+
add,
|
|
19091
19205
|
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;
|
|
19206
|
+
lock(value) { locked = value; syncPicking(); entries.forEach(controls); },
|
|
19207
|
+
disablePicking(value) { pickingDisabled = value; syncPicking(); },
|
|
19094
19208
|
renewSession(previousToken, nextToken) {
|
|
19095
19209
|
for (const entry of entries) {
|
|
19096
19210
|
if (entry.context?.expectedSessionToken === previousToken)
|
|
@@ -19098,11 +19212,175 @@ function createFormAttachments(client, prefix, context) {
|
|
|
19098
19212
|
}
|
|
19099
19213
|
},
|
|
19100
19214
|
clear,
|
|
19101
|
-
destroy(preserveComplete = false) {
|
|
19215
|
+
destroy(preserveComplete = false) {
|
|
19216
|
+
destroyed = true;
|
|
19217
|
+
clear(preserveComplete);
|
|
19218
|
+
input.removeEventListener('change', onChange);
|
|
19219
|
+
attach.removeEventListener('click', onAttach);
|
|
19220
|
+
},
|
|
19221
|
+
};
|
|
19222
|
+
}
|
|
19223
|
+
|
|
19224
|
+
const FOLDER_COPY = 'Folders can’t be attached. Add the files inside them instead.';
|
|
19225
|
+
function carriesFiles(event) {
|
|
19226
|
+
return Array.from(event.dataTransfer?.types ?? []).includes('Files');
|
|
19227
|
+
}
|
|
19228
|
+
/**
|
|
19229
|
+
* The details field as a composer. A file pasted into the summary or the
|
|
19230
|
+
* details, or dropped anywhere on the request step, joins the form's one
|
|
19231
|
+
* attachment pipeline (`attachments.add`), under the same limits and
|
|
19232
|
+
* refusals as a picked one; the drop target shows only over the composer. A
|
|
19233
|
+
* paste or drag of text alone stays the browser's. A file brought over the
|
|
19234
|
+
* form is never the browser's to open in place of the unsent request: on the
|
|
19235
|
+
* reply-to step, or while the form takes no files, it is refused outright,
|
|
19236
|
+
* and a desk that takes no files says so when the file is dropped.
|
|
19237
|
+
*/
|
|
19238
|
+
function createComposer(options) {
|
|
19239
|
+
const { form, summary, textarea, attachments, deskRefusesFiles, onRequestStep } = options;
|
|
19240
|
+
const frame = document.createElement('div');
|
|
19241
|
+
frame.className = 'svhd-composer';
|
|
19242
|
+
textarea.classList.add('svhd-composer-input');
|
|
19243
|
+
const drop = document.createElement('p');
|
|
19244
|
+
drop.className = 'svhd-composer-drop';
|
|
19245
|
+
drop.textContent = 'Drop the files to attach them.';
|
|
19246
|
+
drop.hidden = true;
|
|
19247
|
+
frame.append(textarea, drop);
|
|
19248
|
+
if (attachments)
|
|
19249
|
+
frame.append(attachments.toolbar, attachments.list);
|
|
19250
|
+
const notice = attachments?.notice ?? createNotice();
|
|
19251
|
+
const fields = [summary, textarea];
|
|
19252
|
+
let pastedImages = 0;
|
|
19253
|
+
function fileAction() {
|
|
19254
|
+
if (!onRequestStep())
|
|
19255
|
+
return 'none';
|
|
19256
|
+
if (attachments)
|
|
19257
|
+
return attachments.accepting ? 'attach' : 'none';
|
|
19258
|
+
return deskRefusesFiles ? 'refuse' : 'none';
|
|
19259
|
+
}
|
|
19260
|
+
function dragging(value) {
|
|
19261
|
+
frame.classList.toggle('svhd-composer-dragging', value);
|
|
19262
|
+
drop.hidden = !value;
|
|
19263
|
+
}
|
|
19264
|
+
function refuseFiles() {
|
|
19265
|
+
if (!notice.hidden && notice.textContent === NO_CUSTOMER_FILES_COPY)
|
|
19266
|
+
return;
|
|
19267
|
+
setNotice(notice, NO_CUSTOMER_FILES_COPY);
|
|
19268
|
+
}
|
|
19269
|
+
// A dropped folder arrives as a file that cannot be read, so it is left out,
|
|
19270
|
+
// and said so beside any refusal the files with it met.
|
|
19271
|
+
function attachDropped(transfer) {
|
|
19272
|
+
const files = [];
|
|
19273
|
+
let folders = 0;
|
|
19274
|
+
for (const item of Array.from(transfer.items)) {
|
|
19275
|
+
if (item.kind !== 'file')
|
|
19276
|
+
continue;
|
|
19277
|
+
if (item.webkitGetAsEntry()?.isDirectory) {
|
|
19278
|
+
folders += 1;
|
|
19279
|
+
continue;
|
|
19280
|
+
}
|
|
19281
|
+
const file = item.getAsFile();
|
|
19282
|
+
if (file)
|
|
19283
|
+
files.push(file);
|
|
19284
|
+
}
|
|
19285
|
+
if (files.length > 0)
|
|
19286
|
+
attachments?.add(files);
|
|
19287
|
+
if (folders > 0)
|
|
19288
|
+
setNotice(notice, files.length > 0 && !notice.hidden ? `${FOLDER_COPY} ${notice.textContent}` : FOLDER_COPY);
|
|
19289
|
+
}
|
|
19290
|
+
// A picture pasted from the clipboard is named "image.png" every time;
|
|
19291
|
+
// numbering the pastes tells their chips, and their Remove buttons, apart.
|
|
19292
|
+
function pastedName(file) {
|
|
19293
|
+
const extension = /^image\.(\w+)$/.exec(file.name)?.[1];
|
|
19294
|
+
if (extension === undefined)
|
|
19295
|
+
return file;
|
|
19296
|
+
pastedImages += 1;
|
|
19297
|
+
return new File([file], `Pasted image ${pastedImages}.${extension}`, { type: file.type, lastModified: file.lastModified });
|
|
19298
|
+
}
|
|
19299
|
+
// Cancelling dragenter and dragover keeps the browser from opening the file
|
|
19300
|
+
// in place of the page. A drop effect of none cancels the drop itself, so a
|
|
19301
|
+
// file the desk refuses keeps one to be refused in words when it lands.
|
|
19302
|
+
const onDragOver = (event) => {
|
|
19303
|
+
if (!carriesFiles(event))
|
|
19304
|
+
return;
|
|
19305
|
+
event.preventDefault();
|
|
19306
|
+
const action = fileAction();
|
|
19307
|
+
if (event.dataTransfer)
|
|
19308
|
+
event.dataTransfer.dropEffect = action === 'none' ? 'none' : 'copy';
|
|
19309
|
+
dragging(action === 'attach' && event.target instanceof Node && frame.contains(event.target));
|
|
19310
|
+
};
|
|
19311
|
+
const onDragLeave = (event) => {
|
|
19312
|
+
if (!(event.relatedTarget instanceof Node) || !frame.contains(event.relatedTarget))
|
|
19313
|
+
dragging(false);
|
|
19314
|
+
};
|
|
19315
|
+
const onDrop = (event) => {
|
|
19316
|
+
if (!carriesFiles(event))
|
|
19317
|
+
return;
|
|
19318
|
+
event.preventDefault();
|
|
19319
|
+
dragging(false);
|
|
19320
|
+
const action = fileAction();
|
|
19321
|
+
if (action === 'attach' && event.dataTransfer)
|
|
19322
|
+
attachDropped(event.dataTransfer);
|
|
19323
|
+
else if (action === 'refuse')
|
|
19324
|
+
refuseFiles();
|
|
19325
|
+
};
|
|
19326
|
+
// A paste that carries files is those files, and the text beside them is
|
|
19327
|
+
// only their names (a file copied in the system's file manager), so none of
|
|
19328
|
+
// it lands in the field. Office apps are the exception: copied cells or
|
|
19329
|
+
// paragraphs come as text and formatted text, with a picture of them as a
|
|
19330
|
+
// file, and that paste is the text.
|
|
19331
|
+
const onPaste = (event) => {
|
|
19332
|
+
const clipboard = event.clipboardData;
|
|
19333
|
+
if (!clipboard || clipboard.files.length === 0)
|
|
19334
|
+
return;
|
|
19335
|
+
if (Array.from(clipboard.types).includes('text/html') && clipboard.getData('text/plain'))
|
|
19336
|
+
return;
|
|
19337
|
+
const action = fileAction();
|
|
19338
|
+
if (action === 'none')
|
|
19339
|
+
return;
|
|
19340
|
+
event.preventDefault();
|
|
19341
|
+
if (action === 'attach')
|
|
19342
|
+
attachments?.add(Array.from(clipboard.files, pastedName));
|
|
19343
|
+
else
|
|
19344
|
+
refuseFiles();
|
|
19345
|
+
};
|
|
19346
|
+
const onInput = () => { if (!attachments)
|
|
19347
|
+
setNotice(notice, null); };
|
|
19348
|
+
form.addEventListener('dragenter', onDragOver);
|
|
19349
|
+
form.addEventListener('dragover', onDragOver);
|
|
19350
|
+
form.addEventListener('dragleave', onDragLeave);
|
|
19351
|
+
form.addEventListener('drop', onDrop);
|
|
19352
|
+
for (const field of fields) {
|
|
19353
|
+
field.addEventListener('paste', onPaste);
|
|
19354
|
+
field.addEventListener('input', onInput);
|
|
19355
|
+
}
|
|
19356
|
+
return {
|
|
19357
|
+
frame,
|
|
19358
|
+
notice,
|
|
19359
|
+
clearNotice: () => setNotice(notice, null),
|
|
19360
|
+
destroy() {
|
|
19361
|
+
form.removeEventListener('dragenter', onDragOver);
|
|
19362
|
+
form.removeEventListener('dragover', onDragOver);
|
|
19363
|
+
form.removeEventListener('dragleave', onDragLeave);
|
|
19364
|
+
form.removeEventListener('drop', onDrop);
|
|
19365
|
+
for (const field of fields) {
|
|
19366
|
+
field.removeEventListener('paste', onPaste);
|
|
19367
|
+
field.removeEventListener('input', onInput);
|
|
19368
|
+
}
|
|
19369
|
+
},
|
|
19102
19370
|
};
|
|
19103
19371
|
}
|
|
19104
19372
|
|
|
19105
19373
|
const TTL_MS = 30 * 60 * 1000;
|
|
19374
|
+
/** JSON writes one character of a field as up to six: a control character or lone surrogate becomes an escape like \u0001. */
|
|
19375
|
+
const MAX_ESCAPED_CHAR = 6;
|
|
19376
|
+
/** Room in a row for its keys, ids, timestamps, attachment list and article id. */
|
|
19377
|
+
const ROW_FRAME_CHARS = 8192;
|
|
19378
|
+
/** The longest row a writer can store with these fields, so a reader refuses only rows no writer made. */
|
|
19379
|
+
const maxRowChars = (bodies, subjects) => MAX_ESCAPED_CHAR * (bodies * MAX_BODY_BYTES + subjects * MAX_SUBJECT_LEN) + ROW_FRAME_CHARS;
|
|
19380
|
+
/** The question, the request's subject and description, and the question the request was filled from. */
|
|
19381
|
+
const MAX_ISSUE_ROW_CHARS = maxRowChars(3, 1);
|
|
19382
|
+
/** The request and the uncertain send, each with a subject and description. */
|
|
19383
|
+
const MAX_DRAFT_ROW_CHARS = maxRowChars(2, 2);
|
|
19106
19384
|
const storageKey = (deskId, requesterId) => isHelpDeskId(deskId) && isResourceIdOf('requester', requesterId) ? `sv-hd-draft:${deskId}:${requesterId}:new` : null;
|
|
19107
19385
|
const validBody = (value) => typeof value === 'string' && value.length <= MAX_BODY_BYTES && new TextEncoder().encode(value).length <= MAX_BODY_BYTES;
|
|
19108
19386
|
const validSubject = (value) => typeof value === 'string' && value.length <= MAX_SUBJECT_LEN;
|
|
@@ -19123,14 +19401,19 @@ function readSupportDraft(deskId) {
|
|
|
19123
19401
|
const raw = sessionStorage.getItem(`sv-hd-issue:${deskId}`);
|
|
19124
19402
|
if (!raw)
|
|
19125
19403
|
return null;
|
|
19126
|
-
if (raw.length >
|
|
19404
|
+
if (raw.length > MAX_ISSUE_ROW_CHARS)
|
|
19127
19405
|
throw new Error('Invalid issue');
|
|
19128
19406
|
const row = JSON.parse(raw);
|
|
19129
19407
|
if (row?.desk_id !== deskId || !validBody(row.issue) || !Number.isFinite(row.expires_at) ||
|
|
19130
19408
|
row.expires_at <= Date.now() || row.expires_at > Date.now() + TTL_MS ||
|
|
19131
19409
|
(row.composition !== undefined && (!validSubject(row.composition?.subject) || !validBody(row.composition?.body))))
|
|
19132
19410
|
throw new Error('Invalid issue');
|
|
19133
|
-
|
|
19411
|
+
if (row.composition === undefined)
|
|
19412
|
+
return { issue: row.issue };
|
|
19413
|
+
// The question a request was filled from only steers refilling it: one that
|
|
19414
|
+
// is not a question, or belongs to no request, is left out, never the row.
|
|
19415
|
+
return { issue: row.issue, composition: { subject: row.composition.subject, body: row.composition.body },
|
|
19416
|
+
...(validBody(row.composed_from) && { composedFrom: row.composed_from }) };
|
|
19134
19417
|
}
|
|
19135
19418
|
catch {
|
|
19136
19419
|
clearSupportIssue(deskId);
|
|
@@ -19138,25 +19421,34 @@ function readSupportDraft(deskId) {
|
|
|
19138
19421
|
}
|
|
19139
19422
|
}
|
|
19140
19423
|
function readSupportIssue(deskId) { return readSupportDraft(deskId)?.issue ?? null; }
|
|
19141
|
-
function readAnonymousFormDraft(deskId) {
|
|
19142
|
-
|
|
19424
|
+
function readAnonymousFormDraft(deskId) {
|
|
19425
|
+
const draft = readSupportDraft(deskId);
|
|
19426
|
+
return draft?.composition ? { ...draft.composition, composedFrom: draft.composedFrom ?? '' } : null;
|
|
19427
|
+
}
|
|
19428
|
+
function writeSupportDraft(deskId, draft) {
|
|
19143
19429
|
try {
|
|
19144
|
-
sessionStorage.setItem(`sv-hd-issue:${deskId}`, JSON.stringify({ desk_id: deskId, issue,
|
|
19145
|
-
...(composition && { composition }),
|
|
19430
|
+
sessionStorage.setItem(`sv-hd-issue:${deskId}`, JSON.stringify({ desk_id: deskId, issue: draft.issue,
|
|
19431
|
+
...(draft.composition && { composition: draft.composition }), ...(draft.composedFrom !== undefined && { composed_from: draft.composedFrom }),
|
|
19432
|
+
expires_at: Date.now() + TTL_MS }));
|
|
19146
19433
|
}
|
|
19147
19434
|
catch { /* The live wizard still keeps its composition in memory. */ }
|
|
19148
19435
|
}
|
|
19149
19436
|
function saveSupportIssue(deskId, issue) {
|
|
19150
19437
|
if (!isHelpDeskId(deskId) || !validBody(issue))
|
|
19151
19438
|
return;
|
|
19152
|
-
const
|
|
19153
|
-
if (!issue && !composition) {
|
|
19439
|
+
const draft = readSupportDraft(deskId);
|
|
19440
|
+
if (!issue && !draft?.composition) {
|
|
19154
19441
|
clearSupportIssue(deskId);
|
|
19155
19442
|
return;
|
|
19156
19443
|
}
|
|
19157
|
-
writeSupportDraft(deskId,
|
|
19444
|
+
writeSupportDraft(deskId, { ...draft, issue });
|
|
19158
19445
|
}
|
|
19159
|
-
|
|
19446
|
+
/**
|
|
19447
|
+
* Save a signed-out customer's request beside the tab's question, with the
|
|
19448
|
+
* question it was filled from when the support wizard filled it. A question
|
|
19449
|
+
* too long to keep is left out, so the request reads as the customer's own.
|
|
19450
|
+
*/
|
|
19451
|
+
function saveAnonymousFormDraft(deskId, composition, composedFrom) {
|
|
19160
19452
|
if (!isHelpDeskId(deskId) || !validSubject(composition.subject) || !validBody(composition.body))
|
|
19161
19453
|
return;
|
|
19162
19454
|
const issue = readSupportIssue(deskId) ?? '';
|
|
@@ -19164,7 +19456,7 @@ function saveAnonymousFormDraft(deskId, composition) {
|
|
|
19164
19456
|
clearSupportIssue(deskId);
|
|
19165
19457
|
return;
|
|
19166
19458
|
}
|
|
19167
|
-
writeSupportDraft(deskId, issue, { subject: composition.subject, body: composition.body });
|
|
19459
|
+
writeSupportDraft(deskId, { issue, composition: { subject: composition.subject, body: composition.body }, ...(validBody(composedFrom) && { composedFrom }) });
|
|
19168
19460
|
}
|
|
19169
19461
|
function removeFormDraft(deskId, requesterId) {
|
|
19170
19462
|
const key = storageKey(deskId, requesterId);
|
|
@@ -19182,7 +19474,7 @@ function readFormDraft(deskId, requesterId) {
|
|
|
19182
19474
|
const raw = sessionStorage.getItem(key);
|
|
19183
19475
|
if (!raw)
|
|
19184
19476
|
return null;
|
|
19185
|
-
if (raw.length >
|
|
19477
|
+
if (raw.length > MAX_DRAFT_ROW_CHARS)
|
|
19186
19478
|
throw new Error('Invalid draft');
|
|
19187
19479
|
const row = JSON.parse(raw);
|
|
19188
19480
|
const sent = row?.uncertain;
|
|
@@ -19231,9 +19523,47 @@ function unknownSubmissionOutcome(error) {
|
|
|
19231
19523
|
const status = error instanceof SparkVaultError ? error.statusCode : undefined;
|
|
19232
19524
|
return status === undefined || status < 400 || status === 408 || status >= 500;
|
|
19233
19525
|
}
|
|
19234
|
-
|
|
19235
|
-
|
|
19526
|
+
/**
|
|
19527
|
+
* A ticket's body: the details the customer wrote, or, when they wrote none,
|
|
19528
|
+
* the summary, since every ticket carries a message. The one place the two
|
|
19529
|
+
* fields become the body that is checked against the limit and sent.
|
|
19530
|
+
*/
|
|
19531
|
+
function ticketBody(summary, details) {
|
|
19532
|
+
return details.trim() ? details : summary;
|
|
19533
|
+
}
|
|
19534
|
+
/** The details field that gives a send's body back through `ticketBody`: empty when the body is its summary. */
|
|
19535
|
+
function detailsOf(submission) {
|
|
19536
|
+
return submission.body === submission.subject ? '' : submission.body;
|
|
19537
|
+
}
|
|
19538
|
+
/** A signed-in customer as the form names them: "Alex M." for Alex Morgan, a one-word name as it is, else their email. */
|
|
19539
|
+
function postingName(customer) {
|
|
19540
|
+
const words = (customer.display_name ?? '').trim().split(/\s+/).filter(Boolean);
|
|
19541
|
+
if (words.length === 0)
|
|
19542
|
+
return customer.email;
|
|
19543
|
+
if (words.length === 1)
|
|
19544
|
+
return words[0];
|
|
19545
|
+
return `${words[0]} ${Array.from(words[words.length - 1])[0]}.`;
|
|
19546
|
+
}
|
|
19547
|
+
function focusAtEnd(field, focusOptions) {
|
|
19548
|
+
field.focus(focusOptions);
|
|
19549
|
+
// An email field has no caret to place.
|
|
19550
|
+
if (field.type !== 'email')
|
|
19551
|
+
field.setSelectionRange(field.value.length, field.value.length);
|
|
19236
19552
|
}
|
|
19553
|
+
/** A button that reads as a link: an action beside text, never the step's own. */
|
|
19554
|
+
function textButton(text, action) {
|
|
19555
|
+
const button = document.createElement('button');
|
|
19556
|
+
button.type = 'button';
|
|
19557
|
+
button.className = 'svhd-text-button';
|
|
19558
|
+
button.textContent = text;
|
|
19559
|
+
button.addEventListener('click', action);
|
|
19560
|
+
return button;
|
|
19561
|
+
}
|
|
19562
|
+
const SIGN_IN_CANCELLED_COPY = 'Sign-in was cancelled. Your request is still here and hasn’t been sent.';
|
|
19563
|
+
const RECOVER_STATUS_COPY = 'Sign in again to recover your saved request.';
|
|
19564
|
+
const RECOVER_WEBSITE_COPY = 'Sign in to your website account again to recover your saved request.';
|
|
19565
|
+
const WEBSITE_SIGNED_OUT_COPY = 'You’re not signed in to the website. Sign in there, then choose Use website account again.';
|
|
19566
|
+
const RECOVER_NOTE_COPY = 'Sign in with the same email as before to recover your saved request.';
|
|
19237
19567
|
/** Host callback failures do not change a ticket's accepted or failed result. */
|
|
19238
19568
|
function notify$1(callback, value) {
|
|
19239
19569
|
try {
|
|
@@ -19261,6 +19591,22 @@ function edited(input, prefill) {
|
|
|
19261
19591
|
const text = input.value.trim();
|
|
19262
19592
|
return text !== '' && text !== prefill.trim();
|
|
19263
19593
|
}
|
|
19594
|
+
/**
|
|
19595
|
+
* The longest issue that fills the summary when contact starts. An issue this
|
|
19596
|
+
* short, on one line, already names the request; a longer one is the
|
|
19597
|
+
* customer's description, and cutting a summary from it would put words in
|
|
19598
|
+
* their mouth.
|
|
19599
|
+
*/
|
|
19600
|
+
const SUMMARY_PREFILL_MAX = 100;
|
|
19601
|
+
/** Whether trimmed text is one line of at most `max` characters. */
|
|
19602
|
+
function oneLine(text, max) {
|
|
19603
|
+
return text.length <= max && !/[\r\n]/.test(text);
|
|
19604
|
+
}
|
|
19605
|
+
/** What contact starts from: a short one-line issue as the summary; any other as the details, every character as written. */
|
|
19606
|
+
function composeIssue(issue) {
|
|
19607
|
+
const text = issue.trim();
|
|
19608
|
+
return oneLine(text, SUMMARY_PREFILL_MAX) ? { subject: text, body: '' } : { subject: '', body: issue };
|
|
19609
|
+
}
|
|
19264
19610
|
function companySignInUrl(value) {
|
|
19265
19611
|
try {
|
|
19266
19612
|
const url = new URL(value ?? '');
|
|
@@ -19280,24 +19626,54 @@ function companySignInUrl(value) {
|
|
|
19280
19626
|
* line carries the flow (a code sent, a send in progress or uncertain, a
|
|
19281
19627
|
* changed sign-in, a server error). Closing with unsent work asks first.
|
|
19282
19628
|
* A confirmed send replaces the form with its confirmation.
|
|
19629
|
+
*
|
|
19630
|
+
* The request is a summary and optional details, in a composer that also
|
|
19631
|
+
* takes files. A signed-out widget customer writes it as step 1 of 2; step 2
|
|
19632
|
+
* asks who the reply goes to and proves it in the native sign-in window.
|
|
19283
19633
|
*/
|
|
19284
19634
|
function mountHelpDeskForm(client, options) {
|
|
19285
19635
|
const target = resolveTarget(options.target);
|
|
19286
19636
|
injectHelpDeskFormStyles();
|
|
19637
|
+
const widget = options.widgetIdentity;
|
|
19287
19638
|
const shell = new InlineShell(target, {
|
|
19288
19639
|
containerClassName: 'svhd-container',
|
|
19289
19640
|
bodyClassName: 'svhd-body',
|
|
19290
|
-
|
|
19641
|
+
// The page that lays the support wizard out carries the attribution itself.
|
|
19642
|
+
footer: options.hostShowsAttribution ? null : createSecuredByFooter('svhd'),
|
|
19291
19643
|
});
|
|
19292
19644
|
const prefix = `svhd-${++formSequence}`;
|
|
19293
|
-
const heading = document.createElement('h2');
|
|
19294
|
-
heading.id = `${prefix}-heading`;
|
|
19295
|
-
heading.textContent = 'Contact support';
|
|
19296
19645
|
const form = document.createElement('form');
|
|
19297
19646
|
form.className = 'svhd-form';
|
|
19298
19647
|
form.noValidate = true;
|
|
19648
|
+
shell.body.append(form);
|
|
19649
|
+
/** A step's heading, which takes focus when the step is entered, under its "Step N of 2" label when it has one. */
|
|
19650
|
+
function stepHead(id, title, label) {
|
|
19651
|
+
const head = document.createElement('div');
|
|
19652
|
+
head.className = 'svhd-step-head';
|
|
19653
|
+
const stepLabel = label === null ? null : document.createElement('p');
|
|
19654
|
+
if (stepLabel) {
|
|
19655
|
+
stepLabel.className = 'svhd-step-label';
|
|
19656
|
+
stepLabel.textContent = label;
|
|
19657
|
+
head.append(stepLabel);
|
|
19658
|
+
}
|
|
19659
|
+
const stepHeading = document.createElement('h2');
|
|
19660
|
+
stepHeading.id = id;
|
|
19661
|
+
stepHeading.tabIndex = -1;
|
|
19662
|
+
stepHeading.textContent = title;
|
|
19663
|
+
head.append(stepHeading);
|
|
19664
|
+
return { head, heading: stepHeading, label: stepLabel };
|
|
19665
|
+
}
|
|
19666
|
+
function stepContainer(step) {
|
|
19667
|
+
const container = document.createElement('div');
|
|
19668
|
+
container.className = 'svhd-step';
|
|
19669
|
+
container.dataset.contactStep = step;
|
|
19670
|
+
return container;
|
|
19671
|
+
}
|
|
19672
|
+
const request = stepHead(`${prefix}-heading`, widget ? `Contact ${client.desk.organization_name || 'support'}` : 'Contact support', widget ? 'Step 1 of 2' : null);
|
|
19673
|
+
const heading = request.heading;
|
|
19299
19674
|
form.setAttribute('aria-labelledby', heading.id);
|
|
19300
|
-
|
|
19675
|
+
const details = stepContainer('details');
|
|
19676
|
+
details.append(request.head);
|
|
19301
19677
|
// A field's error is an alert only while it shows, so it is announced
|
|
19302
19678
|
// even when focus already sits on the field it names.
|
|
19303
19679
|
function setFieldError(entry, text) {
|
|
@@ -19329,10 +19705,11 @@ function mountHelpDeskForm(client, options) {
|
|
|
19329
19705
|
label.className = 'svhd-label';
|
|
19330
19706
|
label.htmlFor = `${prefix}-${name}`;
|
|
19331
19707
|
label.textContent = labelText;
|
|
19332
|
-
const input = textarea ?
|
|
19708
|
+
const input = textarea ? document.createElement('textarea') : document.createElement('input');
|
|
19333
19709
|
input.id = label.htmlFor;
|
|
19334
19710
|
input.name = name;
|
|
19335
|
-
|
|
19711
|
+
if (!textarea)
|
|
19712
|
+
input.className = 'svhd-input';
|
|
19336
19713
|
const error = document.createElement('p');
|
|
19337
19714
|
error.id = `${input.id}-error`;
|
|
19338
19715
|
error.className = 'svhd-field-error';
|
|
@@ -19342,19 +19719,23 @@ function mountHelpDeskForm(client, options) {
|
|
|
19342
19719
|
input.addEventListener('input', () => clearFieldError(created));
|
|
19343
19720
|
return created;
|
|
19344
19721
|
}
|
|
19345
|
-
const subject = field('
|
|
19346
|
-
const description = field('
|
|
19722
|
+
const subject = field('Summary', 'subject');
|
|
19723
|
+
const description = field('Additional details', 'description', true);
|
|
19347
19724
|
const email = field('Email address', 'email');
|
|
19348
19725
|
const code = field('Email code', 'code');
|
|
19349
19726
|
const name = field('Your name', 'display_name');
|
|
19350
19727
|
const firstName = field('First name', 'given_name');
|
|
19351
19728
|
const lastName = field('Last name (optional)', 'family_name');
|
|
19352
19729
|
const fields = [subject, description, email, code, name, firstName, lastName];
|
|
19353
|
-
//
|
|
19354
|
-
|
|
19730
|
+
// The support wizard's issue the form was last filled from, which either
|
|
19731
|
+
// field may hold; undefined for a form filled from the host's subject and body.
|
|
19732
|
+
let filledFrom = options.issue;
|
|
19733
|
+
/** What a field was filled with: text the customer did not write. */
|
|
19734
|
+
const filledWith = (key) => filledFrom ?? options[key] ?? '';
|
|
19735
|
+
const filled = filledFrom === undefined ? { subject: filledWith('subject'), body: filledWith('body') } : composeIssue(filledFrom);
|
|
19355
19736
|
subject.input.maxLength = MAX_SUBJECT_LEN;
|
|
19356
|
-
subject.input.value =
|
|
19357
|
-
description.input.value =
|
|
19737
|
+
subject.input.value = filled.subject;
|
|
19738
|
+
description.input.value = filled.body;
|
|
19358
19739
|
email.input.type = 'email';
|
|
19359
19740
|
email.input.autocomplete = 'email';
|
|
19360
19741
|
code.input.inputMode = 'numeric';
|
|
@@ -19366,7 +19747,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
19366
19747
|
lastName.input.maxLength = 100;
|
|
19367
19748
|
const codeHint = document.createElement('p');
|
|
19368
19749
|
codeHint.id = `${code.input.id}-hint`;
|
|
19369
|
-
codeHint.className = 'svhd-
|
|
19750
|
+
codeHint.className = 'svhd-hint';
|
|
19370
19751
|
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
19752
|
code.input.setAttribute('aria-describedby', codeHint.id);
|
|
19372
19753
|
const resend = document.createElement('button');
|
|
@@ -19383,23 +19764,93 @@ function mountHelpDeskForm(client, options) {
|
|
|
19383
19764
|
code.wrapper.append(codeHint, codeLinks);
|
|
19384
19765
|
code.wrapper.hidden = true;
|
|
19385
19766
|
name.wrapper.hidden = true;
|
|
19767
|
+
subject.input.required = true;
|
|
19768
|
+
// Enter in the summary moves on to the details it leads into, never sends a request half written.
|
|
19769
|
+
subject.input.addEventListener('keydown', (event) => {
|
|
19770
|
+
if (event.key !== 'Enter' || event.isComposing || event.keyCode === 229)
|
|
19771
|
+
return;
|
|
19772
|
+
event.preventDefault();
|
|
19773
|
+
focusAtEnd(description.input);
|
|
19774
|
+
});
|
|
19775
|
+
const attachments = client.desk.customer_can_attach_files && options.attachments !== false
|
|
19776
|
+
? createFormAttachments(client, prefix, async () => {
|
|
19777
|
+
const ownGeneration = generation;
|
|
19778
|
+
const token = await tokenFor(ownGeneration);
|
|
19779
|
+
if (!token || !alive(ownGeneration))
|
|
19780
|
+
return null;
|
|
19781
|
+
const id = await ensureDraft(ownGeneration, token);
|
|
19782
|
+
if (!alive(ownGeneration))
|
|
19783
|
+
return null;
|
|
19784
|
+
return { draftId: id, expectedSessionToken: token };
|
|
19785
|
+
}, () => {
|
|
19786
|
+
if (attachments?.hasEntries)
|
|
19787
|
+
restoredFiles = false;
|
|
19788
|
+
persistDraft();
|
|
19789
|
+
syncLeaveGuard();
|
|
19790
|
+
})
|
|
19791
|
+
: undefined;
|
|
19792
|
+
const composer = createComposer({
|
|
19793
|
+
form, summary: subject.input, textarea: description.input, attachments,
|
|
19794
|
+
deskRefusesFiles: !client.desk.customer_can_attach_files, onRequestStep: () => step === 'details',
|
|
19795
|
+
});
|
|
19796
|
+
description.wrapper.classList.add('svhd-composer-field');
|
|
19797
|
+
description.wrapper.insertBefore(composer.frame, description.error);
|
|
19798
|
+
description.wrapper.insertBefore(composer.notice, description.error);
|
|
19799
|
+
details.append(subject.wrapper, description.wrapper);
|
|
19386
19800
|
const auth = document.createElement('fieldset');
|
|
19387
19801
|
auth.className = 'svhd-auth';
|
|
19388
19802
|
auth.hidden = true;
|
|
19389
|
-
auth.append(
|
|
19803
|
+
auth.append(code.wrapper, name.wrapper);
|
|
19390
19804
|
const widgetAccount = document.createElement('div');
|
|
19391
19805
|
widgetAccount.className = 'svhd-widget-account';
|
|
19392
|
-
let widgetCustomer =
|
|
19393
|
-
|
|
19394
|
-
|
|
19395
|
-
|
|
19396
|
-
|
|
19397
|
-
|
|
19806
|
+
let widgetCustomer = widget?.customer ?? null;
|
|
19807
|
+
// A desk that signs in with SparkVault Identity asks only the email: its sign-in window asks a missing name.
|
|
19808
|
+
const asksName = client.desk.auth_mode !== 'identity';
|
|
19809
|
+
const reply = widget ? stepHead(`${prefix}-reply-heading`, asksName ? 'Who should we reply to?' : 'Sign in to send your request', 'Step 2 of 2') : null;
|
|
19810
|
+
const identity = widget ? stepContainer('identity') : null;
|
|
19811
|
+
const recap = document.createElement('div');
|
|
19812
|
+
recap.className = 'svhd-recap';
|
|
19813
|
+
const recapText = document.createElement('p');
|
|
19814
|
+
recapText.className = 'svhd-recap-text';
|
|
19815
|
+
const editRequest = textButton('Edit', () => { if (!pending && !destroyed)
|
|
19816
|
+
enterStep('details'); });
|
|
19817
|
+
editRequest.setAttribute('aria-label', 'Edit your request');
|
|
19818
|
+
const noteText = document.createTextNode('');
|
|
19819
|
+
const unsentNote = asksName
|
|
19820
|
+
? 'Your request hasn’t been sent yet. Tell us who to reply to, then we’ll send it.'
|
|
19821
|
+
: 'Your request hasn’t been sent yet. Sign in so we know who to reply to, then we’ll send it.';
|
|
19822
|
+
const live = createLiveRegion('svhd-live');
|
|
19823
|
+
if (identity && reply) {
|
|
19398
19824
|
form.classList.add('svhd-widget-form');
|
|
19399
|
-
|
|
19400
|
-
|
|
19401
|
-
|
|
19402
|
-
|
|
19825
|
+
details.append(widgetAccount);
|
|
19826
|
+
identity.hidden = true;
|
|
19827
|
+
const note = document.createElement('p');
|
|
19828
|
+
note.className = 'svhd-note';
|
|
19829
|
+
note.dataset.unsentNote = '';
|
|
19830
|
+
note.append(helpDeskIcon('info'), noteText);
|
|
19831
|
+
const recapRequest = document.createElement('div');
|
|
19832
|
+
recapRequest.className = 'svhd-recap-request';
|
|
19833
|
+
const recapLabel = document.createElement('span');
|
|
19834
|
+
recapLabel.className = 'svhd-recap-label';
|
|
19835
|
+
recapLabel.textContent = 'Your request';
|
|
19836
|
+
recapRequest.append(recapLabel, recapText);
|
|
19837
|
+
recap.append(recapRequest, editRequest);
|
|
19838
|
+
const helper = document.createElement('p');
|
|
19839
|
+
helper.id = `${email.input.id}-help`;
|
|
19840
|
+
helper.className = 'svhd-hint';
|
|
19841
|
+
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.';
|
|
19842
|
+
email.input.setAttribute('aria-describedby', helper.id);
|
|
19843
|
+
identity.append(reply.head, note, recap);
|
|
19844
|
+
if (asksName) {
|
|
19845
|
+
const names = document.createElement('div');
|
|
19846
|
+
names.className = 'svhd-widget-names';
|
|
19847
|
+
names.append(firstName.wrapper, lastName.wrapper);
|
|
19848
|
+
identity.append(names);
|
|
19849
|
+
}
|
|
19850
|
+
identity.append(email.wrapper, helper);
|
|
19851
|
+
}
|
|
19852
|
+
else
|
|
19853
|
+
auth.prepend(email.wrapper);
|
|
19403
19854
|
const status = document.createElement('p');
|
|
19404
19855
|
status.className = 'svhd-status';
|
|
19405
19856
|
status.setAttribute('role', 'status');
|
|
@@ -19419,13 +19870,15 @@ function mountHelpDeskForm(client, options) {
|
|
|
19419
19870
|
const send = document.createElement('button');
|
|
19420
19871
|
send.className = 'svhd-button';
|
|
19421
19872
|
send.type = 'submit';
|
|
19422
|
-
send.textContent = options.widgetIdentity ? widgetCustomer ? 'Send message' : 'Continue' : 'Send request';
|
|
19423
19873
|
const cancel = document.createElement('button');
|
|
19424
19874
|
cancel.className = 'svhd-button svhd-secondary';
|
|
19425
19875
|
cancel.type = 'button';
|
|
19426
19876
|
cancel.textContent = 'Cancel';
|
|
19427
19877
|
cancel.hidden = !options.onCancel;
|
|
19428
|
-
|
|
19878
|
+
const startNew = textButton('Start a new request', () => { if (!pending && !destroyed && recovery !== null)
|
|
19879
|
+
leaveRecovery(); });
|
|
19880
|
+
startNew.hidden = true;
|
|
19881
|
+
actions.append(send, startNew, cancel);
|
|
19429
19882
|
const confirm = document.createElement('div');
|
|
19430
19883
|
confirm.className = 'svhd-confirm';
|
|
19431
19884
|
confirm.setAttribute('role', 'group');
|
|
@@ -19451,8 +19904,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
19451
19904
|
discard.textContent = DISCARD_REQUEST_COPY.discard;
|
|
19452
19905
|
confirmActions.append(keepEditing, discard);
|
|
19453
19906
|
confirm.append(confirmTitle, confirmNote, confirmActions);
|
|
19454
|
-
form.append(
|
|
19907
|
+
form.append(details, ...(identity ? [identity] : []), auth, status, hosted, actions, confirm, live.element);
|
|
19455
19908
|
let state = 'editing';
|
|
19909
|
+
let step = 'details';
|
|
19910
|
+
let guardingLeave = false;
|
|
19456
19911
|
let destroyed = false;
|
|
19457
19912
|
let pending = false;
|
|
19458
19913
|
let completed = false;
|
|
@@ -19472,43 +19927,56 @@ function mountHelpDeskForm(client, options) {
|
|
|
19472
19927
|
let uncertainSubmission = null;
|
|
19473
19928
|
let sessionToken = null;
|
|
19474
19929
|
let sessionKnown = false;
|
|
19475
|
-
let attachments;
|
|
19476
19930
|
let submittedCode = null;
|
|
19477
19931
|
let resendAt = 0;
|
|
19478
19932
|
let resendTimer = null;
|
|
19479
19933
|
let confirmReturn = null;
|
|
19480
19934
|
let done = null;
|
|
19481
|
-
|
|
19935
|
+
// The verified customer whose saved request the form holds.
|
|
19936
|
+
let draftOwner = null;
|
|
19482
19937
|
let restoredDraft = false;
|
|
19483
19938
|
let restoredAnonymous = false;
|
|
19484
19939
|
let restoredFiles = false;
|
|
19485
|
-
|
|
19940
|
+
// How the customer whose saved request the form hides signed in, while it
|
|
19941
|
+
// waits for them to sign in again: that is the only way back to it.
|
|
19942
|
+
let recovery = null;
|
|
19943
|
+
// The website gave no account back when asked for the hidden request's customer.
|
|
19944
|
+
let websiteSignedOut = false;
|
|
19486
19945
|
function persistDraft() {
|
|
19487
19946
|
if (!options.persist || completed || destroyed)
|
|
19488
19947
|
return;
|
|
19489
|
-
if (!
|
|
19490
|
-
|
|
19491
|
-
|
|
19948
|
+
if (!draftOwner) {
|
|
19949
|
+
// The hidden request is a previous customer's; nothing is saved over it.
|
|
19950
|
+
if (recovery === null)
|
|
19951
|
+
saveAnonymousFormDraft(client.desk.desk_id, { subject: subject.input.value, body: description.input.value }, filledFrom);
|
|
19492
19952
|
return;
|
|
19493
19953
|
}
|
|
19494
|
-
saveFormDraft(client.desk.desk_id,
|
|
19954
|
+
saveFormDraft(client.desk.desk_id, draftOwner.requester_id, {
|
|
19495
19955
|
subject: subject.input.value, body: description.input.value, ticketId: draftId,
|
|
19496
19956
|
uncertain: uncertainSubmission, hadFiles: restoredFiles || attachments?.hasEntries === true,
|
|
19497
19957
|
});
|
|
19498
19958
|
}
|
|
19499
19959
|
function forgetDraft() {
|
|
19500
|
-
if (
|
|
19501
|
-
|
|
19502
|
-
|
|
19960
|
+
if (!options.persist)
|
|
19961
|
+
return;
|
|
19962
|
+
if (draftOwner)
|
|
19963
|
+
removeFormDraft(client.desk.desk_id, draftOwner.requester_id);
|
|
19964
|
+
else
|
|
19503
19965
|
clearSupportIssue(client.desk.desk_id);
|
|
19504
19966
|
}
|
|
19505
|
-
/**
|
|
19967
|
+
/**
|
|
19968
|
+
* The request is now this verified customer's, saved in this tab or not.
|
|
19969
|
+
* Only /me or the verified sign-in answer can select a saved requester's draft.
|
|
19970
|
+
*/
|
|
19506
19971
|
function restoreDraft(customer) {
|
|
19507
|
-
if (
|
|
19972
|
+
if (draftOwner?.requester_id === customer.requester_id)
|
|
19508
19973
|
return false;
|
|
19509
|
-
|
|
19510
|
-
|
|
19511
|
-
|
|
19974
|
+
draftOwner = customer;
|
|
19975
|
+
recovery = null;
|
|
19976
|
+
renderActions();
|
|
19977
|
+
if (!options.persist)
|
|
19978
|
+
return false;
|
|
19979
|
+
const saved = readFormDraft(client.desk.desk_id, customer.requester_id);
|
|
19512
19980
|
clearSupportIssue(client.desk.desk_id);
|
|
19513
19981
|
if (!saved) {
|
|
19514
19982
|
persistDraft();
|
|
@@ -19517,12 +19985,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
19517
19985
|
restoredDraft = true;
|
|
19518
19986
|
restoredFiles = saved.hadFiles && !saved.uncertain;
|
|
19519
19987
|
subject.input.value = saved.uncertain?.subject ?? saved.subject;
|
|
19520
|
-
description.input.value = saved.uncertain
|
|
19988
|
+
description.input.value = saved.uncertain ? detailsOf(saved.uncertain) : saved.body;
|
|
19521
19989
|
draftId = saved.ticketId;
|
|
19522
19990
|
uncertainSubmission = saved.uncertain;
|
|
19523
|
-
|
|
19524
|
-
description.input.readOnly = uncertainSubmission !== null;
|
|
19525
|
-
send.textContent = uncertainSubmission ? 'Check submission' : options.widgetIdentity ? widgetCustomer ? 'Send message' : 'Continue' : 'Send request';
|
|
19991
|
+
send.textContent = idleLabel();
|
|
19526
19992
|
setState(uncertainSubmission ? 'uncertain' : 'editing');
|
|
19527
19993
|
message(uncertainSubmission
|
|
19528
19994
|
? 'Your original request is preserved. Check submission before starting another request.'
|
|
@@ -19534,55 +20000,136 @@ function mountHelpDeskForm(client, options) {
|
|
|
19534
20000
|
// An account switch must not turn an uncertain send into a fresh request.
|
|
19535
20001
|
return pending || uncertainSubmission !== null || completed ? null : { subject: subject.input.value, body: description.input.value };
|
|
19536
20002
|
}
|
|
20003
|
+
/** What the send button reads while nothing is in flight. */
|
|
20004
|
+
function idleLabel() {
|
|
20005
|
+
if (uncertainSubmission)
|
|
20006
|
+
return 'Check submission';
|
|
20007
|
+
if (challenge)
|
|
20008
|
+
return 'Verify and send request';
|
|
20009
|
+
if (recovery === 'external_sso' && widget)
|
|
20010
|
+
return 'Use website account';
|
|
20011
|
+
if (recovery !== null && step === 'details')
|
|
20012
|
+
return 'Sign in to recover request';
|
|
20013
|
+
return widget && !widgetCustomer ? 'Continue' : 'Send request';
|
|
20014
|
+
}
|
|
20015
|
+
/**
|
|
20016
|
+
* The signed-in widget customer writes and sends in one step, posting as
|
|
20017
|
+
* the account named under it; a signed-out one writes the request as step
|
|
20018
|
+
* 1 of 2. Either way the form shows the request.
|
|
20019
|
+
*/
|
|
19537
20020
|
function renderWidgetIdentity() {
|
|
19538
|
-
if (!
|
|
20021
|
+
if (!widget)
|
|
19539
20022
|
return;
|
|
19540
|
-
|
|
19541
|
-
|
|
19542
|
-
auth.hidden =
|
|
19543
|
-
email.wrapper.hidden = false;
|
|
20023
|
+
if (request.label)
|
|
20024
|
+
request.label.hidden = widgetCustomer !== null;
|
|
20025
|
+
auth.hidden = true;
|
|
19544
20026
|
code.wrapper.hidden = true;
|
|
19545
20027
|
name.wrapper.hidden = true;
|
|
20028
|
+
widgetAccount.replaceChildren();
|
|
20029
|
+
const free = () => !pending && !destroyed && uncertainSubmission === null && !completed;
|
|
19546
20030
|
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);
|
|
20031
|
+
const postingAs = document.createElement('p');
|
|
20032
|
+
postingAs.className = 'svhd-posting-as';
|
|
20033
|
+
const shown = postingName(widgetCustomer);
|
|
20034
|
+
// Not you? opens the sign-in window in this click: nothing may await before it.
|
|
20035
|
+
postingAs.append(`Posting as ${shown}${shown.endsWith('.') ? '' : '.'} `, textButton('Not you?', () => {
|
|
20036
|
+
if (free())
|
|
20037
|
+
widget.switchAccount(safeComposition());
|
|
20038
|
+
}));
|
|
20039
|
+
widgetAccount.append(postingAs);
|
|
19564
20040
|
}
|
|
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);
|
|
20041
|
+
if (widget.useWebsiteAccount && widget.offerWebsiteAccount) {
|
|
20042
|
+
widgetAccount.append(textButton('Use website account', () => {
|
|
20043
|
+
if (free())
|
|
20044
|
+
widget.useWebsiteAccount?.(safeComposition());
|
|
20045
|
+
}));
|
|
19581
20046
|
}
|
|
20047
|
+
setStep('details');
|
|
20048
|
+
}
|
|
20049
|
+
/**
|
|
20050
|
+
* The actions and notes for where the request is. While the form hides a
|
|
20051
|
+
* previous customer's saved request (`recovery`), nothing shows of it, nor
|
|
20052
|
+
* says it was not sent, since it may be a send whose answer was lost: the
|
|
20053
|
+
* request step's status line says how to get it back and the reply-to
|
|
20054
|
+
* step's note alone speaks there, Start a new request leaves it, and the
|
|
20055
|
+
* account row is away. A website-account customer's request comes back only
|
|
20056
|
+
* through that account, so Use website account is its one way on when the
|
|
20057
|
+
* website bridges one, and there is none when it does not.
|
|
20058
|
+
*/
|
|
20059
|
+
function renderActions() {
|
|
20060
|
+
send.textContent = idleLabel();
|
|
20061
|
+
send.hidden = recovery === 'external_sso' && widget !== undefined && !widget.useWebsiteAccount;
|
|
20062
|
+
startNew.hidden = recovery === null;
|
|
20063
|
+
widgetAccount.hidden = recovery !== null || widgetAccount.childElementCount === 0;
|
|
20064
|
+
recap.hidden = recovery !== null;
|
|
20065
|
+
noteText.data = recovery === 'identity' || recovery === 'email_pin' ? RECOVER_NOTE_COPY : unsentNote;
|
|
20066
|
+
if (recovery !== null)
|
|
20067
|
+
message(step === 'identity' ? '' : recoveryStatus());
|
|
20068
|
+
}
|
|
20069
|
+
/** What the request step's status line asks for while a saved request is hidden. */
|
|
20070
|
+
function recoveryStatus() {
|
|
20071
|
+
if (recovery !== 'external_sso')
|
|
20072
|
+
return RECOVER_STATUS_COPY;
|
|
20073
|
+
return websiteSignedOut ? WEBSITE_SIGNED_OUT_COPY : RECOVER_WEBSITE_COPY;
|
|
20074
|
+
}
|
|
20075
|
+
/** Start a new request in place of the hidden one, which stays saved for its customer. */
|
|
20076
|
+
function leaveRecovery() {
|
|
20077
|
+
recovery = null;
|
|
20078
|
+
disable(false);
|
|
20079
|
+
message('');
|
|
20080
|
+
// A question asked while the saved request was hidden fills the new one.
|
|
20081
|
+
widget?.followIssue();
|
|
20082
|
+
if (step === 'identity')
|
|
20083
|
+
enterStep('details');
|
|
20084
|
+
else {
|
|
20085
|
+
renderActions();
|
|
20086
|
+
options.onScreenChange?.();
|
|
20087
|
+
controller.focusEntry();
|
|
20088
|
+
}
|
|
20089
|
+
}
|
|
20090
|
+
/** Show one step, the request or who the reply goes to, without moving focus. */
|
|
20091
|
+
function setStep(next) {
|
|
20092
|
+
const changed = next !== step;
|
|
20093
|
+
step = next;
|
|
20094
|
+
details.hidden = next !== 'details';
|
|
20095
|
+
if (identity)
|
|
20096
|
+
identity.hidden = next !== 'identity';
|
|
20097
|
+
if (next === 'identity')
|
|
20098
|
+
recapText.textContent = subject.input.value.trim();
|
|
20099
|
+
renderActions();
|
|
20100
|
+
syncLeaveGuard();
|
|
20101
|
+
if (changed)
|
|
20102
|
+
options.onScreenChange?.();
|
|
20103
|
+
}
|
|
20104
|
+
/** The customer moves between the steps: the new step's heading takes focus and its place is announced. */
|
|
20105
|
+
function enterStep(next) {
|
|
20106
|
+
setStep(next);
|
|
20107
|
+
live.announce(next === 'identity' ? 'Step 2 of 2' : 'Step 1 of 2');
|
|
20108
|
+
(next === 'identity' && reply ? reply.heading : heading).focus();
|
|
20109
|
+
}
|
|
20110
|
+
// An inline wizard, on any host page that gives a `target`, asks before that
|
|
20111
|
+
// page unloads while the request holds unsent work: leaving would lose it.
|
|
20112
|
+
// The floating panel never holds the page.
|
|
20113
|
+
// Chrome and Edge below 119, inside the SDK's browser floor, ask only when
|
|
20114
|
+
// returnValue is set; preventDefault is the standard signal.
|
|
20115
|
+
const onBeforeUnload = (event) => {
|
|
20116
|
+
event.preventDefault();
|
|
20117
|
+
event.returnValue = '';
|
|
20118
|
+
};
|
|
20119
|
+
function syncLeaveGuard() {
|
|
20120
|
+
const needed = options.pageLayout === true && !destroyed && holdsUnsentWork();
|
|
20121
|
+
if (needed === guardingLeave)
|
|
20122
|
+
return;
|
|
20123
|
+
guardingLeave = needed;
|
|
20124
|
+
if (needed)
|
|
20125
|
+
window.addEventListener('beforeunload', onBeforeUnload);
|
|
20126
|
+
else
|
|
20127
|
+
window.removeEventListener('beforeunload', onBeforeUnload);
|
|
19582
20128
|
}
|
|
19583
20129
|
function setState(next) {
|
|
19584
20130
|
state = next;
|
|
19585
20131
|
persistDraft();
|
|
20132
|
+
syncLeaveGuard();
|
|
19586
20133
|
notify$1(options.onStateChange, next);
|
|
19587
20134
|
}
|
|
19588
20135
|
function message(text, isError = false) {
|
|
@@ -19609,13 +20156,22 @@ function mountHelpDeskForm(client, options) {
|
|
|
19609
20156
|
resendTimer = setInterval(renderResend, 1000);
|
|
19610
20157
|
renderResend();
|
|
19611
20158
|
}
|
|
20159
|
+
/**
|
|
20160
|
+
* Disable every control while `disabled`. The request stays read-only, and
|
|
20161
|
+
* takes no files, while a send is unanswered, its exact text kept for the
|
|
20162
|
+
* check, and while it hides a saved request, which signing in brings back
|
|
20163
|
+
* in place of anything written.
|
|
20164
|
+
*/
|
|
19612
20165
|
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])
|
|
20166
|
+
for (const input of [subject.input, description.input, email.input, code.input, name.input, firstName.input, lastName.input, send, cancel, changeEmail, editRequest, startNew])
|
|
19614
20167
|
input.disabled = disabled;
|
|
20168
|
+
const held = uncertainSubmission !== null || recovery !== null;
|
|
20169
|
+
subject.input.readOnly = held;
|
|
20170
|
+
description.input.readOnly = held;
|
|
19615
20171
|
for (const button of widgetAccount.querySelectorAll('button'))
|
|
19616
20172
|
button.disabled = disabled || uncertainSubmission !== null || completed;
|
|
19617
20173
|
renderResend();
|
|
19618
|
-
attachments?.disablePicking(disabled);
|
|
20174
|
+
attachments?.disablePicking(disabled || recovery !== null);
|
|
19619
20175
|
attachments?.lock(completed || uncertainSubmission !== null);
|
|
19620
20176
|
}
|
|
19621
20177
|
function clearCode() {
|
|
@@ -19644,8 +20200,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
19644
20200
|
? 'We may already have received this request. Closing now loses the way to check it.'
|
|
19645
20201
|
: DISCARD_REQUEST_COPY.note;
|
|
19646
20202
|
}
|
|
19647
|
-
/** The field of the step in view: the code, name or email the sign-in asks for, else the
|
|
20203
|
+
/** 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
20204
|
function stepField() {
|
|
20205
|
+
if (step === 'identity')
|
|
20206
|
+
return (asksName ? firstName : email).input;
|
|
19649
20207
|
const asked = auth.hidden ? undefined : [code, name, email].find((entry) => !entry.wrapper.hidden);
|
|
19650
20208
|
return (asked ?? subject).input;
|
|
19651
20209
|
}
|
|
@@ -19686,25 +20244,27 @@ function mountHelpDeskForm(client, options) {
|
|
|
19686
20244
|
}
|
|
19687
20245
|
/**
|
|
19688
20246
|
* Whether closing now would lose something: a send under way or
|
|
19689
|
-
* unanswered, a code step,
|
|
19690
|
-
*
|
|
19691
|
-
* no work of the customer's.
|
|
20247
|
+
* unanswered, a code step, a request moved on to who the reply goes to, or
|
|
20248
|
+
* text and files of the customer's own. The silent company sign-in the
|
|
20249
|
+
* form runs as it opens (`authenticating`) is no work of the customer's.
|
|
19692
20250
|
*/
|
|
19693
20251
|
function holdsUnsentWork() {
|
|
19694
20252
|
if (completed)
|
|
19695
20253
|
return false;
|
|
19696
|
-
return (pending && state !== 'authenticating') || uncertainSubmission !== null || challenge !== null
|
|
19697
|
-
|| edited(subject.input,
|
|
20254
|
+
return (pending && state !== 'authenticating') || uncertainSubmission !== null || challenge !== null || step === 'identity'
|
|
20255
|
+
|| edited(subject.input, filledWith('subject')) || edited(description.input, filledWith('body'))
|
|
19698
20256
|
|| attachments?.hasEntries === true;
|
|
19699
20257
|
}
|
|
19700
|
-
/**
|
|
20258
|
+
/**
|
|
20259
|
+
* The field a request the ticket write would refuse is refused under, with
|
|
20260
|
+
* what it reads there; null for one it takes. The body is `ticketBody`'s,
|
|
20261
|
+
* so a request of a summary alone always has one.
|
|
20262
|
+
*/
|
|
19701
20263
|
function refusal(subjectText, body) {
|
|
19702
20264
|
if (!subjectText)
|
|
19703
|
-
return [subject, 'Add a
|
|
20265
|
+
return [subject, 'Add a summary.'];
|
|
19704
20266
|
if (subjectText.length > MAX_SUBJECT_LEN)
|
|
19705
|
-
return [subject, `Keep the
|
|
19706
|
-
if (!body.trim())
|
|
19707
|
-
return [description, 'Describe what you need help with.'];
|
|
20267
|
+
return [subject, `Keep the summary to ${MAX_SUBJECT_LEN} characters.`];
|
|
19708
20268
|
// The limit counts UTF-8 bytes, so a message of fewer characters can be over it;
|
|
19709
20269
|
// a message of more UTF-16 units than that is over it without being encoded.
|
|
19710
20270
|
if (body.length > MAX_BODY_BYTES || new TextEncoder().encode(body).length > MAX_BODY_BYTES)
|
|
@@ -19773,7 +20333,8 @@ function mountHelpDeskForm(client, options) {
|
|
|
19773
20333
|
attachments?.clear(completed || uncertainSubmission !== null);
|
|
19774
20334
|
attachments?.lock(false);
|
|
19775
20335
|
if (attachments)
|
|
19776
|
-
attachments.
|
|
20336
|
+
attachments.list.hidden = false;
|
|
20337
|
+
composer.clearNotice();
|
|
19777
20338
|
subject.input.value = '';
|
|
19778
20339
|
description.input.value = '';
|
|
19779
20340
|
email.input.value = '';
|
|
@@ -19794,13 +20355,13 @@ function mountHelpDeskForm(client, options) {
|
|
|
19794
20355
|
draftId = null;
|
|
19795
20356
|
draftPromise = null;
|
|
19796
20357
|
uncertainSubmission = null;
|
|
19797
|
-
|
|
20358
|
+
recovery = null;
|
|
20359
|
+
websiteSignedOut = false;
|
|
19798
20360
|
restoredAnonymous = false;
|
|
19799
|
-
subject.input.readOnly = false;
|
|
19800
|
-
description.input.readOnly = false;
|
|
19801
20361
|
completed = false;
|
|
19802
|
-
send.textContent = 'Send request';
|
|
19803
20362
|
message('');
|
|
20363
|
+
renderActions();
|
|
20364
|
+
syncLeaveGuard();
|
|
19804
20365
|
}
|
|
19805
20366
|
function sessionChanged(change) {
|
|
19806
20367
|
if (destroyed)
|
|
@@ -19833,18 +20394,26 @@ function mountHelpDeskForm(client, options) {
|
|
|
19833
20394
|
// during a pending proof must not leave the previous composer visible.
|
|
19834
20395
|
subject.input.value = '';
|
|
19835
20396
|
description.input.value = '';
|
|
20397
|
+
recapText.textContent = '';
|
|
19836
20398
|
name.input.value = '';
|
|
19837
20399
|
email.input.value = '';
|
|
19838
20400
|
clearCode();
|
|
19839
20401
|
if (attachments)
|
|
19840
|
-
attachments.
|
|
20402
|
+
attachments.list.hidden = true;
|
|
19841
20403
|
return;
|
|
19842
20404
|
}
|
|
19843
20405
|
// Preserve the old request before hiding it. The next verified requester
|
|
19844
20406
|
// selects only their own storage key, including after a 401 and sign-in.
|
|
19845
20407
|
persistDraft();
|
|
19846
|
-
|
|
19847
|
-
|
|
20408
|
+
// A signed-in customer's request leaves view, saved or not, and with it the
|
|
20409
|
+
// question it was filled from: nothing the form holds may write it back.
|
|
20410
|
+
const hidesCustomer = draftOwner !== null;
|
|
20411
|
+
if (hidesCustomer && filledFrom !== undefined)
|
|
20412
|
+
filledFrom = '';
|
|
20413
|
+
// A saved request stays hidden for its customer, through any further change.
|
|
20414
|
+
const hidden = draftOwner === null ? recovery
|
|
20415
|
+
: options.persist && readFormDraft(client.desk.desk_id, draftOwner.requester_id) !== null ? draftOwner.assurance : null;
|
|
20416
|
+
draftOwner = null;
|
|
19848
20417
|
restoredDraft = false;
|
|
19849
20418
|
restoredFiles = false;
|
|
19850
20419
|
generation += 1;
|
|
@@ -19853,15 +20422,19 @@ function mountHelpDeskForm(client, options) {
|
|
|
19853
20422
|
if (options.widgetIdentity)
|
|
19854
20423
|
widgetCustomer = null;
|
|
19855
20424
|
clearComposer();
|
|
19856
|
-
|
|
20425
|
+
recovery = hidden;
|
|
19857
20426
|
disable(false);
|
|
19858
20427
|
setState('editing');
|
|
19859
|
-
|
|
19860
|
-
|
|
19861
|
-
|
|
19862
|
-
|
|
19863
|
-
else
|
|
20428
|
+
// The question that led here was the previous customer's too.
|
|
20429
|
+
if (hidesCustomer)
|
|
20430
|
+
widget?.forgetIssue();
|
|
20431
|
+
if (recovery === null)
|
|
19864
20432
|
message('Your sign-in changed. Start a new request for the current account.');
|
|
20433
|
+
else
|
|
20434
|
+
renderActions();
|
|
20435
|
+
// The request and its actions changed under the pointer: a press already
|
|
20436
|
+
// under way must not act on what replaced them.
|
|
20437
|
+
options.onScreenChange?.();
|
|
19865
20438
|
}
|
|
19866
20439
|
const unsubscribe = client.subscribeSession(sessionChanged);
|
|
19867
20440
|
const alive = (ownGeneration) => !destroyed && generation === ownGeneration;
|
|
@@ -19902,19 +20475,6 @@ function mountHelpDeskForm(client, options) {
|
|
|
19902
20475
|
}
|
|
19903
20476
|
return draftPromise;
|
|
19904
20477
|
}
|
|
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
20478
|
function showEmail() {
|
|
19919
20479
|
auth.hidden = false;
|
|
19920
20480
|
email.wrapper.hidden = false;
|
|
@@ -19947,31 +20507,46 @@ function mountHelpDeskForm(client, options) {
|
|
|
19947
20507
|
// Sending (Enter in a field, a code's last digit) answers the discard
|
|
19948
20508
|
// question: the customer kept going.
|
|
19949
20509
|
closeConfirm(false);
|
|
20510
|
+
if (recovery === 'external_sso' && widget) {
|
|
20511
|
+
// Only the website account reaches a website-account customer's saved
|
|
20512
|
+
// request: a code or the secure window would sign in someone else.
|
|
20513
|
+
widget.useWebsiteAccount?.(null, true);
|
|
20514
|
+
return;
|
|
20515
|
+
}
|
|
19950
20516
|
for (const entry of fields)
|
|
19951
20517
|
clearFieldError(entry);
|
|
19952
20518
|
const recoveringSubmission = uncertainSubmission !== null;
|
|
19953
20519
|
const subjectText = uncertainSubmission?.subject ?? subject.input.value.trim();
|
|
19954
|
-
const
|
|
20520
|
+
const detailsText = uncertainSubmission ? detailsOf(uncertainSubmission) : description.input.value;
|
|
20521
|
+
const body = uncertainSubmission?.body ?? ticketBody(subjectText, detailsText);
|
|
19955
20522
|
if (uncertainSubmission) {
|
|
19956
20523
|
// Retrying recovers this exact request. A lost response must never make
|
|
19957
20524
|
// newly typed text appear to have been accepted as the earlier ticket.
|
|
19958
20525
|
subject.input.value = subjectText;
|
|
19959
|
-
description.input.value =
|
|
20526
|
+
description.input.value = detailsText;
|
|
19960
20527
|
}
|
|
19961
20528
|
const refused = refusal(subjectText, body);
|
|
19962
|
-
const recoveringAfterSignIn =
|
|
20529
|
+
const recoveringAfterSignIn = recovery !== null;
|
|
19963
20530
|
if (refused && !recoveringAfterSignIn) {
|
|
19964
20531
|
const [entry, text] = refused;
|
|
20532
|
+
if (step !== 'details')
|
|
20533
|
+
setStep('details');
|
|
19965
20534
|
setFieldError(entry, text);
|
|
19966
20535
|
entry.input.focus();
|
|
19967
20536
|
return;
|
|
19968
20537
|
}
|
|
19969
20538
|
let widgetSignIn;
|
|
19970
|
-
if (
|
|
19971
|
-
|
|
19972
|
-
|
|
20539
|
+
if (widget && !widgetCustomer) {
|
|
20540
|
+
// The request is written; who the reply goes to is the next step, and
|
|
20541
|
+
// nothing reaches the network before it.
|
|
20542
|
+
if (step === 'details') {
|
|
20543
|
+
enterStep('identity');
|
|
20544
|
+
return;
|
|
20545
|
+
}
|
|
20546
|
+
const givenName = asksName ? firstName.input.value.trim() : '';
|
|
20547
|
+
const familyName = asksName ? lastName.input.value.trim() : '';
|
|
19973
20548
|
const emailAddress = email.input.value.trim();
|
|
19974
|
-
const invalid = !givenName ? firstName : !email.input.validity.valid || !emailAddress ? email : null;
|
|
20549
|
+
const invalid = asksName && !givenName ? firstName : !email.input.validity.valid || !emailAddress ? email : null;
|
|
19975
20550
|
if (invalid) {
|
|
19976
20551
|
setFieldError(invalid, invalid === email ? 'Enter your email address.' : 'Enter your first name.');
|
|
19977
20552
|
invalid.input.focus();
|
|
@@ -19980,7 +20555,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
19980
20555
|
// Invoke in the original submit gesture, before any awaited token read:
|
|
19981
20556
|
// the Identity adapter can open its native window without a popup block.
|
|
19982
20557
|
try {
|
|
19983
|
-
widgetSignIn =
|
|
20558
|
+
widgetSignIn = widget.signIn(asksName ? { email: emailAddress, givenName, familyName } : { email: emailAddress });
|
|
19984
20559
|
}
|
|
19985
20560
|
catch (failure) {
|
|
19986
20561
|
const error = failure instanceof Error ? failure : new Error('Sign-in could not be opened.');
|
|
@@ -19997,12 +20572,13 @@ function mountHelpDeskForm(client, options) {
|
|
|
19997
20572
|
pending = true;
|
|
19998
20573
|
disable(true);
|
|
19999
20574
|
message('');
|
|
20575
|
+
syncLeaveGuard();
|
|
20000
20576
|
try {
|
|
20001
20577
|
if (widgetSignIn) {
|
|
20002
20578
|
authenticating = true;
|
|
20003
20579
|
authNotification = false;
|
|
20004
20580
|
setState('authenticating');
|
|
20005
|
-
message('
|
|
20581
|
+
message('Finish signing in in the secure window.');
|
|
20006
20582
|
}
|
|
20007
20583
|
let token = await tokenFor(ownGeneration);
|
|
20008
20584
|
if (!alive(ownGeneration))
|
|
@@ -20028,10 +20604,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
20028
20604
|
sessionKnown = true;
|
|
20029
20605
|
authenticating = false;
|
|
20030
20606
|
if (attachments)
|
|
20031
|
-
attachments.
|
|
20607
|
+
attachments.list.hidden = false;
|
|
20032
20608
|
subject.input.value = subjectText;
|
|
20033
|
-
description.input.value =
|
|
20034
|
-
if (
|
|
20609
|
+
description.input.value = detailsText;
|
|
20610
|
+
if (widget && session) {
|
|
20035
20611
|
widgetCustomer = session.customer;
|
|
20036
20612
|
renderWidgetIdentity();
|
|
20037
20613
|
message('');
|
|
@@ -20047,7 +20623,8 @@ function mountHelpDeskForm(client, options) {
|
|
|
20047
20623
|
if (!alive(ownGeneration))
|
|
20048
20624
|
return;
|
|
20049
20625
|
if (!token) {
|
|
20050
|
-
|
|
20626
|
+
// A website-account customer's saved request never comes back through an emailed code.
|
|
20627
|
+
if (recovery === 'external_sso' || (client.desk.auth_mode !== 'email_pin' && !(client.desk.auth_mode === 'external_sso' && client.desk.external_identity?.guest_email === true))) {
|
|
20051
20628
|
showHosted();
|
|
20052
20629
|
return;
|
|
20053
20630
|
}
|
|
@@ -20091,10 +20668,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
20091
20668
|
sessionKnown = true;
|
|
20092
20669
|
authenticating = false;
|
|
20093
20670
|
if (attachments)
|
|
20094
|
-
attachments.
|
|
20671
|
+
attachments.list.hidden = false;
|
|
20095
20672
|
dropChallenge();
|
|
20096
20673
|
subject.input.value = subjectText;
|
|
20097
|
-
description.input.value =
|
|
20674
|
+
description.input.value = detailsText;
|
|
20098
20675
|
notify$1(options.onSession, verified);
|
|
20099
20676
|
}
|
|
20100
20677
|
if (!token || !alive(ownGeneration))
|
|
@@ -20122,7 +20699,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20122
20699
|
email.wrapper.hidden = true;
|
|
20123
20700
|
code.wrapper.hidden = true;
|
|
20124
20701
|
name.wrapper.hidden = false;
|
|
20125
|
-
send.textContent =
|
|
20702
|
+
send.textContent = idleLabel();
|
|
20126
20703
|
setState('editing');
|
|
20127
20704
|
setFieldError(name, 'Add your name before sending your request.');
|
|
20128
20705
|
focusAfter = name.input;
|
|
@@ -20144,7 +20721,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20144
20721
|
setState('submitting');
|
|
20145
20722
|
if (!alive(ownGeneration))
|
|
20146
20723
|
return;
|
|
20147
|
-
send.textContent =
|
|
20724
|
+
send.textContent = 'Sending request';
|
|
20148
20725
|
if (!uncertainSubmission) {
|
|
20149
20726
|
const id = await ensureDraft(ownGeneration, token);
|
|
20150
20727
|
if (!alive(ownGeneration) || !(await tokenFor(ownGeneration)))
|
|
@@ -20187,14 +20764,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
20187
20764
|
const draftExpired = ticketAttempted && error instanceof SparkVaultError
|
|
20188
20765
|
&& (error.serviceCode === 'DRAFT_EXPIRED' || error.code === 'DRAFT_EXPIRED');
|
|
20189
20766
|
if (uncertainSubmission && !draftExpired && (!ticketAttempted || recoveringSubmission || unknownSubmissionOutcome(error))) {
|
|
20190
|
-
subject.input.readOnly = true;
|
|
20191
|
-
description.input.readOnly = true;
|
|
20192
20767
|
message('We could not confirm whether your request was sent. Check submission to recover it. Your original text is kept unchanged.', true);
|
|
20193
20768
|
}
|
|
20194
20769
|
else {
|
|
20195
20770
|
uncertainSubmission = null;
|
|
20196
|
-
subject.input.readOnly = false;
|
|
20197
|
-
description.input.readOnly = false;
|
|
20198
20771
|
if (draftExpired) {
|
|
20199
20772
|
draftId = null;
|
|
20200
20773
|
draftPromise = null;
|
|
@@ -20205,6 +20778,13 @@ function mountHelpDeskForm(client, options) {
|
|
|
20205
20778
|
setFieldError(code, HELP_DESK_CODE_STEP_COPY.codeRefused);
|
|
20206
20779
|
focusAfter = code.input;
|
|
20207
20780
|
}
|
|
20781
|
+
else if (widgetSignIn && error instanceof SparkVaultError && error.code === 'user_cancelled') {
|
|
20782
|
+
// The request stays on who the reply goes to, ready to sign in again;
|
|
20783
|
+
// a hidden saved request is not here to speak of, so its note alone stays.
|
|
20784
|
+
if (recovery === null)
|
|
20785
|
+
message(SIGN_IN_CANCELLED_COPY);
|
|
20786
|
+
focusAfter = send;
|
|
20787
|
+
}
|
|
20208
20788
|
else {
|
|
20209
20789
|
message(draftExpired ? 'Your saved draft expired. Your text is kept. Choose your files again before sending.' : error.message, true);
|
|
20210
20790
|
}
|
|
@@ -20212,7 +20792,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20212
20792
|
setState(uncertainSubmission ? 'uncertain' : challenge ? 'verifying' : 'editing');
|
|
20213
20793
|
if (!alive(ownGeneration))
|
|
20214
20794
|
return;
|
|
20215
|
-
send.textContent =
|
|
20795
|
+
send.textContent = idleLabel();
|
|
20216
20796
|
notify$1(options.onError, error);
|
|
20217
20797
|
}
|
|
20218
20798
|
finally {
|
|
@@ -20220,6 +20800,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20220
20800
|
authenticating = false;
|
|
20221
20801
|
pending = false;
|
|
20222
20802
|
disable(completed);
|
|
20803
|
+
syncLeaveGuard();
|
|
20223
20804
|
focusSettled();
|
|
20224
20805
|
}
|
|
20225
20806
|
}
|
|
@@ -20292,6 +20873,8 @@ function mountHelpDeskForm(client, options) {
|
|
|
20292
20873
|
generation += 1;
|
|
20293
20874
|
stopResendCountdown();
|
|
20294
20875
|
attachments?.destroy(completed || uncertainSubmission !== null);
|
|
20876
|
+
composer.destroy();
|
|
20877
|
+
live.destroy();
|
|
20295
20878
|
unsubscribe();
|
|
20296
20879
|
form.removeEventListener('submit', onSubmit);
|
|
20297
20880
|
shell.destroy();
|
|
@@ -20316,24 +20899,50 @@ function mountHelpDeskForm(client, options) {
|
|
|
20316
20899
|
subject.input.value = composition.subject;
|
|
20317
20900
|
description.input.value = composition.body;
|
|
20318
20901
|
persistDraft();
|
|
20902
|
+
syncLeaveGuard();
|
|
20319
20903
|
},
|
|
20320
|
-
refill(
|
|
20321
|
-
if (destroyed || restoredDraft || safeComposition() === null)
|
|
20904
|
+
refill(issue) {
|
|
20905
|
+
if (destroyed || restoredDraft || recovery !== null || safeComposition() === null)
|
|
20322
20906
|
return false;
|
|
20907
|
+
const own = { subject: edited(subject.input, filledWith('subject')), body: edited(description.input, filledWith('body')) };
|
|
20908
|
+
const text = issue.trim();
|
|
20909
|
+
const placed = !own.subject && !own.body ? composeIssue(issue) : { subject: oneLine(text, MAX_SUBJECT_LEN) ? text : '', body: issue };
|
|
20323
20910
|
for (const [entry, key] of [[subject, 'subject'], [description, 'body']]) {
|
|
20324
|
-
if (
|
|
20325
|
-
|
|
20326
|
-
|
|
20327
|
-
|
|
20328
|
-
prefill[key] = composition[key];
|
|
20911
|
+
if (own[key])
|
|
20912
|
+
continue;
|
|
20913
|
+
entry.input.value = placed[key];
|
|
20914
|
+
clearFieldError(entry);
|
|
20329
20915
|
}
|
|
20916
|
+
filledFrom = issue;
|
|
20917
|
+
if (step === 'identity')
|
|
20918
|
+
recapText.textContent = subject.input.value.trim();
|
|
20330
20919
|
persistDraft();
|
|
20920
|
+
syncLeaveGuard();
|
|
20331
20921
|
return true;
|
|
20332
20922
|
},
|
|
20333
20923
|
resumeAfterAccess() {
|
|
20334
20924
|
if (!destroyed && !pending && !completed && uncertainSubmission === null)
|
|
20335
20925
|
message('');
|
|
20336
20926
|
},
|
|
20927
|
+
returnToRequest() {
|
|
20928
|
+
if (destroyed || step !== 'identity')
|
|
20929
|
+
return false;
|
|
20930
|
+
// While the sign-in window is open the request stays where it is.
|
|
20931
|
+
if (!pending)
|
|
20932
|
+
enterStep('details');
|
|
20933
|
+
return true;
|
|
20934
|
+
},
|
|
20935
|
+
focusEntry(focusOptions) {
|
|
20936
|
+
if (destroyed || form.hidden)
|
|
20937
|
+
return false;
|
|
20938
|
+
const asked = stepField();
|
|
20939
|
+
const entry = asked === subject.input && subject.input.value.trim() ? description.input : asked;
|
|
20940
|
+
if (entry.disabled || entry.readOnly)
|
|
20941
|
+
(step === 'identity' && reply ? reply.heading : heading).focus(focusOptions);
|
|
20942
|
+
else
|
|
20943
|
+
focusAtEnd(entry, focusOptions);
|
|
20944
|
+
return true;
|
|
20945
|
+
},
|
|
20337
20946
|
requestDismiss() {
|
|
20338
20947
|
if (destroyed)
|
|
20339
20948
|
return;
|
|
@@ -20367,18 +20976,28 @@ function mountHelpDeskForm(client, options) {
|
|
|
20367
20976
|
keepEditing.addEventListener('click', () => closeConfirm(true));
|
|
20368
20977
|
discard.addEventListener('click', dismiss);
|
|
20369
20978
|
form.addEventListener('submit', onSubmit);
|
|
20370
|
-
form.addEventListener('input',
|
|
20371
|
-
form.addEventListener('change', () => {
|
|
20372
|
-
if (attachments?.hasEntries)
|
|
20373
|
-
restoredFiles = false;
|
|
20979
|
+
form.addEventListener('input', () => {
|
|
20374
20980
|
persistDraft();
|
|
20981
|
+
syncLeaveGuard();
|
|
20375
20982
|
});
|
|
20983
|
+
send.textContent = idleLabel();
|
|
20376
20984
|
renderWidgetIdentity();
|
|
20985
|
+
// A signed-out widget customer starts on step 1 of 2 with focus in the request.
|
|
20986
|
+
if (widget && !widgetCustomer)
|
|
20987
|
+
live.announce('Step 1 of 2');
|
|
20377
20988
|
if (options.widgetIdentity?.customer) {
|
|
20378
20989
|
restoreDraft(options.widgetIdentity.customer);
|
|
20379
20990
|
disable(false);
|
|
20380
20991
|
}
|
|
20381
|
-
else if (
|
|
20992
|
+
else if (widget?.recovering) {
|
|
20993
|
+
recovery = 'external_sso';
|
|
20994
|
+
websiteSignedOut = widget.recovering.websiteSignedOut;
|
|
20995
|
+
disable(false);
|
|
20996
|
+
renderActions();
|
|
20997
|
+
}
|
|
20998
|
+
else if (options.persist && filledFrom === undefined) {
|
|
20999
|
+
// The support wizard hands a composition it carries to restoreComposition;
|
|
21000
|
+
// a form of the host's own restores the one saved before a reload.
|
|
20382
21001
|
const saved = readAnonymousFormDraft(client.desk.desk_id);
|
|
20383
21002
|
if (saved) {
|
|
20384
21003
|
subject.input.value = saved.subject;
|
|
@@ -20386,6 +21005,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20386
21005
|
restoredAnonymous = true;
|
|
20387
21006
|
}
|
|
20388
21007
|
}
|
|
21008
|
+
syncLeaveGuard();
|
|
20389
21009
|
notify$1(options.onStateChange, state);
|
|
20390
21010
|
// Native company identity starts as the form opens, never from a Connect,
|
|
20391
21011
|
// Allow, verification or submit gesture. Guest email is explicit desk policy.
|
|
@@ -22613,58 +23233,6 @@ function createSupportLauncher(options, open) {
|
|
|
22613
23233
|
};
|
|
22614
23234
|
}
|
|
22615
23235
|
|
|
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
23236
|
/** The support journey's only skin. Customer content stays in the product register. */
|
|
22669
23237
|
function injectHelpDeskSupportStyles() {
|
|
22670
23238
|
if (document.getElementById('sparkvault-help-desk-support-styles'))
|
|
@@ -22790,11 +23358,10 @@ function injectHelpDeskSupportStyles() {
|
|
|
22790
23358
|
.svhs-unlock-form{margin:0}
|
|
22791
23359
|
.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
23360
|
.svhs-contact-target .svhd-body{display:flex;flex:1;flex-direction:column;min-height:0}
|
|
22793
|
-
.svhs-contact-target .svhd-container h2{
|
|
23361
|
+
.svhs-contact-target .svhd-container h2{font-size:22px;line-height:1.25;letter-spacing:-.6px;overflow-wrap:anywhere}
|
|
22794
23362
|
.svhs-contact-target .svhd-form{gap:16px}
|
|
22795
23363
|
.svhs-contact-target .svhd-label{font-size:13px;line-height:1.5}
|
|
22796
23364
|
.svhs-contact-target .svhd-input{font-size:16px;line-height:1.5}
|
|
22797
|
-
.svhs-contact-target .svhd-description{min-height:138px}
|
|
22798
23365
|
.svhs-contact-target .svhd-actions{gap:10px}
|
|
22799
23366
|
.svhs-contact-target .svhd-button:not(.svhd-secondary){background:var(--hd-accent,${DS.action});color:var(--hd-on-accent,${DS.white})}
|
|
22800
23367
|
.svhs-contact-target .svhd-button:not(.svhd-secondary):hover{background:var(--hd-accent-hover,${DS.actionHover})}
|
|
@@ -22802,18 +23369,19 @@ function injectHelpDeskSupportStyles() {
|
|
|
22802
23369
|
.svhs-contact-target .svhd-actions>.svhd-button:first-child{flex:1}
|
|
22803
23370
|
.svhs-contact-target .svhd-status{font-size:14px}
|
|
22804
23371
|
.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}}
|
|
23372
|
+
.svhs-contact-target .svhd-text-button{color:var(--hd-accent-ink,${DS.action})}
|
|
23373
|
+
.svhs-contact-target .svhd-text-button:disabled{color:${DS.slate500}}
|
|
23374
|
+
.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}
|
|
23375
|
+
@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}}
|
|
23376
|
+
.svhs-panel .svhd-composer-input:focus-visible{outline:none}
|
|
23377
|
+
.svhs-panel .svhd-composer button:focus-visible{outline-offset:-2px}
|
|
22813
23378
|
.svhs-contact-target .svhd-widget-names{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:12px}
|
|
22814
23379
|
.svhs-contact-target .svhd-widget-form{display:flex;flex:1;flex-direction:column;gap:16px}
|
|
22815
|
-
|
|
22816
|
-
.svhs-contact-target .svhd-widget-
|
|
23380
|
+
/* The request fills the panel: the details step, and in it the composer and its text, take the height the fields leave. */
|
|
23381
|
+
.svhs-contact-target .svhd-widget-form>[data-contact-step=details]{display:flex;flex:1;flex-direction:column;gap:16px}
|
|
23382
|
+
.svhs-contact-target .svhd-widget-form .svhd-composer-field{display:flex;flex:1;flex-direction:column;gap:6px;min-height:164px}
|
|
23383
|
+
.svhs-contact-target .svhd-widget-form .svhd-composer{flex:1}
|
|
23384
|
+
.svhs-contact-target .svhd-widget-form .svhd-composer-input{flex:1;min-height:120px}
|
|
22817
23385
|
.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
23386
|
.svhs-contact-target .svhd-widget-form>.svhd-actions>.svhd-secondary{display:none}
|
|
22819
23387
|
.svhs-contact-target .svhd-widget-form .svhd-actions>.svhd-button{font-size:14px}
|
|
@@ -22826,7 +23394,6 @@ function injectHelpDeskSupportStyles() {
|
|
|
22826
23394
|
.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
23395
|
.svhs-receipt-note{white-space:pre-wrap;overflow-wrap:anywhere}
|
|
22828
23396
|
.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
23397
|
.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
23398
|
.svhs-toast svg{width:18px;height:18px;flex:none;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round}
|
|
22832
23399
|
.svhs-overlay{position:fixed;inset:0;z-index:2147482900;display:flex;background:${DS.white};padding:0;overflow:hidden}
|
|
@@ -22861,7 +23428,6 @@ function injectHelpDeskSupportStyles() {
|
|
|
22861
23428
|
.svhs-feedback-actions{margin-top:30px}
|
|
22862
23429
|
.svhs-feedback-actions .svhs-primary,.svhs-feedback-actions .svhs-secondary{min-height:48px}
|
|
22863
23430
|
.svhs-contact-scroll{padding:0}
|
|
22864
|
-
.svhs-contact-target .svhd-description{min-height:160px}
|
|
22865
23431
|
.svhs-contact-target>.svhd-container{padding:24px}
|
|
22866
23432
|
.svhs-contact-target .svhd-widget-form>.svhd-actions{padding-bottom:env(safe-area-inset-bottom)}
|
|
22867
23433
|
.svhs-receipt-scroll{padding-top:58px}
|
|
@@ -23227,24 +23793,6 @@ function button(className, text, action) {
|
|
|
23227
23793
|
node.addEventListener('click', action);
|
|
23228
23794
|
return node;
|
|
23229
23795
|
}
|
|
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
23796
|
function httpUrl(value, base = window.location.href) {
|
|
23249
23797
|
if (!value)
|
|
23250
23798
|
return null;
|
|
@@ -23303,7 +23851,6 @@ class SupportView {
|
|
|
23303
23851
|
this.receiptCopy = element('p', 'svhs-copy');
|
|
23304
23852
|
this.receiptTicket = element('a', 'svhs-ticket-link');
|
|
23305
23853
|
this.receiptMessage = element('p', 'svhs-copy svhs-receipt-note');
|
|
23306
|
-
this.live = element('div', 'svhs-live');
|
|
23307
23854
|
this.identityNotice = element('div', 'svhs-identity-notice');
|
|
23308
23855
|
this.onMediaChange = () => this.syncPresentation();
|
|
23309
23856
|
this.onViewportChange = () => this.syncViewport();
|
|
@@ -23316,6 +23863,24 @@ class SupportView {
|
|
|
23316
23863
|
this.ticketGateSignature = '';
|
|
23317
23864
|
this.toastCleanups = new Set();
|
|
23318
23865
|
this.destroyed = false;
|
|
23866
|
+
// A multi-click that began before the screen changed (the panel opening, a
|
|
23867
|
+
// new stage or article, a new contact form, its step, or its request and
|
|
23868
|
+
// actions changing in place), wherever its first press
|
|
23869
|
+
// was, lands its later presses on a screen the customer has not seen yet:
|
|
23870
|
+
// they neither take focus there nor reach what is under them. A press in the
|
|
23871
|
+
// panel that starts anew, or a key press, acts as usual.
|
|
23872
|
+
this.screenChanges = 0;
|
|
23873
|
+
this.pressedAt = 0;
|
|
23874
|
+
this.onPress = (event) => {
|
|
23875
|
+
if (event.detail <= 1) {
|
|
23876
|
+
this.pressedAt = this.screenChanges;
|
|
23877
|
+
return;
|
|
23878
|
+
}
|
|
23879
|
+
if (this.screenChanges === this.pressedAt)
|
|
23880
|
+
return;
|
|
23881
|
+
event.preventDefault();
|
|
23882
|
+
event.stopPropagation();
|
|
23883
|
+
};
|
|
23319
23884
|
injectHelpDeskSupportStyles();
|
|
23320
23885
|
this.phoneHistory = !target && actions.onBrowserBack && actions.onBrowserForward ? new SupportPhoneHistory({
|
|
23321
23886
|
onBack: () => this.actions.onBrowserBack?.(),
|
|
@@ -23328,20 +23893,20 @@ class SupportView {
|
|
|
23328
23893
|
this.panel.hidden = true;
|
|
23329
23894
|
this.panel.setAttribute('aria-labelledby', `${this.prefix}-name`);
|
|
23330
23895
|
this.deskName.id = `${this.prefix}-name`;
|
|
23331
|
-
this.
|
|
23332
|
-
this.
|
|
23896
|
+
this.panel.addEventListener('mousedown', this.onPress, true);
|
|
23897
|
+
this.panel.addEventListener('click', this.onPress, true);
|
|
23333
23898
|
const toolbar = element('header', 'svhs-toolbar');
|
|
23334
23899
|
this.toolbar = toolbar;
|
|
23335
23900
|
this.back = button('svhs-back', 'Back', () => this.actions.onBack());
|
|
23336
|
-
this.back.prepend(
|
|
23901
|
+
this.back.prepend(helpDeskIcon('back'));
|
|
23337
23902
|
this.close = button('svhs-icon-button', '', () => this.actions.onClose());
|
|
23338
23903
|
this.close.setAttribute('aria-label', 'Close support');
|
|
23339
|
-
this.close.append(
|
|
23904
|
+
this.close.append(helpDeskIcon('close'));
|
|
23340
23905
|
this.external.setAttribute('aria-label', 'Open article in a new tab');
|
|
23341
23906
|
this.external.title = 'Open article in a new tab';
|
|
23342
23907
|
this.external.target = '_blank';
|
|
23343
23908
|
this.external.rel = 'noopener noreferrer';
|
|
23344
|
-
this.external.append(
|
|
23909
|
+
this.external.append(helpDeskIcon('external'));
|
|
23345
23910
|
const toolbarActions = element('div', 'svhs-toolbar-actions');
|
|
23346
23911
|
toolbarActions.append(this.external);
|
|
23347
23912
|
if (!target)
|
|
@@ -23415,9 +23980,9 @@ class SupportView {
|
|
|
23415
23980
|
const readerActions = element('div', 'svhs-reader-actions');
|
|
23416
23981
|
const yes = button('svhs-primary', 'Yes', () => { if (this.state?.article && !this.state.busy && !this.state.error)
|
|
23417
23982
|
this.actions.onAnswered(); });
|
|
23418
|
-
yes.prepend(
|
|
23983
|
+
yes.prepend(helpDeskIcon('thumbUp'));
|
|
23419
23984
|
const no = button('svhs-text-button', 'No, create a ticket', () => this.actions.onContact('article_not_answered'));
|
|
23420
|
-
no.prepend(
|
|
23985
|
+
no.prepend(helpDeskIcon('thumbDown'));
|
|
23421
23986
|
readerActions.append(yes, no);
|
|
23422
23987
|
this.articleFooter.append(element('span', 'svhs-article-question', 'Did this resolve your question?'), readerActions);
|
|
23423
23988
|
this.screens.get('article').append(this.articleFooter);
|
|
@@ -23459,7 +24024,7 @@ class SupportView {
|
|
|
23459
24024
|
contact.append(this.contactTarget);
|
|
23460
24025
|
const receipt = this.screen('receipt', 'Message sent');
|
|
23461
24026
|
receipt.classList.add('svhs-receipt-scroll');
|
|
23462
|
-
const receiptMark =
|
|
24027
|
+
const receiptMark = helpDeskIcon('check');
|
|
23463
24028
|
receiptMark.classList.add('svhs-receipt-mark');
|
|
23464
24029
|
receipt.prepend(receiptMark);
|
|
23465
24030
|
this.receiptTicket.target = '_blank';
|
|
@@ -23470,7 +24035,6 @@ class SupportView {
|
|
|
23470
24035
|
if (!target)
|
|
23471
24036
|
receiptFooter.append(button('svhs-secondary svhs-full', 'Done', () => this.actions.onClose()));
|
|
23472
24037
|
receiptFooter.append(this.restart);
|
|
23473
|
-
this.panel.append(this.live);
|
|
23474
24038
|
this.media = typeof window.matchMedia === 'function' ? window.matchMedia('(max-width:640px)') : null;
|
|
23475
24039
|
if (!target) {
|
|
23476
24040
|
this.media?.addEventListener('change', this.onMediaChange);
|
|
@@ -23559,24 +24123,34 @@ class SupportView {
|
|
|
23559
24123
|
if (!next.visible)
|
|
23560
24124
|
return;
|
|
23561
24125
|
if (!previous?.visible || previous.stage !== next.stage || previous.article?.id !== next.article?.id) {
|
|
24126
|
+
// A new screen, however it opened: from a press in the panel, the
|
|
24127
|
+
// launcher or a host link.
|
|
24128
|
+
this.screenChanges += 1;
|
|
23562
24129
|
this.restoreScroll(next);
|
|
23563
24130
|
this.focusCurrent();
|
|
23564
24131
|
}
|
|
23565
24132
|
}
|
|
24133
|
+
/** A new contact form, or one whose controls changed in place: a change of screen, as a new stage is. */
|
|
24134
|
+
contactScreenChanged() {
|
|
24135
|
+
this.screenChanges += 1;
|
|
24136
|
+
}
|
|
23566
24137
|
/** Programmatic close invalidates Forward restoration even after neutral Back. */
|
|
23567
24138
|
deactivateHistory() {
|
|
23568
24139
|
this.phoneHistory?.deactivate();
|
|
23569
24140
|
}
|
|
23570
|
-
/** Focus the shared form after its controller has mounted it. */
|
|
24141
|
+
/** Focus the shared form where the customer goes on, else its heading, after its controller has mounted it. */
|
|
23571
24142
|
focusContact() {
|
|
23572
24143
|
if (this.destroyed || !this.state?.visible || this.state.stage !== 'contact')
|
|
23573
24144
|
return;
|
|
23574
24145
|
const heading = this.contactTarget.querySelector('h1,h2,h3');
|
|
23575
24146
|
this.contactTitle.hidden = Boolean(heading);
|
|
23576
24147
|
this.contactTitle.parentElement.hidden = this.contactTitle.hidden && this.contactStatus.hidden && this.contactError.hidden && this.sourceArticle.hidden;
|
|
24148
|
+
const focusOptions = { preventScroll: !this.target };
|
|
24149
|
+
if (!this.contactTarget.hidden && this.actions.onFocusContact?.(focusOptions))
|
|
24150
|
+
return;
|
|
23577
24151
|
const target = heading ?? this.contactTarget;
|
|
23578
24152
|
target.tabIndex = -1;
|
|
23579
|
-
target.focus(
|
|
24153
|
+
target.focus(focusOptions);
|
|
23580
24154
|
}
|
|
23581
24155
|
/** Hydrate only the current reader's matching authorized publication assets. */
|
|
23582
24156
|
setArticleAsset(path, blobUrl) {
|
|
@@ -23627,7 +24201,7 @@ class SupportView {
|
|
|
23627
24201
|
const toast = element('div', 'svhs-toast');
|
|
23628
24202
|
toast.setAttribute('role', 'status');
|
|
23629
24203
|
toast.setAttribute('aria-atomic', 'true');
|
|
23630
|
-
toast.append(
|
|
24204
|
+
toast.append(helpDeskIcon('check'), document.createTextNode(message));
|
|
23631
24205
|
document.body.append(toast);
|
|
23632
24206
|
const arrange = () => {
|
|
23633
24207
|
let offset = 0;
|
|
@@ -23678,6 +24252,8 @@ class SupportView {
|
|
|
23678
24252
|
return;
|
|
23679
24253
|
this.destroyed = true;
|
|
23680
24254
|
this.phoneHistory?.destroy();
|
|
24255
|
+
this.panel.removeEventListener('mousedown', this.onPress, true);
|
|
24256
|
+
this.panel.removeEventListener('click', this.onPress, true);
|
|
23681
24257
|
document.removeEventListener('keydown', this.onKeydown);
|
|
23682
24258
|
this.media?.removeEventListener('change', this.onMediaChange);
|
|
23683
24259
|
window.visualViewport?.removeEventListener('resize', this.onViewportChange);
|
|
@@ -23748,9 +24324,9 @@ class SupportView {
|
|
|
23748
24324
|
copy.append(element('span', 'svhs-result-excerpt', result.summary));
|
|
23749
24325
|
if (result.category)
|
|
23750
24326
|
copy.append(element('span', 'svhs-result-category', result.category));
|
|
23751
|
-
const documentIcon =
|
|
24327
|
+
const documentIcon = helpDeskIcon('article');
|
|
23752
24328
|
documentIcon.classList.add('svhs-result-icon');
|
|
23753
|
-
const chevron =
|
|
24329
|
+
const chevron = helpDeskIcon('chevron');
|
|
23754
24330
|
chevron.classList.add('svhs-result-chevron');
|
|
23755
24331
|
open.append(documentIcon, copy, chevron);
|
|
23756
24332
|
item.append(open);
|
|
@@ -24122,8 +24698,6 @@ class SupportView {
|
|
|
24122
24698
|
}
|
|
24123
24699
|
}
|
|
24124
24700
|
|
|
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
24701
|
function notify(callback, value) {
|
|
24128
24702
|
try {
|
|
24129
24703
|
void Promise.resolve(callback?.(value)).catch(() => undefined);
|
|
@@ -24149,10 +24723,14 @@ function createHelpDeskSupport(config, options) {
|
|
|
24149
24723
|
// only while it is the current sequence, so whatever supersedes it frees it.
|
|
24150
24724
|
let contactOpening = null;
|
|
24151
24725
|
let pendingComposition = null;
|
|
24152
|
-
//
|
|
24153
|
-
//
|
|
24154
|
-
|
|
24155
|
-
//
|
|
24726
|
+
// A website-account customer's saved request the next form keeps hidden,
|
|
24727
|
+
// asked for through the website account, which may give no account back.
|
|
24728
|
+
let pendingRecovery = null;
|
|
24729
|
+
// The issue, as written, that the held composition (the mounted form, the one
|
|
24730
|
+
// a re-authorized form will take, or the one saved before a reload) was last
|
|
24731
|
+
// filled from: '' for one filled from none. A form taking that composition is
|
|
24732
|
+
// filled from it too, so the text it carries is the customer's own, or not,
|
|
24733
|
+
// as it was in the form it came from.
|
|
24156
24734
|
let composedFrom = '';
|
|
24157
24735
|
let nativeIdentity = null;
|
|
24158
24736
|
let switchedAccount = false;
|
|
@@ -24186,6 +24764,9 @@ function createHelpDeskSupport(config, options) {
|
|
|
24186
24764
|
onBack: () => {
|
|
24187
24765
|
if (destroyed || state.navigationLocked || state.identityPending)
|
|
24188
24766
|
return;
|
|
24767
|
+
// On who the reply goes to, Back returns to the request it is for.
|
|
24768
|
+
if (state.stage === 'contact' && !state.ticketAccessRequired && contact?.returnToRequest())
|
|
24769
|
+
return;
|
|
24189
24770
|
// A held form shows at once while contact still checks access behind it,
|
|
24190
24771
|
// so a contact opening in flight is cancelled even when nothing is busy.
|
|
24191
24772
|
if (state.busy || contactOpening === sequence)
|
|
@@ -24232,6 +24813,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24232
24813
|
onUnlock: (password) => { void unlock(password); },
|
|
24233
24814
|
onUnlockTicketAccess: (password) => { void unlockTicketAccess(password); },
|
|
24234
24815
|
onCancelIdentity: () => nativeIdentity?.abort(),
|
|
24816
|
+
onFocusContact: (focusOptions) => contact?.focusEntry(focusOptions) ?? false,
|
|
24235
24817
|
onBrowserBack: minimize,
|
|
24236
24818
|
onBrowserForward: () => update({ visible: true }),
|
|
24237
24819
|
}, options.target === undefined ? undefined : resolveTarget(options.target));
|
|
@@ -24311,7 +24893,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24311
24893
|
const saved = readFormDraft(active.desk.desk_id, customer.requester_id);
|
|
24312
24894
|
const composition = readAnonymousFormDraft(active.desk.desk_id);
|
|
24313
24895
|
if ((saved || composition) && !state.issue) {
|
|
24314
|
-
update({ issue: saved
|
|
24896
|
+
update({ issue: saved ? ticketBody(saved.subject, saved.body) : readSupportIssue(active.desk.desk_id) ?? '' });
|
|
24315
24897
|
await showContact('direct');
|
|
24316
24898
|
}
|
|
24317
24899
|
else if (!state.issue)
|
|
@@ -24390,6 +24972,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24390
24972
|
results = [];
|
|
24391
24973
|
requestedArticle = null;
|
|
24392
24974
|
pendingComposition = null;
|
|
24975
|
+
pendingRecovery = null;
|
|
24393
24976
|
feedbackSequence += 1;
|
|
24394
24977
|
sourceArticleId = undefined;
|
|
24395
24978
|
if (options.persist && client)
|
|
@@ -24550,18 +25133,28 @@ function createHelpDeskSupport(config, options) {
|
|
|
24550
25133
|
notify(options.onError, error);
|
|
24551
25134
|
}
|
|
24552
25135
|
}
|
|
24553
|
-
|
|
25136
|
+
/** Mount the contact form filled from `composedFrom`, then put a composition carried from an earlier form in it. */
|
|
25137
|
+
function mountContact(carried, customer) {
|
|
24554
25138
|
if (!client || destroyed)
|
|
24555
25139
|
return;
|
|
24556
25140
|
contactCustomer = customer;
|
|
25141
|
+
// A customer the website gave back sees their own saved request; none keeps it hidden.
|
|
25142
|
+
const recovering = customer ? null : pendingRecovery;
|
|
25143
|
+
pendingRecovery = null;
|
|
24557
25144
|
let activeAttempt = null;
|
|
25145
|
+
// A ticket carries the attempt the form opened under only while it is still
|
|
25146
|
+
// the journey's: recovery drops it with the previous customer's question.
|
|
25147
|
+
const formAttempt = attempt;
|
|
25148
|
+
const bridged = Boolean(options.getSessionToken || options.getIdentityAssertion || options.identityEndpoint);
|
|
24558
25149
|
contact = mountHelpDeskForm(client, {
|
|
24559
25150
|
target: view.contactTarget,
|
|
24560
|
-
// Filled
|
|
25151
|
+
// Filled from the issue its composition came from, so text the customer
|
|
24561
25152
|
// wrote in an earlier form and carried here stays their own.
|
|
24562
|
-
|
|
25153
|
+
issue: composedFrom,
|
|
24563
25154
|
attachments: options.attachments,
|
|
24564
25155
|
persist: options.persist,
|
|
25156
|
+
pageLayout: options.target !== undefined,
|
|
25157
|
+
hostShowsAttribution: options.hostShowsAttribution === true,
|
|
24565
25158
|
onSession: (session) => {
|
|
24566
25159
|
anonymous = false;
|
|
24567
25160
|
if (options.persist)
|
|
@@ -24572,9 +25165,14 @@ function createHelpDeskSupport(config, options) {
|
|
|
24572
25165
|
customer,
|
|
24573
25166
|
signIn: (input) => signIn(input).then((session) => { contactCustomer = session.customer; return session; }),
|
|
24574
25167
|
switchAccount: (safe) => { void switchAccount(safe); },
|
|
24575
|
-
...(
|
|
25168
|
+
...(bridged && { useWebsiteAccount: (safe, recover) => { void useWebsiteAccount(safe, recover); } }),
|
|
25169
|
+
offerWebsiteAccount: switchedAccount,
|
|
25170
|
+
forgetIssue,
|
|
25171
|
+
followIssue,
|
|
25172
|
+
...(recovering && { recovering }),
|
|
24576
25173
|
},
|
|
24577
|
-
|
|
25174
|
+
onScreenChange: () => view.contactScreenChanged(),
|
|
25175
|
+
assistanceContext: () => (attempt === formAttempt ? activeAttempt?.ticketContext() : undefined),
|
|
24578
25176
|
sourceArticleId: () => sourceArticleId,
|
|
24579
25177
|
onError: (error) => {
|
|
24580
25178
|
notify(options.onError, error);
|
|
@@ -24593,11 +25191,14 @@ function createHelpDeskSupport(config, options) {
|
|
|
24593
25191
|
onSuccess: (ticket) => receipt(ticket),
|
|
24594
25192
|
onStateChange: (next) => update({ navigationLocked: ['authenticating', 'submitting', 'uncertain'].includes(next) }),
|
|
24595
25193
|
});
|
|
24596
|
-
|
|
24597
|
-
|
|
25194
|
+
// A form in place of another can put a different control under the pointer.
|
|
25195
|
+
view.contactScreenChanged();
|
|
25196
|
+
if (carried)
|
|
25197
|
+
contact.restoreComposition(carried);
|
|
25198
|
+
// A carried composition was filled from the issue as it read then.
|
|
24598
25199
|
followIssue();
|
|
24599
25200
|
const activeForm = contact;
|
|
24600
|
-
void
|
|
25201
|
+
void formAttempt?.then((active) => {
|
|
24601
25202
|
// Keep the mutable callback small: an analytics response arriving late
|
|
24602
25203
|
// must not delay contact, authentication or ticket submission.
|
|
24603
25204
|
if (contact === activeForm && active)
|
|
@@ -24613,10 +25214,30 @@ function createHelpDeskSupport(config, options) {
|
|
|
24613
25214
|
*/
|
|
24614
25215
|
function followIssue() {
|
|
24615
25216
|
const issue = state.issue.trim();
|
|
24616
|
-
if (!contact || !issue || issue === composedFrom)
|
|
25217
|
+
if (!contact || !issue || issue === composedFrom.trim())
|
|
24617
25218
|
return;
|
|
24618
|
-
if (contact.refill(
|
|
24619
|
-
composedFrom = issue;
|
|
25219
|
+
if (contact.refill(state.issue))
|
|
25220
|
+
composedFrom = state.issue;
|
|
25221
|
+
}
|
|
25222
|
+
/**
|
|
25223
|
+
* Forget the question of a customer whose request just left the contact
|
|
25224
|
+
* form: it, and the answers and article it led to, are theirs, in view and
|
|
25225
|
+
* in this tab's storage. The visitor is unknown again until one signs in,
|
|
25226
|
+
* so the tab keeps their next question as any signed-out visitor's.
|
|
25227
|
+
*/
|
|
25228
|
+
function forgetIssue() {
|
|
25229
|
+
cancelArticleAssets?.();
|
|
25230
|
+
cancelArticleAssets = null;
|
|
25231
|
+
kbConfig = null;
|
|
25232
|
+
results = [];
|
|
25233
|
+
requestedArticle = null;
|
|
25234
|
+
attempt = null;
|
|
25235
|
+
sourceArticleId = undefined;
|
|
25236
|
+
composedFrom = '';
|
|
25237
|
+
anonymous = true;
|
|
25238
|
+
if (options.persist && client)
|
|
25239
|
+
clearSupportIssue(client.desk.desk_id);
|
|
25240
|
+
update({ issue: '', results: [], article: undefined, articleUrl: undefined, kbState: undefined, sourceArticle: undefined });
|
|
24620
25241
|
}
|
|
24621
25242
|
async function showContact(reason) {
|
|
24622
25243
|
if (destroyed || contactOpening === sequence)
|
|
@@ -24663,12 +25284,16 @@ function createHelpDeskSupport(config, options) {
|
|
|
24663
25284
|
return;
|
|
24664
25285
|
update({ busy: false, ticketAccessRequired: false, ticketAccessMode: undefined });
|
|
24665
25286
|
anonymous = !customer;
|
|
24666
|
-
|
|
25287
|
+
// A composition saved before a reload goes on from the issue it was filled
|
|
25288
|
+
// from; with none carried, the form fills itself from the issue as written.
|
|
25289
|
+
const saved = pendingComposition === null && options.persist ? readAnonymousFormDraft(active.desk.desk_id) : null;
|
|
25290
|
+
if (saved)
|
|
25291
|
+
composedFrom = saved.composedFrom;
|
|
25292
|
+
else if (pendingComposition === null)
|
|
25293
|
+
composedFrom = state.issue;
|
|
24667
25294
|
if (customer && options.persist)
|
|
24668
25295
|
clearSupportIssue(active.desk.desk_id);
|
|
24669
|
-
|
|
24670
|
-
composedFrom = state.issue.trim();
|
|
24671
|
-
mountContact(composition, customer);
|
|
25296
|
+
mountContact(pendingComposition ?? saved, customer);
|
|
24672
25297
|
pendingComposition = null;
|
|
24673
25298
|
}
|
|
24674
25299
|
catch (value) {
|
|
@@ -24732,6 +25357,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24732
25357
|
cancelArticleAssets?.();
|
|
24733
25358
|
cancelArticleAssets = null;
|
|
24734
25359
|
pendingComposition = composition ?? { subject: '', body: '' };
|
|
25360
|
+
pendingRecovery = null;
|
|
24735
25361
|
kb?.clearAccess();
|
|
24736
25362
|
kbConfig = null;
|
|
24737
25363
|
results = [];
|
|
@@ -24771,7 +25397,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24771
25397
|
await showContact('direct');
|
|
24772
25398
|
}
|
|
24773
25399
|
}
|
|
24774
|
-
async function useWebsiteAccount(composition) {
|
|
25400
|
+
async function useWebsiteAccount(composition, recovering = false) {
|
|
24775
25401
|
if (!client || destroyed || state.navigationLocked)
|
|
24776
25402
|
return;
|
|
24777
25403
|
const ownSequence = ++sequence;
|
|
@@ -24780,6 +25406,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24780
25406
|
cancelArticleAssets?.();
|
|
24781
25407
|
cancelArticleAssets = null;
|
|
24782
25408
|
pendingComposition = composition ?? { subject: '', body: '' };
|
|
25409
|
+
pendingRecovery = recovering ? { websiteSignedOut: true } : null;
|
|
24783
25410
|
kb?.clearAccess();
|
|
24784
25411
|
kbConfig = null;
|
|
24785
25412
|
results = [];
|
|
@@ -24800,6 +25427,9 @@ function createHelpDeskSupport(config, options) {
|
|
|
24800
25427
|
return;
|
|
24801
25428
|
const error = failure(value);
|
|
24802
25429
|
update({ busy: false, error: error.message });
|
|
25430
|
+
// The website was not reached, so it is not known to have no account.
|
|
25431
|
+
if (pendingRecovery)
|
|
25432
|
+
pendingRecovery = { websiteSignedOut: false };
|
|
24803
25433
|
if (client.hasTicketAccess) {
|
|
24804
25434
|
mountContact(composition ?? { subject: '', body: '' }, null);
|
|
24805
25435
|
pendingComposition = null;
|
|
@@ -29614,7 +30244,7 @@ class SparkVault {
|
|
|
29614
30244
|
}
|
|
29615
30245
|
/** Get the SDK version */
|
|
29616
30246
|
static get version() {
|
|
29617
|
-
return '16.
|
|
30247
|
+
return '16.5.0';
|
|
29618
30248
|
}
|
|
29619
30249
|
}
|
|
29620
30250
|
if (typeof window !== 'undefined') {
|