@sparkvault/sdk-js 16.4.0 → 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 +1148 -457
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +31 -4
- package/dist/index.mjs +1148 -457
- 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/products/identity/views/icons.d.ts +4 -4
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/dist/ui/ds-tokens.d.ts +3 -2
- 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
|
@@ -4392,15 +4392,108 @@ class LoadingView {
|
|
|
4392
4392
|
}
|
|
4393
4393
|
}
|
|
4394
4394
|
|
|
4395
|
+
/**
|
|
4396
|
+
* The sign-in providers' marks and the social networks' marks, each stated
|
|
4397
|
+
* once: the identity dialog (the browser SDK, which bundles this module) and
|
|
4398
|
+
* the console's Identity page draw the providers from here, and the marketing
|
|
4399
|
+
* site's footer and the help center's X post cards draw the networks, so no
|
|
4400
|
+
* two surfaces show one brand two ways.
|
|
4401
|
+
*
|
|
4402
|
+
* Every mark sits in one 24-unit box (BRAND_MARK_VIEWBOX), in one of two
|
|
4403
|
+
* forms, so each surface takes only the form it draws:
|
|
4404
|
+
* - BRAND_MARK_LAYERS: a sign-in provider's mark in its owner's colors, its
|
|
4405
|
+
* shapes painted in order, each `{ d, fill }`. A letter its owner draws
|
|
4406
|
+
* white (Facebook's "f", LinkedIn's "in") is a white shape over a solid
|
|
4407
|
+
* ground, never a cut-out, so a dark button cannot show through it. A
|
|
4408
|
+
* one-color logo (Apple, GitHub) fills with `currentColor`, taking the
|
|
4409
|
+
* color its surface sets for its icons.
|
|
4410
|
+
* - BRAND_MARK_SILHOUETTES: a network's mark as one shape with its letters
|
|
4411
|
+
* cut out, for a surface that paints it in one color.
|
|
4412
|
+
*
|
|
4413
|
+
* Facebook's, LinkedIn's, Instagram's and X's shapes are Simple Icons'
|
|
4414
|
+
* (CC0-1.0): Instagram's, Facebook's and X's from 16.38.0, LinkedIn's from
|
|
4415
|
+
* 13.21.0, the last release that ships it. Each silhouette is that path
|
|
4416
|
+
* exactly. LinkedIn's colored form is the silhouette's square and letters
|
|
4417
|
+
* apart; Facebook's is its whole circle under the cut-out "f", closed along
|
|
4418
|
+
* that circle.
|
|
4419
|
+
*
|
|
4420
|
+
* Browser-safe and import-free.
|
|
4421
|
+
*/
|
|
4422
|
+
|
|
4423
|
+
/** The box every mark is drawn in. */
|
|
4424
|
+
const BRAND_MARK_VIEWBOX = '0 0 24 24';
|
|
4425
|
+
|
|
4426
|
+
/**
|
|
4427
|
+
* Facebook's "f", from its left foot on the circle's edge up and around to its
|
|
4428
|
+
* right foot, (13.454, 23.956), also on the edge. The circle is centered on
|
|
4429
|
+
* (12, 12.044) with radius 12.
|
|
4430
|
+
*/
|
|
4431
|
+
const FACEBOOK_F_OUTLINE = 'M9.101 23.691v-7.98H6.627v-3.667h2.474v-1.58c0-4.085 1.848-5.978 5.858-5.978.401 0 .955.042 1.468.103a8.68 8.68 0 0 1 1.141.195v3.325a8.623 8.623 0 0 0-.653-.036 26.805 26.805 0 0 0-.733-.009c-.707 0-1.259.096-1.675.309a1.686 1.686 0 0 0-.679.622c-.258.42-.374.995-.374 1.752v1.297h3.919l-.386 2.103-.287 1.564h-3.246v8.245';
|
|
4432
|
+
|
|
4433
|
+
/** The short way along the circle's edge between the f's feet, closing the "f" itself. */
|
|
4434
|
+
const FACEBOOK_F_FOOT = 'A12 12 0 0 1 9.101 23.691Z';
|
|
4435
|
+
|
|
4436
|
+
/** Facebook's whole circle, the ground its white "f" stands on. */
|
|
4437
|
+
const FACEBOOK_DISC = 'M24 12.044c0-6.627-5.373-12-12-12s-12 5.373-12 12 5.373 12 12 12 12-5.373 12-12Z';
|
|
4438
|
+
|
|
4439
|
+
/** LinkedIn's "in": the n, the i's dot, the i's stem. */
|
|
4440
|
+
const LINKEDIN_IN = 'M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452z';
|
|
4441
|
+
|
|
4442
|
+
/** LinkedIn's rounded square, the ground its white "in" stands on. */
|
|
4443
|
+
const LINKEDIN_SQUARE = 'M22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z';
|
|
4444
|
+
|
|
4445
|
+
/** A white letter on its owner's ground. */
|
|
4446
|
+
const WHITE = '#FFFFFF';
|
|
4447
|
+
|
|
4448
|
+
function deepFreeze(value) {
|
|
4449
|
+
for (const child of Object.values(value)) {
|
|
4450
|
+
if (child && typeof child === 'object') deepFreeze(child);
|
|
4451
|
+
}
|
|
4452
|
+
return Object.freeze(value);
|
|
4453
|
+
}
|
|
4454
|
+
|
|
4455
|
+
/**
|
|
4456
|
+
* Each sign-in provider's mark in its owner's colors, by the identity
|
|
4457
|
+
* methods' icon name. Pure, so a bundle that draws no provider drops it.
|
|
4458
|
+
*/
|
|
4459
|
+
const BRAND_MARK_LAYERS = /* @__PURE__ */ deepFreeze({
|
|
4460
|
+
google: [
|
|
4461
|
+
{ d: 'M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z', fill: '#4285F4' },
|
|
4462
|
+
{ d: 'M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z', fill: '#34A853' },
|
|
4463
|
+
{ d: 'M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z', fill: '#FBBC05' },
|
|
4464
|
+
{ d: 'M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z', fill: '#EA4335' },
|
|
4465
|
+
],
|
|
4466
|
+
apple: [
|
|
4467
|
+
{ d: 'M18.71 19.5c-.83 1.24-1.71 2.45-3.05 2.47-1.34.03-1.77-.79-3.29-.79-1.53 0-2 .77-3.27.82-1.31.05-2.3-1.32-3.14-2.53C4.25 17 2.94 12.45 4.7 9.39c.87-1.52 2.43-2.48 4.12-2.51 1.28-.02 2.5.87 3.29.87.78 0 2.26-1.07 3.81-.91.65.03 2.47.26 3.64 1.98-.09.06-2.17 1.28-2.15 3.81.03 3.02 2.65 4.03 2.68 4.04-.03.07-.42 1.44-1.38 2.83M13 3.5c.73-.83 1.94-1.46 2.94-1.5.13 1.17-.34 2.35-1.04 3.19-.69.85-1.83 1.51-2.95 1.42-.15-1.15.41-2.35 1.05-3.11z', fill: 'currentColor' },
|
|
4468
|
+
],
|
|
4469
|
+
microsoft: [
|
|
4470
|
+
{ d: 'M1 1h10v10H1z', fill: '#F25022' },
|
|
4471
|
+
{ d: 'M1 13h10v10H1z', fill: '#00A4EF' },
|
|
4472
|
+
{ d: 'M13 1h10v10H13z', fill: '#7FBA00' },
|
|
4473
|
+
{ d: 'M13 13h10v10H13z', fill: '#FFB900' },
|
|
4474
|
+
],
|
|
4475
|
+
github: [
|
|
4476
|
+
{ d: 'M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z', fill: 'currentColor' },
|
|
4477
|
+
],
|
|
4478
|
+
facebook: [
|
|
4479
|
+
{ d: FACEBOOK_DISC, fill: '#0866FF' },
|
|
4480
|
+
{ d: FACEBOOK_F_OUTLINE + FACEBOOK_F_FOOT, fill: WHITE },
|
|
4481
|
+
],
|
|
4482
|
+
linkedin: [
|
|
4483
|
+
{ d: LINKEDIN_SQUARE, fill: '#0A66C2' },
|
|
4484
|
+
{ d: LINKEDIN_IN, fill: WHITE },
|
|
4485
|
+
],
|
|
4486
|
+
});
|
|
4487
|
+
|
|
4395
4488
|
/**
|
|
4396
4489
|
* SVG Icon Factory
|
|
4397
4490
|
*
|
|
4398
4491
|
* Bare outline glyphs per the SparkVault design system: stroke `currentColor`
|
|
4399
4492
|
* so the stylesheet drives color, no tinted container backgrounds, round
|
|
4400
|
-
* caps/joins. The sign-in providers' marks are
|
|
4401
|
-
*
|
|
4402
|
-
*
|
|
4403
|
-
* for security.
|
|
4493
|
+
* caps/joins. The sign-in providers' marks are their owners' filled logos,
|
|
4494
|
+
* drawn from `@sparkvault/app-sdk/brand-marks` in their owners' colors, a
|
|
4495
|
+
* one-color logo (Apple, GitHub) in `currentColor`. Uses proper DOM element
|
|
4496
|
+
* creation for security.
|
|
4404
4497
|
*/
|
|
4405
4498
|
function createSvgElement(viewBox, width = 16, height = 16) {
|
|
4406
4499
|
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
@@ -4550,17 +4643,12 @@ function methodIconGlyph(iconName) {
|
|
|
4550
4643
|
case 'link':
|
|
4551
4644
|
return createLinkIcon();
|
|
4552
4645
|
case 'google':
|
|
4553
|
-
return createGoogleIcon();
|
|
4554
4646
|
case 'apple':
|
|
4555
|
-
return createAppleIcon();
|
|
4556
4647
|
case 'microsoft':
|
|
4557
|
-
return createMicrosoftIcon();
|
|
4558
4648
|
case 'github':
|
|
4559
|
-
return createGithubIcon();
|
|
4560
4649
|
case 'facebook':
|
|
4561
|
-
return createFacebookIcon();
|
|
4562
4650
|
case 'linkedin':
|
|
4563
|
-
return
|
|
4651
|
+
return createBrandMarkIcon(iconName);
|
|
4564
4652
|
case 'building':
|
|
4565
4653
|
return createBuildingIcon();
|
|
4566
4654
|
case 'users':
|
|
@@ -4642,43 +4730,15 @@ function createLinkIcon() {
|
|
|
4642
4730
|
svg.appendChild(createPath('M11.67 9.17a3.75 3.75 0 00-5.66-.41l-2.25 2.25a3.75 3.75 0 005.3 5.3l1.28-1.28'));
|
|
4643
4731
|
return svg;
|
|
4644
4732
|
}
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
svg
|
|
4651
|
-
|
|
4652
|
-
}
|
|
4653
|
-
|
|
4654
|
-
const svg = createSvgElement('0 0 20 20', 20, 20);
|
|
4655
|
-
svg.setAttribute('fill', 'currentColor');
|
|
4656
|
-
svg.appendChild(createPath('M14.21 16.9c-.82.79-1.71.67-2.57.29-.91-.38-1.74-.4-2.7 0-1.2.51-1.83.37-2.55-.29C2.7 12.71 3.3 6.33 7.54 6.09c1.13.06 1.91.61 2.57.66.98-.2 1.92-.78 2.97-.7 1.26.1 2.21.6 2.83 1.5-2.6 1.56-1.98 4.99.4 5.94-.48 1.25-1.09 2.49-2.11 3.41h.01zM10.02 6.04c-.12-1.86 1.38-3.39 3.11-3.54.24 2.15-1.95 3.75-3.11 3.54z'));
|
|
4657
|
-
return svg;
|
|
4658
|
-
}
|
|
4659
|
-
function createMicrosoftIcon() {
|
|
4660
|
-
const svg = createSvgElement('0 0 20 20', 20, 20);
|
|
4661
|
-
svg.appendChild(createPath('M1 1h8.33v8.33H1z', { fill: '#F25022' }));
|
|
4662
|
-
svg.appendChild(createPath('M1 10.67h8.33V19H1z', { fill: '#00A4EF' }));
|
|
4663
|
-
svg.appendChild(createPath('M10.67 1H19v8.33h-8.33z', { fill: '#7FBA00' }));
|
|
4664
|
-
svg.appendChild(createPath('M10.67 10.67H19V19h-8.33z', { fill: '#FFB900' }));
|
|
4665
|
-
return svg;
|
|
4666
|
-
}
|
|
4667
|
-
function createGithubIcon() {
|
|
4668
|
-
const svg = createSvgElement('0 0 20 20', 20, 20);
|
|
4669
|
-
svg.setAttribute('fill', 'currentColor');
|
|
4670
|
-
svg.appendChild(createPath('M10 0C4.48 0 0 4.48 0 10c0 4.42 2.86 8.17 6.84 9.49.5.09.68-.22.68-.48 0-.24-.01-1.02-.01-1.86-2.51.46-3.16-.61-3.36-1.18-.11-.29-.6-1.18-1.02-1.41-.35-.19-.85-.65-.01-.66.79-.01 1.35.72 1.54 1.02.9 1.51 2.34 1.09 2.91.83.09-.65.35-1.09.64-1.34-2.22-.25-4.55-1.11-4.55-4.94 0-1.09.39-1.99 1.02-2.69-.1-.25-.45-1.27.1-2.65 0 0 .84-.27 2.75 1.02.8-.22 1.65-.33 2.5-.33s1.7.11 2.5.33c1.91-1.3 2.75-1.02 2.75-1.02.55 1.38.2 2.4.1 2.65.64.7 1.02 1.59 1.02 2.69 0 3.84-2.34 4.69-4.57 4.94.36.31.67.91.67 1.85 0 1.34-.01 2.41-.01 2.75 0 .27.18.58.69.48C17.14 18.16 20 14.42 20 10c0-5.52-4.48-10-10-10z'));
|
|
4671
|
-
return svg;
|
|
4672
|
-
}
|
|
4673
|
-
/** Facebook's mark and blue as Simple Icons (CC0-1.0) draws them, in its own 24-unit box. */
|
|
4674
|
-
function createFacebookIcon() {
|
|
4675
|
-
const svg = createSvgElement('0 0 24 24', 20, 20);
|
|
4676
|
-
svg.appendChild(createPath('M9.101 23.691v-7.98H6.627v-3.667h2.474v-1.58c0-4.085 1.848-5.978 5.858-5.978.401 0 .955.042 1.468.103a8.68 8.68 0 0 1 1.141.195v3.325a8.623 8.623 0 0 0-.653-.036 26.805 26.805 0 0 0-.733-.009c-.707 0-1.259.096-1.675.309a1.686 1.686 0 0 0-.679.622c-.258.42-.374.995-.374 1.752v1.297h3.919l-.386 2.103-.287 1.564h-3.246v8.245C19.396 23.238 24 18.179 24 12.044c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.628 3.874 10.35 9.101 11.647Z', { fill: '#0866FF' }));
|
|
4677
|
-
return svg;
|
|
4678
|
-
}
|
|
4679
|
-
function createLinkedinIcon() {
|
|
4680
|
-
const svg = createSvgElement('0 0 20 20', 20, 20);
|
|
4681
|
-
svg.appendChild(createPath('M17.04 17.04h-2.96v-4.64c0-1.11-.02-2.53-1.54-2.53-1.55 0-1.78 1.2-1.78 2.45v4.73H7.8V7.5h2.84v1.3h.04c.4-.75 1.36-1.54 2.81-1.54 3 0 3.56 1.98 3.56 4.55v5.24zM4.45 6.19c-.95 0-1.72-.77-1.72-1.72s.77-1.72 1.72-1.72 1.72.77 1.72 1.72-.77 1.72-1.72 1.72zm1.48 10.85H2.96V7.5h2.97v9.54zM18.52 0H1.47C.66 0 0 .65 0 1.44v17.12c0 .79.66 1.44 1.48 1.44h17.04c.82 0 1.48-.65 1.48-1.44V1.44c0-.79-.66-1.44-1.48-1.44z', { fill: '#0A66C2' }));
|
|
4733
|
+
/**
|
|
4734
|
+
* A sign-in provider's mark: its layers painted in order, each path carrying
|
|
4735
|
+
* its layer's own fill, which the svg's `fill="none"` never reaches.
|
|
4736
|
+
*/
|
|
4737
|
+
function createBrandMarkIcon(name) {
|
|
4738
|
+
const svg = createSvgElement(BRAND_MARK_VIEWBOX, 20, 20);
|
|
4739
|
+
for (const { d, fill } of BRAND_MARK_LAYERS[name]) {
|
|
4740
|
+
svg.appendChild(createPath(d, { fill }));
|
|
4741
|
+
}
|
|
4682
4742
|
return svg;
|
|
4683
4743
|
}
|
|
4684
4744
|
function createBuildingIcon() {
|
|
@@ -6394,8 +6454,9 @@ class ErrorView {
|
|
|
6394
6454
|
* neutrals. The published bundle cannot read those CSS files, so the values
|
|
6395
6455
|
* the widgets use are mirrored here, each naming the token it mirrors.
|
|
6396
6456
|
* tests/ds-tokens.test.ts holds every value to the design system's own, and
|
|
6397
|
-
* refuses a hex color anywhere else in the SDK's source (
|
|
6398
|
-
*
|
|
6457
|
+
* refuses a hex color anywhere else in the SDK's source and an rgba() whose
|
|
6458
|
+
* color is not the design system's. The sign-in providers' marks keep their
|
|
6459
|
+
* owners' colors, which live in @sparkvault/app-sdk/brand-marks.
|
|
6399
6460
|
*/
|
|
6400
6461
|
/** The design-system token each mirrored value is. */
|
|
6401
6462
|
/** The design system's values for {@link DS_TOKEN_SOURCES}. */
|
|
@@ -6876,6 +6937,50 @@ class OriginNotAllowedView {
|
|
|
6876
6937
|
}
|
|
6877
6938
|
}
|
|
6878
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
|
+
|
|
6879
6984
|
/**
|
|
6880
6985
|
* Identity View Renderer
|
|
6881
6986
|
*
|
|
@@ -6904,12 +7009,6 @@ function blockedSignInMessage(companyName) {
|
|
|
6904
7009
|
: 'Sign-in is temporarily unavailable. Please contact the site owner for assistance.';
|
|
6905
7010
|
}
|
|
6906
7011
|
const BLOCKED_ERROR_CODES = new Set(IDENTITY_BLOCKED_ERROR_CODES);
|
|
6907
|
-
/**
|
|
6908
|
-
* How long the live region waits after a view is in place before it takes
|
|
6909
|
-
* the view's words: long enough that assistive technology has seen the
|
|
6910
|
-
* view's change and hears the region's as a change of its own.
|
|
6911
|
-
*/
|
|
6912
|
-
const STATUS_ANNOUNCE_DELAY_MS = 100;
|
|
6913
7012
|
const SPARKLINK_CSP_BLOCKED_ERROR = {
|
|
6914
7013
|
message: [
|
|
6915
7014
|
'Connection blocked by security policy.',
|
|
@@ -6956,11 +7055,8 @@ class IdentityRenderer {
|
|
|
6956
7055
|
this.untouchedStep = null;
|
|
6957
7056
|
// The page's one live region: placed beside the flow content when the
|
|
6958
7057
|
// container opens, empty, and kept across views, so the words a view
|
|
6959
|
-
// announces (View.announcement) land in a region already in the page
|
|
6960
|
-
// assistive technology hears change. A region created with its words already
|
|
6961
|
-
// in it is often never announced.
|
|
7058
|
+
// announces (View.announcement) land in a region already in the page.
|
|
6962
7059
|
this.statusRegion = null;
|
|
6963
|
-
this.statusTimer = null;
|
|
6964
7060
|
this.container = container;
|
|
6965
7061
|
this.api = api;
|
|
6966
7062
|
this.options = options;
|
|
@@ -7217,11 +7313,7 @@ class IdentityRenderer {
|
|
|
7217
7313
|
window.removeEventListener('pageshow', this.pageRestoreHandler);
|
|
7218
7314
|
this.pageRestoreHandler = null;
|
|
7219
7315
|
}
|
|
7220
|
-
|
|
7221
|
-
clearTimeout(this.statusTimer);
|
|
7222
|
-
this.statusTimer = null;
|
|
7223
|
-
}
|
|
7224
|
-
this.statusRegion?.remove();
|
|
7316
|
+
this.statusRegion?.destroy();
|
|
7225
7317
|
this.statusRegion = null;
|
|
7226
7318
|
this.cleanupSparkLink();
|
|
7227
7319
|
this.destroyCurrentView();
|
|
@@ -7466,7 +7558,7 @@ class IdentityRenderer {
|
|
|
7466
7558
|
this.container.setMinimalChrome(minimalChromeViews.includes(this.viewState.view));
|
|
7467
7559
|
const view = this.createViewForState(this.viewState);
|
|
7468
7560
|
this.currentView = view;
|
|
7469
|
-
this.announce(view.announcement ?? '');
|
|
7561
|
+
this.statusRegion?.announce(view.announcement ?? '');
|
|
7470
7562
|
const rendered = view.render();
|
|
7471
7563
|
// Each step enters with a calm fade + rise (see .sv-step-enter). The brand
|
|
7472
7564
|
// lockup and footer live outside `body`, so only the flow content moves.
|
|
@@ -7502,37 +7594,11 @@ class IdentityRenderer {
|
|
|
7502
7594
|
/** Place the empty live region beside the flow content, once per container. */
|
|
7503
7595
|
placeStatusRegion() {
|
|
7504
7596
|
const body = this.container.getBody();
|
|
7505
|
-
if (!body || this.statusRegion?.isConnected)
|
|
7597
|
+
if (!body || this.statusRegion?.element.isConnected)
|
|
7506
7598
|
return;
|
|
7507
|
-
|
|
7508
|
-
|
|
7509
|
-
|
|
7510
|
-
region.setAttribute('aria-live', 'polite');
|
|
7511
|
-
region.setAttribute('aria-atomic', 'true');
|
|
7512
|
-
body.insertAdjacentElement('beforebegin', region);
|
|
7513
|
-
this.statusRegion = region;
|
|
7514
|
-
}
|
|
7515
|
-
/**
|
|
7516
|
-
* Put `words` in the live region, a moment after the view that says them
|
|
7517
|
-
* is in place, so they never land in the same change as the region or the
|
|
7518
|
-
* view that holds them; empty words clear it at once.
|
|
7519
|
-
*/
|
|
7520
|
-
announce(words) {
|
|
7521
|
-
if (this.statusTimer !== null) {
|
|
7522
|
-
clearTimeout(this.statusTimer);
|
|
7523
|
-
this.statusTimer = null;
|
|
7524
|
-
}
|
|
7525
|
-
const region = this.statusRegion;
|
|
7526
|
-
if (!region)
|
|
7527
|
-
return;
|
|
7528
|
-
if (!words) {
|
|
7529
|
-
region.textContent = '';
|
|
7530
|
-
return;
|
|
7531
|
-
}
|
|
7532
|
-
this.statusTimer = setTimeout(() => {
|
|
7533
|
-
this.statusTimer = null;
|
|
7534
|
-
region.textContent = words;
|
|
7535
|
-
}, STATUS_ANNOUNCE_DELAY_MS);
|
|
7599
|
+
this.statusRegion?.destroy();
|
|
7600
|
+
this.statusRegion = createLiveRegion('sv-sr-only');
|
|
7601
|
+
body.insertAdjacentElement('beforebegin', this.statusRegion.element);
|
|
7536
7602
|
}
|
|
7537
7603
|
destroyCurrentView() {
|
|
7538
7604
|
if (this.currentView?.destroy) {
|
|
@@ -18174,16 +18240,16 @@ function injectHelpDeskFormStyles() {
|
|
|
18174
18240
|
.svhd-modal .svhd-container{max-width:none;border:0;border-radius:0;padding-top:8px}
|
|
18175
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}
|
|
18176
18242
|
.svhd-container *{box-sizing:border-box}
|
|
18177
|
-
.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}
|
|
18178
18245
|
.svhd-form{display:grid;gap:16px}
|
|
18179
18246
|
.svhd-field{display:grid;gap:6px}
|
|
18180
18247
|
.svhd-label{font-weight:600}
|
|
18181
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}
|
|
18182
18249
|
.svhd-input:focus-visible,.svhd-button:focus-visible,.svhd-link:focus-visible{outline:3px solid ${DS.action};outline-offset:2px}
|
|
18183
18250
|
.svhd-input:disabled{background:${DS.slate50}}
|
|
18184
|
-
.svhd-description{min-height:140px;resize:vertical}
|
|
18185
18251
|
.svhd-auth{display:grid;gap:16px;border:0;padding:0;margin:0}
|
|
18186
|
-
.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}
|
|
18187
18253
|
.svhd-actions{display:flex;align-items:center;gap:12px;flex-wrap:wrap}
|
|
18188
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}
|
|
18189
18255
|
.svhd-button:hover{background:${DS.actionHover}}
|
|
@@ -18201,14 +18267,53 @@ function injectHelpDeskFormStyles() {
|
|
|
18201
18267
|
.svhd-done-title:focus{outline:none}
|
|
18202
18268
|
.svhd-confirmation-message{white-space:pre-wrap;overflow-wrap:anywhere}
|
|
18203
18269
|
.svhd-link{display:inline-flex;align-items:center;justify-self:start;min-height:44px;color:${DS.action};text-decoration:underline}
|
|
18204
|
-
.svhd-
|
|
18205
|
-
.svhd-
|
|
18206
|
-
.svhd-
|
|
18207
|
-
.svhd-
|
|
18208
|
-
.svhd-
|
|
18209
|
-
.svhd-
|
|
18210
|
-
.svhd-
|
|
18211
|
-
.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}
|
|
18212
18317
|
.svhd-footer{margin-top:20px;font-size:12px;color:${DS.slate500}}
|
|
18213
18318
|
`;
|
|
18214
18319
|
document.head.appendChild(style);
|
|
@@ -18412,23 +18517,6 @@ function lastExtension(name) {
|
|
|
18412
18517
|
return shownExtension(closeUpSpaces(name));
|
|
18413
18518
|
}
|
|
18414
18519
|
|
|
18415
|
-
/**
|
|
18416
|
-
* The longest prefix of `text` within `maxLength` UTF-16 units that splits no
|
|
18417
|
-
* character.
|
|
18418
|
-
*
|
|
18419
|
-
* @param {string} text
|
|
18420
|
-
* @param {number} maxLength
|
|
18421
|
-
* @returns {string}
|
|
18422
|
-
*/
|
|
18423
|
-
function truncateToLength(text, maxLength) {
|
|
18424
|
-
let truncated = '';
|
|
18425
|
-
for (const character of text) {
|
|
18426
|
-
if (truncated.length + character.length > maxLength) break;
|
|
18427
|
-
truncated += character;
|
|
18428
|
-
}
|
|
18429
|
-
return truncated;
|
|
18430
|
-
}
|
|
18431
|
-
|
|
18432
18520
|
/**
|
|
18433
18521
|
* What a help-desk attachment may be named and what its first bytes may not
|
|
18434
18522
|
* be: the one list of the files a ticket accepts, beside the one list of
|
|
@@ -18727,6 +18815,15 @@ const ACCEPTED_ATTACHMENTS_COPY = acceptedKindsCopy(ACCEPTED_ATTACHMENT_KINDS);
|
|
|
18727
18815
|
const CUSTOMER_ATTACHMENTS_HINT =
|
|
18728
18816
|
`Add screenshots, documents or recordings. Up to ${MAX_ATTACHMENTS_PER_MESSAGE} files, ${formatBytes(CUSTOMER_ATTACHMENT_MAX_BYTES)} each.`;
|
|
18729
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
|
+
|
|
18730
18827
|
/**
|
|
18731
18828
|
* A file input's `accept`: every extension a ticket accepts
|
|
18732
18829
|
* (ACCEPTED_ATTACHMENT_EXTENSIONS), each with its dot, so the system's file
|
|
@@ -18774,7 +18871,56 @@ function refusalCopy(refusal, maxBytes) {
|
|
|
18774
18871
|
return REFUSAL_COPY[refusal] ?? "This file can't be attached.";
|
|
18775
18872
|
}
|
|
18776
18873
|
|
|
18777
|
-
|
|
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
|
+
}
|
|
18778
18924
|
/** A failed mint's quota/size refusal remains a visible file error, never a silently omitted file. */
|
|
18779
18925
|
function problem(error) {
|
|
18780
18926
|
if (error instanceof SparkVaultError) {
|
|
@@ -18786,7 +18932,7 @@ function problem(error) {
|
|
|
18786
18932
|
}
|
|
18787
18933
|
if (error.statusCode === 402) {
|
|
18788
18934
|
const reason = error.details?.reason;
|
|
18789
|
-
return { copy: reason === CUSTOMER_UPLOAD_REFUSALS.UPLOADS_OFF ?
|
|
18935
|
+
return { copy: reason === CUSTOMER_UPLOAD_REFUSALS.UPLOADS_OFF ? NO_CUSTOMER_FILES_COPY
|
|
18790
18936
|
: reason === CUSTOMER_UPLOAD_REFUSALS.ALLOWANCE_REACHED ? 'You have reached this help desk’s upload allowance.'
|
|
18791
18937
|
: 'This help desk cannot store more files right now.', retryable: false };
|
|
18792
18938
|
}
|
|
@@ -18796,48 +18942,58 @@ function problem(error) {
|
|
|
18796
18942
|
}
|
|
18797
18943
|
return { copy: 'This file could not be uploaded. Try again or remove it.', retryable: true };
|
|
18798
18944
|
}
|
|
18799
|
-
/**
|
|
18800
|
-
|
|
18801
|
-
|
|
18802
|
-
|
|
18803
|
-
|
|
18804
|
-
|
|
18805
|
-
label.textContent = 'Attachments';
|
|
18806
|
-
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) {
|
|
18807
18951
|
const input = document.createElement('input');
|
|
18808
18952
|
input.type = 'file';
|
|
18809
18953
|
input.name = 'attachments';
|
|
18810
|
-
input.id = label.htmlFor;
|
|
18811
18954
|
input.multiple = true;
|
|
18812
18955
|
input.accept = ATTACHMENT_INPUT_ACCEPT;
|
|
18813
|
-
input.
|
|
18956
|
+
input.hidden = true;
|
|
18957
|
+
input.tabIndex = -1;
|
|
18814
18958
|
const hint = document.createElement('p');
|
|
18815
18959
|
hint.id = `${prefix}-attachment-hint`;
|
|
18816
|
-
hint.className = 'svhd-
|
|
18960
|
+
hint.className = 'svhd-composer-hint';
|
|
18817
18961
|
hint.textContent = CUSTOMER_ATTACHMENTS_HINT;
|
|
18818
|
-
|
|
18819
|
-
|
|
18820
|
-
|
|
18821
|
-
|
|
18822
|
-
|
|
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();
|
|
18823
18974
|
const list = document.createElement('ul');
|
|
18824
|
-
list.className = 'svhd-
|
|
18825
|
-
list.setAttribute('aria-label', '
|
|
18826
|
-
element.append(label, input, hint, notice, list);
|
|
18975
|
+
list.className = 'svhd-attachment-chips';
|
|
18976
|
+
list.setAttribute('aria-label', 'Attached files');
|
|
18827
18977
|
let entries = [];
|
|
18828
18978
|
let revision = 0;
|
|
18829
18979
|
let locked = false;
|
|
18830
18980
|
let pickingDisabled = false;
|
|
18831
18981
|
let destroyed = false;
|
|
18832
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
|
+
}
|
|
18833
18987
|
function controls(entry) {
|
|
18834
18988
|
entry.remove.disabled = locked;
|
|
18835
18989
|
entry.retry.disabled = locked || !!entry.operation;
|
|
18836
18990
|
}
|
|
18837
18991
|
function update(entry, state, text) {
|
|
18838
18992
|
entry.state = state;
|
|
18993
|
+
entry.row.dataset.state = state;
|
|
18839
18994
|
entry.status.textContent = text;
|
|
18840
18995
|
entry.status.classList.toggle('svhd-error', state === 'failed');
|
|
18996
|
+
entry.progress.hidden = state !== 'uploading';
|
|
18841
18997
|
entry.retry.hidden = !(entry.retryable && (state === 'failed' || state === 'received'));
|
|
18842
18998
|
entry.retry.textContent = state === 'received' ? 'Check upload' : 'Retry';
|
|
18843
18999
|
entry.retry.setAttribute('aria-label', `${state === 'received' ? 'Check upload' : 'Retry'} ${entry.file.name}`);
|
|
@@ -18877,7 +19033,7 @@ function createFormAttachments(client, prefix, context) {
|
|
|
18877
19033
|
if (!stillCurrent())
|
|
18878
19034
|
return;
|
|
18879
19035
|
if (!owner) {
|
|
18880
|
-
update(entry, 'queued', '
|
|
19036
|
+
update(entry, 'queued', 'Uploads when you send your request.');
|
|
18881
19037
|
return;
|
|
18882
19038
|
}
|
|
18883
19039
|
const options = {
|
|
@@ -18960,54 +19116,70 @@ function createFormAttachments(client, prefix, context) {
|
|
|
18960
19116
|
function remove(entry) {
|
|
18961
19117
|
if (locked)
|
|
18962
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);
|
|
18963
19122
|
entry.controller?.abort();
|
|
18964
19123
|
entries = entries.filter(candidate => candidate !== entry);
|
|
18965
19124
|
entry.row.remove();
|
|
18966
|
-
notice
|
|
19125
|
+
setNotice(notice, null);
|
|
18967
19126
|
void cancel(entry);
|
|
19127
|
+
onEntriesChange();
|
|
19128
|
+
if (refocus)
|
|
19129
|
+
(entries[Math.min(index, entries.length - 1)]?.remove ?? attach).focus();
|
|
18968
19130
|
}
|
|
18969
19131
|
function add(files) {
|
|
18970
19132
|
if (locked || pickingDisabled || destroyed)
|
|
18971
19133
|
return;
|
|
18972
19134
|
const incoming = Array.from(files);
|
|
19135
|
+
if (incoming.length === 0)
|
|
19136
|
+
return;
|
|
18973
19137
|
const room = Math.max(0, MAX_ATTACHMENTS_PER_MESSAGE - entries.length);
|
|
18974
|
-
notice
|
|
18975
|
-
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);
|
|
18976
19139
|
for (const file of incoming.slice(0, room)) {
|
|
18977
19140
|
const row = document.createElement('li');
|
|
18978
|
-
row.className = 'svhd-
|
|
19141
|
+
row.className = 'svhd-attachment-chip';
|
|
18979
19142
|
const filename = document.createElement('span');
|
|
18980
|
-
filename.className = 'svhd-
|
|
19143
|
+
filename.className = 'svhd-attachment-name';
|
|
18981
19144
|
filename.textContent = file.name;
|
|
19145
|
+
filename.title = file.name;
|
|
18982
19146
|
const status = document.createElement('span');
|
|
19147
|
+
status.className = 'svhd-attachment-status';
|
|
18983
19148
|
status.setAttribute('role', 'status');
|
|
18984
19149
|
status.setAttribute('aria-live', 'polite');
|
|
18985
|
-
const progress =
|
|
19150
|
+
const progress = document.createElement('progress');
|
|
19151
|
+
progress.className = 'svhd-attachment-progress';
|
|
18986
19152
|
progress.max = 100;
|
|
18987
19153
|
progress.value = 0;
|
|
19154
|
+
progress.hidden = true;
|
|
18988
19155
|
progress.setAttribute('aria-label', `Upload progress for ${file.name}`);
|
|
18989
19156
|
const removeButton = document.createElement('button');
|
|
18990
19157
|
removeButton.type = 'button';
|
|
18991
|
-
removeButton.className = 'svhd-
|
|
18992
|
-
removeButton.textContent = 'Remove';
|
|
19158
|
+
removeButton.className = 'svhd-attachment-remove';
|
|
18993
19159
|
removeButton.setAttribute('aria-label', `Remove ${file.name}`);
|
|
19160
|
+
removeButton.append(helpDeskIcon('close'));
|
|
18994
19161
|
const retry = document.createElement('button');
|
|
18995
19162
|
retry.type = 'button';
|
|
18996
|
-
retry.className = 'svhd-
|
|
19163
|
+
retry.className = 'svhd-attachment-retry';
|
|
18997
19164
|
retry.hidden = true;
|
|
18998
19165
|
const entry = { file, row, status, progress, remove: removeButton, retry, state: 'queued', retryable: false };
|
|
18999
19166
|
removeButton.onclick = () => remove(entry);
|
|
19000
19167
|
retry.onclick = () => { if (!locked && entry.retryable)
|
|
19001
19168
|
void run(entry); };
|
|
19002
|
-
row.append(filename,
|
|
19169
|
+
row.append(filename, removeButton, status, retry, progress);
|
|
19003
19170
|
list.append(row);
|
|
19004
19171
|
entries.push(entry);
|
|
19005
19172
|
void run(entry);
|
|
19006
19173
|
}
|
|
19174
|
+
if (room > 0)
|
|
19175
|
+
onEntriesChange();
|
|
19007
19176
|
}
|
|
19008
19177
|
const onChange = () => { if (input.files)
|
|
19009
19178
|
add(input.files); input.value = ''; };
|
|
19179
|
+
const onAttach = () => { if (!attach.disabled)
|
|
19180
|
+
input.click(); };
|
|
19010
19181
|
input.addEventListener('change', onChange);
|
|
19182
|
+
attach.addEventListener('click', onAttach);
|
|
19011
19183
|
function clear(preserveComplete = false) {
|
|
19012
19184
|
revision += 1;
|
|
19013
19185
|
const previous = entries;
|
|
@@ -19019,17 +19191,20 @@ function createFormAttachments(client, prefix, context) {
|
|
|
19019
19191
|
}
|
|
19020
19192
|
list.replaceChildren();
|
|
19021
19193
|
input.value = '';
|
|
19022
|
-
notice
|
|
19194
|
+
setNotice(notice, null);
|
|
19023
19195
|
}
|
|
19024
19196
|
return {
|
|
19025
|
-
|
|
19197
|
+
toolbar,
|
|
19198
|
+
list,
|
|
19199
|
+
notice,
|
|
19200
|
+
get accepting() { return !locked && !pickingDisabled && !destroyed; },
|
|
19026
19201
|
get attachmentIds() { return entries.filter(entry => entry.state === 'complete' && entry.attachmentId).map(entry => entry.attachmentId); },
|
|
19027
19202
|
get unresolved() { return entries.some(entry => entry.state !== 'complete'); },
|
|
19028
19203
|
get hasEntries() { return entries.length > 0; },
|
|
19029
|
-
|
|
19204
|
+
add,
|
|
19030
19205
|
async start() { await Promise.all(entries.map(entry => entry.operation ?? (entry.state === 'queued' ? run(entry) : Promise.resolve()))); },
|
|
19031
|
-
lock(value) { locked = value;
|
|
19032
|
-
disablePicking(value) { pickingDisabled = value;
|
|
19206
|
+
lock(value) { locked = value; syncPicking(); entries.forEach(controls); },
|
|
19207
|
+
disablePicking(value) { pickingDisabled = value; syncPicking(); },
|
|
19033
19208
|
renewSession(previousToken, nextToken) {
|
|
19034
19209
|
for (const entry of entries) {
|
|
19035
19210
|
if (entry.context?.expectedSessionToken === previousToken)
|
|
@@ -19037,11 +19212,175 @@ function createFormAttachments(client, prefix, context) {
|
|
|
19037
19212
|
}
|
|
19038
19213
|
},
|
|
19039
19214
|
clear,
|
|
19040
|
-
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
|
+
},
|
|
19041
19370
|
};
|
|
19042
19371
|
}
|
|
19043
19372
|
|
|
19044
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);
|
|
19045
19384
|
const storageKey = (deskId, requesterId) => isHelpDeskId(deskId) && isResourceIdOf('requester', requesterId) ? `sv-hd-draft:${deskId}:${requesterId}:new` : null;
|
|
19046
19385
|
const validBody = (value) => typeof value === 'string' && value.length <= MAX_BODY_BYTES && new TextEncoder().encode(value).length <= MAX_BODY_BYTES;
|
|
19047
19386
|
const validSubject = (value) => typeof value === 'string' && value.length <= MAX_SUBJECT_LEN;
|
|
@@ -19062,14 +19401,19 @@ function readSupportDraft(deskId) {
|
|
|
19062
19401
|
const raw = sessionStorage.getItem(`sv-hd-issue:${deskId}`);
|
|
19063
19402
|
if (!raw)
|
|
19064
19403
|
return null;
|
|
19065
|
-
if (raw.length >
|
|
19404
|
+
if (raw.length > MAX_ISSUE_ROW_CHARS)
|
|
19066
19405
|
throw new Error('Invalid issue');
|
|
19067
19406
|
const row = JSON.parse(raw);
|
|
19068
19407
|
if (row?.desk_id !== deskId || !validBody(row.issue) || !Number.isFinite(row.expires_at) ||
|
|
19069
19408
|
row.expires_at <= Date.now() || row.expires_at > Date.now() + TTL_MS ||
|
|
19070
19409
|
(row.composition !== undefined && (!validSubject(row.composition?.subject) || !validBody(row.composition?.body))))
|
|
19071
19410
|
throw new Error('Invalid issue');
|
|
19072
|
-
|
|
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 }) };
|
|
19073
19417
|
}
|
|
19074
19418
|
catch {
|
|
19075
19419
|
clearSupportIssue(deskId);
|
|
@@ -19077,25 +19421,34 @@ function readSupportDraft(deskId) {
|
|
|
19077
19421
|
}
|
|
19078
19422
|
}
|
|
19079
19423
|
function readSupportIssue(deskId) { return readSupportDraft(deskId)?.issue ?? null; }
|
|
19080
|
-
function readAnonymousFormDraft(deskId) {
|
|
19081
|
-
|
|
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) {
|
|
19082
19429
|
try {
|
|
19083
|
-
sessionStorage.setItem(`sv-hd-issue:${deskId}`, JSON.stringify({ desk_id: deskId, issue,
|
|
19084
|
-
...(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 }));
|
|
19085
19433
|
}
|
|
19086
19434
|
catch { /* The live wizard still keeps its composition in memory. */ }
|
|
19087
19435
|
}
|
|
19088
19436
|
function saveSupportIssue(deskId, issue) {
|
|
19089
19437
|
if (!isHelpDeskId(deskId) || !validBody(issue))
|
|
19090
19438
|
return;
|
|
19091
|
-
const
|
|
19092
|
-
if (!issue && !composition) {
|
|
19439
|
+
const draft = readSupportDraft(deskId);
|
|
19440
|
+
if (!issue && !draft?.composition) {
|
|
19093
19441
|
clearSupportIssue(deskId);
|
|
19094
19442
|
return;
|
|
19095
19443
|
}
|
|
19096
|
-
writeSupportDraft(deskId,
|
|
19444
|
+
writeSupportDraft(deskId, { ...draft, issue });
|
|
19097
19445
|
}
|
|
19098
|
-
|
|
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) {
|
|
19099
19452
|
if (!isHelpDeskId(deskId) || !validSubject(composition.subject) || !validBody(composition.body))
|
|
19100
19453
|
return;
|
|
19101
19454
|
const issue = readSupportIssue(deskId) ?? '';
|
|
@@ -19103,7 +19456,7 @@ function saveAnonymousFormDraft(deskId, composition) {
|
|
|
19103
19456
|
clearSupportIssue(deskId);
|
|
19104
19457
|
return;
|
|
19105
19458
|
}
|
|
19106
|
-
writeSupportDraft(deskId, issue, { subject: composition.subject, body: composition.body });
|
|
19459
|
+
writeSupportDraft(deskId, { issue, composition: { subject: composition.subject, body: composition.body }, ...(validBody(composedFrom) && { composedFrom }) });
|
|
19107
19460
|
}
|
|
19108
19461
|
function removeFormDraft(deskId, requesterId) {
|
|
19109
19462
|
const key = storageKey(deskId, requesterId);
|
|
@@ -19121,7 +19474,7 @@ function readFormDraft(deskId, requesterId) {
|
|
|
19121
19474
|
const raw = sessionStorage.getItem(key);
|
|
19122
19475
|
if (!raw)
|
|
19123
19476
|
return null;
|
|
19124
|
-
if (raw.length >
|
|
19477
|
+
if (raw.length > MAX_DRAFT_ROW_CHARS)
|
|
19125
19478
|
throw new Error('Invalid draft');
|
|
19126
19479
|
const row = JSON.parse(raw);
|
|
19127
19480
|
const sent = row?.uncertain;
|
|
@@ -19170,9 +19523,47 @@ function unknownSubmissionOutcome(error) {
|
|
|
19170
19523
|
const status = error instanceof SparkVaultError ? error.statusCode : undefined;
|
|
19171
19524
|
return status === undefined || status < 400 || status === 408 || status >= 500;
|
|
19172
19525
|
}
|
|
19173
|
-
|
|
19174
|
-
|
|
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);
|
|
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;
|
|
19175
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.';
|
|
19176
19567
|
/** Host callback failures do not change a ticket's accepted or failed result. */
|
|
19177
19568
|
function notify$1(callback, value) {
|
|
19178
19569
|
try {
|
|
@@ -19200,6 +19591,22 @@ function edited(input, prefill) {
|
|
|
19200
19591
|
const text = input.value.trim();
|
|
19201
19592
|
return text !== '' && text !== prefill.trim();
|
|
19202
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
|
+
}
|
|
19203
19610
|
function companySignInUrl(value) {
|
|
19204
19611
|
try {
|
|
19205
19612
|
const url = new URL(value ?? '');
|
|
@@ -19219,24 +19626,54 @@ function companySignInUrl(value) {
|
|
|
19219
19626
|
* line carries the flow (a code sent, a send in progress or uncertain, a
|
|
19220
19627
|
* changed sign-in, a server error). Closing with unsent work asks first.
|
|
19221
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.
|
|
19222
19633
|
*/
|
|
19223
19634
|
function mountHelpDeskForm(client, options) {
|
|
19224
19635
|
const target = resolveTarget(options.target);
|
|
19225
19636
|
injectHelpDeskFormStyles();
|
|
19637
|
+
const widget = options.widgetIdentity;
|
|
19226
19638
|
const shell = new InlineShell(target, {
|
|
19227
19639
|
containerClassName: 'svhd-container',
|
|
19228
19640
|
bodyClassName: 'svhd-body',
|
|
19229
|
-
|
|
19641
|
+
// The page that lays the support wizard out carries the attribution itself.
|
|
19642
|
+
footer: options.hostShowsAttribution ? null : createSecuredByFooter('svhd'),
|
|
19230
19643
|
});
|
|
19231
19644
|
const prefix = `svhd-${++formSequence}`;
|
|
19232
|
-
const heading = document.createElement('h2');
|
|
19233
|
-
heading.id = `${prefix}-heading`;
|
|
19234
|
-
heading.textContent = 'Contact support';
|
|
19235
19645
|
const form = document.createElement('form');
|
|
19236
19646
|
form.className = 'svhd-form';
|
|
19237
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;
|
|
19238
19674
|
form.setAttribute('aria-labelledby', heading.id);
|
|
19239
|
-
|
|
19675
|
+
const details = stepContainer('details');
|
|
19676
|
+
details.append(request.head);
|
|
19240
19677
|
// A field's error is an alert only while it shows, so it is announced
|
|
19241
19678
|
// even when focus already sits on the field it names.
|
|
19242
19679
|
function setFieldError(entry, text) {
|
|
@@ -19268,10 +19705,11 @@ function mountHelpDeskForm(client, options) {
|
|
|
19268
19705
|
label.className = 'svhd-label';
|
|
19269
19706
|
label.htmlFor = `${prefix}-${name}`;
|
|
19270
19707
|
label.textContent = labelText;
|
|
19271
|
-
const input = textarea ?
|
|
19708
|
+
const input = textarea ? document.createElement('textarea') : document.createElement('input');
|
|
19272
19709
|
input.id = label.htmlFor;
|
|
19273
19710
|
input.name = name;
|
|
19274
|
-
|
|
19711
|
+
if (!textarea)
|
|
19712
|
+
input.className = 'svhd-input';
|
|
19275
19713
|
const error = document.createElement('p');
|
|
19276
19714
|
error.id = `${input.id}-error`;
|
|
19277
19715
|
error.className = 'svhd-field-error';
|
|
@@ -19281,19 +19719,23 @@ function mountHelpDeskForm(client, options) {
|
|
|
19281
19719
|
input.addEventListener('input', () => clearFieldError(created));
|
|
19282
19720
|
return created;
|
|
19283
19721
|
}
|
|
19284
|
-
const subject = field('
|
|
19285
|
-
const description = field('
|
|
19722
|
+
const subject = field('Summary', 'subject');
|
|
19723
|
+
const description = field('Additional details', 'description', true);
|
|
19286
19724
|
const email = field('Email address', 'email');
|
|
19287
19725
|
const code = field('Email code', 'code');
|
|
19288
19726
|
const name = field('Your name', 'display_name');
|
|
19289
19727
|
const firstName = field('First name', 'given_name');
|
|
19290
19728
|
const lastName = field('Last name (optional)', 'family_name');
|
|
19291
19729
|
const fields = [subject, description, email, code, name, firstName, lastName];
|
|
19292
|
-
//
|
|
19293
|
-
|
|
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);
|
|
19294
19736
|
subject.input.maxLength = MAX_SUBJECT_LEN;
|
|
19295
|
-
subject.input.value =
|
|
19296
|
-
description.input.value =
|
|
19737
|
+
subject.input.value = filled.subject;
|
|
19738
|
+
description.input.value = filled.body;
|
|
19297
19739
|
email.input.type = 'email';
|
|
19298
19740
|
email.input.autocomplete = 'email';
|
|
19299
19741
|
code.input.inputMode = 'numeric';
|
|
@@ -19305,7 +19747,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
19305
19747
|
lastName.input.maxLength = 100;
|
|
19306
19748
|
const codeHint = document.createElement('p');
|
|
19307
19749
|
codeHint.id = `${code.input.id}-hint`;
|
|
19308
|
-
codeHint.className = 'svhd-
|
|
19750
|
+
codeHint.className = 'svhd-hint';
|
|
19309
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)}.`;
|
|
19310
19752
|
code.input.setAttribute('aria-describedby', codeHint.id);
|
|
19311
19753
|
const resend = document.createElement('button');
|
|
@@ -19322,23 +19764,93 @@ function mountHelpDeskForm(client, options) {
|
|
|
19322
19764
|
code.wrapper.append(codeHint, codeLinks);
|
|
19323
19765
|
code.wrapper.hidden = true;
|
|
19324
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);
|
|
19325
19800
|
const auth = document.createElement('fieldset');
|
|
19326
19801
|
auth.className = 'svhd-auth';
|
|
19327
19802
|
auth.hidden = true;
|
|
19328
|
-
auth.append(
|
|
19803
|
+
auth.append(code.wrapper, name.wrapper);
|
|
19329
19804
|
const widgetAccount = document.createElement('div');
|
|
19330
19805
|
widgetAccount.className = 'svhd-widget-account';
|
|
19331
|
-
let widgetCustomer =
|
|
19332
|
-
|
|
19333
|
-
|
|
19334
|
-
|
|
19335
|
-
|
|
19336
|
-
|
|
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) {
|
|
19337
19824
|
form.classList.add('svhd-widget-form');
|
|
19338
|
-
|
|
19339
|
-
|
|
19340
|
-
|
|
19341
|
-
|
|
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);
|
|
19342
19854
|
const status = document.createElement('p');
|
|
19343
19855
|
status.className = 'svhd-status';
|
|
19344
19856
|
status.setAttribute('role', 'status');
|
|
@@ -19358,13 +19870,15 @@ function mountHelpDeskForm(client, options) {
|
|
|
19358
19870
|
const send = document.createElement('button');
|
|
19359
19871
|
send.className = 'svhd-button';
|
|
19360
19872
|
send.type = 'submit';
|
|
19361
|
-
send.textContent = options.widgetIdentity ? widgetCustomer ? 'Send message' : 'Continue' : 'Send request';
|
|
19362
19873
|
const cancel = document.createElement('button');
|
|
19363
19874
|
cancel.className = 'svhd-button svhd-secondary';
|
|
19364
19875
|
cancel.type = 'button';
|
|
19365
19876
|
cancel.textContent = 'Cancel';
|
|
19366
19877
|
cancel.hidden = !options.onCancel;
|
|
19367
|
-
|
|
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);
|
|
19368
19882
|
const confirm = document.createElement('div');
|
|
19369
19883
|
confirm.className = 'svhd-confirm';
|
|
19370
19884
|
confirm.setAttribute('role', 'group');
|
|
@@ -19390,8 +19904,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
19390
19904
|
discard.textContent = DISCARD_REQUEST_COPY.discard;
|
|
19391
19905
|
confirmActions.append(keepEditing, discard);
|
|
19392
19906
|
confirm.append(confirmTitle, confirmNote, confirmActions);
|
|
19393
|
-
form.append(
|
|
19907
|
+
form.append(details, ...(identity ? [identity] : []), auth, status, hosted, actions, confirm, live.element);
|
|
19394
19908
|
let state = 'editing';
|
|
19909
|
+
let step = 'details';
|
|
19910
|
+
let guardingLeave = false;
|
|
19395
19911
|
let destroyed = false;
|
|
19396
19912
|
let pending = false;
|
|
19397
19913
|
let completed = false;
|
|
@@ -19411,43 +19927,56 @@ function mountHelpDeskForm(client, options) {
|
|
|
19411
19927
|
let uncertainSubmission = null;
|
|
19412
19928
|
let sessionToken = null;
|
|
19413
19929
|
let sessionKnown = false;
|
|
19414
|
-
let attachments;
|
|
19415
19930
|
let submittedCode = null;
|
|
19416
19931
|
let resendAt = 0;
|
|
19417
19932
|
let resendTimer = null;
|
|
19418
19933
|
let confirmReturn = null;
|
|
19419
19934
|
let done = null;
|
|
19420
|
-
|
|
19935
|
+
// The verified customer whose saved request the form holds.
|
|
19936
|
+
let draftOwner = null;
|
|
19421
19937
|
let restoredDraft = false;
|
|
19422
19938
|
let restoredAnonymous = false;
|
|
19423
19939
|
let restoredFiles = false;
|
|
19424
|
-
|
|
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;
|
|
19425
19945
|
function persistDraft() {
|
|
19426
19946
|
if (!options.persist || completed || destroyed)
|
|
19427
19947
|
return;
|
|
19428
|
-
if (!
|
|
19429
|
-
|
|
19430
|
-
|
|
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);
|
|
19431
19952
|
return;
|
|
19432
19953
|
}
|
|
19433
|
-
saveFormDraft(client.desk.desk_id,
|
|
19954
|
+
saveFormDraft(client.desk.desk_id, draftOwner.requester_id, {
|
|
19434
19955
|
subject: subject.input.value, body: description.input.value, ticketId: draftId,
|
|
19435
19956
|
uncertain: uncertainSubmission, hadFiles: restoredFiles || attachments?.hasEntries === true,
|
|
19436
19957
|
});
|
|
19437
19958
|
}
|
|
19438
19959
|
function forgetDraft() {
|
|
19439
|
-
if (
|
|
19440
|
-
|
|
19441
|
-
|
|
19960
|
+
if (!options.persist)
|
|
19961
|
+
return;
|
|
19962
|
+
if (draftOwner)
|
|
19963
|
+
removeFormDraft(client.desk.desk_id, draftOwner.requester_id);
|
|
19964
|
+
else
|
|
19442
19965
|
clearSupportIssue(client.desk.desk_id);
|
|
19443
19966
|
}
|
|
19444
|
-
/**
|
|
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
|
+
*/
|
|
19445
19971
|
function restoreDraft(customer) {
|
|
19446
|
-
if (
|
|
19972
|
+
if (draftOwner?.requester_id === customer.requester_id)
|
|
19973
|
+
return false;
|
|
19974
|
+
draftOwner = customer;
|
|
19975
|
+
recovery = null;
|
|
19976
|
+
renderActions();
|
|
19977
|
+
if (!options.persist)
|
|
19447
19978
|
return false;
|
|
19448
|
-
|
|
19449
|
-
draftRequester = customer.requester_id;
|
|
19450
|
-
const saved = readFormDraft(client.desk.desk_id, draftRequester);
|
|
19979
|
+
const saved = readFormDraft(client.desk.desk_id, customer.requester_id);
|
|
19451
19980
|
clearSupportIssue(client.desk.desk_id);
|
|
19452
19981
|
if (!saved) {
|
|
19453
19982
|
persistDraft();
|
|
@@ -19456,12 +19985,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
19456
19985
|
restoredDraft = true;
|
|
19457
19986
|
restoredFiles = saved.hadFiles && !saved.uncertain;
|
|
19458
19987
|
subject.input.value = saved.uncertain?.subject ?? saved.subject;
|
|
19459
|
-
description.input.value = saved.uncertain
|
|
19988
|
+
description.input.value = saved.uncertain ? detailsOf(saved.uncertain) : saved.body;
|
|
19460
19989
|
draftId = saved.ticketId;
|
|
19461
19990
|
uncertainSubmission = saved.uncertain;
|
|
19462
|
-
|
|
19463
|
-
description.input.readOnly = uncertainSubmission !== null;
|
|
19464
|
-
send.textContent = uncertainSubmission ? 'Check submission' : options.widgetIdentity ? widgetCustomer ? 'Send message' : 'Continue' : 'Send request';
|
|
19991
|
+
send.textContent = idleLabel();
|
|
19465
19992
|
setState(uncertainSubmission ? 'uncertain' : 'editing');
|
|
19466
19993
|
message(uncertainSubmission
|
|
19467
19994
|
? 'Your original request is preserved. Check submission before starting another request.'
|
|
@@ -19473,55 +20000,136 @@ function mountHelpDeskForm(client, options) {
|
|
|
19473
20000
|
// An account switch must not turn an uncertain send into a fresh request.
|
|
19474
20001
|
return pending || uncertainSubmission !== null || completed ? null : { subject: subject.input.value, body: description.input.value };
|
|
19475
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
|
+
*/
|
|
19476
20020
|
function renderWidgetIdentity() {
|
|
19477
|
-
if (!
|
|
20021
|
+
if (!widget)
|
|
19478
20022
|
return;
|
|
19479
|
-
|
|
19480
|
-
|
|
19481
|
-
auth.hidden =
|
|
19482
|
-
email.wrapper.hidden = false;
|
|
20023
|
+
if (request.label)
|
|
20024
|
+
request.label.hidden = widgetCustomer !== null;
|
|
20025
|
+
auth.hidden = true;
|
|
19483
20026
|
code.wrapper.hidden = true;
|
|
19484
20027
|
name.wrapper.hidden = true;
|
|
20028
|
+
widgetAccount.replaceChildren();
|
|
20029
|
+
const free = () => !pending && !destroyed && uncertainSubmission === null && !completed;
|
|
19485
20030
|
if (widgetCustomer) {
|
|
19486
|
-
const
|
|
19487
|
-
|
|
19488
|
-
const
|
|
19489
|
-
|
|
19490
|
-
|
|
19491
|
-
|
|
19492
|
-
|
|
19493
|
-
|
|
19494
|
-
|
|
19495
|
-
change.className = 'svhd-widget-account-link';
|
|
19496
|
-
change.textContent = 'Not you?';
|
|
19497
|
-
change.addEventListener('click', () => {
|
|
19498
|
-
if (pending || destroyed || uncertainSubmission !== null || completed)
|
|
19499
|
-
return;
|
|
19500
|
-
options.widgetIdentity?.switchAccount(safeComposition());
|
|
19501
|
-
});
|
|
19502
|
-
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);
|
|
19503
20040
|
}
|
|
19504
|
-
|
|
19505
|
-
|
|
19506
|
-
|
|
19507
|
-
|
|
19508
|
-
|
|
19509
|
-
}
|
|
19510
|
-
if (options.widgetIdentity.useWebsiteAccount) {
|
|
19511
|
-
const website = document.createElement('button');
|
|
19512
|
-
website.type = 'button';
|
|
19513
|
-
website.className = 'svhd-widget-account-link';
|
|
19514
|
-
website.textContent = 'Use website account';
|
|
19515
|
-
website.addEventListener('click', () => {
|
|
19516
|
-
if (!pending && !destroyed && uncertainSubmission === null && !completed)
|
|
19517
|
-
options.widgetIdentity?.useWebsiteAccount?.(safeComposition());
|
|
19518
|
-
});
|
|
19519
|
-
widgetAccount.append(website);
|
|
20041
|
+
if (widget.useWebsiteAccount && widget.offerWebsiteAccount) {
|
|
20042
|
+
widgetAccount.append(textButton('Use website account', () => {
|
|
20043
|
+
if (free())
|
|
20044
|
+
widget.useWebsiteAccount?.(safeComposition());
|
|
20045
|
+
}));
|
|
19520
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);
|
|
19521
20128
|
}
|
|
19522
20129
|
function setState(next) {
|
|
19523
20130
|
state = next;
|
|
19524
20131
|
persistDraft();
|
|
20132
|
+
syncLeaveGuard();
|
|
19525
20133
|
notify$1(options.onStateChange, next);
|
|
19526
20134
|
}
|
|
19527
20135
|
function message(text, isError = false) {
|
|
@@ -19548,13 +20156,22 @@ function mountHelpDeskForm(client, options) {
|
|
|
19548
20156
|
resendTimer = setInterval(renderResend, 1000);
|
|
19549
20157
|
renderResend();
|
|
19550
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
|
+
*/
|
|
19551
20165
|
function disable(disabled) {
|
|
19552
|
-
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])
|
|
19553
20167
|
input.disabled = disabled;
|
|
20168
|
+
const held = uncertainSubmission !== null || recovery !== null;
|
|
20169
|
+
subject.input.readOnly = held;
|
|
20170
|
+
description.input.readOnly = held;
|
|
19554
20171
|
for (const button of widgetAccount.querySelectorAll('button'))
|
|
19555
20172
|
button.disabled = disabled || uncertainSubmission !== null || completed;
|
|
19556
20173
|
renderResend();
|
|
19557
|
-
attachments?.disablePicking(disabled);
|
|
20174
|
+
attachments?.disablePicking(disabled || recovery !== null);
|
|
19558
20175
|
attachments?.lock(completed || uncertainSubmission !== null);
|
|
19559
20176
|
}
|
|
19560
20177
|
function clearCode() {
|
|
@@ -19583,8 +20200,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
19583
20200
|
? 'We may already have received this request. Closing now loses the way to check it.'
|
|
19584
20201
|
: DISCARD_REQUEST_COPY.note;
|
|
19585
20202
|
}
|
|
19586
|
-
/** 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. */
|
|
19587
20204
|
function stepField() {
|
|
20205
|
+
if (step === 'identity')
|
|
20206
|
+
return (asksName ? firstName : email).input;
|
|
19588
20207
|
const asked = auth.hidden ? undefined : [code, name, email].find((entry) => !entry.wrapper.hidden);
|
|
19589
20208
|
return (asked ?? subject).input;
|
|
19590
20209
|
}
|
|
@@ -19625,25 +20244,27 @@ function mountHelpDeskForm(client, options) {
|
|
|
19625
20244
|
}
|
|
19626
20245
|
/**
|
|
19627
20246
|
* Whether closing now would lose something: a send under way or
|
|
19628
|
-
* unanswered, a code step,
|
|
19629
|
-
*
|
|
19630
|
-
* 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.
|
|
19631
20250
|
*/
|
|
19632
20251
|
function holdsUnsentWork() {
|
|
19633
20252
|
if (completed)
|
|
19634
20253
|
return false;
|
|
19635
|
-
return (pending && state !== 'authenticating') || uncertainSubmission !== null || challenge !== null
|
|
19636
|
-
|| 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'))
|
|
19637
20256
|
|| attachments?.hasEntries === true;
|
|
19638
20257
|
}
|
|
19639
|
-
/**
|
|
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
|
+
*/
|
|
19640
20263
|
function refusal(subjectText, body) {
|
|
19641
20264
|
if (!subjectText)
|
|
19642
|
-
return [subject, 'Add a
|
|
20265
|
+
return [subject, 'Add a summary.'];
|
|
19643
20266
|
if (subjectText.length > MAX_SUBJECT_LEN)
|
|
19644
|
-
return [subject, `Keep the
|
|
19645
|
-
if (!body.trim())
|
|
19646
|
-
return [description, 'Describe what you need help with.'];
|
|
20267
|
+
return [subject, `Keep the summary to ${MAX_SUBJECT_LEN} characters.`];
|
|
19647
20268
|
// The limit counts UTF-8 bytes, so a message of fewer characters can be over it;
|
|
19648
20269
|
// a message of more UTF-16 units than that is over it without being encoded.
|
|
19649
20270
|
if (body.length > MAX_BODY_BYTES || new TextEncoder().encode(body).length > MAX_BODY_BYTES)
|
|
@@ -19712,7 +20333,8 @@ function mountHelpDeskForm(client, options) {
|
|
|
19712
20333
|
attachments?.clear(completed || uncertainSubmission !== null);
|
|
19713
20334
|
attachments?.lock(false);
|
|
19714
20335
|
if (attachments)
|
|
19715
|
-
attachments.
|
|
20336
|
+
attachments.list.hidden = false;
|
|
20337
|
+
composer.clearNotice();
|
|
19716
20338
|
subject.input.value = '';
|
|
19717
20339
|
description.input.value = '';
|
|
19718
20340
|
email.input.value = '';
|
|
@@ -19733,13 +20355,13 @@ function mountHelpDeskForm(client, options) {
|
|
|
19733
20355
|
draftId = null;
|
|
19734
20356
|
draftPromise = null;
|
|
19735
20357
|
uncertainSubmission = null;
|
|
19736
|
-
|
|
20358
|
+
recovery = null;
|
|
20359
|
+
websiteSignedOut = false;
|
|
19737
20360
|
restoredAnonymous = false;
|
|
19738
|
-
subject.input.readOnly = false;
|
|
19739
|
-
description.input.readOnly = false;
|
|
19740
20361
|
completed = false;
|
|
19741
|
-
send.textContent = 'Send request';
|
|
19742
20362
|
message('');
|
|
20363
|
+
renderActions();
|
|
20364
|
+
syncLeaveGuard();
|
|
19743
20365
|
}
|
|
19744
20366
|
function sessionChanged(change) {
|
|
19745
20367
|
if (destroyed)
|
|
@@ -19772,18 +20394,26 @@ function mountHelpDeskForm(client, options) {
|
|
|
19772
20394
|
// during a pending proof must not leave the previous composer visible.
|
|
19773
20395
|
subject.input.value = '';
|
|
19774
20396
|
description.input.value = '';
|
|
20397
|
+
recapText.textContent = '';
|
|
19775
20398
|
name.input.value = '';
|
|
19776
20399
|
email.input.value = '';
|
|
19777
20400
|
clearCode();
|
|
19778
20401
|
if (attachments)
|
|
19779
|
-
attachments.
|
|
20402
|
+
attachments.list.hidden = true;
|
|
19780
20403
|
return;
|
|
19781
20404
|
}
|
|
19782
20405
|
// Preserve the old request before hiding it. The next verified requester
|
|
19783
20406
|
// selects only their own storage key, including after a 401 and sign-in.
|
|
19784
20407
|
persistDraft();
|
|
19785
|
-
|
|
19786
|
-
|
|
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;
|
|
19787
20417
|
restoredDraft = false;
|
|
19788
20418
|
restoredFiles = false;
|
|
19789
20419
|
generation += 1;
|
|
@@ -19792,15 +20422,19 @@ function mountHelpDeskForm(client, options) {
|
|
|
19792
20422
|
if (options.widgetIdentity)
|
|
19793
20423
|
widgetCustomer = null;
|
|
19794
20424
|
clearComposer();
|
|
19795
|
-
|
|
20425
|
+
recovery = hidden;
|
|
19796
20426
|
disable(false);
|
|
19797
20427
|
setState('editing');
|
|
19798
|
-
|
|
19799
|
-
|
|
19800
|
-
|
|
19801
|
-
|
|
19802
|
-
else
|
|
20428
|
+
// The question that led here was the previous customer's too.
|
|
20429
|
+
if (hidesCustomer)
|
|
20430
|
+
widget?.forgetIssue();
|
|
20431
|
+
if (recovery === null)
|
|
19803
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?.();
|
|
19804
20438
|
}
|
|
19805
20439
|
const unsubscribe = client.subscribeSession(sessionChanged);
|
|
19806
20440
|
const alive = (ownGeneration) => !destroyed && generation === ownGeneration;
|
|
@@ -19841,19 +20475,6 @@ function mountHelpDeskForm(client, options) {
|
|
|
19841
20475
|
}
|
|
19842
20476
|
return draftPromise;
|
|
19843
20477
|
}
|
|
19844
|
-
if (client.desk.customer_can_attach_files && options.attachments !== false) {
|
|
19845
|
-
attachments = createFormAttachments(client, prefix, async () => {
|
|
19846
|
-
const ownGeneration = generation;
|
|
19847
|
-
const token = await tokenFor(ownGeneration);
|
|
19848
|
-
if (!token || !alive(ownGeneration))
|
|
19849
|
-
return null;
|
|
19850
|
-
const id = await ensureDraft(ownGeneration, token);
|
|
19851
|
-
if (!alive(ownGeneration))
|
|
19852
|
-
return null;
|
|
19853
|
-
return { draftId: id, expectedSessionToken: token };
|
|
19854
|
-
});
|
|
19855
|
-
form.insertBefore(attachments.element, auth);
|
|
19856
|
-
}
|
|
19857
20478
|
function showEmail() {
|
|
19858
20479
|
auth.hidden = false;
|
|
19859
20480
|
email.wrapper.hidden = false;
|
|
@@ -19886,31 +20507,46 @@ function mountHelpDeskForm(client, options) {
|
|
|
19886
20507
|
// Sending (Enter in a field, a code's last digit) answers the discard
|
|
19887
20508
|
// question: the customer kept going.
|
|
19888
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
|
+
}
|
|
19889
20516
|
for (const entry of fields)
|
|
19890
20517
|
clearFieldError(entry);
|
|
19891
20518
|
const recoveringSubmission = uncertainSubmission !== null;
|
|
19892
20519
|
const subjectText = uncertainSubmission?.subject ?? subject.input.value.trim();
|
|
19893
|
-
const
|
|
20520
|
+
const detailsText = uncertainSubmission ? detailsOf(uncertainSubmission) : description.input.value;
|
|
20521
|
+
const body = uncertainSubmission?.body ?? ticketBody(subjectText, detailsText);
|
|
19894
20522
|
if (uncertainSubmission) {
|
|
19895
20523
|
// Retrying recovers this exact request. A lost response must never make
|
|
19896
20524
|
// newly typed text appear to have been accepted as the earlier ticket.
|
|
19897
20525
|
subject.input.value = subjectText;
|
|
19898
|
-
description.input.value =
|
|
20526
|
+
description.input.value = detailsText;
|
|
19899
20527
|
}
|
|
19900
20528
|
const refused = refusal(subjectText, body);
|
|
19901
|
-
const recoveringAfterSignIn =
|
|
20529
|
+
const recoveringAfterSignIn = recovery !== null;
|
|
19902
20530
|
if (refused && !recoveringAfterSignIn) {
|
|
19903
20531
|
const [entry, text] = refused;
|
|
20532
|
+
if (step !== 'details')
|
|
20533
|
+
setStep('details');
|
|
19904
20534
|
setFieldError(entry, text);
|
|
19905
20535
|
entry.input.focus();
|
|
19906
20536
|
return;
|
|
19907
20537
|
}
|
|
19908
20538
|
let widgetSignIn;
|
|
19909
|
-
if (
|
|
19910
|
-
|
|
19911
|
-
|
|
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() : '';
|
|
19912
20548
|
const emailAddress = email.input.value.trim();
|
|
19913
|
-
const invalid = !givenName ? firstName : !email.input.validity.valid || !emailAddress ? email : null;
|
|
20549
|
+
const invalid = asksName && !givenName ? firstName : !email.input.validity.valid || !emailAddress ? email : null;
|
|
19914
20550
|
if (invalid) {
|
|
19915
20551
|
setFieldError(invalid, invalid === email ? 'Enter your email address.' : 'Enter your first name.');
|
|
19916
20552
|
invalid.input.focus();
|
|
@@ -19919,7 +20555,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
19919
20555
|
// Invoke in the original submit gesture, before any awaited token read:
|
|
19920
20556
|
// the Identity adapter can open its native window without a popup block.
|
|
19921
20557
|
try {
|
|
19922
|
-
widgetSignIn =
|
|
20558
|
+
widgetSignIn = widget.signIn(asksName ? { email: emailAddress, givenName, familyName } : { email: emailAddress });
|
|
19923
20559
|
}
|
|
19924
20560
|
catch (failure) {
|
|
19925
20561
|
const error = failure instanceof Error ? failure : new Error('Sign-in could not be opened.');
|
|
@@ -19936,12 +20572,13 @@ function mountHelpDeskForm(client, options) {
|
|
|
19936
20572
|
pending = true;
|
|
19937
20573
|
disable(true);
|
|
19938
20574
|
message('');
|
|
20575
|
+
syncLeaveGuard();
|
|
19939
20576
|
try {
|
|
19940
20577
|
if (widgetSignIn) {
|
|
19941
20578
|
authenticating = true;
|
|
19942
20579
|
authNotification = false;
|
|
19943
20580
|
setState('authenticating');
|
|
19944
|
-
message('
|
|
20581
|
+
message('Finish signing in in the secure window.');
|
|
19945
20582
|
}
|
|
19946
20583
|
let token = await tokenFor(ownGeneration);
|
|
19947
20584
|
if (!alive(ownGeneration))
|
|
@@ -19967,10 +20604,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
19967
20604
|
sessionKnown = true;
|
|
19968
20605
|
authenticating = false;
|
|
19969
20606
|
if (attachments)
|
|
19970
|
-
attachments.
|
|
20607
|
+
attachments.list.hidden = false;
|
|
19971
20608
|
subject.input.value = subjectText;
|
|
19972
|
-
description.input.value =
|
|
19973
|
-
if (
|
|
20609
|
+
description.input.value = detailsText;
|
|
20610
|
+
if (widget && session) {
|
|
19974
20611
|
widgetCustomer = session.customer;
|
|
19975
20612
|
renderWidgetIdentity();
|
|
19976
20613
|
message('');
|
|
@@ -19986,7 +20623,8 @@ function mountHelpDeskForm(client, options) {
|
|
|
19986
20623
|
if (!alive(ownGeneration))
|
|
19987
20624
|
return;
|
|
19988
20625
|
if (!token) {
|
|
19989
|
-
|
|
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))) {
|
|
19990
20628
|
showHosted();
|
|
19991
20629
|
return;
|
|
19992
20630
|
}
|
|
@@ -20030,10 +20668,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
20030
20668
|
sessionKnown = true;
|
|
20031
20669
|
authenticating = false;
|
|
20032
20670
|
if (attachments)
|
|
20033
|
-
attachments.
|
|
20671
|
+
attachments.list.hidden = false;
|
|
20034
20672
|
dropChallenge();
|
|
20035
20673
|
subject.input.value = subjectText;
|
|
20036
|
-
description.input.value =
|
|
20674
|
+
description.input.value = detailsText;
|
|
20037
20675
|
notify$1(options.onSession, verified);
|
|
20038
20676
|
}
|
|
20039
20677
|
if (!token || !alive(ownGeneration))
|
|
@@ -20061,7 +20699,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20061
20699
|
email.wrapper.hidden = true;
|
|
20062
20700
|
code.wrapper.hidden = true;
|
|
20063
20701
|
name.wrapper.hidden = false;
|
|
20064
|
-
send.textContent =
|
|
20702
|
+
send.textContent = idleLabel();
|
|
20065
20703
|
setState('editing');
|
|
20066
20704
|
setFieldError(name, 'Add your name before sending your request.');
|
|
20067
20705
|
focusAfter = name.input;
|
|
@@ -20083,7 +20721,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20083
20721
|
setState('submitting');
|
|
20084
20722
|
if (!alive(ownGeneration))
|
|
20085
20723
|
return;
|
|
20086
|
-
send.textContent =
|
|
20724
|
+
send.textContent = 'Sending request';
|
|
20087
20725
|
if (!uncertainSubmission) {
|
|
20088
20726
|
const id = await ensureDraft(ownGeneration, token);
|
|
20089
20727
|
if (!alive(ownGeneration) || !(await tokenFor(ownGeneration)))
|
|
@@ -20126,14 +20764,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
20126
20764
|
const draftExpired = ticketAttempted && error instanceof SparkVaultError
|
|
20127
20765
|
&& (error.serviceCode === 'DRAFT_EXPIRED' || error.code === 'DRAFT_EXPIRED');
|
|
20128
20766
|
if (uncertainSubmission && !draftExpired && (!ticketAttempted || recoveringSubmission || unknownSubmissionOutcome(error))) {
|
|
20129
|
-
subject.input.readOnly = true;
|
|
20130
|
-
description.input.readOnly = true;
|
|
20131
20767
|
message('We could not confirm whether your request was sent. Check submission to recover it. Your original text is kept unchanged.', true);
|
|
20132
20768
|
}
|
|
20133
20769
|
else {
|
|
20134
20770
|
uncertainSubmission = null;
|
|
20135
|
-
subject.input.readOnly = false;
|
|
20136
|
-
description.input.readOnly = false;
|
|
20137
20771
|
if (draftExpired) {
|
|
20138
20772
|
draftId = null;
|
|
20139
20773
|
draftPromise = null;
|
|
@@ -20144,6 +20778,13 @@ function mountHelpDeskForm(client, options) {
|
|
|
20144
20778
|
setFieldError(code, HELP_DESK_CODE_STEP_COPY.codeRefused);
|
|
20145
20779
|
focusAfter = code.input;
|
|
20146
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
|
+
}
|
|
20147
20788
|
else {
|
|
20148
20789
|
message(draftExpired ? 'Your saved draft expired. Your text is kept. Choose your files again before sending.' : error.message, true);
|
|
20149
20790
|
}
|
|
@@ -20151,7 +20792,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20151
20792
|
setState(uncertainSubmission ? 'uncertain' : challenge ? 'verifying' : 'editing');
|
|
20152
20793
|
if (!alive(ownGeneration))
|
|
20153
20794
|
return;
|
|
20154
|
-
send.textContent =
|
|
20795
|
+
send.textContent = idleLabel();
|
|
20155
20796
|
notify$1(options.onError, error);
|
|
20156
20797
|
}
|
|
20157
20798
|
finally {
|
|
@@ -20159,6 +20800,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20159
20800
|
authenticating = false;
|
|
20160
20801
|
pending = false;
|
|
20161
20802
|
disable(completed);
|
|
20803
|
+
syncLeaveGuard();
|
|
20162
20804
|
focusSettled();
|
|
20163
20805
|
}
|
|
20164
20806
|
}
|
|
@@ -20231,6 +20873,8 @@ function mountHelpDeskForm(client, options) {
|
|
|
20231
20873
|
generation += 1;
|
|
20232
20874
|
stopResendCountdown();
|
|
20233
20875
|
attachments?.destroy(completed || uncertainSubmission !== null);
|
|
20876
|
+
composer.destroy();
|
|
20877
|
+
live.destroy();
|
|
20234
20878
|
unsubscribe();
|
|
20235
20879
|
form.removeEventListener('submit', onSubmit);
|
|
20236
20880
|
shell.destroy();
|
|
@@ -20255,24 +20899,50 @@ function mountHelpDeskForm(client, options) {
|
|
|
20255
20899
|
subject.input.value = composition.subject;
|
|
20256
20900
|
description.input.value = composition.body;
|
|
20257
20901
|
persistDraft();
|
|
20902
|
+
syncLeaveGuard();
|
|
20258
20903
|
},
|
|
20259
|
-
refill(
|
|
20260
|
-
if (destroyed || restoredDraft || safeComposition() === null)
|
|
20904
|
+
refill(issue) {
|
|
20905
|
+
if (destroyed || restoredDraft || recovery !== null || safeComposition() === null)
|
|
20261
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 };
|
|
20262
20910
|
for (const [entry, key] of [[subject, 'subject'], [description, 'body']]) {
|
|
20263
|
-
if (
|
|
20264
|
-
|
|
20265
|
-
|
|
20266
|
-
|
|
20267
|
-
prefill[key] = composition[key];
|
|
20911
|
+
if (own[key])
|
|
20912
|
+
continue;
|
|
20913
|
+
entry.input.value = placed[key];
|
|
20914
|
+
clearFieldError(entry);
|
|
20268
20915
|
}
|
|
20916
|
+
filledFrom = issue;
|
|
20917
|
+
if (step === 'identity')
|
|
20918
|
+
recapText.textContent = subject.input.value.trim();
|
|
20269
20919
|
persistDraft();
|
|
20920
|
+
syncLeaveGuard();
|
|
20270
20921
|
return true;
|
|
20271
20922
|
},
|
|
20272
20923
|
resumeAfterAccess() {
|
|
20273
20924
|
if (!destroyed && !pending && !completed && uncertainSubmission === null)
|
|
20274
20925
|
message('');
|
|
20275
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
|
+
},
|
|
20276
20946
|
requestDismiss() {
|
|
20277
20947
|
if (destroyed)
|
|
20278
20948
|
return;
|
|
@@ -20306,18 +20976,28 @@ function mountHelpDeskForm(client, options) {
|
|
|
20306
20976
|
keepEditing.addEventListener('click', () => closeConfirm(true));
|
|
20307
20977
|
discard.addEventListener('click', dismiss);
|
|
20308
20978
|
form.addEventListener('submit', onSubmit);
|
|
20309
|
-
form.addEventListener('input',
|
|
20310
|
-
form.addEventListener('change', () => {
|
|
20311
|
-
if (attachments?.hasEntries)
|
|
20312
|
-
restoredFiles = false;
|
|
20979
|
+
form.addEventListener('input', () => {
|
|
20313
20980
|
persistDraft();
|
|
20981
|
+
syncLeaveGuard();
|
|
20314
20982
|
});
|
|
20983
|
+
send.textContent = idleLabel();
|
|
20315
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');
|
|
20316
20988
|
if (options.widgetIdentity?.customer) {
|
|
20317
20989
|
restoreDraft(options.widgetIdentity.customer);
|
|
20318
20990
|
disable(false);
|
|
20319
20991
|
}
|
|
20320
|
-
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.
|
|
20321
21001
|
const saved = readAnonymousFormDraft(client.desk.desk_id);
|
|
20322
21002
|
if (saved) {
|
|
20323
21003
|
subject.input.value = saved.subject;
|
|
@@ -20325,6 +21005,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20325
21005
|
restoredAnonymous = true;
|
|
20326
21006
|
}
|
|
20327
21007
|
}
|
|
21008
|
+
syncLeaveGuard();
|
|
20328
21009
|
notify$1(options.onStateChange, state);
|
|
20329
21010
|
// Native company identity starts as the form opens, never from a Connect,
|
|
20330
21011
|
// Allow, verification or submit gesture. Guest email is explicit desk policy.
|
|
@@ -22552,58 +23233,6 @@ function createSupportLauncher(options, open) {
|
|
|
22552
23233
|
};
|
|
22553
23234
|
}
|
|
22554
23235
|
|
|
22555
|
-
/** A title written with a period: in "Dear Mr. Smith," that period ends no sentence. */
|
|
22556
|
-
const HONORIFIC = String.raw `(?:Mr|Mrs|Ms|Mx|Dr|Prof)\.`;
|
|
22557
|
-
/**
|
|
22558
|
-
* Where a sentence ends: after a period, exclamation or question mark that
|
|
22559
|
-
* whitespace follows. An honorific's period is matched first, whole, and left
|
|
22560
|
-
* as it is.
|
|
22561
|
-
*/
|
|
22562
|
-
const SENTENCE_END = new RegExp(String.raw `\b${HONORIFIC}(?=\s)|([.!?])(?=\s)`, 'g');
|
|
22563
|
-
/** The word a greeting opens with, whole: "Hi", "Hello", "Good morning", "Morning". */
|
|
22564
|
-
const SALUTATION = /^(?:hi|hello|hey|hiya|howdy|greetings|dear|good\s+day|(?:good\s+)?(?:morning|afternoon|evening))(?!\p{L})/iu;
|
|
22565
|
-
/** The few words greetings use for whom they address. */
|
|
22566
|
-
const ADDRESS_WORDS = 'again|there|team|all|everyone|everybody|folks|guys|support|customer|service|sir|madam|or|and';
|
|
22567
|
-
/**
|
|
22568
|
-
* What may follow the salutation in a greeting: up to four words of address,
|
|
22569
|
-
* each an honorific, a name or one of the few words greetings use, in lower
|
|
22570
|
-
* case or capitals ("Mr. Smith", "Privacy Bee team", "there", "AGAIN", "Sir
|
|
22571
|
-
* or Madam"), then anything but letters and digits: punctuation, symbols and
|
|
22572
|
-
* emoji. The words of an issue ("Hi, I can't sign in", "Hey refund please",
|
|
22573
|
-
* "HELLO I CANT LOGIN") are none of these, so a sentence holding them is the
|
|
22574
|
-
* issue. A name is a capital and lowercase letters, again for each capital of
|
|
22575
|
-
* one like PayPal or McKenzie, so a word in capitals is shouted, not a name.
|
|
22576
|
-
* Case-sensitive, so that case tells a name: a case-insensitive \p{Lu} matches
|
|
22577
|
-
* every letter. A name's apostrophes and hyphens only join letters, so a word
|
|
22578
|
-
* of address ends in a letter or an honorific's period, and the closing run
|
|
22579
|
-
* never competes with it for more than that one period; that keeps the read
|
|
22580
|
-
* linear.
|
|
22581
|
-
*/
|
|
22582
|
-
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');
|
|
22583
|
-
const TO_WHOM = /^to\s+whom\s+it\s+may\s+concern[^\p{L}\p{N}]*$/iu;
|
|
22584
|
-
const LETTER = /\p{L}/u;
|
|
22585
|
-
/** A line or sentence that only greets: "Hi there,", "Good morning team!", "Dear Sir or Madam,", "To whom it may concern:". */
|
|
22586
|
-
function isGreeting(sentence) {
|
|
22587
|
-
const salutation = SALUTATION.exec(sentence);
|
|
22588
|
-
return salutation ? ADDRESS.test(sentence.slice(salutation[0].length)) : TO_WHOM.test(sentence);
|
|
22589
|
-
}
|
|
22590
|
-
/**
|
|
22591
|
-
* The subject a support issue prefills: its first line or sentence that holds
|
|
22592
|
-
* a word and says more than a greeting (its first one when none does),
|
|
22593
|
-
* shortened at a word boundary with an ellipsis to fit MAX_SUBJECT_LEN. The
|
|
22594
|
-
* message carries the whole issue, so the subject only needs to name it.
|
|
22595
|
-
*/
|
|
22596
|
-
function issueSubject(issue) {
|
|
22597
|
-
const sentences = issue.replace(SENTENCE_END, (match, end) => end ? `${end}\n` : match)
|
|
22598
|
-
.split('\n').map((sentence) => sentence.trim()).filter(Boolean);
|
|
22599
|
-
const subject = sentences.find((sentence) => LETTER.test(sentence) && !isGreeting(sentence)) ?? sentences[0] ?? '';
|
|
22600
|
-
if (subject.length <= MAX_SUBJECT_LEN)
|
|
22601
|
-
return subject;
|
|
22602
|
-
const kept = truncateToLength(subject, MAX_SUBJECT_LEN - 1);
|
|
22603
|
-
const atWord = /\s/u.test(subject.charAt(kept.length)) ? kept : kept.replace(/\s+\S*$/u, '');
|
|
22604
|
-
return `${atWord.trimEnd()}…`;
|
|
22605
|
-
}
|
|
22606
|
-
|
|
22607
23236
|
/** The support journey's only skin. Customer content stays in the product register. */
|
|
22608
23237
|
function injectHelpDeskSupportStyles() {
|
|
22609
23238
|
if (document.getElementById('sparkvault-help-desk-support-styles'))
|
|
@@ -22729,11 +23358,10 @@ function injectHelpDeskSupportStyles() {
|
|
|
22729
23358
|
.svhs-unlock-form{margin:0}
|
|
22730
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}
|
|
22731
23360
|
.svhs-contact-target .svhd-body{display:flex;flex:1;flex-direction:column;min-height:0}
|
|
22732
|
-
.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}
|
|
22733
23362
|
.svhs-contact-target .svhd-form{gap:16px}
|
|
22734
23363
|
.svhs-contact-target .svhd-label{font-size:13px;line-height:1.5}
|
|
22735
23364
|
.svhs-contact-target .svhd-input{font-size:16px;line-height:1.5}
|
|
22736
|
-
.svhs-contact-target .svhd-description{min-height:138px}
|
|
22737
23365
|
.svhs-contact-target .svhd-actions{gap:10px}
|
|
22738
23366
|
.svhs-contact-target .svhd-button:not(.svhd-secondary){background:var(--hd-accent,${DS.action});color:var(--hd-on-accent,${DS.white})}
|
|
22739
23367
|
.svhs-contact-target .svhd-button:not(.svhd-secondary):hover{background:var(--hd-accent-hover,${DS.actionHover})}
|
|
@@ -22741,18 +23369,19 @@ function injectHelpDeskSupportStyles() {
|
|
|
22741
23369
|
.svhs-contact-target .svhd-actions>.svhd-button:first-child{flex:1}
|
|
22742
23370
|
.svhs-contact-target .svhd-status{font-size:14px}
|
|
22743
23371
|
.svhs-contact-target .svhd-auth{gap:14px}
|
|
22744
|
-
.svhs-contact-target .svhd-
|
|
22745
|
-
.svhs-contact-target .svhd-
|
|
22746
|
-
.svhs-contact-target .svhd-
|
|
22747
|
-
.svhs-contact-target .svhd-
|
|
22748
|
-
.svhs-
|
|
22749
|
-
.svhs-
|
|
22750
|
-
.svhs-contact-target .svhd-widget-account-link:focus-visible{outline:2px solid var(--hd-focus,var(--hd-accent-ink,${DS.action}));outline-offset:3px}
|
|
22751
|
-
.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}
|
|
22752
23378
|
.svhs-contact-target .svhd-widget-names{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:12px}
|
|
22753
23379
|
.svhs-contact-target .svhd-widget-form{display:flex;flex:1;flex-direction:column;gap:16px}
|
|
22754
|
-
|
|
22755
|
-
.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}
|
|
22756
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}}
|
|
22757
23386
|
.svhs-contact-target .svhd-widget-form>.svhd-actions>.svhd-secondary{display:none}
|
|
22758
23387
|
.svhs-contact-target .svhd-widget-form .svhd-actions>.svhd-button{font-size:14px}
|
|
@@ -22765,7 +23394,6 @@ function injectHelpDeskSupportStyles() {
|
|
|
22765
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}
|
|
22766
23395
|
.svhs-receipt-note{white-space:pre-wrap;overflow-wrap:anywhere}
|
|
22767
23396
|
.svhs-receipt-actions{display:flex;flex-direction:column;align-items:center;gap:4px}
|
|
22768
|
-
.svhs-live{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
|
|
22769
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}
|
|
22770
23398
|
.svhs-toast svg{width:18px;height:18px;flex:none;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round}
|
|
22771
23399
|
.svhs-overlay{position:fixed;inset:0;z-index:2147482900;display:flex;background:${DS.white};padding:0;overflow:hidden}
|
|
@@ -22800,7 +23428,6 @@ function injectHelpDeskSupportStyles() {
|
|
|
22800
23428
|
.svhs-feedback-actions{margin-top:30px}
|
|
22801
23429
|
.svhs-feedback-actions .svhs-primary,.svhs-feedback-actions .svhs-secondary{min-height:48px}
|
|
22802
23430
|
.svhs-contact-scroll{padding:0}
|
|
22803
|
-
.svhs-contact-target .svhd-description{min-height:160px}
|
|
22804
23431
|
.svhs-contact-target>.svhd-container{padding:24px}
|
|
22805
23432
|
.svhs-contact-target .svhd-widget-form>.svhd-actions{padding-bottom:env(safe-area-inset-bottom)}
|
|
22806
23433
|
.svhs-receipt-scroll{padding-top:58px}
|
|
@@ -23166,24 +23793,6 @@ function button(className, text, action) {
|
|
|
23166
23793
|
node.addEventListener('click', action);
|
|
23167
23794
|
return node;
|
|
23168
23795
|
}
|
|
23169
|
-
function icon(name) {
|
|
23170
|
-
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
23171
|
-
svg.setAttribute('viewBox', '0 0 24 24');
|
|
23172
|
-
svg.setAttribute('aria-hidden', 'true');
|
|
23173
|
-
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
23174
|
-
path.setAttribute('d', {
|
|
23175
|
-
back: 'm14.5 6-6 6 6 6',
|
|
23176
|
-
close: 'm6 6 12 12M18 6 6 18',
|
|
23177
|
-
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',
|
|
23178
|
-
check: 'm5 12 4 4L19 6',
|
|
23179
|
-
article: 'M14 3H6a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8Zm0 0v5h5M8 12h8M8 16h6',
|
|
23180
|
-
chevron: 'm9 6 6 6-6 6',
|
|
23181
|
-
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',
|
|
23182
|
-
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',
|
|
23183
|
-
}[name]);
|
|
23184
|
-
svg.append(path);
|
|
23185
|
-
return svg;
|
|
23186
|
-
}
|
|
23187
23796
|
function httpUrl(value, base = window.location.href) {
|
|
23188
23797
|
if (!value)
|
|
23189
23798
|
return null;
|
|
@@ -23242,7 +23851,6 @@ class SupportView {
|
|
|
23242
23851
|
this.receiptCopy = element('p', 'svhs-copy');
|
|
23243
23852
|
this.receiptTicket = element('a', 'svhs-ticket-link');
|
|
23244
23853
|
this.receiptMessage = element('p', 'svhs-copy svhs-receipt-note');
|
|
23245
|
-
this.live = element('div', 'svhs-live');
|
|
23246
23854
|
this.identityNotice = element('div', 'svhs-identity-notice');
|
|
23247
23855
|
this.onMediaChange = () => this.syncPresentation();
|
|
23248
23856
|
this.onViewportChange = () => this.syncViewport();
|
|
@@ -23255,6 +23863,24 @@ class SupportView {
|
|
|
23255
23863
|
this.ticketGateSignature = '';
|
|
23256
23864
|
this.toastCleanups = new Set();
|
|
23257
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
|
+
};
|
|
23258
23884
|
injectHelpDeskSupportStyles();
|
|
23259
23885
|
this.phoneHistory = !target && actions.onBrowserBack && actions.onBrowserForward ? new SupportPhoneHistory({
|
|
23260
23886
|
onBack: () => this.actions.onBrowserBack?.(),
|
|
@@ -23267,20 +23893,20 @@ class SupportView {
|
|
|
23267
23893
|
this.panel.hidden = true;
|
|
23268
23894
|
this.panel.setAttribute('aria-labelledby', `${this.prefix}-name`);
|
|
23269
23895
|
this.deskName.id = `${this.prefix}-name`;
|
|
23270
|
-
this.
|
|
23271
|
-
this.
|
|
23896
|
+
this.panel.addEventListener('mousedown', this.onPress, true);
|
|
23897
|
+
this.panel.addEventListener('click', this.onPress, true);
|
|
23272
23898
|
const toolbar = element('header', 'svhs-toolbar');
|
|
23273
23899
|
this.toolbar = toolbar;
|
|
23274
23900
|
this.back = button('svhs-back', 'Back', () => this.actions.onBack());
|
|
23275
|
-
this.back.prepend(
|
|
23901
|
+
this.back.prepend(helpDeskIcon('back'));
|
|
23276
23902
|
this.close = button('svhs-icon-button', '', () => this.actions.onClose());
|
|
23277
23903
|
this.close.setAttribute('aria-label', 'Close support');
|
|
23278
|
-
this.close.append(
|
|
23904
|
+
this.close.append(helpDeskIcon('close'));
|
|
23279
23905
|
this.external.setAttribute('aria-label', 'Open article in a new tab');
|
|
23280
23906
|
this.external.title = 'Open article in a new tab';
|
|
23281
23907
|
this.external.target = '_blank';
|
|
23282
23908
|
this.external.rel = 'noopener noreferrer';
|
|
23283
|
-
this.external.append(
|
|
23909
|
+
this.external.append(helpDeskIcon('external'));
|
|
23284
23910
|
const toolbarActions = element('div', 'svhs-toolbar-actions');
|
|
23285
23911
|
toolbarActions.append(this.external);
|
|
23286
23912
|
if (!target)
|
|
@@ -23354,9 +23980,9 @@ class SupportView {
|
|
|
23354
23980
|
const readerActions = element('div', 'svhs-reader-actions');
|
|
23355
23981
|
const yes = button('svhs-primary', 'Yes', () => { if (this.state?.article && !this.state.busy && !this.state.error)
|
|
23356
23982
|
this.actions.onAnswered(); });
|
|
23357
|
-
yes.prepend(
|
|
23983
|
+
yes.prepend(helpDeskIcon('thumbUp'));
|
|
23358
23984
|
const no = button('svhs-text-button', 'No, create a ticket', () => this.actions.onContact('article_not_answered'));
|
|
23359
|
-
no.prepend(
|
|
23985
|
+
no.prepend(helpDeskIcon('thumbDown'));
|
|
23360
23986
|
readerActions.append(yes, no);
|
|
23361
23987
|
this.articleFooter.append(element('span', 'svhs-article-question', 'Did this resolve your question?'), readerActions);
|
|
23362
23988
|
this.screens.get('article').append(this.articleFooter);
|
|
@@ -23398,7 +24024,7 @@ class SupportView {
|
|
|
23398
24024
|
contact.append(this.contactTarget);
|
|
23399
24025
|
const receipt = this.screen('receipt', 'Message sent');
|
|
23400
24026
|
receipt.classList.add('svhs-receipt-scroll');
|
|
23401
|
-
const receiptMark =
|
|
24027
|
+
const receiptMark = helpDeskIcon('check');
|
|
23402
24028
|
receiptMark.classList.add('svhs-receipt-mark');
|
|
23403
24029
|
receipt.prepend(receiptMark);
|
|
23404
24030
|
this.receiptTicket.target = '_blank';
|
|
@@ -23409,7 +24035,6 @@ class SupportView {
|
|
|
23409
24035
|
if (!target)
|
|
23410
24036
|
receiptFooter.append(button('svhs-secondary svhs-full', 'Done', () => this.actions.onClose()));
|
|
23411
24037
|
receiptFooter.append(this.restart);
|
|
23412
|
-
this.panel.append(this.live);
|
|
23413
24038
|
this.media = typeof window.matchMedia === 'function' ? window.matchMedia('(max-width:640px)') : null;
|
|
23414
24039
|
if (!target) {
|
|
23415
24040
|
this.media?.addEventListener('change', this.onMediaChange);
|
|
@@ -23498,24 +24123,34 @@ class SupportView {
|
|
|
23498
24123
|
if (!next.visible)
|
|
23499
24124
|
return;
|
|
23500
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;
|
|
23501
24129
|
this.restoreScroll(next);
|
|
23502
24130
|
this.focusCurrent();
|
|
23503
24131
|
}
|
|
23504
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
|
+
}
|
|
23505
24137
|
/** Programmatic close invalidates Forward restoration even after neutral Back. */
|
|
23506
24138
|
deactivateHistory() {
|
|
23507
24139
|
this.phoneHistory?.deactivate();
|
|
23508
24140
|
}
|
|
23509
|
-
/** 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. */
|
|
23510
24142
|
focusContact() {
|
|
23511
24143
|
if (this.destroyed || !this.state?.visible || this.state.stage !== 'contact')
|
|
23512
24144
|
return;
|
|
23513
24145
|
const heading = this.contactTarget.querySelector('h1,h2,h3');
|
|
23514
24146
|
this.contactTitle.hidden = Boolean(heading);
|
|
23515
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;
|
|
23516
24151
|
const target = heading ?? this.contactTarget;
|
|
23517
24152
|
target.tabIndex = -1;
|
|
23518
|
-
target.focus(
|
|
24153
|
+
target.focus(focusOptions);
|
|
23519
24154
|
}
|
|
23520
24155
|
/** Hydrate only the current reader's matching authorized publication assets. */
|
|
23521
24156
|
setArticleAsset(path, blobUrl) {
|
|
@@ -23566,7 +24201,7 @@ class SupportView {
|
|
|
23566
24201
|
const toast = element('div', 'svhs-toast');
|
|
23567
24202
|
toast.setAttribute('role', 'status');
|
|
23568
24203
|
toast.setAttribute('aria-atomic', 'true');
|
|
23569
|
-
toast.append(
|
|
24204
|
+
toast.append(helpDeskIcon('check'), document.createTextNode(message));
|
|
23570
24205
|
document.body.append(toast);
|
|
23571
24206
|
const arrange = () => {
|
|
23572
24207
|
let offset = 0;
|
|
@@ -23617,6 +24252,8 @@ class SupportView {
|
|
|
23617
24252
|
return;
|
|
23618
24253
|
this.destroyed = true;
|
|
23619
24254
|
this.phoneHistory?.destroy();
|
|
24255
|
+
this.panel.removeEventListener('mousedown', this.onPress, true);
|
|
24256
|
+
this.panel.removeEventListener('click', this.onPress, true);
|
|
23620
24257
|
document.removeEventListener('keydown', this.onKeydown);
|
|
23621
24258
|
this.media?.removeEventListener('change', this.onMediaChange);
|
|
23622
24259
|
window.visualViewport?.removeEventListener('resize', this.onViewportChange);
|
|
@@ -23687,9 +24324,9 @@ class SupportView {
|
|
|
23687
24324
|
copy.append(element('span', 'svhs-result-excerpt', result.summary));
|
|
23688
24325
|
if (result.category)
|
|
23689
24326
|
copy.append(element('span', 'svhs-result-category', result.category));
|
|
23690
|
-
const documentIcon =
|
|
24327
|
+
const documentIcon = helpDeskIcon('article');
|
|
23691
24328
|
documentIcon.classList.add('svhs-result-icon');
|
|
23692
|
-
const chevron =
|
|
24329
|
+
const chevron = helpDeskIcon('chevron');
|
|
23693
24330
|
chevron.classList.add('svhs-result-chevron');
|
|
23694
24331
|
open.append(documentIcon, copy, chevron);
|
|
23695
24332
|
item.append(open);
|
|
@@ -24061,8 +24698,6 @@ class SupportView {
|
|
|
24061
24698
|
}
|
|
24062
24699
|
}
|
|
24063
24700
|
|
|
24064
|
-
/** What contact starts from: the issue's subject and, as the message, every character of the issue. */
|
|
24065
|
-
function composeIssue(issue) { return { subject: issueSubject(issue), body: issue }; }
|
|
24066
24701
|
function notify(callback, value) {
|
|
24067
24702
|
try {
|
|
24068
24703
|
void Promise.resolve(callback?.(value)).catch(() => undefined);
|
|
@@ -24088,10 +24723,14 @@ function createHelpDeskSupport(config, options) {
|
|
|
24088
24723
|
// only while it is the current sequence, so whatever supersedes it frees it.
|
|
24089
24724
|
let contactOpening = null;
|
|
24090
24725
|
let pendingComposition = null;
|
|
24091
|
-
//
|
|
24092
|
-
//
|
|
24093
|
-
|
|
24094
|
-
//
|
|
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.
|
|
24095
24734
|
let composedFrom = '';
|
|
24096
24735
|
let nativeIdentity = null;
|
|
24097
24736
|
let switchedAccount = false;
|
|
@@ -24125,6 +24764,9 @@ function createHelpDeskSupport(config, options) {
|
|
|
24125
24764
|
onBack: () => {
|
|
24126
24765
|
if (destroyed || state.navigationLocked || state.identityPending)
|
|
24127
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;
|
|
24128
24770
|
// A held form shows at once while contact still checks access behind it,
|
|
24129
24771
|
// so a contact opening in flight is cancelled even when nothing is busy.
|
|
24130
24772
|
if (state.busy || contactOpening === sequence)
|
|
@@ -24171,6 +24813,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24171
24813
|
onUnlock: (password) => { void unlock(password); },
|
|
24172
24814
|
onUnlockTicketAccess: (password) => { void unlockTicketAccess(password); },
|
|
24173
24815
|
onCancelIdentity: () => nativeIdentity?.abort(),
|
|
24816
|
+
onFocusContact: (focusOptions) => contact?.focusEntry(focusOptions) ?? false,
|
|
24174
24817
|
onBrowserBack: minimize,
|
|
24175
24818
|
onBrowserForward: () => update({ visible: true }),
|
|
24176
24819
|
}, options.target === undefined ? undefined : resolveTarget(options.target));
|
|
@@ -24250,7 +24893,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24250
24893
|
const saved = readFormDraft(active.desk.desk_id, customer.requester_id);
|
|
24251
24894
|
const composition = readAnonymousFormDraft(active.desk.desk_id);
|
|
24252
24895
|
if ((saved || composition) && !state.issue) {
|
|
24253
|
-
update({ issue: saved
|
|
24896
|
+
update({ issue: saved ? ticketBody(saved.subject, saved.body) : readSupportIssue(active.desk.desk_id) ?? '' });
|
|
24254
24897
|
await showContact('direct');
|
|
24255
24898
|
}
|
|
24256
24899
|
else if (!state.issue)
|
|
@@ -24329,6 +24972,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24329
24972
|
results = [];
|
|
24330
24973
|
requestedArticle = null;
|
|
24331
24974
|
pendingComposition = null;
|
|
24975
|
+
pendingRecovery = null;
|
|
24332
24976
|
feedbackSequence += 1;
|
|
24333
24977
|
sourceArticleId = undefined;
|
|
24334
24978
|
if (options.persist && client)
|
|
@@ -24489,18 +25133,28 @@ function createHelpDeskSupport(config, options) {
|
|
|
24489
25133
|
notify(options.onError, error);
|
|
24490
25134
|
}
|
|
24491
25135
|
}
|
|
24492
|
-
|
|
25136
|
+
/** Mount the contact form filled from `composedFrom`, then put a composition carried from an earlier form in it. */
|
|
25137
|
+
function mountContact(carried, customer) {
|
|
24493
25138
|
if (!client || destroyed)
|
|
24494
25139
|
return;
|
|
24495
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;
|
|
24496
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);
|
|
24497
25149
|
contact = mountHelpDeskForm(client, {
|
|
24498
25150
|
target: view.contactTarget,
|
|
24499
|
-
// Filled
|
|
25151
|
+
// Filled from the issue its composition came from, so text the customer
|
|
24500
25152
|
// wrote in an earlier form and carried here stays their own.
|
|
24501
|
-
|
|
25153
|
+
issue: composedFrom,
|
|
24502
25154
|
attachments: options.attachments,
|
|
24503
25155
|
persist: options.persist,
|
|
25156
|
+
pageLayout: options.target !== undefined,
|
|
25157
|
+
hostShowsAttribution: options.hostShowsAttribution === true,
|
|
24504
25158
|
onSession: (session) => {
|
|
24505
25159
|
anonymous = false;
|
|
24506
25160
|
if (options.persist)
|
|
@@ -24511,9 +25165,14 @@ function createHelpDeskSupport(config, options) {
|
|
|
24511
25165
|
customer,
|
|
24512
25166
|
signIn: (input) => signIn(input).then((session) => { contactCustomer = session.customer; return session; }),
|
|
24513
25167
|
switchAccount: (safe) => { void switchAccount(safe); },
|
|
24514
|
-
...(
|
|
25168
|
+
...(bridged && { useWebsiteAccount: (safe, recover) => { void useWebsiteAccount(safe, recover); } }),
|
|
25169
|
+
offerWebsiteAccount: switchedAccount,
|
|
25170
|
+
forgetIssue,
|
|
25171
|
+
followIssue,
|
|
25172
|
+
...(recovering && { recovering }),
|
|
24515
25173
|
},
|
|
24516
|
-
|
|
25174
|
+
onScreenChange: () => view.contactScreenChanged(),
|
|
25175
|
+
assistanceContext: () => (attempt === formAttempt ? activeAttempt?.ticketContext() : undefined),
|
|
24517
25176
|
sourceArticleId: () => sourceArticleId,
|
|
24518
25177
|
onError: (error) => {
|
|
24519
25178
|
notify(options.onError, error);
|
|
@@ -24532,11 +25191,14 @@ function createHelpDeskSupport(config, options) {
|
|
|
24532
25191
|
onSuccess: (ticket) => receipt(ticket),
|
|
24533
25192
|
onStateChange: (next) => update({ navigationLocked: ['authenticating', 'submitting', 'uncertain'].includes(next) }),
|
|
24534
25193
|
});
|
|
24535
|
-
|
|
24536
|
-
|
|
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.
|
|
24537
25199
|
followIssue();
|
|
24538
25200
|
const activeForm = contact;
|
|
24539
|
-
void
|
|
25201
|
+
void formAttempt?.then((active) => {
|
|
24540
25202
|
// Keep the mutable callback small: an analytics response arriving late
|
|
24541
25203
|
// must not delay contact, authentication or ticket submission.
|
|
24542
25204
|
if (contact === activeForm && active)
|
|
@@ -24552,10 +25214,30 @@ function createHelpDeskSupport(config, options) {
|
|
|
24552
25214
|
*/
|
|
24553
25215
|
function followIssue() {
|
|
24554
25216
|
const issue = state.issue.trim();
|
|
24555
|
-
if (!contact || !issue || issue === composedFrom)
|
|
25217
|
+
if (!contact || !issue || issue === composedFrom.trim())
|
|
24556
25218
|
return;
|
|
24557
|
-
if (contact.refill(
|
|
24558
|
-
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 });
|
|
24559
25241
|
}
|
|
24560
25242
|
async function showContact(reason) {
|
|
24561
25243
|
if (destroyed || contactOpening === sequence)
|
|
@@ -24602,12 +25284,16 @@ function createHelpDeskSupport(config, options) {
|
|
|
24602
25284
|
return;
|
|
24603
25285
|
update({ busy: false, ticketAccessRequired: false, ticketAccessMode: undefined });
|
|
24604
25286
|
anonymous = !customer;
|
|
24605
|
-
|
|
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;
|
|
24606
25294
|
if (customer && options.persist)
|
|
24607
25295
|
clearSupportIssue(active.desk.desk_id);
|
|
24608
|
-
|
|
24609
|
-
composedFrom = state.issue.trim();
|
|
24610
|
-
mountContact(composition, customer);
|
|
25296
|
+
mountContact(pendingComposition ?? saved, customer);
|
|
24611
25297
|
pendingComposition = null;
|
|
24612
25298
|
}
|
|
24613
25299
|
catch (value) {
|
|
@@ -24671,6 +25357,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24671
25357
|
cancelArticleAssets?.();
|
|
24672
25358
|
cancelArticleAssets = null;
|
|
24673
25359
|
pendingComposition = composition ?? { subject: '', body: '' };
|
|
25360
|
+
pendingRecovery = null;
|
|
24674
25361
|
kb?.clearAccess();
|
|
24675
25362
|
kbConfig = null;
|
|
24676
25363
|
results = [];
|
|
@@ -24710,7 +25397,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24710
25397
|
await showContact('direct');
|
|
24711
25398
|
}
|
|
24712
25399
|
}
|
|
24713
|
-
async function useWebsiteAccount(composition) {
|
|
25400
|
+
async function useWebsiteAccount(composition, recovering = false) {
|
|
24714
25401
|
if (!client || destroyed || state.navigationLocked)
|
|
24715
25402
|
return;
|
|
24716
25403
|
const ownSequence = ++sequence;
|
|
@@ -24719,6 +25406,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24719
25406
|
cancelArticleAssets?.();
|
|
24720
25407
|
cancelArticleAssets = null;
|
|
24721
25408
|
pendingComposition = composition ?? { subject: '', body: '' };
|
|
25409
|
+
pendingRecovery = recovering ? { websiteSignedOut: true } : null;
|
|
24722
25410
|
kb?.clearAccess();
|
|
24723
25411
|
kbConfig = null;
|
|
24724
25412
|
results = [];
|
|
@@ -24739,6 +25427,9 @@ function createHelpDeskSupport(config, options) {
|
|
|
24739
25427
|
return;
|
|
24740
25428
|
const error = failure(value);
|
|
24741
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 };
|
|
24742
25433
|
if (client.hasTicketAccess) {
|
|
24743
25434
|
mountContact(composition ?? { subject: '', body: '' }, null);
|
|
24744
25435
|
pendingComposition = null;
|
|
@@ -29553,7 +30244,7 @@ class SparkVault {
|
|
|
29553
30244
|
}
|
|
29554
30245
|
/** Get the SDK version */
|
|
29555
30246
|
static get version() {
|
|
29556
|
-
return '16.
|
|
30247
|
+
return '16.5.0';
|
|
29557
30248
|
}
|
|
29558
30249
|
}
|
|
29559
30250
|
if (typeof window !== 'undefined') {
|