@sparkvault/sdk-js 16.6.0 → 16.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -14337,25 +14337,23 @@ Array.from({ length: 1 << BRAND_BITS.size }, (_, mask) =>
14337
14337
  * question a customer's new request asks before it is discarded, session,
14338
14338
  * sign-in code (its length, lifetime, sender, resend wait, countdown and
14339
14339
  * the code step's words), merge and pending-attachment timings, hold
14340
- * presets, tag and size limits, the operator display and desk mode choices,
14341
- * the operator queue's views and orders, the reply review list's views and
14340
+ * presets, size limits, the operator display and desk mode choices, the
14341
+ * operator queue's views and orders, the reply review list's views and
14342
14342
  * states, the response-time histogram's bucket edges, the sections of a
14343
14343
  * desk's settings an address names, and the messages the widget's native
14344
14344
  * sign-in posts between the website and its first-party page live here for
14345
- * the same reason. So do the one rule a tag is stored by (ticketTag), which
14346
- * Core applies where it stores a tag and the console applies where one is
14347
- * typed, and the one rule a typed or pasted sign-in code is read by
14348
- * (helpDeskPinDigits), which every sign-in form applies. So
14349
- * does the one way a client names a message it sends (newMessageId), which
14350
- * the portal, the SDK and the console's composer each send their messages
14351
- * under, and the one rule that a message sent again is the same message
14345
+ * the same reason. So does the one rule a typed or pasted sign-in code is
14346
+ * read by (helpDeskPinDigits), which every sign-in form applies. So does the
14347
+ * one way a client names a message it sends (newMessageId), which the
14348
+ * portal, the SDK and the console's composer each send their messages under,
14349
+ * and the one rule that a message sent again is the same message
14352
14350
  * (sameMessage), which keeps its name.
14353
14351
  *
14354
14352
  * BROWSER-SAFE: data and pure functions, and newMessageId's count of the ids
14355
- * its page named; its imports are the platform's label
14356
- * rule a tag is built on (./display-text.js), the mail products whose fixed
14357
- * From local parts no team alias may take (./mail-products.js) and the brand
14358
- * rule no team alias may read as (./organization-name.js).
14353
+ * its page named; its imports are the mail products whose fixed From local
14354
+ * parts no team alias may take (./mail-products.js), the brand rule no team
14355
+ * alias may read as (./organization-name.js) and the resource id rule a desk
14356
+ * id is read by (./ids.js).
14359
14357
  */
14360
14358
 
14361
14359
 
@@ -14420,11 +14418,10 @@ const DISCARD_REQUEST_COPY = Object.freeze({
14420
14418
  });
14421
14419
 
14422
14420
  /**
14423
- * What the emailed-code step of a customer's sign-in says, word for word in
14424
- * the portal's sign-in page and the SDK's support form: the refusal of a code
14425
- * that is wrong, spent or expired (Core's PIN_INVALID), and the note once a
14426
- * new code is sent. Neither names who sent the email, so both read right on
14427
- * the portal and on a company's own site.
14421
+ * What the emailed-code step of the SDK support form's sign-in says: the
14422
+ * refusal of a code that is wrong, spent or expired (Core's PIN_INVALID), and
14423
+ * the note once a new code is sent. Neither names who sent the email, so both
14424
+ * read right on any site the form runs on.
14428
14425
  */
14429
14426
  const HELP_DESK_CODE_STEP_COPY = Object.freeze({
14430
14427
  codeRefused: 'That code is wrong or has expired. Check the newest email, or send a new code.',
@@ -14539,7 +14536,7 @@ const HELP_DESK_ROLES = Object.freeze(['manager', 'agent', 'trainee']);
14539
14536
  *
14540
14537
  * see_desk list the desk, read its settings and queues
14541
14538
  * view_tickets read every ticket of the desk, every queue and untriaged included
14542
- * work_tickets notes, status, priority, tags, assignment changes, attachments, merges
14539
+ * work_tickets notes, status, priority, assignment changes, attachments, merges
14543
14540
  * reply send a customer reply directly (a Trainee's reply becomes a review instead)
14544
14541
  * submit_reply_for_approval a customer reply is held for a Manager's approval
14545
14542
  * open_request open a request for a customer with a first message
@@ -19238,6 +19235,7 @@ function createFormAttachments(client, prefix, context, onEntriesChange) {
19238
19235
  get attachmentIds() { return entries.filter(entry => entry.state === 'complete' && entry.attachmentId).map(entry => entry.attachmentId); },
19239
19236
  get unresolved() { return entries.some(entry => entry.state !== 'complete'); },
19240
19237
  get hasEntries() { return entries.length > 0; },
19238
+ get names() { return entries.map(entry => entry.file.name); },
19241
19239
  add,
19242
19240
  async start() { await Promise.all(entries.map(entry => entry.operation ?? (entry.state === 'queued' ? run(entry) : Promise.resolve()))); },
19243
19241
  lock(value) { locked = value; syncPicking(); entries.forEach(controls); },
@@ -19258,19 +19256,178 @@ function createFormAttachments(client, prefix, context, onEntriesChange) {
19258
19256
  };
19259
19257
  }
19260
19258
 
19261
- const FOLDER_COPY = 'Folders can’t be attached. Add the files inside them instead.';
19262
- function carriesFiles(event) {
19263
- return Array.from(event.dataTransfer?.types ?? []).includes('Files');
19259
+ /**
19260
+ * Files brought to a message's composer by drag, drop and paste, handled
19261
+ * alike by every composer that takes them: the console's reply composer and
19262
+ * the SDK's support form. A composer says what a file brought now does
19263
+ * (attach, refuse in words, or nothing) and what attaching and refusing are;
19264
+ * this owns the rest of the policy.
19265
+ *
19266
+ * - A drag carries files only when its types name them; a drag or paste of
19267
+ * text is the browser's.
19268
+ * - A drag of files is never the browser's to open in place of the page:
19269
+ * dragenter and dragover are cancelled. A file the composer refuses keeps a
19270
+ * drop effect, so it is refused in words when it lands; one it takes
19271
+ * nothing from (a send under way) shows the cursor's refusal.
19272
+ * - The drop prompt shows while files the composer attaches are over its
19273
+ * frame, and goes when they leave the frame or land.
19274
+ * - A dropped folder arrives as a file that cannot be read, so a drop's files
19275
+ * leave the folders out and count them, for the composer to say so.
19276
+ * - A paste that carries files is those files, and the text beside them is
19277
+ * only their names (a file copied in the system's file manager). Office
19278
+ * apps are the exception: copied cells or paragraphs come as text and
19279
+ * formatted text, with a picture of them as a file, and that paste is the
19280
+ * text.
19281
+ * - A picture pasted from the clipboard is named "image.png" every time, so
19282
+ * it is numbered after the highest "Pasted image N" the composer holds
19283
+ * ("Pasted image 1.png"), which tells chips, and their Remove buttons,
19284
+ * apart, a restored draft's among them.
19285
+ *
19286
+ * BROWSER-SAFE: reads only the events it is handed and what the composer
19287
+ * says.
19288
+ */
19289
+
19290
+ /** What a composer reads while files are dragged over it. */
19291
+ const DROP_FILES_COPY = 'Drop the files to attach them.';
19292
+
19293
+ /** What a person reads when a drop held a folder, which is never attached. */
19294
+ const FOLDER_REFUSAL_COPY = 'Folders can’t be attached. Add the files inside them instead.';
19295
+
19296
+ /** The name the clipboard gives every pasted picture, with its extension. */
19297
+ const CLIPBOARD_IMAGE_NAME = /^image\.(\w+)$/;
19298
+
19299
+ /** A pasted picture's name once numbered, its number captured. */
19300
+ const PASTED_IMAGE_NAME = /^Pasted image (\d+)\./;
19301
+
19302
+ /**
19303
+ * Whether a drag carries files.
19304
+ *
19305
+ * @param {DataTransfer|null|undefined} transfer - The drag event's dataTransfer
19306
+ * @returns {boolean}
19307
+ */
19308
+ function carriesFiles(transfer) {
19309
+ return Array.from(transfer?.types ?? []).includes('Files');
19310
+ }
19311
+
19312
+ /**
19313
+ * The files a paste carries, or none when the paste is text: one with no
19314
+ * files, or an Office app's copy (formatted text and its text beside a
19315
+ * picture of them).
19316
+ *
19317
+ * @param {DataTransfer|null|undefined} clipboard - The paste event's clipboardData
19318
+ * @returns {File[]}
19319
+ */
19320
+ function pastedFiles(clipboard) {
19321
+ if (!clipboard || clipboard.files.length === 0) return [];
19322
+ if (Array.from(clipboard.types).includes('text/html') && clipboard.getData('text/plain')) return [];
19323
+ return Array.from(clipboard.files);
19324
+ }
19325
+
19326
+ /**
19327
+ * The files a drop carries, its folders left out and counted.
19328
+ *
19329
+ * @param {DataTransfer} transfer - The drop event's dataTransfer
19330
+ * @returns {{ files: File[], folders: number }}
19331
+ */
19332
+ function droppedFiles(transfer) {
19333
+ const files = [];
19334
+ let folders = 0;
19335
+ for (const item of Array.from(transfer.items)) {
19336
+ if (item.kind !== 'file') continue;
19337
+ if (item.webkitGetAsEntry()?.isDirectory) {
19338
+ folders += 1;
19339
+ continue;
19340
+ }
19341
+ const file = item.getAsFile();
19342
+ if (file) files.push(file);
19343
+ }
19344
+ return { files, folders };
19345
+ }
19346
+
19347
+ /**
19348
+ * Pasted files as they join a composer: each the clipboard named
19349
+ * "image.<ext>" comes back as "Pasted image N.<ext>", N counting on from the
19350
+ * highest the composer holds; any other comes back as it is.
19351
+ *
19352
+ * @param {File[]} files - The paste's files
19353
+ * @param {string[]} heldNames - The names of the files the composer holds
19354
+ * @returns {File[]}
19355
+ */
19356
+ function namePasted(files, heldNames) {
19357
+ let number = heldNames.reduce((highest, name) => Math.max(highest, Number(PASTED_IMAGE_NAME.exec(name)?.[1] ?? 0)), 0);
19358
+ return files.map((file) => {
19359
+ const extension = CLIPBOARD_IMAGE_NAME.exec(file.name)?.[1];
19360
+ if (extension === undefined) return file;
19361
+ number += 1;
19362
+ return new File([file], `Pasted image ${number}.${extension}`, { type: file.type, lastModified: file.lastModified });
19363
+ });
19264
19364
  }
19365
+
19366
+ /**
19367
+ * A composer's handlers for files brought to it, alike as DOM listeners and
19368
+ * as React's event props: `dragOver` answers dragenter and dragover, on the
19369
+ * element a file may be dropped anywhere over; `paste`, on each field a file
19370
+ * may be pasted into.
19371
+ *
19372
+ * @param {Object} composer
19373
+ * @param {() => ('attach'|'refuse'|'none')} composer.action - What a file brought now does
19374
+ * @param {(node: EventTarget|null) => boolean} composer.frameHolds - Whether a node lies in the frame, where the drop prompt shows
19375
+ * @param {() => string[]} composer.heldNames - The names of the files the composer holds
19376
+ * @param {(on: boolean) => void} composer.dragging - Shows or hides the drop prompt
19377
+ * @param {(files: File[], folders: number) => void} composer.attach - Attaches files; `folders` counts the folders a drop left out
19378
+ * @param {() => void} composer.refuse - Refuses the files in words
19379
+ * @returns {{ dragOver: (event: DragEvent) => void, dragLeave: (event: DragEvent) => void, drop: (event: DragEvent) => void, paste: (event: ClipboardEvent) => void }}
19380
+ */
19381
+ function composerFileEvents({ action, frameHolds, heldNames, dragging, attach, refuse }) {
19382
+ return {
19383
+ dragOver(event) {
19384
+ if (!carriesFiles(event.dataTransfer)) return;
19385
+ event.preventDefault();
19386
+ const now = action();
19387
+ event.dataTransfer.dropEffect = now === 'none' ? 'none' : 'copy';
19388
+ dragging(now === 'attach' && frameHolds(event.target));
19389
+ },
19390
+ dragLeave(event) {
19391
+ if (!frameHolds(event.relatedTarget)) dragging(false);
19392
+ },
19393
+ drop(event) {
19394
+ if (!carriesFiles(event.dataTransfer)) return;
19395
+ event.preventDefault();
19396
+ dragging(false);
19397
+ const now = action();
19398
+ if (now === 'attach') {
19399
+ const { files, folders } = droppedFiles(event.dataTransfer);
19400
+ attach(files, folders);
19401
+ } else if (now === 'refuse') {
19402
+ refuse();
19403
+ }
19404
+ },
19405
+ // A paste of files lands none of its text (only their names) in the field.
19406
+ paste(event) {
19407
+ const files = pastedFiles(event.clipboardData);
19408
+ if (files.length === 0) return;
19409
+ const now = action();
19410
+ if (now === 'none') return;
19411
+ event.preventDefault();
19412
+ if (now === 'attach') attach(namePasted(files, heldNames()), 0);
19413
+ else refuse();
19414
+ }
19415
+ };
19416
+ }
19417
+
19265
19418
  /**
19266
19419
  * The details field as a composer. A file pasted into the summary or the
19267
19420
  * details, or dropped anywhere on the request step, joins the form's one
19268
19421
  * attachment pipeline (`attachments.add`), under the same limits and
19269
- * refusals as a picked one; the drop target shows only over the composer. A
19270
- * paste or drag of text alone stays the browser's. A file brought over the
19271
- * form is never the browser's to open in place of the unsent request: on the
19272
- * sign-in step, or while the form takes no files, it is refused outright,
19273
- * and a desk that takes no files says so when the file is dropped.
19422
+ * refusals as a picked one; the drop target shows only over the composer.
19423
+ * How a drag, a drop and a paste are answered (which files they carry, the
19424
+ * folders a drop leaves out, the names of pasted pictures, when the drop
19425
+ * target shows) is @sparkvault/app-sdk/composer-files' to decide; this says
19426
+ * what a file brought now does. A paste or drag of text alone stays the
19427
+ * browser's. A file brought over the form is never the browser's to open in
19428
+ * place of the unsent request: on the sign-in step, or while the form takes
19429
+ * no files, it is refused outright, and a desk that takes no files says so
19430
+ * when the file is dropped.
19274
19431
  */
19275
19432
  function createComposer(options) {
19276
19433
  const { form, summary, textarea, attachments, deskRefusesFiles, onRequestStep } = options;
@@ -19279,14 +19436,13 @@ function createComposer(options) {
19279
19436
  textarea.classList.add('svhd-composer-input');
19280
19437
  const drop = document.createElement('p');
19281
19438
  drop.className = 'svhd-composer-drop';
19282
- drop.textContent = 'Drop the files to attach them.';
19439
+ drop.textContent = DROP_FILES_COPY;
19283
19440
  drop.hidden = true;
19284
19441
  frame.append(textarea, drop);
19285
19442
  if (attachments)
19286
19443
  frame.append(attachments.toolbar, attachments.list);
19287
19444
  const notice = attachments?.notice ?? createNotice();
19288
19445
  const fields = [summary, textarea];
19289
- let pastedImages = 0;
19290
19446
  function fileAction() {
19291
19447
  if (!onRequestStep())
19292
19448
  return 'none';
@@ -19303,91 +19459,30 @@ function createComposer(options) {
19303
19459
  return;
19304
19460
  setNotice(notice, NO_CUSTOMER_FILES_COPY);
19305
19461
  }
19306
- // A dropped folder arrives as a file that cannot be read, so it is left out,
19307
- // and said so beside any refusal the files with it met.
19308
- function attachDropped(transfer) {
19309
- const files = [];
19310
- let folders = 0;
19311
- for (const item of Array.from(transfer.items)) {
19312
- if (item.kind !== 'file')
19313
- continue;
19314
- if (item.webkitGetAsEntry()?.isDirectory) {
19315
- folders += 1;
19316
- continue;
19317
- }
19318
- const file = item.getAsFile();
19319
- if (file)
19320
- files.push(file);
19321
- }
19462
+ // A dropped folder is left out, and said so beside any refusal the files
19463
+ // with it met.
19464
+ function attach(files, folders) {
19322
19465
  if (files.length > 0)
19323
19466
  attachments?.add(files);
19324
19467
  if (folders > 0)
19325
- setNotice(notice, files.length > 0 && !notice.hidden ? `${FOLDER_COPY} ${notice.textContent}` : FOLDER_COPY);
19326
- }
19327
- // A picture pasted from the clipboard is named "image.png" every time;
19328
- // numbering the pastes tells their chips, and their Remove buttons, apart.
19329
- function pastedName(file) {
19330
- const extension = /^image\.(\w+)$/.exec(file.name)?.[1];
19331
- if (extension === undefined)
19332
- return file;
19333
- pastedImages += 1;
19334
- return new File([file], `Pasted image ${pastedImages}.${extension}`, { type: file.type, lastModified: file.lastModified });
19335
- }
19336
- // Cancelling dragenter and dragover keeps the browser from opening the file
19337
- // in place of the page. A drop effect of none cancels the drop itself, so a
19338
- // file the desk refuses keeps one to be refused in words when it lands.
19339
- const onDragOver = (event) => {
19340
- if (!carriesFiles(event))
19341
- return;
19342
- event.preventDefault();
19343
- const action = fileAction();
19344
- if (event.dataTransfer)
19345
- event.dataTransfer.dropEffect = action === 'none' ? 'none' : 'copy';
19346
- dragging(action === 'attach' && event.target instanceof Node && frame.contains(event.target));
19347
- };
19348
- const onDragLeave = (event) => {
19349
- if (!(event.relatedTarget instanceof Node) || !frame.contains(event.relatedTarget))
19350
- dragging(false);
19351
- };
19352
- const onDrop = (event) => {
19353
- if (!carriesFiles(event))
19354
- return;
19355
- event.preventDefault();
19356
- dragging(false);
19357
- const action = fileAction();
19358
- if (action === 'attach' && event.dataTransfer)
19359
- attachDropped(event.dataTransfer);
19360
- else if (action === 'refuse')
19361
- refuseFiles();
19362
- };
19363
- // A paste that carries files is those files, and the text beside them is
19364
- // only their names (a file copied in the system's file manager), so none of
19365
- // it lands in the field. Office apps are the exception: copied cells or
19366
- // paragraphs come as text and formatted text, with a picture of them as a
19367
- // file, and that paste is the text.
19368
- const onPaste = (event) => {
19369
- const clipboard = event.clipboardData;
19370
- if (!clipboard || clipboard.files.length === 0)
19371
- return;
19372
- if (Array.from(clipboard.types).includes('text/html') && clipboard.getData('text/plain'))
19373
- return;
19374
- const action = fileAction();
19375
- if (action === 'none')
19376
- return;
19377
- event.preventDefault();
19378
- if (action === 'attach')
19379
- attachments?.add(Array.from(clipboard.files, pastedName));
19380
- else
19381
- refuseFiles();
19382
- };
19468
+ setNotice(notice, files.length > 0 && !notice.hidden ? `${FOLDER_REFUSAL_COPY} ${notice.textContent}` : FOLDER_REFUSAL_COPY);
19469
+ }
19470
+ const fileEvents = composerFileEvents({
19471
+ action: fileAction,
19472
+ frameHolds: (node) => node instanceof Node && frame.contains(node),
19473
+ heldNames: () => attachments?.names ?? [],
19474
+ dragging,
19475
+ attach,
19476
+ refuse: refuseFiles,
19477
+ });
19383
19478
  const onInput = () => { if (!attachments)
19384
19479
  setNotice(notice, null); };
19385
- form.addEventListener('dragenter', onDragOver);
19386
- form.addEventListener('dragover', onDragOver);
19387
- form.addEventListener('dragleave', onDragLeave);
19388
- form.addEventListener('drop', onDrop);
19480
+ form.addEventListener('dragenter', fileEvents.dragOver);
19481
+ form.addEventListener('dragover', fileEvents.dragOver);
19482
+ form.addEventListener('dragleave', fileEvents.dragLeave);
19483
+ form.addEventListener('drop', fileEvents.drop);
19389
19484
  for (const field of fields) {
19390
- field.addEventListener('paste', onPaste);
19485
+ field.addEventListener('paste', fileEvents.paste);
19391
19486
  field.addEventListener('input', onInput);
19392
19487
  }
19393
19488
  return {
@@ -19395,12 +19490,12 @@ function createComposer(options) {
19395
19490
  notice,
19396
19491
  clearNotice: () => setNotice(notice, null),
19397
19492
  destroy() {
19398
- form.removeEventListener('dragenter', onDragOver);
19399
- form.removeEventListener('dragover', onDragOver);
19400
- form.removeEventListener('dragleave', onDragLeave);
19401
- form.removeEventListener('drop', onDrop);
19493
+ form.removeEventListener('dragenter', fileEvents.dragOver);
19494
+ form.removeEventListener('dragover', fileEvents.dragOver);
19495
+ form.removeEventListener('dragleave', fileEvents.dragLeave);
19496
+ form.removeEventListener('drop', fileEvents.drop);
19402
19497
  for (const field of fields) {
19403
- field.removeEventListener('paste', onPaste);
19498
+ field.removeEventListener('paste', fileEvents.paste);
19404
19499
  field.removeEventListener('input', onInput);
19405
19500
  }
19406
19501
  },
@@ -30445,7 +30540,7 @@ class SparkVault {
30445
30540
  }
30446
30541
  /** Get the SDK version */
30447
30542
  static get version() {
30448
- return '16.6.0';
30543
+ return '16.7.1';
30449
30544
  }
30450
30545
  }
30451
30546
  if (typeof window !== 'undefined') {