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