@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.cjs
CHANGED
|
@@ -4396,15 +4396,108 @@ class LoadingView {
|
|
|
4396
4396
|
}
|
|
4397
4397
|
}
|
|
4398
4398
|
|
|
4399
|
+
/**
|
|
4400
|
+
* The sign-in providers' marks and the social networks' marks, each stated
|
|
4401
|
+
* once: the identity dialog (the browser SDK, which bundles this module) and
|
|
4402
|
+
* the console's Identity page draw the providers from here, and the marketing
|
|
4403
|
+
* site's footer and the help center's X post cards draw the networks, so no
|
|
4404
|
+
* two surfaces show one brand two ways.
|
|
4405
|
+
*
|
|
4406
|
+
* Every mark sits in one 24-unit box (BRAND_MARK_VIEWBOX), in one of two
|
|
4407
|
+
* forms, so each surface takes only the form it draws:
|
|
4408
|
+
* - BRAND_MARK_LAYERS: a sign-in provider's mark in its owner's colors, its
|
|
4409
|
+
* shapes painted in order, each `{ d, fill }`. A letter its owner draws
|
|
4410
|
+
* white (Facebook's "f", LinkedIn's "in") is a white shape over a solid
|
|
4411
|
+
* ground, never a cut-out, so a dark button cannot show through it. A
|
|
4412
|
+
* one-color logo (Apple, GitHub) fills with `currentColor`, taking the
|
|
4413
|
+
* color its surface sets for its icons.
|
|
4414
|
+
* - BRAND_MARK_SILHOUETTES: a network's mark as one shape with its letters
|
|
4415
|
+
* cut out, for a surface that paints it in one color.
|
|
4416
|
+
*
|
|
4417
|
+
* Facebook's, LinkedIn's, Instagram's and X's shapes are Simple Icons'
|
|
4418
|
+
* (CC0-1.0): Instagram's, Facebook's and X's from 16.38.0, LinkedIn's from
|
|
4419
|
+
* 13.21.0, the last release that ships it. Each silhouette is that path
|
|
4420
|
+
* exactly. LinkedIn's colored form is the silhouette's square and letters
|
|
4421
|
+
* apart; Facebook's is its whole circle under the cut-out "f", closed along
|
|
4422
|
+
* that circle.
|
|
4423
|
+
*
|
|
4424
|
+
* Browser-safe and import-free.
|
|
4425
|
+
*/
|
|
4426
|
+
|
|
4427
|
+
/** The box every mark is drawn in. */
|
|
4428
|
+
const BRAND_MARK_VIEWBOX = '0 0 24 24';
|
|
4429
|
+
|
|
4430
|
+
/**
|
|
4431
|
+
* Facebook's "f", from its left foot on the circle's edge up and around to its
|
|
4432
|
+
* right foot, (13.454, 23.956), also on the edge. The circle is centered on
|
|
4433
|
+
* (12, 12.044) with radius 12.
|
|
4434
|
+
*/
|
|
4435
|
+
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';
|
|
4436
|
+
|
|
4437
|
+
/** The short way along the circle's edge between the f's feet, closing the "f" itself. */
|
|
4438
|
+
const FACEBOOK_F_FOOT = 'A12 12 0 0 1 9.101 23.691Z';
|
|
4439
|
+
|
|
4440
|
+
/** Facebook's whole circle, the ground its white "f" stands on. */
|
|
4441
|
+
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';
|
|
4442
|
+
|
|
4443
|
+
/** LinkedIn's "in": the n, the i's dot, the i's stem. */
|
|
4444
|
+
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';
|
|
4445
|
+
|
|
4446
|
+
/** LinkedIn's rounded square, the ground its white "in" stands on. */
|
|
4447
|
+
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';
|
|
4448
|
+
|
|
4449
|
+
/** A white letter on its owner's ground. */
|
|
4450
|
+
const WHITE = '#FFFFFF';
|
|
4451
|
+
|
|
4452
|
+
function deepFreeze(value) {
|
|
4453
|
+
for (const child of Object.values(value)) {
|
|
4454
|
+
if (child && typeof child === 'object') deepFreeze(child);
|
|
4455
|
+
}
|
|
4456
|
+
return Object.freeze(value);
|
|
4457
|
+
}
|
|
4458
|
+
|
|
4459
|
+
/**
|
|
4460
|
+
* Each sign-in provider's mark in its owner's colors, by the identity
|
|
4461
|
+
* methods' icon name. Pure, so a bundle that draws no provider drops it.
|
|
4462
|
+
*/
|
|
4463
|
+
const BRAND_MARK_LAYERS = /* @__PURE__ */ deepFreeze({
|
|
4464
|
+
google: [
|
|
4465
|
+
{ 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' },
|
|
4466
|
+
{ 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' },
|
|
4467
|
+
{ 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' },
|
|
4468
|
+
{ 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' },
|
|
4469
|
+
],
|
|
4470
|
+
apple: [
|
|
4471
|
+
{ 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' },
|
|
4472
|
+
],
|
|
4473
|
+
microsoft: [
|
|
4474
|
+
{ d: 'M1 1h10v10H1z', fill: '#F25022' },
|
|
4475
|
+
{ d: 'M1 13h10v10H1z', fill: '#00A4EF' },
|
|
4476
|
+
{ d: 'M13 1h10v10H13z', fill: '#7FBA00' },
|
|
4477
|
+
{ d: 'M13 13h10v10H13z', fill: '#FFB900' },
|
|
4478
|
+
],
|
|
4479
|
+
github: [
|
|
4480
|
+
{ 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' },
|
|
4481
|
+
],
|
|
4482
|
+
facebook: [
|
|
4483
|
+
{ d: FACEBOOK_DISC, fill: '#0866FF' },
|
|
4484
|
+
{ d: FACEBOOK_F_OUTLINE + FACEBOOK_F_FOOT, fill: WHITE },
|
|
4485
|
+
],
|
|
4486
|
+
linkedin: [
|
|
4487
|
+
{ d: LINKEDIN_SQUARE, fill: '#0A66C2' },
|
|
4488
|
+
{ d: LINKEDIN_IN, fill: WHITE },
|
|
4489
|
+
],
|
|
4490
|
+
});
|
|
4491
|
+
|
|
4399
4492
|
/**
|
|
4400
4493
|
* SVG Icon Factory
|
|
4401
4494
|
*
|
|
4402
4495
|
* Bare outline glyphs per the SparkVault design system: stroke `currentColor`
|
|
4403
4496
|
* so the stylesheet drives color, no tinted container backgrounds, round
|
|
4404
|
-
* caps/joins. The sign-in providers' marks are
|
|
4405
|
-
*
|
|
4406
|
-
*
|
|
4407
|
-
* for security.
|
|
4497
|
+
* caps/joins. The sign-in providers' marks are their owners' filled logos,
|
|
4498
|
+
* drawn from `@sparkvault/app-sdk/brand-marks` in their owners' colors, a
|
|
4499
|
+
* one-color logo (Apple, GitHub) in `currentColor`. Uses proper DOM element
|
|
4500
|
+
* creation for security.
|
|
4408
4501
|
*/
|
|
4409
4502
|
function createSvgElement(viewBox, width = 16, height = 16) {
|
|
4410
4503
|
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
@@ -4554,17 +4647,12 @@ function methodIconGlyph(iconName) {
|
|
|
4554
4647
|
case 'link':
|
|
4555
4648
|
return createLinkIcon();
|
|
4556
4649
|
case 'google':
|
|
4557
|
-
return createGoogleIcon();
|
|
4558
4650
|
case 'apple':
|
|
4559
|
-
return createAppleIcon();
|
|
4560
4651
|
case 'microsoft':
|
|
4561
|
-
return createMicrosoftIcon();
|
|
4562
4652
|
case 'github':
|
|
4563
|
-
return createGithubIcon();
|
|
4564
4653
|
case 'facebook':
|
|
4565
|
-
return createFacebookIcon();
|
|
4566
4654
|
case 'linkedin':
|
|
4567
|
-
return
|
|
4655
|
+
return createBrandMarkIcon(iconName);
|
|
4568
4656
|
case 'building':
|
|
4569
4657
|
return createBuildingIcon();
|
|
4570
4658
|
case 'users':
|
|
@@ -4646,43 +4734,15 @@ function createLinkIcon() {
|
|
|
4646
4734
|
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'));
|
|
4647
4735
|
return svg;
|
|
4648
4736
|
}
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
svg
|
|
4655
|
-
|
|
4656
|
-
}
|
|
4657
|
-
|
|
4658
|
-
const svg = createSvgElement('0 0 20 20', 20, 20);
|
|
4659
|
-
svg.setAttribute('fill', 'currentColor');
|
|
4660
|
-
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'));
|
|
4661
|
-
return svg;
|
|
4662
|
-
}
|
|
4663
|
-
function createMicrosoftIcon() {
|
|
4664
|
-
const svg = createSvgElement('0 0 20 20', 20, 20);
|
|
4665
|
-
svg.appendChild(createPath('M1 1h8.33v8.33H1z', { fill: '#F25022' }));
|
|
4666
|
-
svg.appendChild(createPath('M1 10.67h8.33V19H1z', { fill: '#00A4EF' }));
|
|
4667
|
-
svg.appendChild(createPath('M10.67 1H19v8.33h-8.33z', { fill: '#7FBA00' }));
|
|
4668
|
-
svg.appendChild(createPath('M10.67 10.67H19V19h-8.33z', { fill: '#FFB900' }));
|
|
4669
|
-
return svg;
|
|
4670
|
-
}
|
|
4671
|
-
function createGithubIcon() {
|
|
4672
|
-
const svg = createSvgElement('0 0 20 20', 20, 20);
|
|
4673
|
-
svg.setAttribute('fill', 'currentColor');
|
|
4674
|
-
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'));
|
|
4675
|
-
return svg;
|
|
4676
|
-
}
|
|
4677
|
-
/** Facebook's mark and blue as Simple Icons (CC0-1.0) draws them, in its own 24-unit box. */
|
|
4678
|
-
function createFacebookIcon() {
|
|
4679
|
-
const svg = createSvgElement('0 0 24 24', 20, 20);
|
|
4680
|
-
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' }));
|
|
4681
|
-
return svg;
|
|
4682
|
-
}
|
|
4683
|
-
function createLinkedinIcon() {
|
|
4684
|
-
const svg = createSvgElement('0 0 20 20', 20, 20);
|
|
4685
|
-
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' }));
|
|
4737
|
+
/**
|
|
4738
|
+
* A sign-in provider's mark: its layers painted in order, each path carrying
|
|
4739
|
+
* its layer's own fill, which the svg's `fill="none"` never reaches.
|
|
4740
|
+
*/
|
|
4741
|
+
function createBrandMarkIcon(name) {
|
|
4742
|
+
const svg = createSvgElement(BRAND_MARK_VIEWBOX, 20, 20);
|
|
4743
|
+
for (const { d, fill } of BRAND_MARK_LAYERS[name]) {
|
|
4744
|
+
svg.appendChild(createPath(d, { fill }));
|
|
4745
|
+
}
|
|
4686
4746
|
return svg;
|
|
4687
4747
|
}
|
|
4688
4748
|
function createBuildingIcon() {
|
|
@@ -6398,8 +6458,9 @@ class ErrorView {
|
|
|
6398
6458
|
* neutrals. The published bundle cannot read those CSS files, so the values
|
|
6399
6459
|
* the widgets use are mirrored here, each naming the token it mirrors.
|
|
6400
6460
|
* tests/ds-tokens.test.ts holds every value to the design system's own, and
|
|
6401
|
-
* refuses a hex color anywhere else in the SDK's source (
|
|
6402
|
-
*
|
|
6461
|
+
* refuses a hex color anywhere else in the SDK's source and an rgba() whose
|
|
6462
|
+
* color is not the design system's. The sign-in providers' marks keep their
|
|
6463
|
+
* owners' colors, which live in @sparkvault/app-sdk/brand-marks.
|
|
6403
6464
|
*/
|
|
6404
6465
|
/** The design-system token each mirrored value is. */
|
|
6405
6466
|
/** The design system's values for {@link DS_TOKEN_SOURCES}. */
|
|
@@ -6880,6 +6941,50 @@ class OriginNotAllowedView {
|
|
|
6880
6941
|
}
|
|
6881
6942
|
}
|
|
6882
6943
|
|
|
6944
|
+
/**
|
|
6945
|
+
* How long a live region waits before it takes new words: long enough that
|
|
6946
|
+
* assistive technology has seen the change that prompted them, and hears the
|
|
6947
|
+
* region's own change as a change.
|
|
6948
|
+
*/
|
|
6949
|
+
const ANNOUNCE_DELAY_MS = 100;
|
|
6950
|
+
/**
|
|
6951
|
+
* A polite status region for words said as a view changes. It is placed
|
|
6952
|
+
* empty and kept, and every announcement waits a moment, so the words never
|
|
6953
|
+
* land in the same change as the region or the view that holds them: a
|
|
6954
|
+
* region created with its words already in it is often never announced.
|
|
6955
|
+
*/
|
|
6956
|
+
function createLiveRegion(className) {
|
|
6957
|
+
const element = document.createElement('div');
|
|
6958
|
+
element.className = className;
|
|
6959
|
+
element.setAttribute('role', 'status');
|
|
6960
|
+
element.setAttribute('aria-live', 'polite');
|
|
6961
|
+
element.setAttribute('aria-atomic', 'true');
|
|
6962
|
+
let timer = null;
|
|
6963
|
+
const cancel = () => {
|
|
6964
|
+
if (timer !== null)
|
|
6965
|
+
clearTimeout(timer);
|
|
6966
|
+
timer = null;
|
|
6967
|
+
};
|
|
6968
|
+
return {
|
|
6969
|
+
element,
|
|
6970
|
+
announce(words) {
|
|
6971
|
+
cancel();
|
|
6972
|
+
if (!words) {
|
|
6973
|
+
element.textContent = '';
|
|
6974
|
+
return;
|
|
6975
|
+
}
|
|
6976
|
+
timer = setTimeout(() => {
|
|
6977
|
+
timer = null;
|
|
6978
|
+
element.textContent = words;
|
|
6979
|
+
}, ANNOUNCE_DELAY_MS);
|
|
6980
|
+
},
|
|
6981
|
+
destroy() {
|
|
6982
|
+
cancel();
|
|
6983
|
+
element.remove();
|
|
6984
|
+
},
|
|
6985
|
+
};
|
|
6986
|
+
}
|
|
6987
|
+
|
|
6883
6988
|
/**
|
|
6884
6989
|
* Identity View Renderer
|
|
6885
6990
|
*
|
|
@@ -6908,12 +7013,6 @@ function blockedSignInMessage(companyName) {
|
|
|
6908
7013
|
: 'Sign-in is temporarily unavailable. Please contact the site owner for assistance.';
|
|
6909
7014
|
}
|
|
6910
7015
|
const BLOCKED_ERROR_CODES = new Set(IDENTITY_BLOCKED_ERROR_CODES);
|
|
6911
|
-
/**
|
|
6912
|
-
* How long the live region waits after a view is in place before it takes
|
|
6913
|
-
* the view's words: long enough that assistive technology has seen the
|
|
6914
|
-
* view's change and hears the region's as a change of its own.
|
|
6915
|
-
*/
|
|
6916
|
-
const STATUS_ANNOUNCE_DELAY_MS = 100;
|
|
6917
7016
|
const SPARKLINK_CSP_BLOCKED_ERROR = {
|
|
6918
7017
|
message: [
|
|
6919
7018
|
'Connection blocked by security policy.',
|
|
@@ -6960,11 +7059,8 @@ class IdentityRenderer {
|
|
|
6960
7059
|
this.untouchedStep = null;
|
|
6961
7060
|
// The page's one live region: placed beside the flow content when the
|
|
6962
7061
|
// container opens, empty, and kept across views, so the words a view
|
|
6963
|
-
// announces (View.announcement) land in a region already in the page
|
|
6964
|
-
// assistive technology hears change. A region created with its words already
|
|
6965
|
-
// in it is often never announced.
|
|
7062
|
+
// announces (View.announcement) land in a region already in the page.
|
|
6966
7063
|
this.statusRegion = null;
|
|
6967
|
-
this.statusTimer = null;
|
|
6968
7064
|
this.container = container;
|
|
6969
7065
|
this.api = api;
|
|
6970
7066
|
this.options = options;
|
|
@@ -7221,11 +7317,7 @@ class IdentityRenderer {
|
|
|
7221
7317
|
window.removeEventListener('pageshow', this.pageRestoreHandler);
|
|
7222
7318
|
this.pageRestoreHandler = null;
|
|
7223
7319
|
}
|
|
7224
|
-
|
|
7225
|
-
clearTimeout(this.statusTimer);
|
|
7226
|
-
this.statusTimer = null;
|
|
7227
|
-
}
|
|
7228
|
-
this.statusRegion?.remove();
|
|
7320
|
+
this.statusRegion?.destroy();
|
|
7229
7321
|
this.statusRegion = null;
|
|
7230
7322
|
this.cleanupSparkLink();
|
|
7231
7323
|
this.destroyCurrentView();
|
|
@@ -7470,7 +7562,7 @@ class IdentityRenderer {
|
|
|
7470
7562
|
this.container.setMinimalChrome(minimalChromeViews.includes(this.viewState.view));
|
|
7471
7563
|
const view = this.createViewForState(this.viewState);
|
|
7472
7564
|
this.currentView = view;
|
|
7473
|
-
this.announce(view.announcement ?? '');
|
|
7565
|
+
this.statusRegion?.announce(view.announcement ?? '');
|
|
7474
7566
|
const rendered = view.render();
|
|
7475
7567
|
// Each step enters with a calm fade + rise (see .sv-step-enter). The brand
|
|
7476
7568
|
// lockup and footer live outside `body`, so only the flow content moves.
|
|
@@ -7506,37 +7598,11 @@ class IdentityRenderer {
|
|
|
7506
7598
|
/** Place the empty live region beside the flow content, once per container. */
|
|
7507
7599
|
placeStatusRegion() {
|
|
7508
7600
|
const body = this.container.getBody();
|
|
7509
|
-
if (!body || this.statusRegion?.isConnected)
|
|
7601
|
+
if (!body || this.statusRegion?.element.isConnected)
|
|
7510
7602
|
return;
|
|
7511
|
-
|
|
7512
|
-
|
|
7513
|
-
|
|
7514
|
-
region.setAttribute('aria-live', 'polite');
|
|
7515
|
-
region.setAttribute('aria-atomic', 'true');
|
|
7516
|
-
body.insertAdjacentElement('beforebegin', region);
|
|
7517
|
-
this.statusRegion = region;
|
|
7518
|
-
}
|
|
7519
|
-
/**
|
|
7520
|
-
* Put `words` in the live region, a moment after the view that says them
|
|
7521
|
-
* is in place, so they never land in the same change as the region or the
|
|
7522
|
-
* view that holds them; empty words clear it at once.
|
|
7523
|
-
*/
|
|
7524
|
-
announce(words) {
|
|
7525
|
-
if (this.statusTimer !== null) {
|
|
7526
|
-
clearTimeout(this.statusTimer);
|
|
7527
|
-
this.statusTimer = null;
|
|
7528
|
-
}
|
|
7529
|
-
const region = this.statusRegion;
|
|
7530
|
-
if (!region)
|
|
7531
|
-
return;
|
|
7532
|
-
if (!words) {
|
|
7533
|
-
region.textContent = '';
|
|
7534
|
-
return;
|
|
7535
|
-
}
|
|
7536
|
-
this.statusTimer = setTimeout(() => {
|
|
7537
|
-
this.statusTimer = null;
|
|
7538
|
-
region.textContent = words;
|
|
7539
|
-
}, STATUS_ANNOUNCE_DELAY_MS);
|
|
7603
|
+
this.statusRegion?.destroy();
|
|
7604
|
+
this.statusRegion = createLiveRegion('sv-sr-only');
|
|
7605
|
+
body.insertAdjacentElement('beforebegin', this.statusRegion.element);
|
|
7540
7606
|
}
|
|
7541
7607
|
destroyCurrentView() {
|
|
7542
7608
|
if (this.currentView?.destroy) {
|
|
@@ -18178,16 +18244,16 @@ function injectHelpDeskFormStyles() {
|
|
|
18178
18244
|
.svhd-modal .svhd-container{max-width:none;border:0;border-radius:0;padding-top:8px}
|
|
18179
18245
|
.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}
|
|
18180
18246
|
.svhd-container *{box-sizing:border-box}
|
|
18181
|
-
.svhd-container h2{font-size:22px;line-height:1.25;margin:0
|
|
18247
|
+
.svhd-container h2{font-size:22px;line-height:1.25;margin:0}
|
|
18248
|
+
.svhd-step-head h2:focus{outline:none}
|
|
18182
18249
|
.svhd-form{display:grid;gap:16px}
|
|
18183
18250
|
.svhd-field{display:grid;gap:6px}
|
|
18184
18251
|
.svhd-label{font-weight:600}
|
|
18185
18252
|
.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}
|
|
18186
18253
|
.svhd-input:focus-visible,.svhd-button:focus-visible,.svhd-link:focus-visible{outline:3px solid ${DS.action};outline-offset:2px}
|
|
18187
18254
|
.svhd-input:disabled{background:${DS.slate50}}
|
|
18188
|
-
.svhd-description{min-height:140px;resize:vertical}
|
|
18189
18255
|
.svhd-auth{display:grid;gap:16px;border:0;padding:0;margin:0}
|
|
18190
|
-
.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}
|
|
18256
|
+
.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}
|
|
18191
18257
|
.svhd-actions{display:flex;align-items:center;gap:12px;flex-wrap:wrap}
|
|
18192
18258
|
.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}
|
|
18193
18259
|
.svhd-button:hover{background:${DS.actionHover}}
|
|
@@ -18205,14 +18271,53 @@ function injectHelpDeskFormStyles() {
|
|
|
18205
18271
|
.svhd-done-title:focus{outline:none}
|
|
18206
18272
|
.svhd-confirmation-message{white-space:pre-wrap;overflow-wrap:anywhere}
|
|
18207
18273
|
.svhd-link{display:inline-flex;align-items:center;justify-self:start;min-height:44px;color:${DS.action};text-decoration:underline}
|
|
18208
|
-
.svhd-
|
|
18209
|
-
.svhd-
|
|
18210
|
-
.svhd-
|
|
18211
|
-
.svhd-
|
|
18212
|
-
.svhd-
|
|
18213
|
-
.svhd-
|
|
18214
|
-
.svhd-
|
|
18215
|
-
.svhd-
|
|
18274
|
+
.svhd-hint{font-size:13px;color:${DS.slate600};margin:0}
|
|
18275
|
+
.svhd-step{display:grid;gap:16px;min-width:0}
|
|
18276
|
+
.svhd-step-head{display:grid;gap:4px;margin-bottom:4px}
|
|
18277
|
+
.svhd-step-label{margin:0;font-size:13px;font-weight:600;line-height:1.4;color:${DS.slate600}}
|
|
18278
|
+
.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}
|
|
18279
|
+
.svhd-text-button:hover{color:${DS.actionHover}}
|
|
18280
|
+
.svhd-text-button:focus-visible{outline:3px solid ${DS.action};outline-offset:2px}
|
|
18281
|
+
.svhd-text-button:disabled{color:${DS.slate500};cursor:default}
|
|
18282
|
+
.svhd-widget-account{display:flex;align-items:center;flex-wrap:wrap;gap:0 16px;min-width:0}
|
|
18283
|
+
.svhd-posting-as{margin:0;color:${DS.slate600};font-size:14px;line-height:1.5;overflow-wrap:anywhere}
|
|
18284
|
+
.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}
|
|
18285
|
+
.svhd-step .svhd-note svg{display:block;width:18px;height:18px;flex:none;margin-top:2px;color:${DS.action}}
|
|
18286
|
+
.svhd-recap{display:flex;align-items:center;gap:12px;padding:6px 6px 6px 14px;border:1px solid ${DS.slate200};border-radius:8px}
|
|
18287
|
+
.svhd-recap-request{flex:1;min-width:0}
|
|
18288
|
+
.svhd-recap-label{display:block;color:${DS.slate600};font-size:12px;font-weight:600;line-height:1.4}
|
|
18289
|
+
.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}
|
|
18290
|
+
.svhd-recap .svhd-text-button{flex:none}
|
|
18291
|
+
/* The frame is the field: its ring shows wherever focus is inside it, and the text inside draws none of its own. */
|
|
18292
|
+
.svhd-composer{position:relative;display:flex;flex-direction:column;min-width:0;border:1px solid ${DS.slate300};border-radius:6px;background:${DS.white}}
|
|
18293
|
+
.svhd-composer:has(.svhd-composer-input:focus-visible){outline:3px solid ${DS.action};outline-offset:2px}
|
|
18294
|
+
@supports not selector(:has(*)){.svhd-composer:focus-within{outline:3px solid ${DS.action};outline-offset:2px}}
|
|
18295
|
+
.svhd-composer-dragging{border-style:dashed;border-color:${DS.action}}
|
|
18296
|
+
.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}
|
|
18297
|
+
.svhd-composer-input:focus,.svhd-composer-input:focus-visible{outline:none}
|
|
18298
|
+
.svhd-composer-input:disabled{background:${DS.slate50}}
|
|
18299
|
+
.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}
|
|
18300
|
+
.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}}
|
|
18301
|
+
.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}
|
|
18302
|
+
.svhd-composer-attach:hover{background:${DS.slate100};color:${DS.slate900}}
|
|
18303
|
+
.svhd-composer-attach:disabled{opacity:.6;cursor:default}
|
|
18304
|
+
.svhd-composer .svhd-composer-attach svg{display:block;width:18px;height:18px}
|
|
18305
|
+
.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}}
|
|
18306
|
+
.svhd-composer-notice{margin:0;font-size:14px}
|
|
18307
|
+
.svhd-attachment-chips{display:flex;flex-wrap:wrap;gap:8px;list-style:none;margin:0;padding:8px;border-top:1px solid ${DS.slate200}}
|
|
18308
|
+
.svhd-attachment-chips:empty{display:none}
|
|
18309
|
+
.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}
|
|
18310
|
+
.svhd-attachment-name{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:600;color:${DS.slate900}}
|
|
18311
|
+
.svhd-attachment-status{grid-column:1;padding-right:8px;color:${DS.slate600};font-size:12px;overflow-wrap:anywhere}
|
|
18312
|
+
.svhd-attachment-status.svhd-error{color:${DS.error}}
|
|
18313
|
+
.svhd-attachment-progress{grid-column:1/-1;width:calc(100% - 10px);height:6px;margin-top:6px;accent-color:${DS.action}}
|
|
18314
|
+
.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}
|
|
18315
|
+
.svhd-attachment-remove:hover{background:${DS.slate200};color:${DS.slate900}}
|
|
18316
|
+
.svhd-attachment-chip .svhd-attachment-remove svg{display:block;width:16px;height:16px}
|
|
18317
|
+
.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}
|
|
18318
|
+
.svhd-composer button:focus-visible{outline:3px solid ${DS.action};outline-offset:-3px}
|
|
18319
|
+
.svhd-attachment-remove:disabled,.svhd-attachment-retry:disabled{opacity:.6;cursor:default}
|
|
18320
|
+
.svhd-live{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
|
|
18216
18321
|
.svhd-footer{margin-top:20px;font-size:12px;color:${DS.slate500}}
|
|
18217
18322
|
`;
|
|
18218
18323
|
document.head.appendChild(style);
|
|
@@ -18416,23 +18521,6 @@ function lastExtension(name) {
|
|
|
18416
18521
|
return shownExtension(closeUpSpaces(name));
|
|
18417
18522
|
}
|
|
18418
18523
|
|
|
18419
|
-
/**
|
|
18420
|
-
* The longest prefix of `text` within `maxLength` UTF-16 units that splits no
|
|
18421
|
-
* character.
|
|
18422
|
-
*
|
|
18423
|
-
* @param {string} text
|
|
18424
|
-
* @param {number} maxLength
|
|
18425
|
-
* @returns {string}
|
|
18426
|
-
*/
|
|
18427
|
-
function truncateToLength(text, maxLength) {
|
|
18428
|
-
let truncated = '';
|
|
18429
|
-
for (const character of text) {
|
|
18430
|
-
if (truncated.length + character.length > maxLength) break;
|
|
18431
|
-
truncated += character;
|
|
18432
|
-
}
|
|
18433
|
-
return truncated;
|
|
18434
|
-
}
|
|
18435
|
-
|
|
18436
18524
|
/**
|
|
18437
18525
|
* What a help-desk attachment may be named and what its first bytes may not
|
|
18438
18526
|
* be: the one list of the files a ticket accepts, beside the one list of
|
|
@@ -18731,6 +18819,15 @@ const ACCEPTED_ATTACHMENTS_COPY = acceptedKindsCopy(ACCEPTED_ATTACHMENT_KINDS);
|
|
|
18731
18819
|
const CUSTOMER_ATTACHMENTS_HINT =
|
|
18732
18820
|
`Add screenshots, documents or recordings. Up to ${MAX_ATTACHMENTS_PER_MESSAGE} files, ${formatBytes(CUSTOMER_ATTACHMENT_MAX_BYTES)} each.`;
|
|
18733
18821
|
|
|
18822
|
+
/**
|
|
18823
|
+
* What a customer reads at a desk that takes no files from its customers
|
|
18824
|
+
* (the desk lookup's `customer_can_attach_files` is false, the upload refusal
|
|
18825
|
+
* CUSTOMER_UPLOAD_REFUSALS.UPLOADS_OFF): the portal's refusal and its note on
|
|
18826
|
+
* the files an email left out, and the SDK's support form refusing a file
|
|
18827
|
+
* dropped, pasted or uploaded there.
|
|
18828
|
+
*/
|
|
18829
|
+
const NO_CUSTOMER_FILES_COPY = "This help desk doesn't take files from customers.";
|
|
18830
|
+
|
|
18734
18831
|
/**
|
|
18735
18832
|
* A file input's `accept`: every extension a ticket accepts
|
|
18736
18833
|
* (ACCEPTED_ATTACHMENT_EXTENSIONS), each with its dot, so the system's file
|
|
@@ -18778,7 +18875,56 @@ function refusalCopy(refusal, maxBytes) {
|
|
|
18778
18875
|
return REFUSAL_COPY[refusal] ?? "This file can't be attached.";
|
|
18779
18876
|
}
|
|
18780
18877
|
|
|
18781
|
-
|
|
18878
|
+
/**
|
|
18879
|
+
* The help desk's bare outline glyphs, shared by the support wizard and the
|
|
18880
|
+
* ticket form: stroked in `currentColor`, so the stylesheet that sizes them
|
|
18881
|
+
* also colors them, and hidden from assistive technology, since the control
|
|
18882
|
+
* that holds one names it.
|
|
18883
|
+
*/
|
|
18884
|
+
const PATHS = {
|
|
18885
|
+
back: 'm14.5 6-6 6 6 6',
|
|
18886
|
+
close: 'm6 6 12 12M18 6 6 18',
|
|
18887
|
+
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',
|
|
18888
|
+
check: 'm5 12 4 4L19 6',
|
|
18889
|
+
article: 'M14 3H6a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8Zm0 0v5h5M8 12h8M8 16h6',
|
|
18890
|
+
chevron: 'm9 6 6 6-6 6',
|
|
18891
|
+
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',
|
|
18892
|
+
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',
|
|
18893
|
+
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',
|
|
18894
|
+
info: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18Zm0-10v5m0-8h.01',
|
|
18895
|
+
};
|
|
18896
|
+
function helpDeskIcon(name) {
|
|
18897
|
+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
18898
|
+
svg.setAttribute('viewBox', '0 0 24 24');
|
|
18899
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
18900
|
+
svg.setAttribute('focusable', 'false');
|
|
18901
|
+
svg.setAttribute('fill', 'none');
|
|
18902
|
+
svg.setAttribute('stroke', 'currentColor');
|
|
18903
|
+
svg.setAttribute('stroke-width', '1.7');
|
|
18904
|
+
svg.setAttribute('stroke-linecap', 'round');
|
|
18905
|
+
svg.setAttribute('stroke-linejoin', 'round');
|
|
18906
|
+
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
18907
|
+
path.setAttribute('d', PATHS[name]);
|
|
18908
|
+
svg.append(path);
|
|
18909
|
+
return svg;
|
|
18910
|
+
}
|
|
18911
|
+
|
|
18912
|
+
/** A refusal of files read under the composer, hidden until there is one. */
|
|
18913
|
+
function createNotice() {
|
|
18914
|
+
const notice = document.createElement('p');
|
|
18915
|
+
notice.className = 'svhd-composer-notice svhd-error';
|
|
18916
|
+
notice.hidden = true;
|
|
18917
|
+
return notice;
|
|
18918
|
+
}
|
|
18919
|
+
/** Show a notice's refusal, or hide it with null. It is an alert only while it shows, as a field's error is. */
|
|
18920
|
+
function setNotice(notice, text) {
|
|
18921
|
+
notice.textContent = text ?? '';
|
|
18922
|
+
notice.hidden = text === null;
|
|
18923
|
+
if (text === null)
|
|
18924
|
+
notice.removeAttribute('role');
|
|
18925
|
+
else
|
|
18926
|
+
notice.setAttribute('role', 'alert');
|
|
18927
|
+
}
|
|
18782
18928
|
/** A failed mint's quota/size refusal remains a visible file error, never a silently omitted file. */
|
|
18783
18929
|
function problem(error) {
|
|
18784
18930
|
if (error instanceof SparkVaultError) {
|
|
@@ -18790,7 +18936,7 @@ function problem(error) {
|
|
|
18790
18936
|
}
|
|
18791
18937
|
if (error.statusCode === 402) {
|
|
18792
18938
|
const reason = error.details?.reason;
|
|
18793
|
-
return { copy: reason === CUSTOMER_UPLOAD_REFUSALS.UPLOADS_OFF ?
|
|
18939
|
+
return { copy: reason === CUSTOMER_UPLOAD_REFUSALS.UPLOADS_OFF ? NO_CUSTOMER_FILES_COPY
|
|
18794
18940
|
: reason === CUSTOMER_UPLOAD_REFUSALS.ALLOWANCE_REACHED ? 'You have reached this help desk’s upload allowance.'
|
|
18795
18941
|
: 'This help desk cannot store more files right now.', retryable: false };
|
|
18796
18942
|
}
|
|
@@ -18800,48 +18946,58 @@ function problem(error) {
|
|
|
18800
18946
|
}
|
|
18801
18947
|
return { copy: 'This file could not be uploaded. Try again or remove it.', retryable: true };
|
|
18802
18948
|
}
|
|
18803
|
-
/**
|
|
18804
|
-
|
|
18805
|
-
|
|
18806
|
-
|
|
18807
|
-
|
|
18808
|
-
|
|
18809
|
-
label.textContent = 'Attachments';
|
|
18810
|
-
label.htmlFor = `${prefix}-attachments`;
|
|
18949
|
+
/**
|
|
18950
|
+
* The picker owns each file's transfer; it publishes only IDs whose Forge
|
|
18951
|
+
* receipt has confirmed storage. `onEntriesChange` hears each file the
|
|
18952
|
+
* customer adds or removes.
|
|
18953
|
+
*/
|
|
18954
|
+
function createFormAttachments(client, prefix, context, onEntriesChange) {
|
|
18811
18955
|
const input = document.createElement('input');
|
|
18812
18956
|
input.type = 'file';
|
|
18813
18957
|
input.name = 'attachments';
|
|
18814
|
-
input.id = label.htmlFor;
|
|
18815
18958
|
input.multiple = true;
|
|
18816
18959
|
input.accept = ATTACHMENT_INPUT_ACCEPT;
|
|
18817
|
-
input.
|
|
18960
|
+
input.hidden = true;
|
|
18961
|
+
input.tabIndex = -1;
|
|
18818
18962
|
const hint = document.createElement('p');
|
|
18819
18963
|
hint.id = `${prefix}-attachment-hint`;
|
|
18820
|
-
hint.className = 'svhd-
|
|
18964
|
+
hint.className = 'svhd-composer-hint';
|
|
18821
18965
|
hint.textContent = CUSTOMER_ATTACHMENTS_HINT;
|
|
18822
|
-
|
|
18823
|
-
|
|
18824
|
-
|
|
18825
|
-
|
|
18826
|
-
|
|
18966
|
+
const attach = document.createElement('button');
|
|
18967
|
+
attach.type = 'button';
|
|
18968
|
+
attach.className = 'svhd-composer-attach';
|
|
18969
|
+
attach.setAttribute('aria-label', 'Attach files');
|
|
18970
|
+
attach.setAttribute('aria-describedby', hint.id);
|
|
18971
|
+
const attachText = document.createElement('span');
|
|
18972
|
+
attachText.textContent = 'Attach';
|
|
18973
|
+
attach.append(helpDeskIcon('paperclip'), attachText);
|
|
18974
|
+
const toolbar = document.createElement('div');
|
|
18975
|
+
toolbar.className = 'svhd-composer-toolbar';
|
|
18976
|
+
toolbar.append(attach, hint, input);
|
|
18977
|
+
const notice = createNotice();
|
|
18827
18978
|
const list = document.createElement('ul');
|
|
18828
|
-
list.className = 'svhd-
|
|
18829
|
-
list.setAttribute('aria-label', '
|
|
18830
|
-
element.append(label, input, hint, notice, list);
|
|
18979
|
+
list.className = 'svhd-attachment-chips';
|
|
18980
|
+
list.setAttribute('aria-label', 'Attached files');
|
|
18831
18981
|
let entries = [];
|
|
18832
18982
|
let revision = 0;
|
|
18833
18983
|
let locked = false;
|
|
18834
18984
|
let pickingDisabled = false;
|
|
18835
18985
|
let destroyed = false;
|
|
18836
18986
|
const current = (entry, ownRevision) => !destroyed && revision === ownRevision && entries.includes(entry) && !entry.controller?.signal.aborted;
|
|
18987
|
+
function syncPicking() {
|
|
18988
|
+
attach.disabled = locked || pickingDisabled;
|
|
18989
|
+
input.disabled = locked || pickingDisabled;
|
|
18990
|
+
}
|
|
18837
18991
|
function controls(entry) {
|
|
18838
18992
|
entry.remove.disabled = locked;
|
|
18839
18993
|
entry.retry.disabled = locked || !!entry.operation;
|
|
18840
18994
|
}
|
|
18841
18995
|
function update(entry, state, text) {
|
|
18842
18996
|
entry.state = state;
|
|
18997
|
+
entry.row.dataset.state = state;
|
|
18843
18998
|
entry.status.textContent = text;
|
|
18844
18999
|
entry.status.classList.toggle('svhd-error', state === 'failed');
|
|
19000
|
+
entry.progress.hidden = state !== 'uploading';
|
|
18845
19001
|
entry.retry.hidden = !(entry.retryable && (state === 'failed' || state === 'received'));
|
|
18846
19002
|
entry.retry.textContent = state === 'received' ? 'Check upload' : 'Retry';
|
|
18847
19003
|
entry.retry.setAttribute('aria-label', `${state === 'received' ? 'Check upload' : 'Retry'} ${entry.file.name}`);
|
|
@@ -18881,7 +19037,7 @@ function createFormAttachments(client, prefix, context) {
|
|
|
18881
19037
|
if (!stillCurrent())
|
|
18882
19038
|
return;
|
|
18883
19039
|
if (!owner) {
|
|
18884
|
-
update(entry, 'queued', '
|
|
19040
|
+
update(entry, 'queued', 'Uploads when you send your request.');
|
|
18885
19041
|
return;
|
|
18886
19042
|
}
|
|
18887
19043
|
const options = {
|
|
@@ -18964,54 +19120,70 @@ function createFormAttachments(client, prefix, context) {
|
|
|
18964
19120
|
function remove(entry) {
|
|
18965
19121
|
if (locked)
|
|
18966
19122
|
return;
|
|
19123
|
+
// A keyboard removal keeps focus among the files, else on Attach.
|
|
19124
|
+
const refocus = document.activeElement === entry.remove;
|
|
19125
|
+
const index = entries.indexOf(entry);
|
|
18967
19126
|
entry.controller?.abort();
|
|
18968
19127
|
entries = entries.filter(candidate => candidate !== entry);
|
|
18969
19128
|
entry.row.remove();
|
|
18970
|
-
notice
|
|
19129
|
+
setNotice(notice, null);
|
|
18971
19130
|
void cancel(entry);
|
|
19131
|
+
onEntriesChange();
|
|
19132
|
+
if (refocus)
|
|
19133
|
+
(entries[Math.min(index, entries.length - 1)]?.remove ?? attach).focus();
|
|
18972
19134
|
}
|
|
18973
19135
|
function add(files) {
|
|
18974
19136
|
if (locked || pickingDisabled || destroyed)
|
|
18975
19137
|
return;
|
|
18976
19138
|
const incoming = Array.from(files);
|
|
19139
|
+
if (incoming.length === 0)
|
|
19140
|
+
return;
|
|
18977
19141
|
const room = Math.max(0, MAX_ATTACHMENTS_PER_MESSAGE - entries.length);
|
|
18978
|
-
notice
|
|
18979
|
-
notice.textContent = `You can attach up to ${MAX_ATTACHMENTS_PER_MESSAGE} files. Remove a file before adding another.`;
|
|
19142
|
+
setNotice(notice, incoming.length > room ? `You can attach up to ${MAX_ATTACHMENTS_PER_MESSAGE} files. Remove a file before adding another.` : null);
|
|
18980
19143
|
for (const file of incoming.slice(0, room)) {
|
|
18981
19144
|
const row = document.createElement('li');
|
|
18982
|
-
row.className = 'svhd-
|
|
19145
|
+
row.className = 'svhd-attachment-chip';
|
|
18983
19146
|
const filename = document.createElement('span');
|
|
18984
|
-
filename.className = 'svhd-
|
|
19147
|
+
filename.className = 'svhd-attachment-name';
|
|
18985
19148
|
filename.textContent = file.name;
|
|
19149
|
+
filename.title = file.name;
|
|
18986
19150
|
const status = document.createElement('span');
|
|
19151
|
+
status.className = 'svhd-attachment-status';
|
|
18987
19152
|
status.setAttribute('role', 'status');
|
|
18988
19153
|
status.setAttribute('aria-live', 'polite');
|
|
18989
|
-
const progress =
|
|
19154
|
+
const progress = document.createElement('progress');
|
|
19155
|
+
progress.className = 'svhd-attachment-progress';
|
|
18990
19156
|
progress.max = 100;
|
|
18991
19157
|
progress.value = 0;
|
|
19158
|
+
progress.hidden = true;
|
|
18992
19159
|
progress.setAttribute('aria-label', `Upload progress for ${file.name}`);
|
|
18993
19160
|
const removeButton = document.createElement('button');
|
|
18994
19161
|
removeButton.type = 'button';
|
|
18995
|
-
removeButton.className = 'svhd-
|
|
18996
|
-
removeButton.textContent = 'Remove';
|
|
19162
|
+
removeButton.className = 'svhd-attachment-remove';
|
|
18997
19163
|
removeButton.setAttribute('aria-label', `Remove ${file.name}`);
|
|
19164
|
+
removeButton.append(helpDeskIcon('close'));
|
|
18998
19165
|
const retry = document.createElement('button');
|
|
18999
19166
|
retry.type = 'button';
|
|
19000
|
-
retry.className = 'svhd-
|
|
19167
|
+
retry.className = 'svhd-attachment-retry';
|
|
19001
19168
|
retry.hidden = true;
|
|
19002
19169
|
const entry = { file, row, status, progress, remove: removeButton, retry, state: 'queued', retryable: false };
|
|
19003
19170
|
removeButton.onclick = () => remove(entry);
|
|
19004
19171
|
retry.onclick = () => { if (!locked && entry.retryable)
|
|
19005
19172
|
void run(entry); };
|
|
19006
|
-
row.append(filename,
|
|
19173
|
+
row.append(filename, removeButton, status, retry, progress);
|
|
19007
19174
|
list.append(row);
|
|
19008
19175
|
entries.push(entry);
|
|
19009
19176
|
void run(entry);
|
|
19010
19177
|
}
|
|
19178
|
+
if (room > 0)
|
|
19179
|
+
onEntriesChange();
|
|
19011
19180
|
}
|
|
19012
19181
|
const onChange = () => { if (input.files)
|
|
19013
19182
|
add(input.files); input.value = ''; };
|
|
19183
|
+
const onAttach = () => { if (!attach.disabled)
|
|
19184
|
+
input.click(); };
|
|
19014
19185
|
input.addEventListener('change', onChange);
|
|
19186
|
+
attach.addEventListener('click', onAttach);
|
|
19015
19187
|
function clear(preserveComplete = false) {
|
|
19016
19188
|
revision += 1;
|
|
19017
19189
|
const previous = entries;
|
|
@@ -19023,17 +19195,20 @@ function createFormAttachments(client, prefix, context) {
|
|
|
19023
19195
|
}
|
|
19024
19196
|
list.replaceChildren();
|
|
19025
19197
|
input.value = '';
|
|
19026
|
-
notice
|
|
19198
|
+
setNotice(notice, null);
|
|
19027
19199
|
}
|
|
19028
19200
|
return {
|
|
19029
|
-
|
|
19201
|
+
toolbar,
|
|
19202
|
+
list,
|
|
19203
|
+
notice,
|
|
19204
|
+
get accepting() { return !locked && !pickingDisabled && !destroyed; },
|
|
19030
19205
|
get attachmentIds() { return entries.filter(entry => entry.state === 'complete' && entry.attachmentId).map(entry => entry.attachmentId); },
|
|
19031
19206
|
get unresolved() { return entries.some(entry => entry.state !== 'complete'); },
|
|
19032
19207
|
get hasEntries() { return entries.length > 0; },
|
|
19033
|
-
|
|
19208
|
+
add,
|
|
19034
19209
|
async start() { await Promise.all(entries.map(entry => entry.operation ?? (entry.state === 'queued' ? run(entry) : Promise.resolve()))); },
|
|
19035
|
-
lock(value) { locked = value;
|
|
19036
|
-
disablePicking(value) { pickingDisabled = value;
|
|
19210
|
+
lock(value) { locked = value; syncPicking(); entries.forEach(controls); },
|
|
19211
|
+
disablePicking(value) { pickingDisabled = value; syncPicking(); },
|
|
19037
19212
|
renewSession(previousToken, nextToken) {
|
|
19038
19213
|
for (const entry of entries) {
|
|
19039
19214
|
if (entry.context?.expectedSessionToken === previousToken)
|
|
@@ -19041,11 +19216,175 @@ function createFormAttachments(client, prefix, context) {
|
|
|
19041
19216
|
}
|
|
19042
19217
|
},
|
|
19043
19218
|
clear,
|
|
19044
|
-
destroy(preserveComplete = false) {
|
|
19219
|
+
destroy(preserveComplete = false) {
|
|
19220
|
+
destroyed = true;
|
|
19221
|
+
clear(preserveComplete);
|
|
19222
|
+
input.removeEventListener('change', onChange);
|
|
19223
|
+
attach.removeEventListener('click', onAttach);
|
|
19224
|
+
},
|
|
19225
|
+
};
|
|
19226
|
+
}
|
|
19227
|
+
|
|
19228
|
+
const FOLDER_COPY = 'Folders can’t be attached. Add the files inside them instead.';
|
|
19229
|
+
function carriesFiles(event) {
|
|
19230
|
+
return Array.from(event.dataTransfer?.types ?? []).includes('Files');
|
|
19231
|
+
}
|
|
19232
|
+
/**
|
|
19233
|
+
* The details field as a composer. A file pasted into the summary or the
|
|
19234
|
+
* details, or dropped anywhere on the request step, joins the form's one
|
|
19235
|
+
* attachment pipeline (`attachments.add`), under the same limits and
|
|
19236
|
+
* refusals as a picked one; the drop target shows only over the composer. A
|
|
19237
|
+
* paste or drag of text alone stays the browser's. A file brought over the
|
|
19238
|
+
* form is never the browser's to open in place of the unsent request: on the
|
|
19239
|
+
* reply-to step, or while the form takes no files, it is refused outright,
|
|
19240
|
+
* and a desk that takes no files says so when the file is dropped.
|
|
19241
|
+
*/
|
|
19242
|
+
function createComposer(options) {
|
|
19243
|
+
const { form, summary, textarea, attachments, deskRefusesFiles, onRequestStep } = options;
|
|
19244
|
+
const frame = document.createElement('div');
|
|
19245
|
+
frame.className = 'svhd-composer';
|
|
19246
|
+
textarea.classList.add('svhd-composer-input');
|
|
19247
|
+
const drop = document.createElement('p');
|
|
19248
|
+
drop.className = 'svhd-composer-drop';
|
|
19249
|
+
drop.textContent = 'Drop the files to attach them.';
|
|
19250
|
+
drop.hidden = true;
|
|
19251
|
+
frame.append(textarea, drop);
|
|
19252
|
+
if (attachments)
|
|
19253
|
+
frame.append(attachments.toolbar, attachments.list);
|
|
19254
|
+
const notice = attachments?.notice ?? createNotice();
|
|
19255
|
+
const fields = [summary, textarea];
|
|
19256
|
+
let pastedImages = 0;
|
|
19257
|
+
function fileAction() {
|
|
19258
|
+
if (!onRequestStep())
|
|
19259
|
+
return 'none';
|
|
19260
|
+
if (attachments)
|
|
19261
|
+
return attachments.accepting ? 'attach' : 'none';
|
|
19262
|
+
return deskRefusesFiles ? 'refuse' : 'none';
|
|
19263
|
+
}
|
|
19264
|
+
function dragging(value) {
|
|
19265
|
+
frame.classList.toggle('svhd-composer-dragging', value);
|
|
19266
|
+
drop.hidden = !value;
|
|
19267
|
+
}
|
|
19268
|
+
function refuseFiles() {
|
|
19269
|
+
if (!notice.hidden && notice.textContent === NO_CUSTOMER_FILES_COPY)
|
|
19270
|
+
return;
|
|
19271
|
+
setNotice(notice, NO_CUSTOMER_FILES_COPY);
|
|
19272
|
+
}
|
|
19273
|
+
// A dropped folder arrives as a file that cannot be read, so it is left out,
|
|
19274
|
+
// and said so beside any refusal the files with it met.
|
|
19275
|
+
function attachDropped(transfer) {
|
|
19276
|
+
const files = [];
|
|
19277
|
+
let folders = 0;
|
|
19278
|
+
for (const item of Array.from(transfer.items)) {
|
|
19279
|
+
if (item.kind !== 'file')
|
|
19280
|
+
continue;
|
|
19281
|
+
if (item.webkitGetAsEntry()?.isDirectory) {
|
|
19282
|
+
folders += 1;
|
|
19283
|
+
continue;
|
|
19284
|
+
}
|
|
19285
|
+
const file = item.getAsFile();
|
|
19286
|
+
if (file)
|
|
19287
|
+
files.push(file);
|
|
19288
|
+
}
|
|
19289
|
+
if (files.length > 0)
|
|
19290
|
+
attachments?.add(files);
|
|
19291
|
+
if (folders > 0)
|
|
19292
|
+
setNotice(notice, files.length > 0 && !notice.hidden ? `${FOLDER_COPY} ${notice.textContent}` : FOLDER_COPY);
|
|
19293
|
+
}
|
|
19294
|
+
// A picture pasted from the clipboard is named "image.png" every time;
|
|
19295
|
+
// numbering the pastes tells their chips, and their Remove buttons, apart.
|
|
19296
|
+
function pastedName(file) {
|
|
19297
|
+
const extension = /^image\.(\w+)$/.exec(file.name)?.[1];
|
|
19298
|
+
if (extension === undefined)
|
|
19299
|
+
return file;
|
|
19300
|
+
pastedImages += 1;
|
|
19301
|
+
return new File([file], `Pasted image ${pastedImages}.${extension}`, { type: file.type, lastModified: file.lastModified });
|
|
19302
|
+
}
|
|
19303
|
+
// Cancelling dragenter and dragover keeps the browser from opening the file
|
|
19304
|
+
// in place of the page. A drop effect of none cancels the drop itself, so a
|
|
19305
|
+
// file the desk refuses keeps one to be refused in words when it lands.
|
|
19306
|
+
const onDragOver = (event) => {
|
|
19307
|
+
if (!carriesFiles(event))
|
|
19308
|
+
return;
|
|
19309
|
+
event.preventDefault();
|
|
19310
|
+
const action = fileAction();
|
|
19311
|
+
if (event.dataTransfer)
|
|
19312
|
+
event.dataTransfer.dropEffect = action === 'none' ? 'none' : 'copy';
|
|
19313
|
+
dragging(action === 'attach' && event.target instanceof Node && frame.contains(event.target));
|
|
19314
|
+
};
|
|
19315
|
+
const onDragLeave = (event) => {
|
|
19316
|
+
if (!(event.relatedTarget instanceof Node) || !frame.contains(event.relatedTarget))
|
|
19317
|
+
dragging(false);
|
|
19318
|
+
};
|
|
19319
|
+
const onDrop = (event) => {
|
|
19320
|
+
if (!carriesFiles(event))
|
|
19321
|
+
return;
|
|
19322
|
+
event.preventDefault();
|
|
19323
|
+
dragging(false);
|
|
19324
|
+
const action = fileAction();
|
|
19325
|
+
if (action === 'attach' && event.dataTransfer)
|
|
19326
|
+
attachDropped(event.dataTransfer);
|
|
19327
|
+
else if (action === 'refuse')
|
|
19328
|
+
refuseFiles();
|
|
19329
|
+
};
|
|
19330
|
+
// A paste that carries files is those files, and the text beside them is
|
|
19331
|
+
// only their names (a file copied in the system's file manager), so none of
|
|
19332
|
+
// it lands in the field. Office apps are the exception: copied cells or
|
|
19333
|
+
// paragraphs come as text and formatted text, with a picture of them as a
|
|
19334
|
+
// file, and that paste is the text.
|
|
19335
|
+
const onPaste = (event) => {
|
|
19336
|
+
const clipboard = event.clipboardData;
|
|
19337
|
+
if (!clipboard || clipboard.files.length === 0)
|
|
19338
|
+
return;
|
|
19339
|
+
if (Array.from(clipboard.types).includes('text/html') && clipboard.getData('text/plain'))
|
|
19340
|
+
return;
|
|
19341
|
+
const action = fileAction();
|
|
19342
|
+
if (action === 'none')
|
|
19343
|
+
return;
|
|
19344
|
+
event.preventDefault();
|
|
19345
|
+
if (action === 'attach')
|
|
19346
|
+
attachments?.add(Array.from(clipboard.files, pastedName));
|
|
19347
|
+
else
|
|
19348
|
+
refuseFiles();
|
|
19349
|
+
};
|
|
19350
|
+
const onInput = () => { if (!attachments)
|
|
19351
|
+
setNotice(notice, null); };
|
|
19352
|
+
form.addEventListener('dragenter', onDragOver);
|
|
19353
|
+
form.addEventListener('dragover', onDragOver);
|
|
19354
|
+
form.addEventListener('dragleave', onDragLeave);
|
|
19355
|
+
form.addEventListener('drop', onDrop);
|
|
19356
|
+
for (const field of fields) {
|
|
19357
|
+
field.addEventListener('paste', onPaste);
|
|
19358
|
+
field.addEventListener('input', onInput);
|
|
19359
|
+
}
|
|
19360
|
+
return {
|
|
19361
|
+
frame,
|
|
19362
|
+
notice,
|
|
19363
|
+
clearNotice: () => setNotice(notice, null),
|
|
19364
|
+
destroy() {
|
|
19365
|
+
form.removeEventListener('dragenter', onDragOver);
|
|
19366
|
+
form.removeEventListener('dragover', onDragOver);
|
|
19367
|
+
form.removeEventListener('dragleave', onDragLeave);
|
|
19368
|
+
form.removeEventListener('drop', onDrop);
|
|
19369
|
+
for (const field of fields) {
|
|
19370
|
+
field.removeEventListener('paste', onPaste);
|
|
19371
|
+
field.removeEventListener('input', onInput);
|
|
19372
|
+
}
|
|
19373
|
+
},
|
|
19045
19374
|
};
|
|
19046
19375
|
}
|
|
19047
19376
|
|
|
19048
19377
|
const TTL_MS = 30 * 60 * 1000;
|
|
19378
|
+
/** JSON writes one character of a field as up to six: a control character or lone surrogate becomes an escape like \u0001. */
|
|
19379
|
+
const MAX_ESCAPED_CHAR = 6;
|
|
19380
|
+
/** Room in a row for its keys, ids, timestamps, attachment list and article id. */
|
|
19381
|
+
const ROW_FRAME_CHARS = 8192;
|
|
19382
|
+
/** The longest row a writer can store with these fields, so a reader refuses only rows no writer made. */
|
|
19383
|
+
const maxRowChars = (bodies, subjects) => MAX_ESCAPED_CHAR * (bodies * MAX_BODY_BYTES + subjects * MAX_SUBJECT_LEN) + ROW_FRAME_CHARS;
|
|
19384
|
+
/** The question, the request's subject and description, and the question the request was filled from. */
|
|
19385
|
+
const MAX_ISSUE_ROW_CHARS = maxRowChars(3, 1);
|
|
19386
|
+
/** The request and the uncertain send, each with a subject and description. */
|
|
19387
|
+
const MAX_DRAFT_ROW_CHARS = maxRowChars(2, 2);
|
|
19049
19388
|
const storageKey = (deskId, requesterId) => isHelpDeskId(deskId) && isResourceIdOf('requester', requesterId) ? `sv-hd-draft:${deskId}:${requesterId}:new` : null;
|
|
19050
19389
|
const validBody = (value) => typeof value === 'string' && value.length <= MAX_BODY_BYTES && new TextEncoder().encode(value).length <= MAX_BODY_BYTES;
|
|
19051
19390
|
const validSubject = (value) => typeof value === 'string' && value.length <= MAX_SUBJECT_LEN;
|
|
@@ -19066,14 +19405,19 @@ function readSupportDraft(deskId) {
|
|
|
19066
19405
|
const raw = sessionStorage.getItem(`sv-hd-issue:${deskId}`);
|
|
19067
19406
|
if (!raw)
|
|
19068
19407
|
return null;
|
|
19069
|
-
if (raw.length >
|
|
19408
|
+
if (raw.length > MAX_ISSUE_ROW_CHARS)
|
|
19070
19409
|
throw new Error('Invalid issue');
|
|
19071
19410
|
const row = JSON.parse(raw);
|
|
19072
19411
|
if (row?.desk_id !== deskId || !validBody(row.issue) || !Number.isFinite(row.expires_at) ||
|
|
19073
19412
|
row.expires_at <= Date.now() || row.expires_at > Date.now() + TTL_MS ||
|
|
19074
19413
|
(row.composition !== undefined && (!validSubject(row.composition?.subject) || !validBody(row.composition?.body))))
|
|
19075
19414
|
throw new Error('Invalid issue');
|
|
19076
|
-
|
|
19415
|
+
if (row.composition === undefined)
|
|
19416
|
+
return { issue: row.issue };
|
|
19417
|
+
// The question a request was filled from only steers refilling it: one that
|
|
19418
|
+
// is not a question, or belongs to no request, is left out, never the row.
|
|
19419
|
+
return { issue: row.issue, composition: { subject: row.composition.subject, body: row.composition.body },
|
|
19420
|
+
...(validBody(row.composed_from) && { composedFrom: row.composed_from }) };
|
|
19077
19421
|
}
|
|
19078
19422
|
catch {
|
|
19079
19423
|
clearSupportIssue(deskId);
|
|
@@ -19081,25 +19425,34 @@ function readSupportDraft(deskId) {
|
|
|
19081
19425
|
}
|
|
19082
19426
|
}
|
|
19083
19427
|
function readSupportIssue(deskId) { return readSupportDraft(deskId)?.issue ?? null; }
|
|
19084
|
-
function readAnonymousFormDraft(deskId) {
|
|
19085
|
-
|
|
19428
|
+
function readAnonymousFormDraft(deskId) {
|
|
19429
|
+
const draft = readSupportDraft(deskId);
|
|
19430
|
+
return draft?.composition ? { ...draft.composition, composedFrom: draft.composedFrom ?? '' } : null;
|
|
19431
|
+
}
|
|
19432
|
+
function writeSupportDraft(deskId, draft) {
|
|
19086
19433
|
try {
|
|
19087
|
-
sessionStorage.setItem(`sv-hd-issue:${deskId}`, JSON.stringify({ desk_id: deskId, issue,
|
|
19088
|
-
...(composition && { composition }),
|
|
19434
|
+
sessionStorage.setItem(`sv-hd-issue:${deskId}`, JSON.stringify({ desk_id: deskId, issue: draft.issue,
|
|
19435
|
+
...(draft.composition && { composition: draft.composition }), ...(draft.composedFrom !== undefined && { composed_from: draft.composedFrom }),
|
|
19436
|
+
expires_at: Date.now() + TTL_MS }));
|
|
19089
19437
|
}
|
|
19090
19438
|
catch { /* The live wizard still keeps its composition in memory. */ }
|
|
19091
19439
|
}
|
|
19092
19440
|
function saveSupportIssue(deskId, issue) {
|
|
19093
19441
|
if (!isHelpDeskId(deskId) || !validBody(issue))
|
|
19094
19442
|
return;
|
|
19095
|
-
const
|
|
19096
|
-
if (!issue && !composition) {
|
|
19443
|
+
const draft = readSupportDraft(deskId);
|
|
19444
|
+
if (!issue && !draft?.composition) {
|
|
19097
19445
|
clearSupportIssue(deskId);
|
|
19098
19446
|
return;
|
|
19099
19447
|
}
|
|
19100
|
-
writeSupportDraft(deskId,
|
|
19448
|
+
writeSupportDraft(deskId, { ...draft, issue });
|
|
19101
19449
|
}
|
|
19102
|
-
|
|
19450
|
+
/**
|
|
19451
|
+
* Save a signed-out customer's request beside the tab's question, with the
|
|
19452
|
+
* question it was filled from when the support wizard filled it. A question
|
|
19453
|
+
* too long to keep is left out, so the request reads as the customer's own.
|
|
19454
|
+
*/
|
|
19455
|
+
function saveAnonymousFormDraft(deskId, composition, composedFrom) {
|
|
19103
19456
|
if (!isHelpDeskId(deskId) || !validSubject(composition.subject) || !validBody(composition.body))
|
|
19104
19457
|
return;
|
|
19105
19458
|
const issue = readSupportIssue(deskId) ?? '';
|
|
@@ -19107,7 +19460,7 @@ function saveAnonymousFormDraft(deskId, composition) {
|
|
|
19107
19460
|
clearSupportIssue(deskId);
|
|
19108
19461
|
return;
|
|
19109
19462
|
}
|
|
19110
|
-
writeSupportDraft(deskId, issue, { subject: composition.subject, body: composition.body });
|
|
19463
|
+
writeSupportDraft(deskId, { issue, composition: { subject: composition.subject, body: composition.body }, ...(validBody(composedFrom) && { composedFrom }) });
|
|
19111
19464
|
}
|
|
19112
19465
|
function removeFormDraft(deskId, requesterId) {
|
|
19113
19466
|
const key = storageKey(deskId, requesterId);
|
|
@@ -19125,7 +19478,7 @@ function readFormDraft(deskId, requesterId) {
|
|
|
19125
19478
|
const raw = sessionStorage.getItem(key);
|
|
19126
19479
|
if (!raw)
|
|
19127
19480
|
return null;
|
|
19128
|
-
if (raw.length >
|
|
19481
|
+
if (raw.length > MAX_DRAFT_ROW_CHARS)
|
|
19129
19482
|
throw new Error('Invalid draft');
|
|
19130
19483
|
const row = JSON.parse(raw);
|
|
19131
19484
|
const sent = row?.uncertain;
|
|
@@ -19174,9 +19527,47 @@ function unknownSubmissionOutcome(error) {
|
|
|
19174
19527
|
const status = error instanceof SparkVaultError ? error.statusCode : undefined;
|
|
19175
19528
|
return status === undefined || status < 400 || status === 408 || status >= 500;
|
|
19176
19529
|
}
|
|
19177
|
-
|
|
19178
|
-
|
|
19530
|
+
/**
|
|
19531
|
+
* A ticket's body: the details the customer wrote, or, when they wrote none,
|
|
19532
|
+
* the summary, since every ticket carries a message. The one place the two
|
|
19533
|
+
* fields become the body that is checked against the limit and sent.
|
|
19534
|
+
*/
|
|
19535
|
+
function ticketBody(summary, details) {
|
|
19536
|
+
return details.trim() ? details : summary;
|
|
19537
|
+
}
|
|
19538
|
+
/** The details field that gives a send's body back through `ticketBody`: empty when the body is its summary. */
|
|
19539
|
+
function detailsOf(submission) {
|
|
19540
|
+
return submission.body === submission.subject ? '' : submission.body;
|
|
19541
|
+
}
|
|
19542
|
+
/** A signed-in customer as the form names them: "Alex M." for Alex Morgan, a one-word name as it is, else their email. */
|
|
19543
|
+
function postingName(customer) {
|
|
19544
|
+
const words = (customer.display_name ?? '').trim().split(/\s+/).filter(Boolean);
|
|
19545
|
+
if (words.length === 0)
|
|
19546
|
+
return customer.email;
|
|
19547
|
+
if (words.length === 1)
|
|
19548
|
+
return words[0];
|
|
19549
|
+
return `${words[0]} ${Array.from(words[words.length - 1])[0]}.`;
|
|
19550
|
+
}
|
|
19551
|
+
function focusAtEnd(field, focusOptions) {
|
|
19552
|
+
field.focus(focusOptions);
|
|
19553
|
+
// An email field has no caret to place.
|
|
19554
|
+
if (field.type !== 'email')
|
|
19555
|
+
field.setSelectionRange(field.value.length, field.value.length);
|
|
19556
|
+
}
|
|
19557
|
+
/** A button that reads as a link: an action beside text, never the step's own. */
|
|
19558
|
+
function textButton(text, action) {
|
|
19559
|
+
const button = document.createElement('button');
|
|
19560
|
+
button.type = 'button';
|
|
19561
|
+
button.className = 'svhd-text-button';
|
|
19562
|
+
button.textContent = text;
|
|
19563
|
+
button.addEventListener('click', action);
|
|
19564
|
+
return button;
|
|
19179
19565
|
}
|
|
19566
|
+
const SIGN_IN_CANCELLED_COPY = 'Sign-in was cancelled. Your request is still here and hasn’t been sent.';
|
|
19567
|
+
const RECOVER_STATUS_COPY = 'Sign in again to recover your saved request.';
|
|
19568
|
+
const RECOVER_WEBSITE_COPY = 'Sign in to your website account again to recover your saved request.';
|
|
19569
|
+
const WEBSITE_SIGNED_OUT_COPY = 'You’re not signed in to the website. Sign in there, then choose Use website account again.';
|
|
19570
|
+
const RECOVER_NOTE_COPY = 'Sign in with the same email as before to recover your saved request.';
|
|
19180
19571
|
/** Host callback failures do not change a ticket's accepted or failed result. */
|
|
19181
19572
|
function notify$1(callback, value) {
|
|
19182
19573
|
try {
|
|
@@ -19204,6 +19595,22 @@ function edited(input, prefill) {
|
|
|
19204
19595
|
const text = input.value.trim();
|
|
19205
19596
|
return text !== '' && text !== prefill.trim();
|
|
19206
19597
|
}
|
|
19598
|
+
/**
|
|
19599
|
+
* The longest issue that fills the summary when contact starts. An issue this
|
|
19600
|
+
* short, on one line, already names the request; a longer one is the
|
|
19601
|
+
* customer's description, and cutting a summary from it would put words in
|
|
19602
|
+
* their mouth.
|
|
19603
|
+
*/
|
|
19604
|
+
const SUMMARY_PREFILL_MAX = 100;
|
|
19605
|
+
/** Whether trimmed text is one line of at most `max` characters. */
|
|
19606
|
+
function oneLine(text, max) {
|
|
19607
|
+
return text.length <= max && !/[\r\n]/.test(text);
|
|
19608
|
+
}
|
|
19609
|
+
/** What contact starts from: a short one-line issue as the summary; any other as the details, every character as written. */
|
|
19610
|
+
function composeIssue(issue) {
|
|
19611
|
+
const text = issue.trim();
|
|
19612
|
+
return oneLine(text, SUMMARY_PREFILL_MAX) ? { subject: text, body: '' } : { subject: '', body: issue };
|
|
19613
|
+
}
|
|
19207
19614
|
function companySignInUrl(value) {
|
|
19208
19615
|
try {
|
|
19209
19616
|
const url = new URL(value ?? '');
|
|
@@ -19223,24 +19630,54 @@ function companySignInUrl(value) {
|
|
|
19223
19630
|
* line carries the flow (a code sent, a send in progress or uncertain, a
|
|
19224
19631
|
* changed sign-in, a server error). Closing with unsent work asks first.
|
|
19225
19632
|
* A confirmed send replaces the form with its confirmation.
|
|
19633
|
+
*
|
|
19634
|
+
* The request is a summary and optional details, in a composer that also
|
|
19635
|
+
* takes files. A signed-out widget customer writes it as step 1 of 2; step 2
|
|
19636
|
+
* asks who the reply goes to and proves it in the native sign-in window.
|
|
19226
19637
|
*/
|
|
19227
19638
|
function mountHelpDeskForm(client, options) {
|
|
19228
19639
|
const target = resolveTarget(options.target);
|
|
19229
19640
|
injectHelpDeskFormStyles();
|
|
19641
|
+
const widget = options.widgetIdentity;
|
|
19230
19642
|
const shell = new InlineShell(target, {
|
|
19231
19643
|
containerClassName: 'svhd-container',
|
|
19232
19644
|
bodyClassName: 'svhd-body',
|
|
19233
|
-
|
|
19645
|
+
// The page that lays the support wizard out carries the attribution itself.
|
|
19646
|
+
footer: options.hostShowsAttribution ? null : createSecuredByFooter('svhd'),
|
|
19234
19647
|
});
|
|
19235
19648
|
const prefix = `svhd-${++formSequence}`;
|
|
19236
|
-
const heading = document.createElement('h2');
|
|
19237
|
-
heading.id = `${prefix}-heading`;
|
|
19238
|
-
heading.textContent = 'Contact support';
|
|
19239
19649
|
const form = document.createElement('form');
|
|
19240
19650
|
form.className = 'svhd-form';
|
|
19241
19651
|
form.noValidate = true;
|
|
19652
|
+
shell.body.append(form);
|
|
19653
|
+
/** A step's heading, which takes focus when the step is entered, under its "Step N of 2" label when it has one. */
|
|
19654
|
+
function stepHead(id, title, label) {
|
|
19655
|
+
const head = document.createElement('div');
|
|
19656
|
+
head.className = 'svhd-step-head';
|
|
19657
|
+
const stepLabel = label === null ? null : document.createElement('p');
|
|
19658
|
+
if (stepLabel) {
|
|
19659
|
+
stepLabel.className = 'svhd-step-label';
|
|
19660
|
+
stepLabel.textContent = label;
|
|
19661
|
+
head.append(stepLabel);
|
|
19662
|
+
}
|
|
19663
|
+
const stepHeading = document.createElement('h2');
|
|
19664
|
+
stepHeading.id = id;
|
|
19665
|
+
stepHeading.tabIndex = -1;
|
|
19666
|
+
stepHeading.textContent = title;
|
|
19667
|
+
head.append(stepHeading);
|
|
19668
|
+
return { head, heading: stepHeading, label: stepLabel };
|
|
19669
|
+
}
|
|
19670
|
+
function stepContainer(step) {
|
|
19671
|
+
const container = document.createElement('div');
|
|
19672
|
+
container.className = 'svhd-step';
|
|
19673
|
+
container.dataset.contactStep = step;
|
|
19674
|
+
return container;
|
|
19675
|
+
}
|
|
19676
|
+
const request = stepHead(`${prefix}-heading`, widget ? `Contact ${client.desk.organization_name || 'support'}` : 'Contact support', widget ? 'Step 1 of 2' : null);
|
|
19677
|
+
const heading = request.heading;
|
|
19242
19678
|
form.setAttribute('aria-labelledby', heading.id);
|
|
19243
|
-
|
|
19679
|
+
const details = stepContainer('details');
|
|
19680
|
+
details.append(request.head);
|
|
19244
19681
|
// A field's error is an alert only while it shows, so it is announced
|
|
19245
19682
|
// even when focus already sits on the field it names.
|
|
19246
19683
|
function setFieldError(entry, text) {
|
|
@@ -19272,10 +19709,11 @@ function mountHelpDeskForm(client, options) {
|
|
|
19272
19709
|
label.className = 'svhd-label';
|
|
19273
19710
|
label.htmlFor = `${prefix}-${name}`;
|
|
19274
19711
|
label.textContent = labelText;
|
|
19275
|
-
const input = textarea ?
|
|
19712
|
+
const input = textarea ? document.createElement('textarea') : document.createElement('input');
|
|
19276
19713
|
input.id = label.htmlFor;
|
|
19277
19714
|
input.name = name;
|
|
19278
|
-
|
|
19715
|
+
if (!textarea)
|
|
19716
|
+
input.className = 'svhd-input';
|
|
19279
19717
|
const error = document.createElement('p');
|
|
19280
19718
|
error.id = `${input.id}-error`;
|
|
19281
19719
|
error.className = 'svhd-field-error';
|
|
@@ -19285,19 +19723,23 @@ function mountHelpDeskForm(client, options) {
|
|
|
19285
19723
|
input.addEventListener('input', () => clearFieldError(created));
|
|
19286
19724
|
return created;
|
|
19287
19725
|
}
|
|
19288
|
-
const subject = field('
|
|
19289
|
-
const description = field('
|
|
19726
|
+
const subject = field('Summary', 'subject');
|
|
19727
|
+
const description = field('Additional details', 'description', true);
|
|
19290
19728
|
const email = field('Email address', 'email');
|
|
19291
19729
|
const code = field('Email code', 'code');
|
|
19292
19730
|
const name = field('Your name', 'display_name');
|
|
19293
19731
|
const firstName = field('First name', 'given_name');
|
|
19294
19732
|
const lastName = field('Last name (optional)', 'family_name');
|
|
19295
19733
|
const fields = [subject, description, email, code, name, firstName, lastName];
|
|
19296
|
-
//
|
|
19297
|
-
|
|
19734
|
+
// The support wizard's issue the form was last filled from, which either
|
|
19735
|
+
// field may hold; undefined for a form filled from the host's subject and body.
|
|
19736
|
+
let filledFrom = options.issue;
|
|
19737
|
+
/** What a field was filled with: text the customer did not write. */
|
|
19738
|
+
const filledWith = (key) => filledFrom ?? options[key] ?? '';
|
|
19739
|
+
const filled = filledFrom === undefined ? { subject: filledWith('subject'), body: filledWith('body') } : composeIssue(filledFrom);
|
|
19298
19740
|
subject.input.maxLength = MAX_SUBJECT_LEN;
|
|
19299
|
-
subject.input.value =
|
|
19300
|
-
description.input.value =
|
|
19741
|
+
subject.input.value = filled.subject;
|
|
19742
|
+
description.input.value = filled.body;
|
|
19301
19743
|
email.input.type = 'email';
|
|
19302
19744
|
email.input.autocomplete = 'email';
|
|
19303
19745
|
code.input.inputMode = 'numeric';
|
|
@@ -19309,7 +19751,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
19309
19751
|
lastName.input.maxLength = 100;
|
|
19310
19752
|
const codeHint = document.createElement('p');
|
|
19311
19753
|
codeHint.id = `${code.input.id}-hint`;
|
|
19312
|
-
codeHint.className = 'svhd-
|
|
19754
|
+
codeHint.className = 'svhd-hint';
|
|
19313
19755
|
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)}.`;
|
|
19314
19756
|
code.input.setAttribute('aria-describedby', codeHint.id);
|
|
19315
19757
|
const resend = document.createElement('button');
|
|
@@ -19326,23 +19768,93 @@ function mountHelpDeskForm(client, options) {
|
|
|
19326
19768
|
code.wrapper.append(codeHint, codeLinks);
|
|
19327
19769
|
code.wrapper.hidden = true;
|
|
19328
19770
|
name.wrapper.hidden = true;
|
|
19771
|
+
subject.input.required = true;
|
|
19772
|
+
// Enter in the summary moves on to the details it leads into, never sends a request half written.
|
|
19773
|
+
subject.input.addEventListener('keydown', (event) => {
|
|
19774
|
+
if (event.key !== 'Enter' || event.isComposing || event.keyCode === 229)
|
|
19775
|
+
return;
|
|
19776
|
+
event.preventDefault();
|
|
19777
|
+
focusAtEnd(description.input);
|
|
19778
|
+
});
|
|
19779
|
+
const attachments = client.desk.customer_can_attach_files && options.attachments !== false
|
|
19780
|
+
? createFormAttachments(client, prefix, async () => {
|
|
19781
|
+
const ownGeneration = generation;
|
|
19782
|
+
const token = await tokenFor(ownGeneration);
|
|
19783
|
+
if (!token || !alive(ownGeneration))
|
|
19784
|
+
return null;
|
|
19785
|
+
const id = await ensureDraft(ownGeneration, token);
|
|
19786
|
+
if (!alive(ownGeneration))
|
|
19787
|
+
return null;
|
|
19788
|
+
return { draftId: id, expectedSessionToken: token };
|
|
19789
|
+
}, () => {
|
|
19790
|
+
if (attachments?.hasEntries)
|
|
19791
|
+
restoredFiles = false;
|
|
19792
|
+
persistDraft();
|
|
19793
|
+
syncLeaveGuard();
|
|
19794
|
+
})
|
|
19795
|
+
: undefined;
|
|
19796
|
+
const composer = createComposer({
|
|
19797
|
+
form, summary: subject.input, textarea: description.input, attachments,
|
|
19798
|
+
deskRefusesFiles: !client.desk.customer_can_attach_files, onRequestStep: () => step === 'details',
|
|
19799
|
+
});
|
|
19800
|
+
description.wrapper.classList.add('svhd-composer-field');
|
|
19801
|
+
description.wrapper.insertBefore(composer.frame, description.error);
|
|
19802
|
+
description.wrapper.insertBefore(composer.notice, description.error);
|
|
19803
|
+
details.append(subject.wrapper, description.wrapper);
|
|
19329
19804
|
const auth = document.createElement('fieldset');
|
|
19330
19805
|
auth.className = 'svhd-auth';
|
|
19331
19806
|
auth.hidden = true;
|
|
19332
|
-
auth.append(
|
|
19807
|
+
auth.append(code.wrapper, name.wrapper);
|
|
19333
19808
|
const widgetAccount = document.createElement('div');
|
|
19334
19809
|
widgetAccount.className = 'svhd-widget-account';
|
|
19335
|
-
let widgetCustomer =
|
|
19336
|
-
|
|
19337
|
-
|
|
19338
|
-
|
|
19339
|
-
|
|
19340
|
-
|
|
19810
|
+
let widgetCustomer = widget?.customer ?? null;
|
|
19811
|
+
// A desk that signs in with SparkVault Identity asks only the email: its sign-in window asks a missing name.
|
|
19812
|
+
const asksName = client.desk.auth_mode !== 'identity';
|
|
19813
|
+
const reply = widget ? stepHead(`${prefix}-reply-heading`, asksName ? 'Who should we reply to?' : 'Sign in to send your request', 'Step 2 of 2') : null;
|
|
19814
|
+
const identity = widget ? stepContainer('identity') : null;
|
|
19815
|
+
const recap = document.createElement('div');
|
|
19816
|
+
recap.className = 'svhd-recap';
|
|
19817
|
+
const recapText = document.createElement('p');
|
|
19818
|
+
recapText.className = 'svhd-recap-text';
|
|
19819
|
+
const editRequest = textButton('Edit', () => { if (!pending && !destroyed)
|
|
19820
|
+
enterStep('details'); });
|
|
19821
|
+
editRequest.setAttribute('aria-label', 'Edit your request');
|
|
19822
|
+
const noteText = document.createTextNode('');
|
|
19823
|
+
const unsentNote = asksName
|
|
19824
|
+
? 'Your request hasn’t been sent yet. Tell us who to reply to, then we’ll send it.'
|
|
19825
|
+
: 'Your request hasn’t been sent yet. Sign in so we know who to reply to, then we’ll send it.';
|
|
19826
|
+
const live = createLiveRegion('svhd-live');
|
|
19827
|
+
if (identity && reply) {
|
|
19341
19828
|
form.classList.add('svhd-widget-form');
|
|
19342
|
-
|
|
19343
|
-
|
|
19344
|
-
|
|
19345
|
-
|
|
19829
|
+
details.append(widgetAccount);
|
|
19830
|
+
identity.hidden = true;
|
|
19831
|
+
const note = document.createElement('p');
|
|
19832
|
+
note.className = 'svhd-note';
|
|
19833
|
+
note.dataset.unsentNote = '';
|
|
19834
|
+
note.append(helpDeskIcon('info'), noteText);
|
|
19835
|
+
const recapRequest = document.createElement('div');
|
|
19836
|
+
recapRequest.className = 'svhd-recap-request';
|
|
19837
|
+
const recapLabel = document.createElement('span');
|
|
19838
|
+
recapLabel.className = 'svhd-recap-label';
|
|
19839
|
+
recapLabel.textContent = 'Your request';
|
|
19840
|
+
recapRequest.append(recapLabel, recapText);
|
|
19841
|
+
recap.append(recapRequest, editRequest);
|
|
19842
|
+
const helper = document.createElement('p');
|
|
19843
|
+
helper.id = `${email.input.id}-help`;
|
|
19844
|
+
helper.className = 'svhd-hint';
|
|
19845
|
+
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.';
|
|
19846
|
+
email.input.setAttribute('aria-describedby', helper.id);
|
|
19847
|
+
identity.append(reply.head, note, recap);
|
|
19848
|
+
if (asksName) {
|
|
19849
|
+
const names = document.createElement('div');
|
|
19850
|
+
names.className = 'svhd-widget-names';
|
|
19851
|
+
names.append(firstName.wrapper, lastName.wrapper);
|
|
19852
|
+
identity.append(names);
|
|
19853
|
+
}
|
|
19854
|
+
identity.append(email.wrapper, helper);
|
|
19855
|
+
}
|
|
19856
|
+
else
|
|
19857
|
+
auth.prepend(email.wrapper);
|
|
19346
19858
|
const status = document.createElement('p');
|
|
19347
19859
|
status.className = 'svhd-status';
|
|
19348
19860
|
status.setAttribute('role', 'status');
|
|
@@ -19362,13 +19874,15 @@ function mountHelpDeskForm(client, options) {
|
|
|
19362
19874
|
const send = document.createElement('button');
|
|
19363
19875
|
send.className = 'svhd-button';
|
|
19364
19876
|
send.type = 'submit';
|
|
19365
|
-
send.textContent = options.widgetIdentity ? widgetCustomer ? 'Send message' : 'Continue' : 'Send request';
|
|
19366
19877
|
const cancel = document.createElement('button');
|
|
19367
19878
|
cancel.className = 'svhd-button svhd-secondary';
|
|
19368
19879
|
cancel.type = 'button';
|
|
19369
19880
|
cancel.textContent = 'Cancel';
|
|
19370
19881
|
cancel.hidden = !options.onCancel;
|
|
19371
|
-
|
|
19882
|
+
const startNew = textButton('Start a new request', () => { if (!pending && !destroyed && recovery !== null)
|
|
19883
|
+
leaveRecovery(); });
|
|
19884
|
+
startNew.hidden = true;
|
|
19885
|
+
actions.append(send, startNew, cancel);
|
|
19372
19886
|
const confirm = document.createElement('div');
|
|
19373
19887
|
confirm.className = 'svhd-confirm';
|
|
19374
19888
|
confirm.setAttribute('role', 'group');
|
|
@@ -19394,8 +19908,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
19394
19908
|
discard.textContent = DISCARD_REQUEST_COPY.discard;
|
|
19395
19909
|
confirmActions.append(keepEditing, discard);
|
|
19396
19910
|
confirm.append(confirmTitle, confirmNote, confirmActions);
|
|
19397
|
-
form.append(
|
|
19911
|
+
form.append(details, ...(identity ? [identity] : []), auth, status, hosted, actions, confirm, live.element);
|
|
19398
19912
|
let state = 'editing';
|
|
19913
|
+
let step = 'details';
|
|
19914
|
+
let guardingLeave = false;
|
|
19399
19915
|
let destroyed = false;
|
|
19400
19916
|
let pending = false;
|
|
19401
19917
|
let completed = false;
|
|
@@ -19415,43 +19931,56 @@ function mountHelpDeskForm(client, options) {
|
|
|
19415
19931
|
let uncertainSubmission = null;
|
|
19416
19932
|
let sessionToken = null;
|
|
19417
19933
|
let sessionKnown = false;
|
|
19418
|
-
let attachments;
|
|
19419
19934
|
let submittedCode = null;
|
|
19420
19935
|
let resendAt = 0;
|
|
19421
19936
|
let resendTimer = null;
|
|
19422
19937
|
let confirmReturn = null;
|
|
19423
19938
|
let done = null;
|
|
19424
|
-
|
|
19939
|
+
// The verified customer whose saved request the form holds.
|
|
19940
|
+
let draftOwner = null;
|
|
19425
19941
|
let restoredDraft = false;
|
|
19426
19942
|
let restoredAnonymous = false;
|
|
19427
19943
|
let restoredFiles = false;
|
|
19428
|
-
|
|
19944
|
+
// How the customer whose saved request the form hides signed in, while it
|
|
19945
|
+
// waits for them to sign in again: that is the only way back to it.
|
|
19946
|
+
let recovery = null;
|
|
19947
|
+
// The website gave no account back when asked for the hidden request's customer.
|
|
19948
|
+
let websiteSignedOut = false;
|
|
19429
19949
|
function persistDraft() {
|
|
19430
19950
|
if (!options.persist || completed || destroyed)
|
|
19431
19951
|
return;
|
|
19432
|
-
if (!
|
|
19433
|
-
|
|
19434
|
-
|
|
19952
|
+
if (!draftOwner) {
|
|
19953
|
+
// The hidden request is a previous customer's; nothing is saved over it.
|
|
19954
|
+
if (recovery === null)
|
|
19955
|
+
saveAnonymousFormDraft(client.desk.desk_id, { subject: subject.input.value, body: description.input.value }, filledFrom);
|
|
19435
19956
|
return;
|
|
19436
19957
|
}
|
|
19437
|
-
saveFormDraft(client.desk.desk_id,
|
|
19958
|
+
saveFormDraft(client.desk.desk_id, draftOwner.requester_id, {
|
|
19438
19959
|
subject: subject.input.value, body: description.input.value, ticketId: draftId,
|
|
19439
19960
|
uncertain: uncertainSubmission, hadFiles: restoredFiles || attachments?.hasEntries === true,
|
|
19440
19961
|
});
|
|
19441
19962
|
}
|
|
19442
19963
|
function forgetDraft() {
|
|
19443
|
-
if (
|
|
19444
|
-
|
|
19445
|
-
|
|
19964
|
+
if (!options.persist)
|
|
19965
|
+
return;
|
|
19966
|
+
if (draftOwner)
|
|
19967
|
+
removeFormDraft(client.desk.desk_id, draftOwner.requester_id);
|
|
19968
|
+
else
|
|
19446
19969
|
clearSupportIssue(client.desk.desk_id);
|
|
19447
19970
|
}
|
|
19448
|
-
/**
|
|
19971
|
+
/**
|
|
19972
|
+
* The request is now this verified customer's, saved in this tab or not.
|
|
19973
|
+
* Only /me or the verified sign-in answer can select a saved requester's draft.
|
|
19974
|
+
*/
|
|
19449
19975
|
function restoreDraft(customer) {
|
|
19450
|
-
if (
|
|
19976
|
+
if (draftOwner?.requester_id === customer.requester_id)
|
|
19977
|
+
return false;
|
|
19978
|
+
draftOwner = customer;
|
|
19979
|
+
recovery = null;
|
|
19980
|
+
renderActions();
|
|
19981
|
+
if (!options.persist)
|
|
19451
19982
|
return false;
|
|
19452
|
-
|
|
19453
|
-
draftRequester = customer.requester_id;
|
|
19454
|
-
const saved = readFormDraft(client.desk.desk_id, draftRequester);
|
|
19983
|
+
const saved = readFormDraft(client.desk.desk_id, customer.requester_id);
|
|
19455
19984
|
clearSupportIssue(client.desk.desk_id);
|
|
19456
19985
|
if (!saved) {
|
|
19457
19986
|
persistDraft();
|
|
@@ -19460,12 +19989,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
19460
19989
|
restoredDraft = true;
|
|
19461
19990
|
restoredFiles = saved.hadFiles && !saved.uncertain;
|
|
19462
19991
|
subject.input.value = saved.uncertain?.subject ?? saved.subject;
|
|
19463
|
-
description.input.value = saved.uncertain
|
|
19992
|
+
description.input.value = saved.uncertain ? detailsOf(saved.uncertain) : saved.body;
|
|
19464
19993
|
draftId = saved.ticketId;
|
|
19465
19994
|
uncertainSubmission = saved.uncertain;
|
|
19466
|
-
|
|
19467
|
-
description.input.readOnly = uncertainSubmission !== null;
|
|
19468
|
-
send.textContent = uncertainSubmission ? 'Check submission' : options.widgetIdentity ? widgetCustomer ? 'Send message' : 'Continue' : 'Send request';
|
|
19995
|
+
send.textContent = idleLabel();
|
|
19469
19996
|
setState(uncertainSubmission ? 'uncertain' : 'editing');
|
|
19470
19997
|
message(uncertainSubmission
|
|
19471
19998
|
? 'Your original request is preserved. Check submission before starting another request.'
|
|
@@ -19477,55 +20004,136 @@ function mountHelpDeskForm(client, options) {
|
|
|
19477
20004
|
// An account switch must not turn an uncertain send into a fresh request.
|
|
19478
20005
|
return pending || uncertainSubmission !== null || completed ? null : { subject: subject.input.value, body: description.input.value };
|
|
19479
20006
|
}
|
|
20007
|
+
/** What the send button reads while nothing is in flight. */
|
|
20008
|
+
function idleLabel() {
|
|
20009
|
+
if (uncertainSubmission)
|
|
20010
|
+
return 'Check submission';
|
|
20011
|
+
if (challenge)
|
|
20012
|
+
return 'Verify and send request';
|
|
20013
|
+
if (recovery === 'external_sso' && widget)
|
|
20014
|
+
return 'Use website account';
|
|
20015
|
+
if (recovery !== null && step === 'details')
|
|
20016
|
+
return 'Sign in to recover request';
|
|
20017
|
+
return widget && !widgetCustomer ? 'Continue' : 'Send request';
|
|
20018
|
+
}
|
|
20019
|
+
/**
|
|
20020
|
+
* The signed-in widget customer writes and sends in one step, posting as
|
|
20021
|
+
* the account named under it; a signed-out one writes the request as step
|
|
20022
|
+
* 1 of 2. Either way the form shows the request.
|
|
20023
|
+
*/
|
|
19480
20024
|
function renderWidgetIdentity() {
|
|
19481
|
-
if (!
|
|
20025
|
+
if (!widget)
|
|
19482
20026
|
return;
|
|
19483
|
-
|
|
19484
|
-
|
|
19485
|
-
auth.hidden =
|
|
19486
|
-
email.wrapper.hidden = false;
|
|
20027
|
+
if (request.label)
|
|
20028
|
+
request.label.hidden = widgetCustomer !== null;
|
|
20029
|
+
auth.hidden = true;
|
|
19487
20030
|
code.wrapper.hidden = true;
|
|
19488
20031
|
name.wrapper.hidden = true;
|
|
20032
|
+
widgetAccount.replaceChildren();
|
|
20033
|
+
const free = () => !pending && !destroyed && uncertainSubmission === null && !completed;
|
|
19489
20034
|
if (widgetCustomer) {
|
|
19490
|
-
const
|
|
19491
|
-
|
|
19492
|
-
const
|
|
19493
|
-
|
|
19494
|
-
|
|
19495
|
-
|
|
19496
|
-
|
|
19497
|
-
|
|
19498
|
-
|
|
19499
|
-
change.className = 'svhd-widget-account-link';
|
|
19500
|
-
change.textContent = 'Not you?';
|
|
19501
|
-
change.addEventListener('click', () => {
|
|
19502
|
-
if (pending || destroyed || uncertainSubmission !== null || completed)
|
|
19503
|
-
return;
|
|
19504
|
-
options.widgetIdentity?.switchAccount(safeComposition());
|
|
19505
|
-
});
|
|
19506
|
-
widgetAccount.append(identity, change);
|
|
20035
|
+
const postingAs = document.createElement('p');
|
|
20036
|
+
postingAs.className = 'svhd-posting-as';
|
|
20037
|
+
const shown = postingName(widgetCustomer);
|
|
20038
|
+
// Not you? opens the sign-in window in this click: nothing may await before it.
|
|
20039
|
+
postingAs.append(`Posting as ${shown}${shown.endsWith('.') ? '' : '.'} `, textButton('Not you?', () => {
|
|
20040
|
+
if (free())
|
|
20041
|
+
widget.switchAccount(safeComposition());
|
|
20042
|
+
}));
|
|
20043
|
+
widgetAccount.append(postingAs);
|
|
19507
20044
|
}
|
|
19508
|
-
|
|
19509
|
-
|
|
19510
|
-
|
|
19511
|
-
|
|
19512
|
-
|
|
19513
|
-
}
|
|
19514
|
-
if (options.widgetIdentity.useWebsiteAccount) {
|
|
19515
|
-
const website = document.createElement('button');
|
|
19516
|
-
website.type = 'button';
|
|
19517
|
-
website.className = 'svhd-widget-account-link';
|
|
19518
|
-
website.textContent = 'Use website account';
|
|
19519
|
-
website.addEventListener('click', () => {
|
|
19520
|
-
if (!pending && !destroyed && uncertainSubmission === null && !completed)
|
|
19521
|
-
options.widgetIdentity?.useWebsiteAccount?.(safeComposition());
|
|
19522
|
-
});
|
|
19523
|
-
widgetAccount.append(website);
|
|
20045
|
+
if (widget.useWebsiteAccount && widget.offerWebsiteAccount) {
|
|
20046
|
+
widgetAccount.append(textButton('Use website account', () => {
|
|
20047
|
+
if (free())
|
|
20048
|
+
widget.useWebsiteAccount?.(safeComposition());
|
|
20049
|
+
}));
|
|
19524
20050
|
}
|
|
20051
|
+
setStep('details');
|
|
20052
|
+
}
|
|
20053
|
+
/**
|
|
20054
|
+
* The actions and notes for where the request is. While the form hides a
|
|
20055
|
+
* previous customer's saved request (`recovery`), nothing shows of it, nor
|
|
20056
|
+
* says it was not sent, since it may be a send whose answer was lost: the
|
|
20057
|
+
* request step's status line says how to get it back and the reply-to
|
|
20058
|
+
* step's note alone speaks there, Start a new request leaves it, and the
|
|
20059
|
+
* account row is away. A website-account customer's request comes back only
|
|
20060
|
+
* through that account, so Use website account is its one way on when the
|
|
20061
|
+
* website bridges one, and there is none when it does not.
|
|
20062
|
+
*/
|
|
20063
|
+
function renderActions() {
|
|
20064
|
+
send.textContent = idleLabel();
|
|
20065
|
+
send.hidden = recovery === 'external_sso' && widget !== undefined && !widget.useWebsiteAccount;
|
|
20066
|
+
startNew.hidden = recovery === null;
|
|
20067
|
+
widgetAccount.hidden = recovery !== null || widgetAccount.childElementCount === 0;
|
|
20068
|
+
recap.hidden = recovery !== null;
|
|
20069
|
+
noteText.data = recovery === 'identity' || recovery === 'email_pin' ? RECOVER_NOTE_COPY : unsentNote;
|
|
20070
|
+
if (recovery !== null)
|
|
20071
|
+
message(step === 'identity' ? '' : recoveryStatus());
|
|
20072
|
+
}
|
|
20073
|
+
/** What the request step's status line asks for while a saved request is hidden. */
|
|
20074
|
+
function recoveryStatus() {
|
|
20075
|
+
if (recovery !== 'external_sso')
|
|
20076
|
+
return RECOVER_STATUS_COPY;
|
|
20077
|
+
return websiteSignedOut ? WEBSITE_SIGNED_OUT_COPY : RECOVER_WEBSITE_COPY;
|
|
20078
|
+
}
|
|
20079
|
+
/** Start a new request in place of the hidden one, which stays saved for its customer. */
|
|
20080
|
+
function leaveRecovery() {
|
|
20081
|
+
recovery = null;
|
|
20082
|
+
disable(false);
|
|
20083
|
+
message('');
|
|
20084
|
+
// A question asked while the saved request was hidden fills the new one.
|
|
20085
|
+
widget?.followIssue();
|
|
20086
|
+
if (step === 'identity')
|
|
20087
|
+
enterStep('details');
|
|
20088
|
+
else {
|
|
20089
|
+
renderActions();
|
|
20090
|
+
options.onScreenChange?.();
|
|
20091
|
+
controller.focusEntry();
|
|
20092
|
+
}
|
|
20093
|
+
}
|
|
20094
|
+
/** Show one step, the request or who the reply goes to, without moving focus. */
|
|
20095
|
+
function setStep(next) {
|
|
20096
|
+
const changed = next !== step;
|
|
20097
|
+
step = next;
|
|
20098
|
+
details.hidden = next !== 'details';
|
|
20099
|
+
if (identity)
|
|
20100
|
+
identity.hidden = next !== 'identity';
|
|
20101
|
+
if (next === 'identity')
|
|
20102
|
+
recapText.textContent = subject.input.value.trim();
|
|
20103
|
+
renderActions();
|
|
20104
|
+
syncLeaveGuard();
|
|
20105
|
+
if (changed)
|
|
20106
|
+
options.onScreenChange?.();
|
|
20107
|
+
}
|
|
20108
|
+
/** The customer moves between the steps: the new step's heading takes focus and its place is announced. */
|
|
20109
|
+
function enterStep(next) {
|
|
20110
|
+
setStep(next);
|
|
20111
|
+
live.announce(next === 'identity' ? 'Step 2 of 2' : 'Step 1 of 2');
|
|
20112
|
+
(next === 'identity' && reply ? reply.heading : heading).focus();
|
|
20113
|
+
}
|
|
20114
|
+
// An inline wizard, on any host page that gives a `target`, asks before that
|
|
20115
|
+
// page unloads while the request holds unsent work: leaving would lose it.
|
|
20116
|
+
// The floating panel never holds the page.
|
|
20117
|
+
// Chrome and Edge below 119, inside the SDK's browser floor, ask only when
|
|
20118
|
+
// returnValue is set; preventDefault is the standard signal.
|
|
20119
|
+
const onBeforeUnload = (event) => {
|
|
20120
|
+
event.preventDefault();
|
|
20121
|
+
event.returnValue = '';
|
|
20122
|
+
};
|
|
20123
|
+
function syncLeaveGuard() {
|
|
20124
|
+
const needed = options.pageLayout === true && !destroyed && holdsUnsentWork();
|
|
20125
|
+
if (needed === guardingLeave)
|
|
20126
|
+
return;
|
|
20127
|
+
guardingLeave = needed;
|
|
20128
|
+
if (needed)
|
|
20129
|
+
window.addEventListener('beforeunload', onBeforeUnload);
|
|
20130
|
+
else
|
|
20131
|
+
window.removeEventListener('beforeunload', onBeforeUnload);
|
|
19525
20132
|
}
|
|
19526
20133
|
function setState(next) {
|
|
19527
20134
|
state = next;
|
|
19528
20135
|
persistDraft();
|
|
20136
|
+
syncLeaveGuard();
|
|
19529
20137
|
notify$1(options.onStateChange, next);
|
|
19530
20138
|
}
|
|
19531
20139
|
function message(text, isError = false) {
|
|
@@ -19552,13 +20160,22 @@ function mountHelpDeskForm(client, options) {
|
|
|
19552
20160
|
resendTimer = setInterval(renderResend, 1000);
|
|
19553
20161
|
renderResend();
|
|
19554
20162
|
}
|
|
20163
|
+
/**
|
|
20164
|
+
* Disable every control while `disabled`. The request stays read-only, and
|
|
20165
|
+
* takes no files, while a send is unanswered, its exact text kept for the
|
|
20166
|
+
* check, and while it hides a saved request, which signing in brings back
|
|
20167
|
+
* in place of anything written.
|
|
20168
|
+
*/
|
|
19555
20169
|
function disable(disabled) {
|
|
19556
|
-
for (const input of [subject.input, description.input, email.input, code.input, name.input, firstName.input, lastName.input, send, cancel, changeEmail])
|
|
20170
|
+
for (const input of [subject.input, description.input, email.input, code.input, name.input, firstName.input, lastName.input, send, cancel, changeEmail, editRequest, startNew])
|
|
19557
20171
|
input.disabled = disabled;
|
|
20172
|
+
const held = uncertainSubmission !== null || recovery !== null;
|
|
20173
|
+
subject.input.readOnly = held;
|
|
20174
|
+
description.input.readOnly = held;
|
|
19558
20175
|
for (const button of widgetAccount.querySelectorAll('button'))
|
|
19559
20176
|
button.disabled = disabled || uncertainSubmission !== null || completed;
|
|
19560
20177
|
renderResend();
|
|
19561
|
-
attachments?.disablePicking(disabled);
|
|
20178
|
+
attachments?.disablePicking(disabled || recovery !== null);
|
|
19562
20179
|
attachments?.lock(completed || uncertainSubmission !== null);
|
|
19563
20180
|
}
|
|
19564
20181
|
function clearCode() {
|
|
@@ -19587,8 +20204,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
19587
20204
|
? 'We may already have received this request. Closing now loses the way to check it.'
|
|
19588
20205
|
: DISCARD_REQUEST_COPY.note;
|
|
19589
20206
|
}
|
|
19590
|
-
/** The field of the step in view: the code, name or email the sign-in asks for, else the
|
|
20207
|
+
/** 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. */
|
|
19591
20208
|
function stepField() {
|
|
20209
|
+
if (step === 'identity')
|
|
20210
|
+
return (asksName ? firstName : email).input;
|
|
19592
20211
|
const asked = auth.hidden ? undefined : [code, name, email].find((entry) => !entry.wrapper.hidden);
|
|
19593
20212
|
return (asked ?? subject).input;
|
|
19594
20213
|
}
|
|
@@ -19629,25 +20248,27 @@ function mountHelpDeskForm(client, options) {
|
|
|
19629
20248
|
}
|
|
19630
20249
|
/**
|
|
19631
20250
|
* Whether closing now would lose something: a send under way or
|
|
19632
|
-
* unanswered, a code step,
|
|
19633
|
-
*
|
|
19634
|
-
* no work of the customer's.
|
|
20251
|
+
* unanswered, a code step, a request moved on to who the reply goes to, or
|
|
20252
|
+
* text and files of the customer's own. The silent company sign-in the
|
|
20253
|
+
* form runs as it opens (`authenticating`) is no work of the customer's.
|
|
19635
20254
|
*/
|
|
19636
20255
|
function holdsUnsentWork() {
|
|
19637
20256
|
if (completed)
|
|
19638
20257
|
return false;
|
|
19639
|
-
return (pending && state !== 'authenticating') || uncertainSubmission !== null || challenge !== null
|
|
19640
|
-
|| edited(subject.input,
|
|
20258
|
+
return (pending && state !== 'authenticating') || uncertainSubmission !== null || challenge !== null || step === 'identity'
|
|
20259
|
+
|| edited(subject.input, filledWith('subject')) || edited(description.input, filledWith('body'))
|
|
19641
20260
|
|| attachments?.hasEntries === true;
|
|
19642
20261
|
}
|
|
19643
|
-
/**
|
|
20262
|
+
/**
|
|
20263
|
+
* The field a request the ticket write would refuse is refused under, with
|
|
20264
|
+
* what it reads there; null for one it takes. The body is `ticketBody`'s,
|
|
20265
|
+
* so a request of a summary alone always has one.
|
|
20266
|
+
*/
|
|
19644
20267
|
function refusal(subjectText, body) {
|
|
19645
20268
|
if (!subjectText)
|
|
19646
|
-
return [subject, 'Add a
|
|
20269
|
+
return [subject, 'Add a summary.'];
|
|
19647
20270
|
if (subjectText.length > MAX_SUBJECT_LEN)
|
|
19648
|
-
return [subject, `Keep the
|
|
19649
|
-
if (!body.trim())
|
|
19650
|
-
return [description, 'Describe what you need help with.'];
|
|
20271
|
+
return [subject, `Keep the summary to ${MAX_SUBJECT_LEN} characters.`];
|
|
19651
20272
|
// The limit counts UTF-8 bytes, so a message of fewer characters can be over it;
|
|
19652
20273
|
// a message of more UTF-16 units than that is over it without being encoded.
|
|
19653
20274
|
if (body.length > MAX_BODY_BYTES || new TextEncoder().encode(body).length > MAX_BODY_BYTES)
|
|
@@ -19716,7 +20337,8 @@ function mountHelpDeskForm(client, options) {
|
|
|
19716
20337
|
attachments?.clear(completed || uncertainSubmission !== null);
|
|
19717
20338
|
attachments?.lock(false);
|
|
19718
20339
|
if (attachments)
|
|
19719
|
-
attachments.
|
|
20340
|
+
attachments.list.hidden = false;
|
|
20341
|
+
composer.clearNotice();
|
|
19720
20342
|
subject.input.value = '';
|
|
19721
20343
|
description.input.value = '';
|
|
19722
20344
|
email.input.value = '';
|
|
@@ -19737,13 +20359,13 @@ function mountHelpDeskForm(client, options) {
|
|
|
19737
20359
|
draftId = null;
|
|
19738
20360
|
draftPromise = null;
|
|
19739
20361
|
uncertainSubmission = null;
|
|
19740
|
-
|
|
20362
|
+
recovery = null;
|
|
20363
|
+
websiteSignedOut = false;
|
|
19741
20364
|
restoredAnonymous = false;
|
|
19742
|
-
subject.input.readOnly = false;
|
|
19743
|
-
description.input.readOnly = false;
|
|
19744
20365
|
completed = false;
|
|
19745
|
-
send.textContent = 'Send request';
|
|
19746
20366
|
message('');
|
|
20367
|
+
renderActions();
|
|
20368
|
+
syncLeaveGuard();
|
|
19747
20369
|
}
|
|
19748
20370
|
function sessionChanged(change) {
|
|
19749
20371
|
if (destroyed)
|
|
@@ -19776,18 +20398,26 @@ function mountHelpDeskForm(client, options) {
|
|
|
19776
20398
|
// during a pending proof must not leave the previous composer visible.
|
|
19777
20399
|
subject.input.value = '';
|
|
19778
20400
|
description.input.value = '';
|
|
20401
|
+
recapText.textContent = '';
|
|
19779
20402
|
name.input.value = '';
|
|
19780
20403
|
email.input.value = '';
|
|
19781
20404
|
clearCode();
|
|
19782
20405
|
if (attachments)
|
|
19783
|
-
attachments.
|
|
20406
|
+
attachments.list.hidden = true;
|
|
19784
20407
|
return;
|
|
19785
20408
|
}
|
|
19786
20409
|
// Preserve the old request before hiding it. The next verified requester
|
|
19787
20410
|
// selects only their own storage key, including after a 401 and sign-in.
|
|
19788
20411
|
persistDraft();
|
|
19789
|
-
|
|
19790
|
-
|
|
20412
|
+
// A signed-in customer's request leaves view, saved or not, and with it the
|
|
20413
|
+
// question it was filled from: nothing the form holds may write it back.
|
|
20414
|
+
const hidesCustomer = draftOwner !== null;
|
|
20415
|
+
if (hidesCustomer && filledFrom !== undefined)
|
|
20416
|
+
filledFrom = '';
|
|
20417
|
+
// A saved request stays hidden for its customer, through any further change.
|
|
20418
|
+
const hidden = draftOwner === null ? recovery
|
|
20419
|
+
: options.persist && readFormDraft(client.desk.desk_id, draftOwner.requester_id) !== null ? draftOwner.assurance : null;
|
|
20420
|
+
draftOwner = null;
|
|
19791
20421
|
restoredDraft = false;
|
|
19792
20422
|
restoredFiles = false;
|
|
19793
20423
|
generation += 1;
|
|
@@ -19796,15 +20426,19 @@ function mountHelpDeskForm(client, options) {
|
|
|
19796
20426
|
if (options.widgetIdentity)
|
|
19797
20427
|
widgetCustomer = null;
|
|
19798
20428
|
clearComposer();
|
|
19799
|
-
|
|
20429
|
+
recovery = hidden;
|
|
19800
20430
|
disable(false);
|
|
19801
20431
|
setState('editing');
|
|
19802
|
-
|
|
19803
|
-
|
|
19804
|
-
|
|
19805
|
-
|
|
19806
|
-
else
|
|
20432
|
+
// The question that led here was the previous customer's too.
|
|
20433
|
+
if (hidesCustomer)
|
|
20434
|
+
widget?.forgetIssue();
|
|
20435
|
+
if (recovery === null)
|
|
19807
20436
|
message('Your sign-in changed. Start a new request for the current account.');
|
|
20437
|
+
else
|
|
20438
|
+
renderActions();
|
|
20439
|
+
// The request and its actions changed under the pointer: a press already
|
|
20440
|
+
// under way must not act on what replaced them.
|
|
20441
|
+
options.onScreenChange?.();
|
|
19808
20442
|
}
|
|
19809
20443
|
const unsubscribe = client.subscribeSession(sessionChanged);
|
|
19810
20444
|
const alive = (ownGeneration) => !destroyed && generation === ownGeneration;
|
|
@@ -19845,19 +20479,6 @@ function mountHelpDeskForm(client, options) {
|
|
|
19845
20479
|
}
|
|
19846
20480
|
return draftPromise;
|
|
19847
20481
|
}
|
|
19848
|
-
if (client.desk.customer_can_attach_files && options.attachments !== false) {
|
|
19849
|
-
attachments = createFormAttachments(client, prefix, async () => {
|
|
19850
|
-
const ownGeneration = generation;
|
|
19851
|
-
const token = await tokenFor(ownGeneration);
|
|
19852
|
-
if (!token || !alive(ownGeneration))
|
|
19853
|
-
return null;
|
|
19854
|
-
const id = await ensureDraft(ownGeneration, token);
|
|
19855
|
-
if (!alive(ownGeneration))
|
|
19856
|
-
return null;
|
|
19857
|
-
return { draftId: id, expectedSessionToken: token };
|
|
19858
|
-
});
|
|
19859
|
-
form.insertBefore(attachments.element, auth);
|
|
19860
|
-
}
|
|
19861
20482
|
function showEmail() {
|
|
19862
20483
|
auth.hidden = false;
|
|
19863
20484
|
email.wrapper.hidden = false;
|
|
@@ -19890,31 +20511,46 @@ function mountHelpDeskForm(client, options) {
|
|
|
19890
20511
|
// Sending (Enter in a field, a code's last digit) answers the discard
|
|
19891
20512
|
// question: the customer kept going.
|
|
19892
20513
|
closeConfirm(false);
|
|
20514
|
+
if (recovery === 'external_sso' && widget) {
|
|
20515
|
+
// Only the website account reaches a website-account customer's saved
|
|
20516
|
+
// request: a code or the secure window would sign in someone else.
|
|
20517
|
+
widget.useWebsiteAccount?.(null, true);
|
|
20518
|
+
return;
|
|
20519
|
+
}
|
|
19893
20520
|
for (const entry of fields)
|
|
19894
20521
|
clearFieldError(entry);
|
|
19895
20522
|
const recoveringSubmission = uncertainSubmission !== null;
|
|
19896
20523
|
const subjectText = uncertainSubmission?.subject ?? subject.input.value.trim();
|
|
19897
|
-
const
|
|
20524
|
+
const detailsText = uncertainSubmission ? detailsOf(uncertainSubmission) : description.input.value;
|
|
20525
|
+
const body = uncertainSubmission?.body ?? ticketBody(subjectText, detailsText);
|
|
19898
20526
|
if (uncertainSubmission) {
|
|
19899
20527
|
// Retrying recovers this exact request. A lost response must never make
|
|
19900
20528
|
// newly typed text appear to have been accepted as the earlier ticket.
|
|
19901
20529
|
subject.input.value = subjectText;
|
|
19902
|
-
description.input.value =
|
|
20530
|
+
description.input.value = detailsText;
|
|
19903
20531
|
}
|
|
19904
20532
|
const refused = refusal(subjectText, body);
|
|
19905
|
-
const recoveringAfterSignIn =
|
|
20533
|
+
const recoveringAfterSignIn = recovery !== null;
|
|
19906
20534
|
if (refused && !recoveringAfterSignIn) {
|
|
19907
20535
|
const [entry, text] = refused;
|
|
20536
|
+
if (step !== 'details')
|
|
20537
|
+
setStep('details');
|
|
19908
20538
|
setFieldError(entry, text);
|
|
19909
20539
|
entry.input.focus();
|
|
19910
20540
|
return;
|
|
19911
20541
|
}
|
|
19912
20542
|
let widgetSignIn;
|
|
19913
|
-
if (
|
|
19914
|
-
|
|
19915
|
-
|
|
20543
|
+
if (widget && !widgetCustomer) {
|
|
20544
|
+
// The request is written; who the reply goes to is the next step, and
|
|
20545
|
+
// nothing reaches the network before it.
|
|
20546
|
+
if (step === 'details') {
|
|
20547
|
+
enterStep('identity');
|
|
20548
|
+
return;
|
|
20549
|
+
}
|
|
20550
|
+
const givenName = asksName ? firstName.input.value.trim() : '';
|
|
20551
|
+
const familyName = asksName ? lastName.input.value.trim() : '';
|
|
19916
20552
|
const emailAddress = email.input.value.trim();
|
|
19917
|
-
const invalid = !givenName ? firstName : !email.input.validity.valid || !emailAddress ? email : null;
|
|
20553
|
+
const invalid = asksName && !givenName ? firstName : !email.input.validity.valid || !emailAddress ? email : null;
|
|
19918
20554
|
if (invalid) {
|
|
19919
20555
|
setFieldError(invalid, invalid === email ? 'Enter your email address.' : 'Enter your first name.');
|
|
19920
20556
|
invalid.input.focus();
|
|
@@ -19923,7 +20559,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
19923
20559
|
// Invoke in the original submit gesture, before any awaited token read:
|
|
19924
20560
|
// the Identity adapter can open its native window without a popup block.
|
|
19925
20561
|
try {
|
|
19926
|
-
widgetSignIn =
|
|
20562
|
+
widgetSignIn = widget.signIn(asksName ? { email: emailAddress, givenName, familyName } : { email: emailAddress });
|
|
19927
20563
|
}
|
|
19928
20564
|
catch (failure) {
|
|
19929
20565
|
const error = failure instanceof Error ? failure : new Error('Sign-in could not be opened.');
|
|
@@ -19940,12 +20576,13 @@ function mountHelpDeskForm(client, options) {
|
|
|
19940
20576
|
pending = true;
|
|
19941
20577
|
disable(true);
|
|
19942
20578
|
message('');
|
|
20579
|
+
syncLeaveGuard();
|
|
19943
20580
|
try {
|
|
19944
20581
|
if (widgetSignIn) {
|
|
19945
20582
|
authenticating = true;
|
|
19946
20583
|
authNotification = false;
|
|
19947
20584
|
setState('authenticating');
|
|
19948
|
-
message('
|
|
20585
|
+
message('Finish signing in in the secure window.');
|
|
19949
20586
|
}
|
|
19950
20587
|
let token = await tokenFor(ownGeneration);
|
|
19951
20588
|
if (!alive(ownGeneration))
|
|
@@ -19971,10 +20608,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
19971
20608
|
sessionKnown = true;
|
|
19972
20609
|
authenticating = false;
|
|
19973
20610
|
if (attachments)
|
|
19974
|
-
attachments.
|
|
20611
|
+
attachments.list.hidden = false;
|
|
19975
20612
|
subject.input.value = subjectText;
|
|
19976
|
-
description.input.value =
|
|
19977
|
-
if (
|
|
20613
|
+
description.input.value = detailsText;
|
|
20614
|
+
if (widget && session) {
|
|
19978
20615
|
widgetCustomer = session.customer;
|
|
19979
20616
|
renderWidgetIdentity();
|
|
19980
20617
|
message('');
|
|
@@ -19990,7 +20627,8 @@ function mountHelpDeskForm(client, options) {
|
|
|
19990
20627
|
if (!alive(ownGeneration))
|
|
19991
20628
|
return;
|
|
19992
20629
|
if (!token) {
|
|
19993
|
-
|
|
20630
|
+
// A website-account customer's saved request never comes back through an emailed code.
|
|
20631
|
+
if (recovery === 'external_sso' || (client.desk.auth_mode !== 'email_pin' && !(client.desk.auth_mode === 'external_sso' && client.desk.external_identity?.guest_email === true))) {
|
|
19994
20632
|
showHosted();
|
|
19995
20633
|
return;
|
|
19996
20634
|
}
|
|
@@ -20034,10 +20672,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
20034
20672
|
sessionKnown = true;
|
|
20035
20673
|
authenticating = false;
|
|
20036
20674
|
if (attachments)
|
|
20037
|
-
attachments.
|
|
20675
|
+
attachments.list.hidden = false;
|
|
20038
20676
|
dropChallenge();
|
|
20039
20677
|
subject.input.value = subjectText;
|
|
20040
|
-
description.input.value =
|
|
20678
|
+
description.input.value = detailsText;
|
|
20041
20679
|
notify$1(options.onSession, verified);
|
|
20042
20680
|
}
|
|
20043
20681
|
if (!token || !alive(ownGeneration))
|
|
@@ -20065,7 +20703,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20065
20703
|
email.wrapper.hidden = true;
|
|
20066
20704
|
code.wrapper.hidden = true;
|
|
20067
20705
|
name.wrapper.hidden = false;
|
|
20068
|
-
send.textContent =
|
|
20706
|
+
send.textContent = idleLabel();
|
|
20069
20707
|
setState('editing');
|
|
20070
20708
|
setFieldError(name, 'Add your name before sending your request.');
|
|
20071
20709
|
focusAfter = name.input;
|
|
@@ -20087,7 +20725,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20087
20725
|
setState('submitting');
|
|
20088
20726
|
if (!alive(ownGeneration))
|
|
20089
20727
|
return;
|
|
20090
|
-
send.textContent =
|
|
20728
|
+
send.textContent = 'Sending request';
|
|
20091
20729
|
if (!uncertainSubmission) {
|
|
20092
20730
|
const id = await ensureDraft(ownGeneration, token);
|
|
20093
20731
|
if (!alive(ownGeneration) || !(await tokenFor(ownGeneration)))
|
|
@@ -20130,14 +20768,10 @@ function mountHelpDeskForm(client, options) {
|
|
|
20130
20768
|
const draftExpired = ticketAttempted && error instanceof SparkVaultError
|
|
20131
20769
|
&& (error.serviceCode === 'DRAFT_EXPIRED' || error.code === 'DRAFT_EXPIRED');
|
|
20132
20770
|
if (uncertainSubmission && !draftExpired && (!ticketAttempted || recoveringSubmission || unknownSubmissionOutcome(error))) {
|
|
20133
|
-
subject.input.readOnly = true;
|
|
20134
|
-
description.input.readOnly = true;
|
|
20135
20771
|
message('We could not confirm whether your request was sent. Check submission to recover it. Your original text is kept unchanged.', true);
|
|
20136
20772
|
}
|
|
20137
20773
|
else {
|
|
20138
20774
|
uncertainSubmission = null;
|
|
20139
|
-
subject.input.readOnly = false;
|
|
20140
|
-
description.input.readOnly = false;
|
|
20141
20775
|
if (draftExpired) {
|
|
20142
20776
|
draftId = null;
|
|
20143
20777
|
draftPromise = null;
|
|
@@ -20148,6 +20782,13 @@ function mountHelpDeskForm(client, options) {
|
|
|
20148
20782
|
setFieldError(code, HELP_DESK_CODE_STEP_COPY.codeRefused);
|
|
20149
20783
|
focusAfter = code.input;
|
|
20150
20784
|
}
|
|
20785
|
+
else if (widgetSignIn && error instanceof SparkVaultError && error.code === 'user_cancelled') {
|
|
20786
|
+
// The request stays on who the reply goes to, ready to sign in again;
|
|
20787
|
+
// a hidden saved request is not here to speak of, so its note alone stays.
|
|
20788
|
+
if (recovery === null)
|
|
20789
|
+
message(SIGN_IN_CANCELLED_COPY);
|
|
20790
|
+
focusAfter = send;
|
|
20791
|
+
}
|
|
20151
20792
|
else {
|
|
20152
20793
|
message(draftExpired ? 'Your saved draft expired. Your text is kept. Choose your files again before sending.' : error.message, true);
|
|
20153
20794
|
}
|
|
@@ -20155,7 +20796,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20155
20796
|
setState(uncertainSubmission ? 'uncertain' : challenge ? 'verifying' : 'editing');
|
|
20156
20797
|
if (!alive(ownGeneration))
|
|
20157
20798
|
return;
|
|
20158
|
-
send.textContent =
|
|
20799
|
+
send.textContent = idleLabel();
|
|
20159
20800
|
notify$1(options.onError, error);
|
|
20160
20801
|
}
|
|
20161
20802
|
finally {
|
|
@@ -20163,6 +20804,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20163
20804
|
authenticating = false;
|
|
20164
20805
|
pending = false;
|
|
20165
20806
|
disable(completed);
|
|
20807
|
+
syncLeaveGuard();
|
|
20166
20808
|
focusSettled();
|
|
20167
20809
|
}
|
|
20168
20810
|
}
|
|
@@ -20235,6 +20877,8 @@ function mountHelpDeskForm(client, options) {
|
|
|
20235
20877
|
generation += 1;
|
|
20236
20878
|
stopResendCountdown();
|
|
20237
20879
|
attachments?.destroy(completed || uncertainSubmission !== null);
|
|
20880
|
+
composer.destroy();
|
|
20881
|
+
live.destroy();
|
|
20238
20882
|
unsubscribe();
|
|
20239
20883
|
form.removeEventListener('submit', onSubmit);
|
|
20240
20884
|
shell.destroy();
|
|
@@ -20259,24 +20903,50 @@ function mountHelpDeskForm(client, options) {
|
|
|
20259
20903
|
subject.input.value = composition.subject;
|
|
20260
20904
|
description.input.value = composition.body;
|
|
20261
20905
|
persistDraft();
|
|
20906
|
+
syncLeaveGuard();
|
|
20262
20907
|
},
|
|
20263
|
-
refill(
|
|
20264
|
-
if (destroyed || restoredDraft || safeComposition() === null)
|
|
20908
|
+
refill(issue) {
|
|
20909
|
+
if (destroyed || restoredDraft || recovery !== null || safeComposition() === null)
|
|
20265
20910
|
return false;
|
|
20911
|
+
const own = { subject: edited(subject.input, filledWith('subject')), body: edited(description.input, filledWith('body')) };
|
|
20912
|
+
const text = issue.trim();
|
|
20913
|
+
const placed = !own.subject && !own.body ? composeIssue(issue) : { subject: oneLine(text, MAX_SUBJECT_LEN) ? text : '', body: issue };
|
|
20266
20914
|
for (const [entry, key] of [[subject, 'subject'], [description, 'body']]) {
|
|
20267
|
-
if (
|
|
20268
|
-
|
|
20269
|
-
|
|
20270
|
-
|
|
20271
|
-
prefill[key] = composition[key];
|
|
20915
|
+
if (own[key])
|
|
20916
|
+
continue;
|
|
20917
|
+
entry.input.value = placed[key];
|
|
20918
|
+
clearFieldError(entry);
|
|
20272
20919
|
}
|
|
20920
|
+
filledFrom = issue;
|
|
20921
|
+
if (step === 'identity')
|
|
20922
|
+
recapText.textContent = subject.input.value.trim();
|
|
20273
20923
|
persistDraft();
|
|
20924
|
+
syncLeaveGuard();
|
|
20274
20925
|
return true;
|
|
20275
20926
|
},
|
|
20276
20927
|
resumeAfterAccess() {
|
|
20277
20928
|
if (!destroyed && !pending && !completed && uncertainSubmission === null)
|
|
20278
20929
|
message('');
|
|
20279
20930
|
},
|
|
20931
|
+
returnToRequest() {
|
|
20932
|
+
if (destroyed || step !== 'identity')
|
|
20933
|
+
return false;
|
|
20934
|
+
// While the sign-in window is open the request stays where it is.
|
|
20935
|
+
if (!pending)
|
|
20936
|
+
enterStep('details');
|
|
20937
|
+
return true;
|
|
20938
|
+
},
|
|
20939
|
+
focusEntry(focusOptions) {
|
|
20940
|
+
if (destroyed || form.hidden)
|
|
20941
|
+
return false;
|
|
20942
|
+
const asked = stepField();
|
|
20943
|
+
const entry = asked === subject.input && subject.input.value.trim() ? description.input : asked;
|
|
20944
|
+
if (entry.disabled || entry.readOnly)
|
|
20945
|
+
(step === 'identity' && reply ? reply.heading : heading).focus(focusOptions);
|
|
20946
|
+
else
|
|
20947
|
+
focusAtEnd(entry, focusOptions);
|
|
20948
|
+
return true;
|
|
20949
|
+
},
|
|
20280
20950
|
requestDismiss() {
|
|
20281
20951
|
if (destroyed)
|
|
20282
20952
|
return;
|
|
@@ -20310,18 +20980,28 @@ function mountHelpDeskForm(client, options) {
|
|
|
20310
20980
|
keepEditing.addEventListener('click', () => closeConfirm(true));
|
|
20311
20981
|
discard.addEventListener('click', dismiss);
|
|
20312
20982
|
form.addEventListener('submit', onSubmit);
|
|
20313
|
-
form.addEventListener('input',
|
|
20314
|
-
form.addEventListener('change', () => {
|
|
20315
|
-
if (attachments?.hasEntries)
|
|
20316
|
-
restoredFiles = false;
|
|
20983
|
+
form.addEventListener('input', () => {
|
|
20317
20984
|
persistDraft();
|
|
20985
|
+
syncLeaveGuard();
|
|
20318
20986
|
});
|
|
20987
|
+
send.textContent = idleLabel();
|
|
20319
20988
|
renderWidgetIdentity();
|
|
20989
|
+
// A signed-out widget customer starts on step 1 of 2 with focus in the request.
|
|
20990
|
+
if (widget && !widgetCustomer)
|
|
20991
|
+
live.announce('Step 1 of 2');
|
|
20320
20992
|
if (options.widgetIdentity?.customer) {
|
|
20321
20993
|
restoreDraft(options.widgetIdentity.customer);
|
|
20322
20994
|
disable(false);
|
|
20323
20995
|
}
|
|
20324
|
-
else if (
|
|
20996
|
+
else if (widget?.recovering) {
|
|
20997
|
+
recovery = 'external_sso';
|
|
20998
|
+
websiteSignedOut = widget.recovering.websiteSignedOut;
|
|
20999
|
+
disable(false);
|
|
21000
|
+
renderActions();
|
|
21001
|
+
}
|
|
21002
|
+
else if (options.persist && filledFrom === undefined) {
|
|
21003
|
+
// The support wizard hands a composition it carries to restoreComposition;
|
|
21004
|
+
// a form of the host's own restores the one saved before a reload.
|
|
20325
21005
|
const saved = readAnonymousFormDraft(client.desk.desk_id);
|
|
20326
21006
|
if (saved) {
|
|
20327
21007
|
subject.input.value = saved.subject;
|
|
@@ -20329,6 +21009,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20329
21009
|
restoredAnonymous = true;
|
|
20330
21010
|
}
|
|
20331
21011
|
}
|
|
21012
|
+
syncLeaveGuard();
|
|
20332
21013
|
notify$1(options.onStateChange, state);
|
|
20333
21014
|
// Native company identity starts as the form opens, never from a Connect,
|
|
20334
21015
|
// Allow, verification or submit gesture. Guest email is explicit desk policy.
|
|
@@ -22556,58 +23237,6 @@ function createSupportLauncher(options, open) {
|
|
|
22556
23237
|
};
|
|
22557
23238
|
}
|
|
22558
23239
|
|
|
22559
|
-
/** A title written with a period: in "Dear Mr. Smith," that period ends no sentence. */
|
|
22560
|
-
const HONORIFIC = String.raw `(?:Mr|Mrs|Ms|Mx|Dr|Prof)\.`;
|
|
22561
|
-
/**
|
|
22562
|
-
* Where a sentence ends: after a period, exclamation or question mark that
|
|
22563
|
-
* whitespace follows. An honorific's period is matched first, whole, and left
|
|
22564
|
-
* as it is.
|
|
22565
|
-
*/
|
|
22566
|
-
const SENTENCE_END = new RegExp(String.raw `\b${HONORIFIC}(?=\s)|([.!?])(?=\s)`, 'g');
|
|
22567
|
-
/** The word a greeting opens with, whole: "Hi", "Hello", "Good morning", "Morning". */
|
|
22568
|
-
const SALUTATION = /^(?:hi|hello|hey|hiya|howdy|greetings|dear|good\s+day|(?:good\s+)?(?:morning|afternoon|evening))(?!\p{L})/iu;
|
|
22569
|
-
/** The few words greetings use for whom they address. */
|
|
22570
|
-
const ADDRESS_WORDS = 'again|there|team|all|everyone|everybody|folks|guys|support|customer|service|sir|madam|or|and';
|
|
22571
|
-
/**
|
|
22572
|
-
* What may follow the salutation in a greeting: up to four words of address,
|
|
22573
|
-
* each an honorific, a name or one of the few words greetings use, in lower
|
|
22574
|
-
* case or capitals ("Mr. Smith", "Privacy Bee team", "there", "AGAIN", "Sir
|
|
22575
|
-
* or Madam"), then anything but letters and digits: punctuation, symbols and
|
|
22576
|
-
* emoji. The words of an issue ("Hi, I can't sign in", "Hey refund please",
|
|
22577
|
-
* "HELLO I CANT LOGIN") are none of these, so a sentence holding them is the
|
|
22578
|
-
* issue. A name is a capital and lowercase letters, again for each capital of
|
|
22579
|
-
* one like PayPal or McKenzie, so a word in capitals is shouted, not a name.
|
|
22580
|
-
* Case-sensitive, so that case tells a name: a case-insensitive \p{Lu} matches
|
|
22581
|
-
* every letter. A name's apostrophes and hyphens only join letters, so a word
|
|
22582
|
-
* of address ends in a letter or an honorific's period, and the closing run
|
|
22583
|
-
* never competes with it for more than that one period; that keeps the read
|
|
22584
|
-
* linear.
|
|
22585
|
-
*/
|
|
22586
|
-
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');
|
|
22587
|
-
const TO_WHOM = /^to\s+whom\s+it\s+may\s+concern[^\p{L}\p{N}]*$/iu;
|
|
22588
|
-
const LETTER = /\p{L}/u;
|
|
22589
|
-
/** A line or sentence that only greets: "Hi there,", "Good morning team!", "Dear Sir or Madam,", "To whom it may concern:". */
|
|
22590
|
-
function isGreeting(sentence) {
|
|
22591
|
-
const salutation = SALUTATION.exec(sentence);
|
|
22592
|
-
return salutation ? ADDRESS.test(sentence.slice(salutation[0].length)) : TO_WHOM.test(sentence);
|
|
22593
|
-
}
|
|
22594
|
-
/**
|
|
22595
|
-
* The subject a support issue prefills: its first line or sentence that holds
|
|
22596
|
-
* a word and says more than a greeting (its first one when none does),
|
|
22597
|
-
* shortened at a word boundary with an ellipsis to fit MAX_SUBJECT_LEN. The
|
|
22598
|
-
* message carries the whole issue, so the subject only needs to name it.
|
|
22599
|
-
*/
|
|
22600
|
-
function issueSubject(issue) {
|
|
22601
|
-
const sentences = issue.replace(SENTENCE_END, (match, end) => end ? `${end}\n` : match)
|
|
22602
|
-
.split('\n').map((sentence) => sentence.trim()).filter(Boolean);
|
|
22603
|
-
const subject = sentences.find((sentence) => LETTER.test(sentence) && !isGreeting(sentence)) ?? sentences[0] ?? '';
|
|
22604
|
-
if (subject.length <= MAX_SUBJECT_LEN)
|
|
22605
|
-
return subject;
|
|
22606
|
-
const kept = truncateToLength(subject, MAX_SUBJECT_LEN - 1);
|
|
22607
|
-
const atWord = /\s/u.test(subject.charAt(kept.length)) ? kept : kept.replace(/\s+\S*$/u, '');
|
|
22608
|
-
return `${atWord.trimEnd()}…`;
|
|
22609
|
-
}
|
|
22610
|
-
|
|
22611
23240
|
/** The support journey's only skin. Customer content stays in the product register. */
|
|
22612
23241
|
function injectHelpDeskSupportStyles() {
|
|
22613
23242
|
if (document.getElementById('sparkvault-help-desk-support-styles'))
|
|
@@ -22733,11 +23362,10 @@ function injectHelpDeskSupportStyles() {
|
|
|
22733
23362
|
.svhs-unlock-form{margin:0}
|
|
22734
23363
|
.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}
|
|
22735
23364
|
.svhs-contact-target .svhd-body{display:flex;flex:1;flex-direction:column;min-height:0}
|
|
22736
|
-
.svhs-contact-target .svhd-container h2{
|
|
23365
|
+
.svhs-contact-target .svhd-container h2{font-size:22px;line-height:1.25;letter-spacing:-.6px;overflow-wrap:anywhere}
|
|
22737
23366
|
.svhs-contact-target .svhd-form{gap:16px}
|
|
22738
23367
|
.svhs-contact-target .svhd-label{font-size:13px;line-height:1.5}
|
|
22739
23368
|
.svhs-contact-target .svhd-input{font-size:16px;line-height:1.5}
|
|
22740
|
-
.svhs-contact-target .svhd-description{min-height:138px}
|
|
22741
23369
|
.svhs-contact-target .svhd-actions{gap:10px}
|
|
22742
23370
|
.svhs-contact-target .svhd-button:not(.svhd-secondary){background:var(--hd-accent,${DS.action});color:var(--hd-on-accent,${DS.white})}
|
|
22743
23371
|
.svhs-contact-target .svhd-button:not(.svhd-secondary):hover{background:var(--hd-accent-hover,${DS.actionHover})}
|
|
@@ -22745,18 +23373,19 @@ function injectHelpDeskSupportStyles() {
|
|
|
22745
23373
|
.svhs-contact-target .svhd-actions>.svhd-button:first-child{flex:1}
|
|
22746
23374
|
.svhs-contact-target .svhd-status{font-size:14px}
|
|
22747
23375
|
.svhs-contact-target .svhd-auth{gap:14px}
|
|
22748
|
-
.svhs-contact-target .svhd-
|
|
22749
|
-
.svhs-contact-target .svhd-
|
|
22750
|
-
.svhs-contact-target .svhd-
|
|
22751
|
-
.svhs-contact-target .svhd-
|
|
22752
|
-
.svhs-
|
|
22753
|
-
.svhs-
|
|
22754
|
-
.svhs-contact-target .svhd-widget-account-link:focus-visible{outline:2px solid var(--hd-focus,var(--hd-accent-ink,${DS.action}));outline-offset:3px}
|
|
22755
|
-
.svhs-contact-target .svhd-widget-account-link:disabled{cursor:progress;color:${DS.slate500}}
|
|
23376
|
+
.svhs-contact-target .svhd-text-button{color:var(--hd-accent-ink,${DS.action})}
|
|
23377
|
+
.svhs-contact-target .svhd-text-button:disabled{color:${DS.slate500}}
|
|
23378
|
+
.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}
|
|
23379
|
+
@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}}
|
|
23380
|
+
.svhs-panel .svhd-composer-input:focus-visible{outline:none}
|
|
23381
|
+
.svhs-panel .svhd-composer button:focus-visible{outline-offset:-2px}
|
|
22756
23382
|
.svhs-contact-target .svhd-widget-names{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:12px}
|
|
22757
23383
|
.svhs-contact-target .svhd-widget-form{display:flex;flex:1;flex-direction:column;gap:16px}
|
|
22758
|
-
|
|
22759
|
-
.svhs-contact-target .svhd-widget-
|
|
23384
|
+
/* The request fills the panel: the details step, and in it the composer and its text, take the height the fields leave. */
|
|
23385
|
+
.svhs-contact-target .svhd-widget-form>[data-contact-step=details]{display:flex;flex:1;flex-direction:column;gap:16px}
|
|
23386
|
+
.svhs-contact-target .svhd-widget-form .svhd-composer-field{display:flex;flex:1;flex-direction:column;gap:6px;min-height:164px}
|
|
23387
|
+
.svhs-contact-target .svhd-widget-form .svhd-composer{flex:1}
|
|
23388
|
+
.svhs-contact-target .svhd-widget-form .svhd-composer-input{flex:1;min-height:120px}
|
|
22760
23389
|
.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}}
|
|
22761
23390
|
.svhs-contact-target .svhd-widget-form>.svhd-actions>.svhd-secondary{display:none}
|
|
22762
23391
|
.svhs-contact-target .svhd-widget-form .svhd-actions>.svhd-button{font-size:14px}
|
|
@@ -22769,7 +23398,6 @@ function injectHelpDeskSupportStyles() {
|
|
|
22769
23398
|
.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}
|
|
22770
23399
|
.svhs-receipt-note{white-space:pre-wrap;overflow-wrap:anywhere}
|
|
22771
23400
|
.svhs-receipt-actions{display:flex;flex-direction:column;align-items:center;gap:4px}
|
|
22772
|
-
.svhs-live{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
|
|
22773
23401
|
.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}
|
|
22774
23402
|
.svhs-toast svg{width:18px;height:18px;flex:none;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round}
|
|
22775
23403
|
.svhs-overlay{position:fixed;inset:0;z-index:2147482900;display:flex;background:${DS.white};padding:0;overflow:hidden}
|
|
@@ -22804,7 +23432,6 @@ function injectHelpDeskSupportStyles() {
|
|
|
22804
23432
|
.svhs-feedback-actions{margin-top:30px}
|
|
22805
23433
|
.svhs-feedback-actions .svhs-primary,.svhs-feedback-actions .svhs-secondary{min-height:48px}
|
|
22806
23434
|
.svhs-contact-scroll{padding:0}
|
|
22807
|
-
.svhs-contact-target .svhd-description{min-height:160px}
|
|
22808
23435
|
.svhs-contact-target>.svhd-container{padding:24px}
|
|
22809
23436
|
.svhs-contact-target .svhd-widget-form>.svhd-actions{padding-bottom:env(safe-area-inset-bottom)}
|
|
22810
23437
|
.svhs-receipt-scroll{padding-top:58px}
|
|
@@ -23170,24 +23797,6 @@ function button(className, text, action) {
|
|
|
23170
23797
|
node.addEventListener('click', action);
|
|
23171
23798
|
return node;
|
|
23172
23799
|
}
|
|
23173
|
-
function icon(name) {
|
|
23174
|
-
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
23175
|
-
svg.setAttribute('viewBox', '0 0 24 24');
|
|
23176
|
-
svg.setAttribute('aria-hidden', 'true');
|
|
23177
|
-
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
23178
|
-
path.setAttribute('d', {
|
|
23179
|
-
back: 'm14.5 6-6 6 6 6',
|
|
23180
|
-
close: 'm6 6 12 12M18 6 6 18',
|
|
23181
|
-
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',
|
|
23182
|
-
check: 'm5 12 4 4L19 6',
|
|
23183
|
-
article: 'M14 3H6a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8Zm0 0v5h5M8 12h8M8 16h6',
|
|
23184
|
-
chevron: 'm9 6 6 6-6 6',
|
|
23185
|
-
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',
|
|
23186
|
-
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',
|
|
23187
|
-
}[name]);
|
|
23188
|
-
svg.append(path);
|
|
23189
|
-
return svg;
|
|
23190
|
-
}
|
|
23191
23800
|
function httpUrl(value, base = window.location.href) {
|
|
23192
23801
|
if (!value)
|
|
23193
23802
|
return null;
|
|
@@ -23246,7 +23855,6 @@ class SupportView {
|
|
|
23246
23855
|
this.receiptCopy = element('p', 'svhs-copy');
|
|
23247
23856
|
this.receiptTicket = element('a', 'svhs-ticket-link');
|
|
23248
23857
|
this.receiptMessage = element('p', 'svhs-copy svhs-receipt-note');
|
|
23249
|
-
this.live = element('div', 'svhs-live');
|
|
23250
23858
|
this.identityNotice = element('div', 'svhs-identity-notice');
|
|
23251
23859
|
this.onMediaChange = () => this.syncPresentation();
|
|
23252
23860
|
this.onViewportChange = () => this.syncViewport();
|
|
@@ -23259,6 +23867,24 @@ class SupportView {
|
|
|
23259
23867
|
this.ticketGateSignature = '';
|
|
23260
23868
|
this.toastCleanups = new Set();
|
|
23261
23869
|
this.destroyed = false;
|
|
23870
|
+
// A multi-click that began before the screen changed (the panel opening, a
|
|
23871
|
+
// new stage or article, a new contact form, its step, or its request and
|
|
23872
|
+
// actions changing in place), wherever its first press
|
|
23873
|
+
// was, lands its later presses on a screen the customer has not seen yet:
|
|
23874
|
+
// they neither take focus there nor reach what is under them. A press in the
|
|
23875
|
+
// panel that starts anew, or a key press, acts as usual.
|
|
23876
|
+
this.screenChanges = 0;
|
|
23877
|
+
this.pressedAt = 0;
|
|
23878
|
+
this.onPress = (event) => {
|
|
23879
|
+
if (event.detail <= 1) {
|
|
23880
|
+
this.pressedAt = this.screenChanges;
|
|
23881
|
+
return;
|
|
23882
|
+
}
|
|
23883
|
+
if (this.screenChanges === this.pressedAt)
|
|
23884
|
+
return;
|
|
23885
|
+
event.preventDefault();
|
|
23886
|
+
event.stopPropagation();
|
|
23887
|
+
};
|
|
23262
23888
|
injectHelpDeskSupportStyles();
|
|
23263
23889
|
this.phoneHistory = !target && actions.onBrowserBack && actions.onBrowserForward ? new SupportPhoneHistory({
|
|
23264
23890
|
onBack: () => this.actions.onBrowserBack?.(),
|
|
@@ -23271,20 +23897,20 @@ class SupportView {
|
|
|
23271
23897
|
this.panel.hidden = true;
|
|
23272
23898
|
this.panel.setAttribute('aria-labelledby', `${this.prefix}-name`);
|
|
23273
23899
|
this.deskName.id = `${this.prefix}-name`;
|
|
23274
|
-
this.
|
|
23275
|
-
this.
|
|
23900
|
+
this.panel.addEventListener('mousedown', this.onPress, true);
|
|
23901
|
+
this.panel.addEventListener('click', this.onPress, true);
|
|
23276
23902
|
const toolbar = element('header', 'svhs-toolbar');
|
|
23277
23903
|
this.toolbar = toolbar;
|
|
23278
23904
|
this.back = button('svhs-back', 'Back', () => this.actions.onBack());
|
|
23279
|
-
this.back.prepend(
|
|
23905
|
+
this.back.prepend(helpDeskIcon('back'));
|
|
23280
23906
|
this.close = button('svhs-icon-button', '', () => this.actions.onClose());
|
|
23281
23907
|
this.close.setAttribute('aria-label', 'Close support');
|
|
23282
|
-
this.close.append(
|
|
23908
|
+
this.close.append(helpDeskIcon('close'));
|
|
23283
23909
|
this.external.setAttribute('aria-label', 'Open article in a new tab');
|
|
23284
23910
|
this.external.title = 'Open article in a new tab';
|
|
23285
23911
|
this.external.target = '_blank';
|
|
23286
23912
|
this.external.rel = 'noopener noreferrer';
|
|
23287
|
-
this.external.append(
|
|
23913
|
+
this.external.append(helpDeskIcon('external'));
|
|
23288
23914
|
const toolbarActions = element('div', 'svhs-toolbar-actions');
|
|
23289
23915
|
toolbarActions.append(this.external);
|
|
23290
23916
|
if (!target)
|
|
@@ -23358,9 +23984,9 @@ class SupportView {
|
|
|
23358
23984
|
const readerActions = element('div', 'svhs-reader-actions');
|
|
23359
23985
|
const yes = button('svhs-primary', 'Yes', () => { if (this.state?.article && !this.state.busy && !this.state.error)
|
|
23360
23986
|
this.actions.onAnswered(); });
|
|
23361
|
-
yes.prepend(
|
|
23987
|
+
yes.prepend(helpDeskIcon('thumbUp'));
|
|
23362
23988
|
const no = button('svhs-text-button', 'No, create a ticket', () => this.actions.onContact('article_not_answered'));
|
|
23363
|
-
no.prepend(
|
|
23989
|
+
no.prepend(helpDeskIcon('thumbDown'));
|
|
23364
23990
|
readerActions.append(yes, no);
|
|
23365
23991
|
this.articleFooter.append(element('span', 'svhs-article-question', 'Did this resolve your question?'), readerActions);
|
|
23366
23992
|
this.screens.get('article').append(this.articleFooter);
|
|
@@ -23402,7 +24028,7 @@ class SupportView {
|
|
|
23402
24028
|
contact.append(this.contactTarget);
|
|
23403
24029
|
const receipt = this.screen('receipt', 'Message sent');
|
|
23404
24030
|
receipt.classList.add('svhs-receipt-scroll');
|
|
23405
|
-
const receiptMark =
|
|
24031
|
+
const receiptMark = helpDeskIcon('check');
|
|
23406
24032
|
receiptMark.classList.add('svhs-receipt-mark');
|
|
23407
24033
|
receipt.prepend(receiptMark);
|
|
23408
24034
|
this.receiptTicket.target = '_blank';
|
|
@@ -23413,7 +24039,6 @@ class SupportView {
|
|
|
23413
24039
|
if (!target)
|
|
23414
24040
|
receiptFooter.append(button('svhs-secondary svhs-full', 'Done', () => this.actions.onClose()));
|
|
23415
24041
|
receiptFooter.append(this.restart);
|
|
23416
|
-
this.panel.append(this.live);
|
|
23417
24042
|
this.media = typeof window.matchMedia === 'function' ? window.matchMedia('(max-width:640px)') : null;
|
|
23418
24043
|
if (!target) {
|
|
23419
24044
|
this.media?.addEventListener('change', this.onMediaChange);
|
|
@@ -23502,24 +24127,34 @@ class SupportView {
|
|
|
23502
24127
|
if (!next.visible)
|
|
23503
24128
|
return;
|
|
23504
24129
|
if (!previous?.visible || previous.stage !== next.stage || previous.article?.id !== next.article?.id) {
|
|
24130
|
+
// A new screen, however it opened: from a press in the panel, the
|
|
24131
|
+
// launcher or a host link.
|
|
24132
|
+
this.screenChanges += 1;
|
|
23505
24133
|
this.restoreScroll(next);
|
|
23506
24134
|
this.focusCurrent();
|
|
23507
24135
|
}
|
|
23508
24136
|
}
|
|
24137
|
+
/** A new contact form, or one whose controls changed in place: a change of screen, as a new stage is. */
|
|
24138
|
+
contactScreenChanged() {
|
|
24139
|
+
this.screenChanges += 1;
|
|
24140
|
+
}
|
|
23509
24141
|
/** Programmatic close invalidates Forward restoration even after neutral Back. */
|
|
23510
24142
|
deactivateHistory() {
|
|
23511
24143
|
this.phoneHistory?.deactivate();
|
|
23512
24144
|
}
|
|
23513
|
-
/** Focus the shared form after its controller has mounted it. */
|
|
24145
|
+
/** Focus the shared form where the customer goes on, else its heading, after its controller has mounted it. */
|
|
23514
24146
|
focusContact() {
|
|
23515
24147
|
if (this.destroyed || !this.state?.visible || this.state.stage !== 'contact')
|
|
23516
24148
|
return;
|
|
23517
24149
|
const heading = this.contactTarget.querySelector('h1,h2,h3');
|
|
23518
24150
|
this.contactTitle.hidden = Boolean(heading);
|
|
23519
24151
|
this.contactTitle.parentElement.hidden = this.contactTitle.hidden && this.contactStatus.hidden && this.contactError.hidden && this.sourceArticle.hidden;
|
|
24152
|
+
const focusOptions = { preventScroll: !this.target };
|
|
24153
|
+
if (!this.contactTarget.hidden && this.actions.onFocusContact?.(focusOptions))
|
|
24154
|
+
return;
|
|
23520
24155
|
const target = heading ?? this.contactTarget;
|
|
23521
24156
|
target.tabIndex = -1;
|
|
23522
|
-
target.focus(
|
|
24157
|
+
target.focus(focusOptions);
|
|
23523
24158
|
}
|
|
23524
24159
|
/** Hydrate only the current reader's matching authorized publication assets. */
|
|
23525
24160
|
setArticleAsset(path, blobUrl) {
|
|
@@ -23570,7 +24205,7 @@ class SupportView {
|
|
|
23570
24205
|
const toast = element('div', 'svhs-toast');
|
|
23571
24206
|
toast.setAttribute('role', 'status');
|
|
23572
24207
|
toast.setAttribute('aria-atomic', 'true');
|
|
23573
|
-
toast.append(
|
|
24208
|
+
toast.append(helpDeskIcon('check'), document.createTextNode(message));
|
|
23574
24209
|
document.body.append(toast);
|
|
23575
24210
|
const arrange = () => {
|
|
23576
24211
|
let offset = 0;
|
|
@@ -23621,6 +24256,8 @@ class SupportView {
|
|
|
23621
24256
|
return;
|
|
23622
24257
|
this.destroyed = true;
|
|
23623
24258
|
this.phoneHistory?.destroy();
|
|
24259
|
+
this.panel.removeEventListener('mousedown', this.onPress, true);
|
|
24260
|
+
this.panel.removeEventListener('click', this.onPress, true);
|
|
23624
24261
|
document.removeEventListener('keydown', this.onKeydown);
|
|
23625
24262
|
this.media?.removeEventListener('change', this.onMediaChange);
|
|
23626
24263
|
window.visualViewport?.removeEventListener('resize', this.onViewportChange);
|
|
@@ -23691,9 +24328,9 @@ class SupportView {
|
|
|
23691
24328
|
copy.append(element('span', 'svhs-result-excerpt', result.summary));
|
|
23692
24329
|
if (result.category)
|
|
23693
24330
|
copy.append(element('span', 'svhs-result-category', result.category));
|
|
23694
|
-
const documentIcon =
|
|
24331
|
+
const documentIcon = helpDeskIcon('article');
|
|
23695
24332
|
documentIcon.classList.add('svhs-result-icon');
|
|
23696
|
-
const chevron =
|
|
24333
|
+
const chevron = helpDeskIcon('chevron');
|
|
23697
24334
|
chevron.classList.add('svhs-result-chevron');
|
|
23698
24335
|
open.append(documentIcon, copy, chevron);
|
|
23699
24336
|
item.append(open);
|
|
@@ -24065,8 +24702,6 @@ class SupportView {
|
|
|
24065
24702
|
}
|
|
24066
24703
|
}
|
|
24067
24704
|
|
|
24068
|
-
/** What contact starts from: the issue's subject and, as the message, every character of the issue. */
|
|
24069
|
-
function composeIssue(issue) { return { subject: issueSubject(issue), body: issue }; }
|
|
24070
24705
|
function notify(callback, value) {
|
|
24071
24706
|
try {
|
|
24072
24707
|
void Promise.resolve(callback?.(value)).catch(() => undefined);
|
|
@@ -24092,10 +24727,14 @@ function createHelpDeskSupport(config, options) {
|
|
|
24092
24727
|
// only while it is the current sequence, so whatever supersedes it frees it.
|
|
24093
24728
|
let contactOpening = null;
|
|
24094
24729
|
let pendingComposition = null;
|
|
24095
|
-
//
|
|
24096
|
-
//
|
|
24097
|
-
|
|
24098
|
-
//
|
|
24730
|
+
// A website-account customer's saved request the next form keeps hidden,
|
|
24731
|
+
// asked for through the website account, which may give no account back.
|
|
24732
|
+
let pendingRecovery = null;
|
|
24733
|
+
// The issue, as written, that the held composition (the mounted form, the one
|
|
24734
|
+
// a re-authorized form will take, or the one saved before a reload) was last
|
|
24735
|
+
// filled from: '' for one filled from none. A form taking that composition is
|
|
24736
|
+
// filled from it too, so the text it carries is the customer's own, or not,
|
|
24737
|
+
// as it was in the form it came from.
|
|
24099
24738
|
let composedFrom = '';
|
|
24100
24739
|
let nativeIdentity = null;
|
|
24101
24740
|
let switchedAccount = false;
|
|
@@ -24129,6 +24768,9 @@ function createHelpDeskSupport(config, options) {
|
|
|
24129
24768
|
onBack: () => {
|
|
24130
24769
|
if (destroyed || state.navigationLocked || state.identityPending)
|
|
24131
24770
|
return;
|
|
24771
|
+
// On who the reply goes to, Back returns to the request it is for.
|
|
24772
|
+
if (state.stage === 'contact' && !state.ticketAccessRequired && contact?.returnToRequest())
|
|
24773
|
+
return;
|
|
24132
24774
|
// A held form shows at once while contact still checks access behind it,
|
|
24133
24775
|
// so a contact opening in flight is cancelled even when nothing is busy.
|
|
24134
24776
|
if (state.busy || contactOpening === sequence)
|
|
@@ -24175,6 +24817,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24175
24817
|
onUnlock: (password) => { void unlock(password); },
|
|
24176
24818
|
onUnlockTicketAccess: (password) => { void unlockTicketAccess(password); },
|
|
24177
24819
|
onCancelIdentity: () => nativeIdentity?.abort(),
|
|
24820
|
+
onFocusContact: (focusOptions) => contact?.focusEntry(focusOptions) ?? false,
|
|
24178
24821
|
onBrowserBack: minimize,
|
|
24179
24822
|
onBrowserForward: () => update({ visible: true }),
|
|
24180
24823
|
}, options.target === undefined ? undefined : resolveTarget(options.target));
|
|
@@ -24254,7 +24897,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24254
24897
|
const saved = readFormDraft(active.desk.desk_id, customer.requester_id);
|
|
24255
24898
|
const composition = readAnonymousFormDraft(active.desk.desk_id);
|
|
24256
24899
|
if ((saved || composition) && !state.issue) {
|
|
24257
|
-
update({ issue: saved
|
|
24900
|
+
update({ issue: saved ? ticketBody(saved.subject, saved.body) : readSupportIssue(active.desk.desk_id) ?? '' });
|
|
24258
24901
|
await showContact('direct');
|
|
24259
24902
|
}
|
|
24260
24903
|
else if (!state.issue)
|
|
@@ -24333,6 +24976,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24333
24976
|
results = [];
|
|
24334
24977
|
requestedArticle = null;
|
|
24335
24978
|
pendingComposition = null;
|
|
24979
|
+
pendingRecovery = null;
|
|
24336
24980
|
feedbackSequence += 1;
|
|
24337
24981
|
sourceArticleId = undefined;
|
|
24338
24982
|
if (options.persist && client)
|
|
@@ -24493,18 +25137,28 @@ function createHelpDeskSupport(config, options) {
|
|
|
24493
25137
|
notify(options.onError, error);
|
|
24494
25138
|
}
|
|
24495
25139
|
}
|
|
24496
|
-
|
|
25140
|
+
/** Mount the contact form filled from `composedFrom`, then put a composition carried from an earlier form in it. */
|
|
25141
|
+
function mountContact(carried, customer) {
|
|
24497
25142
|
if (!client || destroyed)
|
|
24498
25143
|
return;
|
|
24499
25144
|
contactCustomer = customer;
|
|
25145
|
+
// A customer the website gave back sees their own saved request; none keeps it hidden.
|
|
25146
|
+
const recovering = customer ? null : pendingRecovery;
|
|
25147
|
+
pendingRecovery = null;
|
|
24500
25148
|
let activeAttempt = null;
|
|
25149
|
+
// A ticket carries the attempt the form opened under only while it is still
|
|
25150
|
+
// the journey's: recovery drops it with the previous customer's question.
|
|
25151
|
+
const formAttempt = attempt;
|
|
25152
|
+
const bridged = Boolean(options.getSessionToken || options.getIdentityAssertion || options.identityEndpoint);
|
|
24501
25153
|
contact = mountHelpDeskForm(client, {
|
|
24502
25154
|
target: view.contactTarget,
|
|
24503
|
-
// Filled
|
|
25155
|
+
// Filled from the issue its composition came from, so text the customer
|
|
24504
25156
|
// wrote in an earlier form and carried here stays their own.
|
|
24505
|
-
|
|
25157
|
+
issue: composedFrom,
|
|
24506
25158
|
attachments: options.attachments,
|
|
24507
25159
|
persist: options.persist,
|
|
25160
|
+
pageLayout: options.target !== undefined,
|
|
25161
|
+
hostShowsAttribution: options.hostShowsAttribution === true,
|
|
24508
25162
|
onSession: (session) => {
|
|
24509
25163
|
anonymous = false;
|
|
24510
25164
|
if (options.persist)
|
|
@@ -24515,9 +25169,14 @@ function createHelpDeskSupport(config, options) {
|
|
|
24515
25169
|
customer,
|
|
24516
25170
|
signIn: (input) => signIn(input).then((session) => { contactCustomer = session.customer; return session; }),
|
|
24517
25171
|
switchAccount: (safe) => { void switchAccount(safe); },
|
|
24518
|
-
...(
|
|
25172
|
+
...(bridged && { useWebsiteAccount: (safe, recover) => { void useWebsiteAccount(safe, recover); } }),
|
|
25173
|
+
offerWebsiteAccount: switchedAccount,
|
|
25174
|
+
forgetIssue,
|
|
25175
|
+
followIssue,
|
|
25176
|
+
...(recovering && { recovering }),
|
|
24519
25177
|
},
|
|
24520
|
-
|
|
25178
|
+
onScreenChange: () => view.contactScreenChanged(),
|
|
25179
|
+
assistanceContext: () => (attempt === formAttempt ? activeAttempt?.ticketContext() : undefined),
|
|
24521
25180
|
sourceArticleId: () => sourceArticleId,
|
|
24522
25181
|
onError: (error) => {
|
|
24523
25182
|
notify(options.onError, error);
|
|
@@ -24536,11 +25195,14 @@ function createHelpDeskSupport(config, options) {
|
|
|
24536
25195
|
onSuccess: (ticket) => receipt(ticket),
|
|
24537
25196
|
onStateChange: (next) => update({ navigationLocked: ['authenticating', 'submitting', 'uncertain'].includes(next) }),
|
|
24538
25197
|
});
|
|
24539
|
-
|
|
24540
|
-
|
|
25198
|
+
// A form in place of another can put a different control under the pointer.
|
|
25199
|
+
view.contactScreenChanged();
|
|
25200
|
+
if (carried)
|
|
25201
|
+
contact.restoreComposition(carried);
|
|
25202
|
+
// A carried composition was filled from the issue as it read then.
|
|
24541
25203
|
followIssue();
|
|
24542
25204
|
const activeForm = contact;
|
|
24543
|
-
void
|
|
25205
|
+
void formAttempt?.then((active) => {
|
|
24544
25206
|
// Keep the mutable callback small: an analytics response arriving late
|
|
24545
25207
|
// must not delay contact, authentication or ticket submission.
|
|
24546
25208
|
if (contact === activeForm && active)
|
|
@@ -24556,10 +25218,30 @@ function createHelpDeskSupport(config, options) {
|
|
|
24556
25218
|
*/
|
|
24557
25219
|
function followIssue() {
|
|
24558
25220
|
const issue = state.issue.trim();
|
|
24559
|
-
if (!contact || !issue || issue === composedFrom)
|
|
25221
|
+
if (!contact || !issue || issue === composedFrom.trim())
|
|
24560
25222
|
return;
|
|
24561
|
-
if (contact.refill(
|
|
24562
|
-
composedFrom = issue;
|
|
25223
|
+
if (contact.refill(state.issue))
|
|
25224
|
+
composedFrom = state.issue;
|
|
25225
|
+
}
|
|
25226
|
+
/**
|
|
25227
|
+
* Forget the question of a customer whose request just left the contact
|
|
25228
|
+
* form: it, and the answers and article it led to, are theirs, in view and
|
|
25229
|
+
* in this tab's storage. The visitor is unknown again until one signs in,
|
|
25230
|
+
* so the tab keeps their next question as any signed-out visitor's.
|
|
25231
|
+
*/
|
|
25232
|
+
function forgetIssue() {
|
|
25233
|
+
cancelArticleAssets?.();
|
|
25234
|
+
cancelArticleAssets = null;
|
|
25235
|
+
kbConfig = null;
|
|
25236
|
+
results = [];
|
|
25237
|
+
requestedArticle = null;
|
|
25238
|
+
attempt = null;
|
|
25239
|
+
sourceArticleId = undefined;
|
|
25240
|
+
composedFrom = '';
|
|
25241
|
+
anonymous = true;
|
|
25242
|
+
if (options.persist && client)
|
|
25243
|
+
clearSupportIssue(client.desk.desk_id);
|
|
25244
|
+
update({ issue: '', results: [], article: undefined, articleUrl: undefined, kbState: undefined, sourceArticle: undefined });
|
|
24563
25245
|
}
|
|
24564
25246
|
async function showContact(reason) {
|
|
24565
25247
|
if (destroyed || contactOpening === sequence)
|
|
@@ -24606,12 +25288,16 @@ function createHelpDeskSupport(config, options) {
|
|
|
24606
25288
|
return;
|
|
24607
25289
|
update({ busy: false, ticketAccessRequired: false, ticketAccessMode: undefined });
|
|
24608
25290
|
anonymous = !customer;
|
|
24609
|
-
|
|
25291
|
+
// A composition saved before a reload goes on from the issue it was filled
|
|
25292
|
+
// from; with none carried, the form fills itself from the issue as written.
|
|
25293
|
+
const saved = pendingComposition === null && options.persist ? readAnonymousFormDraft(active.desk.desk_id) : null;
|
|
25294
|
+
if (saved)
|
|
25295
|
+
composedFrom = saved.composedFrom;
|
|
25296
|
+
else if (pendingComposition === null)
|
|
25297
|
+
composedFrom = state.issue;
|
|
24610
25298
|
if (customer && options.persist)
|
|
24611
25299
|
clearSupportIssue(active.desk.desk_id);
|
|
24612
|
-
|
|
24613
|
-
composedFrom = state.issue.trim();
|
|
24614
|
-
mountContact(composition, customer);
|
|
25300
|
+
mountContact(pendingComposition ?? saved, customer);
|
|
24615
25301
|
pendingComposition = null;
|
|
24616
25302
|
}
|
|
24617
25303
|
catch (value) {
|
|
@@ -24675,6 +25361,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24675
25361
|
cancelArticleAssets?.();
|
|
24676
25362
|
cancelArticleAssets = null;
|
|
24677
25363
|
pendingComposition = composition ?? { subject: '', body: '' };
|
|
25364
|
+
pendingRecovery = null;
|
|
24678
25365
|
kb?.clearAccess();
|
|
24679
25366
|
kbConfig = null;
|
|
24680
25367
|
results = [];
|
|
@@ -24714,7 +25401,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24714
25401
|
await showContact('direct');
|
|
24715
25402
|
}
|
|
24716
25403
|
}
|
|
24717
|
-
async function useWebsiteAccount(composition) {
|
|
25404
|
+
async function useWebsiteAccount(composition, recovering = false) {
|
|
24718
25405
|
if (!client || destroyed || state.navigationLocked)
|
|
24719
25406
|
return;
|
|
24720
25407
|
const ownSequence = ++sequence;
|
|
@@ -24723,6 +25410,7 @@ function createHelpDeskSupport(config, options) {
|
|
|
24723
25410
|
cancelArticleAssets?.();
|
|
24724
25411
|
cancelArticleAssets = null;
|
|
24725
25412
|
pendingComposition = composition ?? { subject: '', body: '' };
|
|
25413
|
+
pendingRecovery = recovering ? { websiteSignedOut: true } : null;
|
|
24726
25414
|
kb?.clearAccess();
|
|
24727
25415
|
kbConfig = null;
|
|
24728
25416
|
results = [];
|
|
@@ -24743,6 +25431,9 @@ function createHelpDeskSupport(config, options) {
|
|
|
24743
25431
|
return;
|
|
24744
25432
|
const error = failure(value);
|
|
24745
25433
|
update({ busy: false, error: error.message });
|
|
25434
|
+
// The website was not reached, so it is not known to have no account.
|
|
25435
|
+
if (pendingRecovery)
|
|
25436
|
+
pendingRecovery = { websiteSignedOut: false };
|
|
24746
25437
|
if (client.hasTicketAccess) {
|
|
24747
25438
|
mountContact(composition ?? { subject: '', body: '' }, null);
|
|
24748
25439
|
pendingComposition = null;
|
|
@@ -29557,7 +30248,7 @@ class SparkVault {
|
|
|
29557
30248
|
}
|
|
29558
30249
|
/** Get the SDK version */
|
|
29559
30250
|
static get version() {
|
|
29560
|
-
return '16.
|
|
30251
|
+
return '16.5.0';
|
|
29561
30252
|
}
|
|
29562
30253
|
}
|
|
29563
30254
|
if (typeof window !== 'undefined') {
|