@sparkvault/sdk-js 18.0.4 → 18.0.5
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 +1 -1
- package/dist/index.cjs +594 -123
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +594 -123
- package/dist/index.mjs.map +1 -1
- package/dist/products/help-desk/form.d.ts +4 -4
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -19573,6 +19573,8 @@ const HELP_DESK_COLORS = Object.freeze({
|
|
|
19573
19573
|
fillStrong: `var(--hd-fill-strong,${LIGHT['--color-slate-200']})`,
|
|
19574
19574
|
/** A field's and a secondary action's edge. */
|
|
19575
19575
|
lineStrong: `var(--hd-line-strong,${LIGHT['--color-slate-300']})`,
|
|
19576
|
+
/** A modal's scrim stays dark in either scheme; the alpha belongs to the surface. */
|
|
19577
|
+
modalBackdrop: `var(--hd-modal-backdrop,${LIGHT['--ink']})`,
|
|
19576
19578
|
ink: `var(--hd-ink,${LIGHT['--ink']})`,
|
|
19577
19579
|
body: `var(--hd-text-body,${LIGHT['--text-body']})`,
|
|
19578
19580
|
muted: `var(--hd-text-muted,${LIGHT['--text-muted']})`,
|
|
@@ -19712,7 +19714,6 @@ function injectHelpDeskFormStyles() {
|
|
|
19712
19714
|
.svhd-hint{font-size:13px;color:${HELP_DESK_COLORS.body};margin:0}
|
|
19713
19715
|
.svhd-step{display:grid;gap:16px;min-width:0}
|
|
19714
19716
|
.svhd-step-head{display:grid;gap:4px;margin-bottom:4px}
|
|
19715
|
-
.svhd-step-label{margin:0;font-size:13px;font-weight:600;line-height:1.4;color:${HELP_DESK_COLORS.body}}
|
|
19716
19717
|
.svhd-text-button{display:inline-flex;align-items:center;min-height:44px;padding:0 4px;border:0;border-radius:6px;background:transparent;color:${HELP_DESK_ACCENT.ink};font:inherit;font-size:14px;font-weight:600;text-decoration:underline;text-underline-offset:2px;cursor:pointer}
|
|
19717
19718
|
.svhd-text-button:not(:disabled):hover{text-decoration-thickness:2px}
|
|
19718
19719
|
.svhd-text-button:focus-visible{outline:3px solid ${HELP_DESK_FOCUS};outline-offset:2px}
|
|
@@ -20261,7 +20262,7 @@ function acceptedKindsCopy(kinds) {
|
|
|
20261
20262
|
/**
|
|
20262
20263
|
* The files a ticket accepts, in the one phrase every surface names them by,
|
|
20263
20264
|
* built from the policy's own list (ACCEPTED_ATTACHMENT_KINDS): the help desk
|
|
20264
|
-
* composer's
|
|
20265
|
+
* composer's refusal dialog reads it, and so do the API reference
|
|
20265
20266
|
* (apps/api/openapi/overlay.mjs) and the help desk's page on the site
|
|
20266
20267
|
* (apps/www/_data/helpDeskAttachments.js). A refused file's sentence names
|
|
20267
20268
|
* only that its type can't be attached.
|
|
@@ -20269,10 +20270,9 @@ function acceptedKindsCopy(kinds) {
|
|
|
20269
20270
|
const ACCEPTED_ATTACHMENTS_COPY = acceptedKindsCopy(ACCEPTED_ATTACHMENT_KINDS);
|
|
20270
20271
|
|
|
20271
20272
|
/**
|
|
20272
|
-
*
|
|
20273
|
-
*
|
|
20274
|
-
*
|
|
20275
|
-
* Attach.
|
|
20273
|
+
* The attachment rules shown after a refusal: what to add, how many files a
|
|
20274
|
+
* message takes and how large each may be. The help desk composer's
|
|
20275
|
+
* validation dialog reads this without adding prose to accepted uploads.
|
|
20276
20276
|
*/
|
|
20277
20277
|
const CUSTOMER_ATTACHMENTS_HINT =
|
|
20278
20278
|
`Add screenshots, documents or recordings. Up to ${MAX_ATTACHMENTS_PER_MESSAGE} files, ${formatBytes(CUSTOMER_ATTACHMENT_MAX_BYTES)} each.`;
|
|
@@ -20346,6 +20346,386 @@ function refusalCopy(refusal, maxBytes) {
|
|
|
20346
20346
|
return REFUSAL_COPY[refusal] ?? "This file can't be attached.";
|
|
20347
20347
|
}
|
|
20348
20348
|
|
|
20349
|
+
/**
|
|
20350
|
+
* Strict single-value media type (MIME) parsing.
|
|
20351
|
+
*
|
|
20352
|
+
* The one parser for a stored ingot or spark `content_type`: Core validates
|
|
20353
|
+
* every ingested value with it, Forge derives both the served Content-Type and
|
|
20354
|
+
* the inline-render decision from it, the display rules the web console and
|
|
20355
|
+
* the x.sv pages share (display-content-type.js), the Spark payload rule
|
|
20356
|
+
* (`isTextMediaType`) and the server's registry readings (media-type-node.js)
|
|
20357
|
+
* read the essence through it, so no two readers can disagree about what a
|
|
20358
|
+
* value means. A page that cannot import an ES module runs this module's own
|
|
20359
|
+
* source (MEDIA_TYPE_SCRIPT).
|
|
20360
|
+
*
|
|
20361
|
+
* Grammar (RFC 9110 §8.3.1): `type "/" subtype *( OWS ";" OWS [ parameter ] )`
|
|
20362
|
+
* where type, subtype and parameter names are tokens and parameter values are
|
|
20363
|
+
* tokens or quoted-strings, ASCII only. One deliberate tightening: a comma
|
|
20364
|
+
* anywhere rejects the value. Browsers read Content-Type as a comma-separated
|
|
20365
|
+
* list and keep the LAST valid type (WHATWG Fetch "extract a MIME type"), so a
|
|
20366
|
+
* value that this parser would classify by its first type can render in a
|
|
20367
|
+
* browser as another: `image/png, text/html` executes as HTML.
|
|
20368
|
+
*
|
|
20369
|
+
* BROWSER-SAFE: pure string handling, no Node built-ins.
|
|
20370
|
+
*/
|
|
20371
|
+
|
|
20372
|
+
/** Longest accepted value; RFC 6838 caps type and subtype at 127 chars each. */
|
|
20373
|
+
const MAX_MEDIA_TYPE_LENGTH = 255;
|
|
20374
|
+
const TOKEN_CHAR = /[!#$%&'*+.^_`|~0-9A-Za-z-]/;
|
|
20375
|
+
/** qdtext: HTAB, SP and visible ASCII except `"` and backslash. */
|
|
20376
|
+
const QUOTED_TEXT_CHAR = /[\t\x20\x21\x23-\x5b\x5d-\x7e]/;
|
|
20377
|
+
/** The character after the backslash of a quoted-pair: HTAB, SP or visible ASCII. */
|
|
20378
|
+
const QUOTED_PAIR_CHAR = /[\t\x20-\x7e]/;
|
|
20379
|
+
|
|
20380
|
+
/** Index just past the token starting at `start` (=== start when there is none). */
|
|
20381
|
+
function tokenEnd(value, start) {
|
|
20382
|
+
let end = start;
|
|
20383
|
+
while (end < value.length && TOKEN_CHAR.test(value[end])) end += 1;
|
|
20384
|
+
return end;
|
|
20385
|
+
}
|
|
20386
|
+
|
|
20387
|
+
/** Index just past the optional whitespace (SP / HTAB) starting at `start`. */
|
|
20388
|
+
function owsEnd(value, start) {
|
|
20389
|
+
let end = start;
|
|
20390
|
+
while (value[end] === ' ' || value[end] === '\t') end += 1;
|
|
20391
|
+
return end;
|
|
20392
|
+
}
|
|
20393
|
+
|
|
20394
|
+
/**
|
|
20395
|
+
* Read the quoted-string whose opening quote is at `start`.
|
|
20396
|
+
* @returns {{end: number, text: string} | null} The index past the closing
|
|
20397
|
+
* quote and the unescaped content; null when malformed or unterminated.
|
|
20398
|
+
*/
|
|
20399
|
+
function readQuotedString(value, start) {
|
|
20400
|
+
let text = '';
|
|
20401
|
+
let index = start + 1;
|
|
20402
|
+
while (index < value.length) {
|
|
20403
|
+
const char = value[index];
|
|
20404
|
+
if (char === '"') return { end: index + 1, text };
|
|
20405
|
+
if (char === '\\') {
|
|
20406
|
+
const escaped = value[index + 1];
|
|
20407
|
+
if (escaped === undefined || !QUOTED_PAIR_CHAR.test(escaped)) return null;
|
|
20408
|
+
text += escaped;
|
|
20409
|
+
index += 2;
|
|
20410
|
+
} else if (QUOTED_TEXT_CHAR.test(char)) {
|
|
20411
|
+
text += char;
|
|
20412
|
+
index += 1;
|
|
20413
|
+
} else {
|
|
20414
|
+
return null;
|
|
20415
|
+
}
|
|
20416
|
+
}
|
|
20417
|
+
return null;
|
|
20418
|
+
}
|
|
20419
|
+
|
|
20420
|
+
/**
|
|
20421
|
+
* Parse one media type value.
|
|
20422
|
+
*
|
|
20423
|
+
* A single left-to-right scan: every character is examined a bounded number
|
|
20424
|
+
* of times, so the cost is linear in the (already length-capped) input. Core
|
|
20425
|
+
* runs this on untrusted request bodies, where a backtracking grammar would
|
|
20426
|
+
* let one crafted value stall the process.
|
|
20427
|
+
*
|
|
20428
|
+
* @param {unknown} value - A stored or submitted content type
|
|
20429
|
+
* @returns {{
|
|
20430
|
+
* type: string,
|
|
20431
|
+
* subtype: string,
|
|
20432
|
+
* essence: string,
|
|
20433
|
+
* parameters: Map<string, string>
|
|
20434
|
+
* } | null} Lowercased type/subtype/essence and parameter names, unquoted
|
|
20435
|
+
* parameter values (the first occurrence of a name wins); null when the
|
|
20436
|
+
* value is not exactly one well-formed media type.
|
|
20437
|
+
*/
|
|
20438
|
+
function parseMediaType(value) {
|
|
20439
|
+
if (typeof value !== 'string' || value.length > MAX_MEDIA_TYPE_LENGTH || value.includes(',')) {
|
|
20440
|
+
return null;
|
|
20441
|
+
}
|
|
20442
|
+
|
|
20443
|
+
const typeEnd = tokenEnd(value, 0);
|
|
20444
|
+
if (typeEnd === 0 || value[typeEnd] !== '/') return null;
|
|
20445
|
+
const subtypeEnd = tokenEnd(value, typeEnd + 1);
|
|
20446
|
+
if (subtypeEnd === typeEnd + 1) return null;
|
|
20447
|
+
|
|
20448
|
+
const type = value.slice(0, typeEnd).toLowerCase();
|
|
20449
|
+
const subtype = value.slice(typeEnd + 1, subtypeEnd).toLowerCase();
|
|
20450
|
+
const parameters = new Map();
|
|
20451
|
+
|
|
20452
|
+
// parameters = *( OWS ";" OWS [ parameter ] )
|
|
20453
|
+
let index = subtypeEnd;
|
|
20454
|
+
while (index < value.length) {
|
|
20455
|
+
index = owsEnd(value, index);
|
|
20456
|
+
if (value[index] !== ';') return null;
|
|
20457
|
+
index = owsEnd(value, index + 1);
|
|
20458
|
+
if (index === value.length || value[index] === ';') continue; // empty slot
|
|
20459
|
+
|
|
20460
|
+
const nameEnd = tokenEnd(value, index);
|
|
20461
|
+
if (nameEnd === index || value[nameEnd] !== '=') return null;
|
|
20462
|
+
const name = value.slice(index, nameEnd).toLowerCase();
|
|
20463
|
+
|
|
20464
|
+
let parameterValue;
|
|
20465
|
+
if (value[nameEnd + 1] === '"') {
|
|
20466
|
+
const quoted = readQuotedString(value, nameEnd + 1);
|
|
20467
|
+
if (!quoted) return null;
|
|
20468
|
+
parameterValue = quoted.text;
|
|
20469
|
+
index = quoted.end;
|
|
20470
|
+
} else {
|
|
20471
|
+
const valueEnd = tokenEnd(value, nameEnd + 1);
|
|
20472
|
+
if (valueEnd === nameEnd + 1) return null;
|
|
20473
|
+
parameterValue = value.slice(nameEnd + 1, valueEnd);
|
|
20474
|
+
index = valueEnd;
|
|
20475
|
+
}
|
|
20476
|
+
|
|
20477
|
+
if (!parameters.has(name)) parameters.set(name, parameterValue);
|
|
20478
|
+
}
|
|
20479
|
+
|
|
20480
|
+
return { type, subtype, essence: `${type}/${subtype}`, parameters };
|
|
20481
|
+
}
|
|
20482
|
+
|
|
20483
|
+
/**
|
|
20484
|
+
* The essence of a content type: its lowercased `type/subtype`, parameters
|
|
20485
|
+
* dropped (`application/json` of `Application/JSON; charset=utf-8`). An exact
|
|
20486
|
+
* type filter matches an ingot on it.
|
|
20487
|
+
*
|
|
20488
|
+
* The x.sv page runs this function's source (MEDIA_TYPE_SCRIPT), so it keeps
|
|
20489
|
+
* to the ECMAScript 2018 the page parses as (docs/GOTCHAS.md).
|
|
20490
|
+
*
|
|
20491
|
+
* @param {unknown} value
|
|
20492
|
+
* @returns {string|null} null when the value is not exactly one well-formed
|
|
20493
|
+
* media type
|
|
20494
|
+
*/
|
|
20495
|
+
function mediaTypeEssence(value) {
|
|
20496
|
+
const mediaType = parseMediaType(value);
|
|
20497
|
+
return mediaType === null ? null : mediaType.essence;
|
|
20498
|
+
}
|
|
20499
|
+
|
|
20500
|
+
/**
|
|
20501
|
+
* Sound formats platforms type outside the audio tree, each an essence: the
|
|
20502
|
+
* Ogg container, as Firefox types every `.ogg` file (any other platform's
|
|
20503
|
+
* audio/ogg), and WMA as Chrome on macOS types a `.wma` file (Firefox's
|
|
20504
|
+
* audio/x-ms-wma). Each is filed with the audio (mediaTypeFamily), and is
|
|
20505
|
+
* the audio kind's (./ingot-kind.js), so a file's icon and the type filter
|
|
20506
|
+
* that lists it agree.
|
|
20507
|
+
*/
|
|
20508
|
+
const SOUND_TYPES_OUTSIDE_AUDIO = Object.freeze(['application/ogg', 'video/x-ms-wma']);
|
|
20509
|
+
|
|
20510
|
+
new Set(SOUND_TYPES_OUTSIDE_AUDIO);
|
|
20511
|
+
|
|
20512
|
+
/**
|
|
20513
|
+
* Content-type policy for vault and spark bytes a browser page displays or
|
|
20514
|
+
* saves.
|
|
20515
|
+
*
|
|
20516
|
+
* Every display blob becomes a blob: URL in the displaying page's own origin,
|
|
20517
|
+
* and a viewer can open one as a top-level document ("Open image in new tab",
|
|
20518
|
+
* dragging a thumbnail to the tab bar). A stored content_type is caller-supplied
|
|
20519
|
+
* (the public upload portal and any spark creator included), so a blob typed
|
|
20520
|
+
* image/svg+xml, text/html or any XML type would run that caller's script as
|
|
20521
|
+
* the page. Only types every browser renders inertly may therefore reach one,
|
|
20522
|
+
* decided by allowlist so an unknown or malformed type fails closed: the
|
|
20523
|
+
* essence is read by the platform's one media-type parser, and a declared value
|
|
20524
|
+
* that is not exactly one well-formed media type matches no entry.
|
|
20525
|
+
*
|
|
20526
|
+
* A save hands the browser a blob too, and a browser renames a saved copy by
|
|
20527
|
+
* the blob's type, by its own MIME table, refused extensions included:
|
|
20528
|
+
* Firefox saves `Invoice` handed as `application/x-javascript` as
|
|
20529
|
+
* `Invoice.js`, and `Invoice.pdf` handed as `image/svg+xml` as `Invoice.svg`,
|
|
20530
|
+
* and Chromium completes a name that has no extension from a blob's type
|
|
20531
|
+
* alike. Neither completes or replaces an extension by the type of a name
|
|
20532
|
+
* handed as application/octet-stream (docs/GOTCHAS.md). The name a file
|
|
20533
|
+
* saves under is completed by the MIME registry, which only the server
|
|
20534
|
+
* carries (Core answers it as `download_filename`, by ./media-type-node.js
|
|
20535
|
+
* downloadFilename), so a save hands the browser the display-safe type as
|
|
20536
|
+
* well: an inert type keeps its own, from which a browser completes a name
|
|
20537
|
+
* the registry left bare (`Recording` under `audio/flac` saves as
|
|
20538
|
+
* `Recording.flac`), and every other type goes as opaque bytes.
|
|
20539
|
+
*
|
|
20540
|
+
* The one rule for every surface that does this: the web console consumes these
|
|
20541
|
+
* functions directly (its file display path retypes through withDisplaySafeType,
|
|
20542
|
+
* as the one blob save does, saveBlob in ./browser-download.js), the x.sv pages
|
|
20543
|
+
* run this module's own source (DISPLAY_CONTENT_TYPE_SCRIPT), and Forge serves a
|
|
20544
|
+
* response inline on its own origin only when isInertDocumentType says so
|
|
20545
|
+
* (apps/forge/src/routes/decrypt.js). Forge and every client save hand an
|
|
20546
|
+
* inert type to the browser under its own type whatever the file's name, since
|
|
20547
|
+
* a browser renames a download by the type it is handed: an inert type is an
|
|
20548
|
+
* image, audio, video or PDF format, so whatever extension a browser gives its
|
|
20549
|
+
* copy opens it as what it is.
|
|
20550
|
+
*
|
|
20551
|
+
* BROWSER-SAFE: string handling and the platform's Blob, no Node built-ins.
|
|
20552
|
+
*/
|
|
20553
|
+
|
|
20554
|
+
/**
|
|
20555
|
+
* Raster formats: decoded as pixels by <img>, never parsed as a document that
|
|
20556
|
+
* could carry script. HEIC/HEIF stay listed for the case where on-the-fly JPEG
|
|
20557
|
+
* conversion fails and the original bytes are shown as-is.
|
|
20558
|
+
*/
|
|
20559
|
+
const INERT_IMAGE_TYPES = Object.freeze([
|
|
20560
|
+
'image/jpeg',
|
|
20561
|
+
'image/jpg',
|
|
20562
|
+
'image/pjpeg',
|
|
20563
|
+
'image/png',
|
|
20564
|
+
'image/x-png',
|
|
20565
|
+
'image/apng',
|
|
20566
|
+
'image/gif',
|
|
20567
|
+
'image/webp',
|
|
20568
|
+
'image/avif',
|
|
20569
|
+
'image/jxl',
|
|
20570
|
+
'image/bmp',
|
|
20571
|
+
'image/x-ms-bmp',
|
|
20572
|
+
'image/x-icon',
|
|
20573
|
+
'image/vnd.microsoft.icon',
|
|
20574
|
+
'image/tiff',
|
|
20575
|
+
'image/heic',
|
|
20576
|
+
'image/heif'
|
|
20577
|
+
]);
|
|
20578
|
+
|
|
20579
|
+
new Set(INERT_IMAGE_TYPES);
|
|
20580
|
+
|
|
20581
|
+
/**
|
|
20582
|
+
* The platform's one essence reader (./media-type.js), bound in this module's
|
|
20583
|
+
* own scope. The functions DISPLAY_CONTENT_TYPE_SCRIPT carries read it by this
|
|
20584
|
+
* name, which the page binds to the reader MEDIA_TYPE_SCRIPT declares, never
|
|
20585
|
+
* by its imported name: a module transform rewrites an imported name inside a
|
|
20586
|
+
* function's source (vitest's, which every suite runs this module under, turns
|
|
20587
|
+
* `mediaTypeEssence` into `__vite_ssr_import_0__.mediaTypeEssence`), a name no
|
|
20588
|
+
* page declares.
|
|
20589
|
+
*/
|
|
20590
|
+
const essenceOf = mediaTypeEssence;
|
|
20591
|
+
|
|
20592
|
+
/*
|
|
20593
|
+
* Audio and video formats, each under the types the MIME registry files it
|
|
20594
|
+
* under and the ones browsers and Apple's platforms report for it
|
|
20595
|
+
* (`audio/flac`, `audio/vnd.wave`, `audio/aiff`, Chromium's `video/matroska`
|
|
20596
|
+
* and `audio/matroska`, Firefox's `application/ogg` for a `.ogg` file, and,
|
|
20597
|
+
* where Chromium asks the platform: on macOS `video/avi` for a `.avi` file,
|
|
20598
|
+
* `video/x-ms-wma` for a `.wma` one and `audio/x-m4r` for an iPhone ringtone,
|
|
20599
|
+
* and on Windows `audio/vnd.dlna.adts` for a `.aac` one):
|
|
20600
|
+
* encoded sound and pictures, which a browser plays in its own player, never
|
|
20601
|
+
* as a scriptable document, or downloads under the extension its table names
|
|
20602
|
+
* for the type (`.mp3`, `.mov`, `.avi`, `.ogg`), which a desktop opens in a
|
|
20603
|
+
* media player.
|
|
20604
|
+
*
|
|
20605
|
+
* Never a playlist or a stream redirector (`audio/x-mpegurl`,
|
|
20606
|
+
* `audio/x-scpls`, `video/x-ms-asx`, `audio/x-pn-realaudio`): it names media
|
|
20607
|
+
* a player then fetches, and a browser downloads it whatever name it is
|
|
20608
|
+
* handed, saving it as `.m3u`, `.pls`, `.asx` (which Outlook blocks) or
|
|
20609
|
+
* `.ram`; nor `video/x-ms-asf`, under which the registry files the `.asx`
|
|
20610
|
+
* redirector too. An allowlist, so an audio or video type no entry names
|
|
20611
|
+
* fails closed, one with a structured-syntax suffix among them (`video/x+xml`,
|
|
20612
|
+
* which a navigated browser renders as an XML document, script included).
|
|
20613
|
+
*/
|
|
20614
|
+
|
|
20615
|
+
/** The audio formats: sound, which a browser plays in its player. */
|
|
20616
|
+
const INERT_AUDIO_TYPES = Object.freeze([
|
|
20617
|
+
'audio/3gpp',
|
|
20618
|
+
'audio/aac',
|
|
20619
|
+
'audio/x-aac',
|
|
20620
|
+
'audio/vnd.dlna.adts',
|
|
20621
|
+
'audio/aiff',
|
|
20622
|
+
'audio/x-aiff',
|
|
20623
|
+
'audio/amr',
|
|
20624
|
+
'audio/basic',
|
|
20625
|
+
'audio/flac',
|
|
20626
|
+
'audio/x-flac',
|
|
20627
|
+
'audio/matroska',
|
|
20628
|
+
'audio/x-matroska',
|
|
20629
|
+
'audio/midi',
|
|
20630
|
+
'audio/mp3',
|
|
20631
|
+
'audio/mpeg',
|
|
20632
|
+
'audio/mp4',
|
|
20633
|
+
'audio/x-m4a',
|
|
20634
|
+
'audio/x-m4r',
|
|
20635
|
+
'audio/ogg',
|
|
20636
|
+
'audio/wav',
|
|
20637
|
+
'audio/wave',
|
|
20638
|
+
'audio/vnd.wave',
|
|
20639
|
+
'audio/x-wav',
|
|
20640
|
+
'audio/webm',
|
|
20641
|
+
'audio/x-caf',
|
|
20642
|
+
'audio/x-ms-wma',
|
|
20643
|
+
'video/x-ms-wma'
|
|
20644
|
+
]);
|
|
20645
|
+
|
|
20646
|
+
/**
|
|
20647
|
+
* The Ogg container, as Firefox types a `.ogg` file: the one inert type that
|
|
20648
|
+
* does not say whether its files hold sound alone or pictures too. It renders
|
|
20649
|
+
* as a video, whose player plays either.
|
|
20650
|
+
*/
|
|
20651
|
+
const OGG_CONTAINER_TYPE = 'application/ogg';
|
|
20652
|
+
|
|
20653
|
+
/**
|
|
20654
|
+
* The video formats: pictures and sound, which a browser plays in its player,
|
|
20655
|
+
* the Ogg container among them (OGG_CONTAINER_TYPE).
|
|
20656
|
+
*/
|
|
20657
|
+
const INERT_VIDEO_TYPES = Object.freeze([
|
|
20658
|
+
'video/3gpp',
|
|
20659
|
+
'video/3gpp2',
|
|
20660
|
+
'video/matroska',
|
|
20661
|
+
'video/x-matroska',
|
|
20662
|
+
'video/mp2t',
|
|
20663
|
+
'video/mp4',
|
|
20664
|
+
'video/x-m4v',
|
|
20665
|
+
'video/mpeg',
|
|
20666
|
+
'video/ogg',
|
|
20667
|
+
OGG_CONTAINER_TYPE,
|
|
20668
|
+
'video/quicktime',
|
|
20669
|
+
'video/webm',
|
|
20670
|
+
'video/x-flv',
|
|
20671
|
+
'video/x-msvideo',
|
|
20672
|
+
'video/avi',
|
|
20673
|
+
'video/x-ms-wmv'
|
|
20674
|
+
]);
|
|
20675
|
+
|
|
20676
|
+
const PDF_TYPE = 'application/pdf';
|
|
20677
|
+
|
|
20678
|
+
/**
|
|
20679
|
+
* How each inert type renders as a top-level document, by essence
|
|
20680
|
+
* (inertRendering). The x.sv pages read it through
|
|
20681
|
+
* DISPLAY_CONTENT_TYPE_SCRIPT, which serializes it.
|
|
20682
|
+
*/
|
|
20683
|
+
const INERT_RENDERING = new Map([
|
|
20684
|
+
...INERT_IMAGE_TYPES.map((type) => [type, 'image']),
|
|
20685
|
+
...INERT_AUDIO_TYPES.map((type) => [type, 'audio']),
|
|
20686
|
+
...INERT_VIDEO_TYPES.map((type) => [type, 'video']),
|
|
20687
|
+
[PDF_TYPE, 'pdf']
|
|
20688
|
+
]);
|
|
20689
|
+
|
|
20690
|
+
/**
|
|
20691
|
+
* Every type a browser renders inertly as a top-level document, as an essence:
|
|
20692
|
+
* a raster image (INERT_IMAGE_TYPES), an audio or video format, or a PDF,
|
|
20693
|
+
* which the browser's own PDF viewer renders.
|
|
20694
|
+
*/
|
|
20695
|
+
Object.freeze([...INERT_RENDERING.keys()]);
|
|
20696
|
+
|
|
20697
|
+
const OPAQUE_CONTENT_TYPE = 'application/octet-stream';
|
|
20698
|
+
|
|
20699
|
+
/** isInertDocumentType over an essence already read (essenceOf), null for a value that is no media type. */
|
|
20700
|
+
function isInertDocumentEssence(type) {
|
|
20701
|
+
return INERT_RENDERING.has(type);
|
|
20702
|
+
}
|
|
20703
|
+
|
|
20704
|
+
/**
|
|
20705
|
+
* The type a blob a page hands the browser, to display or to save, may carry:
|
|
20706
|
+
* its own essence when the browser renders it inertly, otherwise
|
|
20707
|
+
* application/octet-stream, which a navigated blob URL downloads instead of
|
|
20708
|
+
* rendering and which no browser completes a saved name from.
|
|
20709
|
+
* @param {string|null|undefined} contentType
|
|
20710
|
+
* @returns {string}
|
|
20711
|
+
*/
|
|
20712
|
+
function displaySafeContentType(contentType) {
|
|
20713
|
+
const type = essenceOf(contentType);
|
|
20714
|
+
return isInertDocumentEssence(type) ? type : OPAQUE_CONTENT_TYPE;
|
|
20715
|
+
}
|
|
20716
|
+
|
|
20717
|
+
/**
|
|
20718
|
+
* A blob as a page hands it to the browser, to display or to save: retyped to
|
|
20719
|
+
* displaySafeContentType of its own type, or the blob itself when it already
|
|
20720
|
+
* carries that type. slice() retypes without copying the bytes.
|
|
20721
|
+
* @param {Blob} blob
|
|
20722
|
+
* @returns {Blob}
|
|
20723
|
+
*/
|
|
20724
|
+
function withDisplaySafeType(blob) {
|
|
20725
|
+
const safeType = displaySafeContentType(blob.type);
|
|
20726
|
+
return blob.type === safeType ? blob : blob.slice(0, blob.size, safeType);
|
|
20727
|
+
}
|
|
20728
|
+
|
|
20349
20729
|
/**
|
|
20350
20730
|
* Files brought to a message's composer by drag, drop and paste, handled
|
|
20351
20731
|
* alike by every composer that takes them: the console's reply composer and
|
|
@@ -20547,6 +20927,7 @@ const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
|
|
|
20547
20927
|
|
|
20548
20928
|
const PATHS = Object.freeze({
|
|
20549
20929
|
back: 'm14.5 6-6 6 6 6',
|
|
20930
|
+
arrowRight: 'M4 12h16m-6-6 6 6-6 6',
|
|
20550
20931
|
close: 'm6 6 12 12M18 6 6 18',
|
|
20551
20932
|
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',
|
|
20552
20933
|
check: 'm5 12 4 4L19 6',
|
|
@@ -20603,10 +20984,10 @@ function helpDeskIcon(name) {
|
|
|
20603
20984
|
* takes no files from its customers is refused in words
|
|
20604
20985
|
* (NO_CUSTOMER_FILES_COPY), and one brought while files cannot join is
|
|
20605
20986
|
* never the browser's to open in place of the unsent message.
|
|
20606
|
-
* - **
|
|
20607
|
-
*
|
|
20608
|
-
*
|
|
20609
|
-
*
|
|
20987
|
+
* - **Requirements.** A rejected file opens one modal with its reason and
|
|
20988
|
+
* the attachment rules. A selection shares that modal, and dismissing it
|
|
20989
|
+
* leaves later refusals from the same selection in their chips. Accepted
|
|
20990
|
+
* images have local previews, including while waiting for sign-in.
|
|
20610
20991
|
* - **Uploading.** The browser's check (attachmentRefusal) first, then the
|
|
20611
20992
|
* host's transport: its target (the request a reply belongs to, or the
|
|
20612
20993
|
* draft a new request uploads to, which may not exist yet: the file then
|
|
@@ -20671,21 +21052,27 @@ const COMPOSER_CSS = `
|
|
|
20671
21052
|
.svhd-composer .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:${HELP_DESK_COLORS.selection};color:${HELP_DESK_ACCENT.ink};font-size:15px;font-weight:600;line-height:1.4;text-align:center;pointer-events:none}
|
|
20672
21053
|
.svhd-composer .svhd-composer-toolbar{display:flex;align-items:center;flex-wrap:wrap;gap:0 4px;padding:0 4px;border-top:1px solid ${HELP_DESK_COLORS.fillStrong}}
|
|
20673
21054
|
.svhd-composer .svhd-composer-attach{display:inline-flex;align-items:center;gap:6px;min-height:44px;margin:0;padding:0 8px;border:0;border-radius:6px;background:transparent;color:${HELP_DESK_COLORS.body};font-family:inherit;font-size:14px;font-weight:600;line-height:1.4;cursor:pointer}
|
|
20674
|
-
.svhd-composer .svhd-composer-attach:hover
|
|
21055
|
+
.svhd-composer .svhd-composer-attach:hover{background:${HELP_DESK_COLORS.fill};color:${HELP_DESK_COLORS.ink}}
|
|
20675
21056
|
.svhd-composer .svhd-composer-attach:disabled{opacity:.6;cursor:default}
|
|
20676
21057
|
.svhd-composer .svhd-composer-attach svg{display:block;width:18px;height:18px}
|
|
20677
|
-
.svhd-composer .svhd-composer-
|
|
20678
|
-
.svhd-composer .svhd-composer-
|
|
20679
|
-
.svhd-composer .svhd-composer-
|
|
20680
|
-
.svhd-composer .svhd-composer-
|
|
20681
|
-
.svhd-composer .svhd-composer-
|
|
20682
|
-
.svhd-composer .svhd-composer-
|
|
20683
|
-
.svhd-composer .svhd-composer-
|
|
20684
|
-
.svhd-composer .svhd-composer-
|
|
20685
|
-
.svhd-composer .svhd-composer-
|
|
21058
|
+
.svhd-composer .svhd-composer-validation-dialog{position:fixed;inset:0;width:min(480px,calc(100vw - 32px));max-height:calc(100dvh - 32px);margin:auto;padding:0;overflow:auto;border:1px solid ${HELP_DESK_COLORS.lineStrong};border-radius:12px;background:${HELP_DESK_COLORS.surface};color:${HELP_DESK_COLORS.ink};font:400 15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;text-align:left;overscroll-behavior:contain}
|
|
21059
|
+
.svhd-composer .svhd-composer-validation-dialog::backdrop{background:color-mix(in srgb,${HELP_DESK_COLORS.modalBackdrop} 60%,transparent)}
|
|
21060
|
+
.svhd-composer .svhd-composer-validation-header{display:flex;align-items:center;gap:12px;padding:16px 16px 8px 24px}
|
|
21061
|
+
.svhd-composer .svhd-composer-validation-title{flex:1;min-width:0;margin:0;font-family:inherit;font-size:20px;font-weight:600;line-height:1.3;overflow-wrap:anywhere}
|
|
21062
|
+
.svhd-composer .svhd-composer-validation-close{display:grid;place-items:center;flex:none;width:44px;height:44px;margin:0;padding:0;border:0;border-radius:6px;background:transparent;color:${HELP_DESK_COLORS.body};cursor:pointer}
|
|
21063
|
+
.svhd-composer .svhd-composer-validation-close:hover,.svhd-composer .svhd-attachment-remove:hover{background:${HELP_DESK_COLORS.fillStrong};color:${HELP_DESK_COLORS.ink}}
|
|
21064
|
+
.svhd-composer .svhd-composer-validation-close svg,.svhd-composer .svhd-attachment-remove svg{display:block;width:16px;height:16px}
|
|
21065
|
+
.svhd-composer .svhd-composer-refusals{display:grid;gap:12px;margin:0;padding:0 24px 24px;list-style:none;color:${HELP_DESK_COLORS.body};overflow-wrap:anywhere}
|
|
21066
|
+
.svhd-composer .svhd-composer-refusals strong{display:block;margin-bottom:2px;color:${HELP_DESK_COLORS.ink};font-weight:600}
|
|
21067
|
+
.svhd-composer .svhd-composer-requirements{padding:20px 24px;border-top:1px solid ${HELP_DESK_COLORS.fillStrong};background:${HELP_DESK_COLORS.canvas};color:${HELP_DESK_COLORS.body};font-size:13px;line-height:1.5}
|
|
21068
|
+
.svhd-composer .svhd-composer-requirements h3{margin:0 0 8px;color:${HELP_DESK_COLORS.ink};font-family:inherit;font-size:14px;font-weight:600}
|
|
21069
|
+
.svhd-composer .svhd-composer-requirements p{margin:0}
|
|
21070
|
+
.svhd-composer .svhd-composer-requirements p+p{margin-top:8px}
|
|
20686
21071
|
.svhd-composer .svhd-attachment-chips{display:flex;flex-wrap:wrap;gap:8px;list-style:none;margin:0;padding:8px;border-top:1px solid ${HELP_DESK_COLORS.fillStrong}}
|
|
20687
21072
|
.svhd-composer .svhd-attachment-chips:empty{display:none}
|
|
20688
21073
|
.svhd-composer .svhd-attachment-chip{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:center;align-content:start;flex:0 1 280px;min-width:0;max-width:100%;margin:0;padding:0 0 8px 10px;border:1px solid ${HELP_DESK_COLORS.fillStrong};border-radius:6px;background:${HELP_DESK_COLORS.canvas};font-size:13px;line-height:1.4}
|
|
21074
|
+
.svhd-composer .svhd-attachment-thumbnail{grid-column:1/-1;display:block;width:100%;height:96px;object-fit:contain;margin:8px 0;background:${HELP_DESK_COLORS.field};border-radius:4px}
|
|
21075
|
+
.svhd-composer .svhd-attachment-preview-unavailable{grid-column:1/-1;margin:8px 8px 0 0;color:${HELP_DESK_COLORS.muted};font-size:12px}
|
|
20689
21076
|
.svhd-composer .svhd-attachment-name{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:600;color:${HELP_DESK_COLORS.ink}}
|
|
20690
21077
|
.svhd-composer .svhd-attachment-status{grid-column:1;padding-right:8px;color:${HELP_DESK_COLORS.body};font-size:12px;overflow-wrap:anywhere}
|
|
20691
21078
|
.svhd-composer .svhd-attachment-status.svhd-composer-problem{color:${HELP_DESK_COLORS.error}}
|
|
@@ -20693,7 +21080,7 @@ const COMPOSER_CSS = `
|
|
|
20693
21080
|
.svhd-composer .svhd-attachment-remove{display:grid;place-items:center;width:44px;height:44px;min-height:44px;margin:0;padding:0;border:0;border-radius:6px;background:transparent;color:${HELP_DESK_COLORS.body};cursor:pointer}
|
|
20694
21081
|
.svhd-composer .svhd-attachment-retry{grid-column:2;min-height:44px;margin:0;padding:0 10px;border:0;border-radius:6px;background:transparent;color:${HELP_DESK_ACCENT.ink};font-family:inherit;font-size:13px;font-weight:600;line-height:1.4;text-decoration:underline;cursor:pointer}
|
|
20695
21082
|
.svhd-composer .svhd-attachment-remove:disabled,.svhd-composer .svhd-attachment-retry:disabled{opacity:.6;cursor:default}
|
|
20696
|
-
.svhd-composer .svhd-composer-attach:focus-visible,.svhd-composer .svhd-composer-
|
|
21083
|
+
.svhd-composer .svhd-composer-attach:focus-visible,.svhd-composer .svhd-composer-validation-close:focus-visible,.svhd-composer .svhd-attachment-remove:focus-visible,.svhd-composer .svhd-attachment-retry:focus-visible{${INSET_RING}}
|
|
20697
21084
|
.svhd-composer-notice{margin:0;color:${HELP_DESK_COLORS.error};font-size:14px;line-height:1.5}
|
|
20698
21085
|
.svhd-composer [hidden],.svhd-composer-notice[hidden]{display:none!important}
|
|
20699
21086
|
`;
|
|
@@ -20730,8 +21117,8 @@ const RECEIVED_COPY = 'File received. Waiting for storage confirmation.';
|
|
|
20730
21117
|
const UPLOAD_FAILED_COPY = "This file couldn't be uploaded. Try again or remove it.";
|
|
20731
21118
|
const UPLOADING_COPY = 'Uploading';
|
|
20732
21119
|
const VERIFYING_COPY = 'Verifying stored file';
|
|
20733
|
-
/**
|
|
20734
|
-
const
|
|
21120
|
+
/** Requirements appear only after a file is refused. */
|
|
21121
|
+
const VALIDATION_TITLE = 'Unable to attach files';
|
|
20735
21122
|
const ACCEPTED_KINDS_COPY = `You can attach ${ACCEPTED_ATTACHMENTS_COPY}.`;
|
|
20736
21123
|
|
|
20737
21124
|
/** What a message's files still need before it can be sent, from the most pressing. */
|
|
@@ -20870,9 +21257,7 @@ function createHelpDeskComposer(options) {
|
|
|
20870
21257
|
const zone = dropZone ?? frame;
|
|
20871
21258
|
const fields = [textarea, ...pasteFields];
|
|
20872
21259
|
|
|
20873
|
-
// The
|
|
20874
|
-
// extensions a request takes first, never the check), and its (?) tip,
|
|
20875
|
-
// whose limits also describe Attach.
|
|
21260
|
+
// The chooser filters names; the canonical attachment check decides.
|
|
20876
21261
|
const input = document.createElement('input');
|
|
20877
21262
|
input.type = 'file';
|
|
20878
21263
|
input.name = 'attachments';
|
|
@@ -20880,40 +21265,13 @@ function createHelpDeskComposer(options) {
|
|
|
20880
21265
|
input.accept = ATTACHMENT_INPUT_ACCEPT;
|
|
20881
21266
|
input.hidden = true;
|
|
20882
21267
|
input.tabIndex = -1;
|
|
20883
|
-
const hint = document.createElement('p');
|
|
20884
|
-
hint.id = `${textarea.id}-attachment-hint`;
|
|
20885
|
-
hint.textContent = CUSTOMER_ATTACHMENTS_HINT;
|
|
20886
|
-
const kinds = document.createElement('p');
|
|
20887
|
-
kinds.textContent = ACCEPTED_KINDS_COPY;
|
|
20888
21268
|
const attach = button$1('svhd-composer-attach', 'Attach files');
|
|
20889
|
-
attach.setAttribute('aria-describedby', hint.id);
|
|
20890
21269
|
const attachText = document.createElement('span');
|
|
20891
21270
|
attachText.textContent = 'Attach';
|
|
20892
21271
|
attach.append(helpDeskIcon('paperclip'), attachText);
|
|
20893
|
-
const helpPanel = document.createElement('div');
|
|
20894
|
-
helpPanel.id = `${textarea.id}-attachment-help`;
|
|
20895
|
-
helpPanel.className = 'svhd-composer-help-panel';
|
|
20896
|
-
helpPanel.setAttribute('role', 'region');
|
|
20897
|
-
helpPanel.setAttribute('aria-label', HELP_TITLE);
|
|
20898
|
-
helpPanel.hidden = true;
|
|
20899
|
-
const helpCopy = document.createElement('div');
|
|
20900
|
-
helpCopy.className = 'svhd-composer-help-copy';
|
|
20901
|
-
helpCopy.append(hint, kinds);
|
|
20902
|
-
const helpClose = button$1('svhd-composer-help-close', 'Close');
|
|
20903
|
-
helpClose.title = 'Close';
|
|
20904
|
-
helpClose.append(helpDeskIcon('close'));
|
|
20905
|
-
helpPanel.append(helpCopy, helpClose);
|
|
20906
|
-
const helpTrigger = button$1('svhd-composer-help', `Help: ${HELP_TITLE}`);
|
|
20907
|
-
helpTrigger.setAttribute('aria-expanded', 'false');
|
|
20908
|
-
helpTrigger.setAttribute('aria-controls', helpPanel.id);
|
|
20909
|
-
const glyph = document.createElement('span');
|
|
20910
|
-
glyph.className = 'svhd-composer-help-glyph';
|
|
20911
|
-
glyph.setAttribute('aria-hidden', 'true');
|
|
20912
|
-
glyph.textContent = '?';
|
|
20913
|
-
helpTrigger.append(glyph);
|
|
20914
21272
|
const toolbar = document.createElement('div');
|
|
20915
21273
|
toolbar.className = 'svhd-composer-toolbar';
|
|
20916
|
-
toolbar.append(attach,
|
|
21274
|
+
toolbar.append(attach, input);
|
|
20917
21275
|
const list = document.createElement('ul');
|
|
20918
21276
|
list.className = 'svhd-attachment-chips';
|
|
20919
21277
|
list.setAttribute('aria-label', 'Attached files');
|
|
@@ -20925,10 +21283,151 @@ function createHelpDeskComposer(options) {
|
|
|
20925
21283
|
let locked = false;
|
|
20926
21284
|
let pickingDisabled = false;
|
|
20927
21285
|
let destroyed = false;
|
|
21286
|
+
let validation = null;
|
|
20928
21287
|
const accepting = () => transport !== null && !locked && !pickingDisabled && !destroyed;
|
|
20929
21288
|
const current = (entry, ownRevision) =>
|
|
20930
21289
|
!destroyed && revision === ownRevision && entries.includes(entry) && !entry.controller?.signal.aborted;
|
|
20931
21290
|
|
|
21291
|
+
/** A selection keeps its refusal lifecycle even when its files settle at different times. */
|
|
21292
|
+
const selection = () => ({
|
|
21293
|
+
dismissed: false,
|
|
21294
|
+
returnFocus: document.activeElement instanceof HTMLElement && document.activeElement !== document.body
|
|
21295
|
+
? document.activeElement : textarea
|
|
21296
|
+
});
|
|
21297
|
+
|
|
21298
|
+
function dismissValidation() {
|
|
21299
|
+
const shown = validation;
|
|
21300
|
+
if (!shown) return;
|
|
21301
|
+
validation = null;
|
|
21302
|
+
for (const batch of shown.batches) batch.dismissed = true;
|
|
21303
|
+
if (shown.dialog.open) shown.dialog.close();
|
|
21304
|
+
shown.dialog.remove();
|
|
21305
|
+
document.documentElement.style.overflow = shown.overflow;
|
|
21306
|
+
if (!destroyed) {
|
|
21307
|
+
const target = shown.returnFocus.isConnected && !shown.returnFocus.disabled ? shown.returnFocus : textarea;
|
|
21308
|
+
target.focus();
|
|
21309
|
+
}
|
|
21310
|
+
}
|
|
21311
|
+
|
|
21312
|
+
/** Exact refusals share one top-layer dialog; later files never steal focus from its reader. */
|
|
21313
|
+
function reportRefusal(batch, key, filename, copy) {
|
|
21314
|
+
if (destroyed || batch.dismissed) return;
|
|
21315
|
+
let shown = validation;
|
|
21316
|
+
if (!shown) {
|
|
21317
|
+
const dialog = document.createElement('dialog');
|
|
21318
|
+
dialog.className = 'svhd-composer-validation-dialog';
|
|
21319
|
+
const title = document.createElement('h2');
|
|
21320
|
+
title.id = `${textarea.id}-attachment-validation-title`;
|
|
21321
|
+
title.className = 'svhd-composer-validation-title';
|
|
21322
|
+
title.textContent = VALIDATION_TITLE;
|
|
21323
|
+
dialog.setAttribute('aria-labelledby', title.id);
|
|
21324
|
+
const close = button$1('svhd-composer-validation-close', 'Close');
|
|
21325
|
+
close.title = 'Close';
|
|
21326
|
+
close.append(helpDeskIcon('close'));
|
|
21327
|
+
const header = document.createElement('div');
|
|
21328
|
+
header.className = 'svhd-composer-validation-header';
|
|
21329
|
+
header.append(title, close);
|
|
21330
|
+
const reasons = document.createElement('ul');
|
|
21331
|
+
reasons.className = 'svhd-composer-refusals';
|
|
21332
|
+
reasons.id = `${textarea.id}-attachment-refusals`;
|
|
21333
|
+
dialog.setAttribute('aria-describedby', reasons.id);
|
|
21334
|
+
reasons.setAttribute('aria-live', 'polite');
|
|
21335
|
+
const requirements = document.createElement('div');
|
|
21336
|
+
requirements.className = 'svhd-composer-requirements';
|
|
21337
|
+
const heading = document.createElement('h3');
|
|
21338
|
+
heading.textContent = 'What you can attach';
|
|
21339
|
+
const limits = document.createElement('p');
|
|
21340
|
+
limits.textContent = deskRefusesFiles ? NO_CUSTOMER_FILES_COPY : CUSTOMER_ATTACHMENTS_HINT;
|
|
21341
|
+
requirements.append(heading, limits);
|
|
21342
|
+
if (!deskRefusesFiles) {
|
|
21343
|
+
const kinds = document.createElement('p');
|
|
21344
|
+
kinds.textContent = ACCEPTED_KINDS_COPY;
|
|
21345
|
+
requirements.append(kinds);
|
|
21346
|
+
}
|
|
21347
|
+
dialog.append(header, reasons, requirements);
|
|
21348
|
+
shown = { dialog, reasons, close, issues: new Map(), batches: new Set(), returnFocus: batch.returnFocus, overflow: document.documentElement.style.overflow };
|
|
21349
|
+
validation = shown;
|
|
21350
|
+
close.addEventListener('click', () => dismissValidation());
|
|
21351
|
+
dialog.addEventListener('cancel', (event) => { event.preventDefault(); event.stopPropagation(); dismissValidation(); });
|
|
21352
|
+
dialog.addEventListener('close', () => { if (validation === shown) dismissValidation(); });
|
|
21353
|
+
dialog.addEventListener('keydown', (event) => {
|
|
21354
|
+
if (event.key === 'Escape') {
|
|
21355
|
+
event.preventDefault();
|
|
21356
|
+
event.stopPropagation();
|
|
21357
|
+
dismissValidation();
|
|
21358
|
+
} else if (event.key === 'Tab') {
|
|
21359
|
+
// Close is this dialog's one focusable control; keep keyboard focus with it.
|
|
21360
|
+
event.preventDefault();
|
|
21361
|
+
close.focus();
|
|
21362
|
+
}
|
|
21363
|
+
});
|
|
21364
|
+
const outside = (event) => {
|
|
21365
|
+
if (event.target !== dialog) return false;
|
|
21366
|
+
const bounds = dialog.getBoundingClientRect();
|
|
21367
|
+
return event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom;
|
|
21368
|
+
};
|
|
21369
|
+
let backdropPress = false;
|
|
21370
|
+
dialog.addEventListener('pointerdown', (event) => { backdropPress = outside(event); });
|
|
21371
|
+
dialog.addEventListener('click', (event) => { if (backdropPress && outside(event)) dismissValidation(); backdropPress = false; });
|
|
21372
|
+
frame.append(dialog);
|
|
21373
|
+
}
|
|
21374
|
+
shown.batches.add(batch);
|
|
21375
|
+
let reason = shown.issues.get(key);
|
|
21376
|
+
if (!reason) {
|
|
21377
|
+
reason = document.createElement('li');
|
|
21378
|
+
shown.issues.set(key, reason);
|
|
21379
|
+
shown.reasons.append(reason);
|
|
21380
|
+
}
|
|
21381
|
+
const text = document.createElement('span');
|
|
21382
|
+
text.textContent = copy;
|
|
21383
|
+
reason.replaceChildren();
|
|
21384
|
+
if (filename) {
|
|
21385
|
+
const name = document.createElement('strong');
|
|
21386
|
+
name.textContent = filename;
|
|
21387
|
+
reason.append(name);
|
|
21388
|
+
}
|
|
21389
|
+
reason.append(text);
|
|
21390
|
+
if (!shown.dialog.open) {
|
|
21391
|
+
shown.dialog.showModal();
|
|
21392
|
+
document.documentElement.style.overflow = 'hidden';
|
|
21393
|
+
shown.close.focus();
|
|
21394
|
+
}
|
|
21395
|
+
}
|
|
21396
|
+
|
|
21397
|
+
function releasePreview(entry) {
|
|
21398
|
+
if (!entry.previewUrl) return;
|
|
21399
|
+
URL.revokeObjectURL(entry.previewUrl);
|
|
21400
|
+
entry.previewUrl = null;
|
|
21401
|
+
}
|
|
21402
|
+
|
|
21403
|
+
/** Local validated images need no transfer; every blob is inert even if its declared MIME is hostile. */
|
|
21404
|
+
function preview(entry) {
|
|
21405
|
+
if (entry.previewAttempted || !ACCEPTED_ATTACHMENT_KINDS.images.includes(lastExtension(entry.file.name))) return;
|
|
21406
|
+
entry.previewAttempted = true;
|
|
21407
|
+
const image = document.createElement('img');
|
|
21408
|
+
image.className = 'svhd-attachment-thumbnail';
|
|
21409
|
+
image.alt = `Preview of ${entry.file.name}`;
|
|
21410
|
+
image.decoding = 'async';
|
|
21411
|
+
const unavailable = () => {
|
|
21412
|
+
releasePreview(entry);
|
|
21413
|
+
image.remove();
|
|
21414
|
+
if (destroyed || !entries.includes(entry)) return;
|
|
21415
|
+
const fallback = document.createElement('span');
|
|
21416
|
+
fallback.className = 'svhd-attachment-preview-unavailable';
|
|
21417
|
+
fallback.textContent = 'Preview unavailable';
|
|
21418
|
+
entry.row.prepend(fallback);
|
|
21419
|
+
};
|
|
21420
|
+
image.addEventListener('error', unavailable, { once: true });
|
|
21421
|
+
try {
|
|
21422
|
+
entry.previewUrl = URL.createObjectURL(withDisplaySafeType(entry.file));
|
|
21423
|
+
image.src = entry.previewUrl;
|
|
21424
|
+
entry.row.prepend(image);
|
|
21425
|
+
} catch {
|
|
21426
|
+
// A browser that cannot create a preview still uploads the original file.
|
|
21427
|
+
unavailable();
|
|
21428
|
+
}
|
|
21429
|
+
}
|
|
21430
|
+
|
|
20932
21431
|
// A refusal of files is an alert only while it shows, as a field's error is.
|
|
20933
21432
|
function setNotice(text) {
|
|
20934
21433
|
notice.textContent = text ?? '';
|
|
@@ -20989,9 +21488,12 @@ function createHelpDeskComposer(options) {
|
|
|
20989
21488
|
if (!stillCurrent()) return;
|
|
20990
21489
|
if (refusal) {
|
|
20991
21490
|
entry.retryable = false;
|
|
20992
|
-
|
|
21491
|
+
const copy = refusalCopy(refusal, CUSTOMER_ATTACHMENT_MAX_BYTES);
|
|
21492
|
+
show(entry, FILE_STATE.REFUSED, copy);
|
|
21493
|
+
reportRefusal(entry.batch, entry, entry.file.name, copy);
|
|
20993
21494
|
return;
|
|
20994
21495
|
}
|
|
21496
|
+
preview(entry);
|
|
20995
21497
|
request = 'host';
|
|
20996
21498
|
const target = await transport.target();
|
|
20997
21499
|
if (!stillCurrent()) return;
|
|
@@ -21037,7 +21539,9 @@ function createHelpDeskComposer(options) {
|
|
|
21037
21539
|
entry.attachmentId = upload.attachment_id;
|
|
21038
21540
|
if (Number.isSafeInteger(upload.max_bytes) && upload.max_bytes > 0 && entry.file.size > upload.max_bytes) {
|
|
21039
21541
|
entry.retryable = false;
|
|
21040
|
-
|
|
21542
|
+
const copy = tooLargeCopy(upload.max_bytes);
|
|
21543
|
+
show(entry, FILE_STATE.FAILED, copy);
|
|
21544
|
+
reportRefusal(entry.batch, entry, entry.file.name, copy);
|
|
21041
21545
|
return;
|
|
21042
21546
|
}
|
|
21043
21547
|
entry.progress.value = 0;
|
|
@@ -21070,6 +21574,7 @@ function createHelpDeskComposer(options) {
|
|
|
21070
21574
|
const problem = uploadProblem(refusalOf(request, error), organization);
|
|
21071
21575
|
entry.retryable = problem.retryable;
|
|
21072
21576
|
show(entry, FILE_STATE.FAILED, problem.copy);
|
|
21577
|
+
if (!problem.retryable) reportRefusal(entry.batch, entry, entry.file.name, problem.copy);
|
|
21073
21578
|
} finally {
|
|
21074
21579
|
if (entry.controller === controller) entry.controller = null;
|
|
21075
21580
|
if (entry.operation === operation) entry.operation = null;
|
|
@@ -21102,6 +21607,7 @@ function createHelpDeskComposer(options) {
|
|
|
21102
21607
|
const refocus = document.activeElement === entry.remove;
|
|
21103
21608
|
const index = entries.indexOf(entry);
|
|
21104
21609
|
entry.controller?.abort();
|
|
21610
|
+
releasePreview(entry);
|
|
21105
21611
|
entries = entries.filter((candidate) => candidate !== entry);
|
|
21106
21612
|
entry.row.remove();
|
|
21107
21613
|
setNotice(null);
|
|
@@ -21111,13 +21617,14 @@ function createHelpDeskComposer(options) {
|
|
|
21111
21617
|
if (refocus) (entries[Math.min(index, entries.length - 1)]?.remove ?? attach).focus();
|
|
21112
21618
|
}
|
|
21113
21619
|
|
|
21114
|
-
function add(files) {
|
|
21620
|
+
function add(files, batch = selection()) {
|
|
21115
21621
|
if (!accepting()) return;
|
|
21116
21622
|
const incoming = Array.from(files);
|
|
21117
21623
|
if (incoming.length === 0) return;
|
|
21118
21624
|
const counted = entries.filter((entry) => entry.state !== FILE_STATE.REFUSED).length;
|
|
21119
21625
|
const room = Math.max(0, MAX_ATTACHMENTS_PER_MESSAGE - counted);
|
|
21120
21626
|
setNotice(incoming.length > room ? LIMIT_COPY : null);
|
|
21627
|
+
if (incoming.length > room) reportRefusal(batch, batch, null, LIMIT_COPY);
|
|
21121
21628
|
for (const file of incoming.slice(0, room)) {
|
|
21122
21629
|
const row = document.createElement('li');
|
|
21123
21630
|
row.className = 'svhd-attachment-chip';
|
|
@@ -21144,11 +21651,14 @@ function createHelpDeskComposer(options) {
|
|
|
21144
21651
|
const entry = {
|
|
21145
21652
|
file, row, status, progress, remove: removeButton, retry,
|
|
21146
21653
|
state: FILE_STATE.QUEUED, retryable: false, controller: null, operation: null,
|
|
21147
|
-
target: null, attachmentId: null, sessionUrl: null
|
|
21654
|
+
target: null, attachmentId: null, sessionUrl: null, batch, previewUrl: null, previewAttempted: false
|
|
21148
21655
|
};
|
|
21149
21656
|
removeButton.addEventListener('click', () => remove(entry));
|
|
21150
21657
|
retry.addEventListener('click', () => {
|
|
21151
|
-
if (!locked && entry.retryable)
|
|
21658
|
+
if (!locked && entry.retryable) {
|
|
21659
|
+
entry.batch = selection();
|
|
21660
|
+
void run(entry);
|
|
21661
|
+
}
|
|
21152
21662
|
});
|
|
21153
21663
|
row.append(name, removeButton, status, retry, progress);
|
|
21154
21664
|
list.append(row);
|
|
@@ -21172,13 +21682,18 @@ function createHelpDeskComposer(options) {
|
|
|
21172
21682
|
drop.hidden = !value;
|
|
21173
21683
|
}
|
|
21174
21684
|
function refuseFiles() {
|
|
21175
|
-
if (!notice.hidden && notice.textContent === NO_CUSTOMER_FILES_COPY) return;
|
|
21176
21685
|
setNotice(NO_CUSTOMER_FILES_COPY);
|
|
21686
|
+
const batch = selection();
|
|
21687
|
+
reportRefusal(batch, batch, null, NO_CUSTOMER_FILES_COPY);
|
|
21177
21688
|
}
|
|
21178
21689
|
// A dropped folder is left out, and said so beside any refusal the files with it met.
|
|
21179
21690
|
function attachBrought(files, folders) {
|
|
21180
|
-
|
|
21181
|
-
if (
|
|
21691
|
+
const batch = selection();
|
|
21692
|
+
if (files.length > 0) add(files, batch);
|
|
21693
|
+
if (folders > 0) {
|
|
21694
|
+
setNotice(files.length > 0 && !notice.hidden ? `${FOLDER_REFUSAL_COPY} ${notice.textContent}` : FOLDER_REFUSAL_COPY);
|
|
21695
|
+
reportRefusal(batch, 'folders', null, FOLDER_REFUSAL_COPY);
|
|
21696
|
+
}
|
|
21182
21697
|
}
|
|
21183
21698
|
const fileEvents = composerFileEvents({
|
|
21184
21699
|
action: fileAction,
|
|
@@ -21189,33 +21704,6 @@ function createHelpDeskComposer(options) {
|
|
|
21189
21704
|
refuse: refuseFiles
|
|
21190
21705
|
});
|
|
21191
21706
|
|
|
21192
|
-
// The (?) tip: a disclosure that closes by its trigger, Escape, its close
|
|
21193
|
-
// button (focus back on the trigger), a press outside it, or focus leaving it.
|
|
21194
|
-
const inTip = (node) => node instanceof Node && (helpTrigger.contains(node) || helpPanel.contains(node));
|
|
21195
|
-
function setHelpOpen(open) {
|
|
21196
|
-
helpPanel.hidden = !open;
|
|
21197
|
-
helpTrigger.setAttribute('aria-expanded', String(open));
|
|
21198
|
-
if (open) document.addEventListener('pointerdown', onPressOutsideHelp);
|
|
21199
|
-
else document.removeEventListener('pointerdown', onPressOutsideHelp);
|
|
21200
|
-
}
|
|
21201
|
-
function onPressOutsideHelp(event) {
|
|
21202
|
-
if (!inTip(event.target)) setHelpOpen(false);
|
|
21203
|
-
}
|
|
21204
|
-
const onHelpToggle = () => setHelpOpen(helpPanel.hidden);
|
|
21205
|
-
const onHelpClose = () => {
|
|
21206
|
-
setHelpOpen(false);
|
|
21207
|
-
helpTrigger.focus();
|
|
21208
|
-
};
|
|
21209
|
-
// Escape is the tip's alone while it is open: a dialog the form sits in leaves a handled key alone.
|
|
21210
|
-
const onHelpKey = (event) => {
|
|
21211
|
-
if (event.key !== 'Escape' || helpPanel.hidden) return;
|
|
21212
|
-
event.preventDefault();
|
|
21213
|
-
onHelpClose();
|
|
21214
|
-
};
|
|
21215
|
-
const onHelpFocusOut = (event) => {
|
|
21216
|
-
if (!helpPanel.hidden && event.relatedTarget && !inTip(event.relatedTarget)) setHelpOpen(false);
|
|
21217
|
-
};
|
|
21218
|
-
|
|
21219
21707
|
// A desk's refusal of files gives way once the customer writes on.
|
|
21220
21708
|
const onInput = () => {
|
|
21221
21709
|
if (!transport) setNotice(null);
|
|
@@ -21239,19 +21727,15 @@ function createHelpDeskComposer(options) {
|
|
|
21239
21727
|
}
|
|
21240
21728
|
input.addEventListener('change', onChoose);
|
|
21241
21729
|
attach.addEventListener('click', onAttach);
|
|
21242
|
-
helpTrigger.addEventListener('click', onHelpToggle);
|
|
21243
|
-
helpClose.addEventListener('click', onHelpClose);
|
|
21244
|
-
for (const part of [helpTrigger, helpPanel]) {
|
|
21245
|
-
part.addEventListener('keydown', onHelpKey);
|
|
21246
|
-
part.addEventListener('focusout', onHelpFocusOut);
|
|
21247
|
-
}
|
|
21248
21730
|
|
|
21249
21731
|
function clear(keepAttached = false) {
|
|
21250
21732
|
revision += 1;
|
|
21733
|
+
dismissValidation();
|
|
21251
21734
|
const previous = entries;
|
|
21252
21735
|
entries = [];
|
|
21253
21736
|
for (const entry of previous) {
|
|
21254
21737
|
entry.controller?.abort();
|
|
21738
|
+
releasePreview(entry);
|
|
21255
21739
|
if (!keepAttached || entry.state !== FILE_STATE.COMPLETE) void cancel(entry.target, entry.attachmentId);
|
|
21256
21740
|
}
|
|
21257
21741
|
list.replaceChildren();
|
|
@@ -21299,7 +21783,6 @@ function createHelpDeskComposer(options) {
|
|
|
21299
21783
|
destroy(keepAttached = false) {
|
|
21300
21784
|
destroyed = true;
|
|
21301
21785
|
clear(keepAttached);
|
|
21302
|
-
setHelpOpen(false);
|
|
21303
21786
|
zone.removeEventListener('dragenter', fileEvents.dragOver);
|
|
21304
21787
|
zone.removeEventListener('dragover', fileEvents.dragOver);
|
|
21305
21788
|
zone.removeEventListener('dragleave', fileEvents.dragLeave);
|
|
@@ -21310,12 +21793,6 @@ function createHelpDeskComposer(options) {
|
|
|
21310
21793
|
}
|
|
21311
21794
|
input.removeEventListener('change', onChoose);
|
|
21312
21795
|
attach.removeEventListener('click', onAttach);
|
|
21313
|
-
helpTrigger.removeEventListener('click', onHelpToggle);
|
|
21314
|
-
helpClose.removeEventListener('click', onHelpClose);
|
|
21315
|
-
for (const part of [helpTrigger, helpPanel]) {
|
|
21316
|
-
part.removeEventListener('keydown', onHelpKey);
|
|
21317
|
-
part.removeEventListener('focusout', onHelpFocusOut);
|
|
21318
|
-
}
|
|
21319
21796
|
}
|
|
21320
21797
|
};
|
|
21321
21798
|
}
|
|
@@ -21463,6 +21940,7 @@ function saveFormDraft(deskId, requesterId, value) {
|
|
|
21463
21940
|
catch { /* Storage is optional; the live form keeps its composition. */ }
|
|
21464
21941
|
}
|
|
21465
21942
|
|
|
21943
|
+
const HELP_DESK_FORM_TITLE = 'Open a Support Ticket';
|
|
21466
21944
|
let formSequence = 0;
|
|
21467
21945
|
/**
|
|
21468
21946
|
* The desk API's refusal of a file's draft or upload, as the composer reads
|
|
@@ -21601,10 +22079,9 @@ function companySignInUrl(value) {
|
|
|
21601
22079
|
* A confirmed send replaces the form with its confirmation.
|
|
21602
22080
|
*
|
|
21603
22081
|
* The request is a summary and optional details, in a composer that also
|
|
21604
|
-
* takes files. A signed-out widget customer writes it
|
|
21605
|
-
*
|
|
21606
|
-
*
|
|
21607
|
-
* beside the request.
|
|
22082
|
+
* takes files. A signed-out widget customer writes it before continuing to
|
|
22083
|
+
* sign-in, where one button opens the native sign-in window and sends it. A
|
|
22084
|
+
* signed-in customer can switch account or sign out beside the request.
|
|
21608
22085
|
*/
|
|
21609
22086
|
function mountHelpDeskForm(client, options) {
|
|
21610
22087
|
const target = resolveTarget(options.target);
|
|
@@ -21622,22 +22099,16 @@ function mountHelpDeskForm(client, options) {
|
|
|
21622
22099
|
form.className = 'svhd-form';
|
|
21623
22100
|
form.noValidate = true;
|
|
21624
22101
|
shell.body.append(form);
|
|
21625
|
-
/** A step's heading
|
|
21626
|
-
function stepHead(id, title
|
|
22102
|
+
/** A step's heading takes focus when the customer enters it. */
|
|
22103
|
+
function stepHead(id, title) {
|
|
21627
22104
|
const head = document.createElement('div');
|
|
21628
22105
|
head.className = 'svhd-step-head';
|
|
21629
|
-
const stepLabel = label === null ? null : document.createElement('p');
|
|
21630
|
-
if (stepLabel) {
|
|
21631
|
-
stepLabel.className = 'svhd-step-label';
|
|
21632
|
-
stepLabel.textContent = label;
|
|
21633
|
-
head.append(stepLabel);
|
|
21634
|
-
}
|
|
21635
22106
|
const stepHeading = document.createElement('h2');
|
|
21636
22107
|
stepHeading.id = id;
|
|
21637
22108
|
stepHeading.tabIndex = -1;
|
|
21638
22109
|
stepHeading.textContent = title;
|
|
21639
22110
|
head.append(stepHeading);
|
|
21640
|
-
return { head, heading: stepHeading
|
|
22111
|
+
return { head, heading: stepHeading };
|
|
21641
22112
|
}
|
|
21642
22113
|
function stepContainer(step) {
|
|
21643
22114
|
const container = document.createElement('div');
|
|
@@ -21645,7 +22116,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
21645
22116
|
container.dataset.contactStep = step;
|
|
21646
22117
|
return container;
|
|
21647
22118
|
}
|
|
21648
|
-
const request = stepHead(`${prefix}-heading`,
|
|
22119
|
+
const request = stepHead(`${prefix}-heading`, HELP_DESK_FORM_TITLE);
|
|
21649
22120
|
const heading = request.heading;
|
|
21650
22121
|
form.setAttribute('aria-labelledby', heading.id);
|
|
21651
22122
|
const details = stepContainer('details');
|
|
@@ -21792,7 +22263,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
21792
22263
|
const widgetAccount = document.createElement('div');
|
|
21793
22264
|
widgetAccount.className = 'svhd-widget-account';
|
|
21794
22265
|
let widgetCustomer = widget?.customer ?? null;
|
|
21795
|
-
const signInStep = widget ? stepHead(`${prefix}-signin-heading`, 'Sign in to send your request'
|
|
22266
|
+
const signInStep = widget ? stepHead(`${prefix}-signin-heading`, 'Sign in to send your request') : null;
|
|
21796
22267
|
const identity = widget ? stepContainer('identity') : null;
|
|
21797
22268
|
const recap = document.createElement('div');
|
|
21798
22269
|
recap.className = 'svhd-recap';
|
|
@@ -22006,13 +22477,12 @@ function mountHelpDeskForm(client, options) {
|
|
|
22006
22477
|
* The signed-in widget customer writes and sends in one step, posting as
|
|
22007
22478
|
* the account named under it, beside Switch account and, but for a website
|
|
22008
22479
|
* account's session, which the website ends, Sign out; a signed-out one
|
|
22009
|
-
* writes the request
|
|
22480
|
+
* writes the request before continuing to sign-in. Either way the form
|
|
22481
|
+
* shows the request.
|
|
22010
22482
|
*/
|
|
22011
22483
|
function renderWidgetIdentity() {
|
|
22012
22484
|
if (!widget)
|
|
22013
22485
|
return;
|
|
22014
|
-
if (request.label)
|
|
22015
|
-
request.label.hidden = widgetCustomer !== null;
|
|
22016
22486
|
auth.hidden = true;
|
|
22017
22487
|
code.wrapper.hidden = true;
|
|
22018
22488
|
name.wrapper.hidden = true;
|
|
@@ -23219,7 +23689,7 @@ function openHelpDeskForm(client, options = {}) {
|
|
|
23219
23689
|
header.className = 'svhd-modal-header';
|
|
23220
23690
|
const title = document.createElement('span');
|
|
23221
23691
|
title.id = `${prefix}-title`;
|
|
23222
|
-
title.textContent =
|
|
23692
|
+
title.textContent = HELP_DESK_FORM_TITLE;
|
|
23223
23693
|
title.hidden = true;
|
|
23224
23694
|
const close = document.createElement('button');
|
|
23225
23695
|
close.type = 'button';
|
|
@@ -25942,11 +26412,12 @@ class SupportView {
|
|
|
25942
26412
|
results.prepend(queryLine);
|
|
25943
26413
|
results.append(this.resultList, this.resultStatus, this.resultError);
|
|
25944
26414
|
this.resultError.setAttribute('role', 'alert');
|
|
25945
|
-
this.contactResults = button('svhs-secondary svhs-full', 'Still need help? Open a ticket', () => {
|
|
26415
|
+
this.contactResults = button('svhs-secondary svhs-full', 'Still need help? Open a support ticket', () => {
|
|
25946
26416
|
if (this.state?.busy)
|
|
25947
26417
|
return;
|
|
25948
26418
|
this.actions.onContact(['locked', 'unavailable'].includes(this.state?.kbState || '') ? 'direct' : this.state?.results?.length ? 'none_match' : 'no_results');
|
|
25949
26419
|
});
|
|
26420
|
+
this.contactResults.append(helpDeskIcon('arrowRight'));
|
|
25950
26421
|
this.contactNote.id = `${this.prefix}-contact-note`;
|
|
25951
26422
|
this.contactNote.hidden = true;
|
|
25952
26423
|
this.resultsFooter = this.footer('results');
|
|
@@ -32481,7 +32952,7 @@ class SparkVault {
|
|
|
32481
32952
|
}
|
|
32482
32953
|
/** Get the SDK version */
|
|
32483
32954
|
static get version() {
|
|
32484
|
-
return '18.0.
|
|
32955
|
+
return '18.0.5';
|
|
32485
32956
|
}
|
|
32486
32957
|
}
|
|
32487
32958
|
if (typeof window !== 'undefined') {
|