dap-design-system 0.44.2 → 0.44.3

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.
@@ -2828,7 +2828,7 @@ declare const DapDSFeedback_base: typeof DdsElement & {
2828
2828
  * @event {{ void }} dds-all-uploads-complete - Fired when all file uploads are complete.
2829
2829
  * @event {{ file: FileListElement }} dds-file-removed - Fired when a file is removed from the file input.
2830
2830
  * @event {{ file: FileListElement, error: Error }} dds-file-delete-error - Fired when a file deletion from server encounters an error.
2831
- * @event {{ files: File[] }} dds-file-change - Fired when the file input value changes.
2831
+ * @event {{ newFiles: File[], files: File[], canceledFiles: Set<File> }} dds-file-change - Fired when the file input value changes. This event is cancelable. Event detail contains: `newFiles` (just the files being added in this operation), `files` (all files after merge with existing when keepValue=true), and `canceledFiles` (Set to add files you want to reject). You can either: (1) Call `event.preventDefault()` to reject all files, or (2) Add specific files to `canceledFiles` to reject only those files.
2832
2832
  *
2833
2833
  * @slot dropzone-content - The content to display in the dropzone.
2834
2834
  *
@@ -2957,6 +2957,11 @@ export declare class DapDSFileInput extends GenericFormElement {
2957
2957
  */
2958
2958
  private deleteUploadedFile;
2959
2959
  private uploadFiles;
2960
+ /**
2961
+ * Calculates what the new file list would be if the given files were added
2962
+ * Does not modify component state
2963
+ */
2964
+ private calculateNewFileList;
2960
2965
  private handleFileList;
2961
2966
  onChange(event: InputEvent): void;
2962
2967
  onDragenter(event: DragEvent): void;
@@ -6455,7 +6460,9 @@ declare class DdsElement extends LitElement {
6455
6460
  export declare type DdsErrorEvent = CustomEvent<Record<PropertyKey, never>>;
6456
6461
 
6457
6462
  export declare type DdsFileChangeEvent = CustomEvent<{
6463
+ newFiles: File[];
6458
6464
  files: File[];
6465
+ canceledFiles: Set<File>;
6459
6466
  }>;
6460
6467
 
6461
6468
  export declare type DdsFileClickEvent = CustomEvent<{
@@ -11523,6 +11523,21 @@ let X = class extends ge {
11523
11523
  }
11524
11524
  });
11525
11525
  }
11526
+ /**
11527
+ * Calculates what the new file list would be if the given files were added
11528
+ * Does not modify component state
11529
+ */
11530
+ calculateNewFileList(t) {
11531
+ var i;
11532
+ if (!t || t.length === 0)
11533
+ return [];
11534
+ const e = [...this._files];
11535
+ return this.keepValue && ((i = this._files) != null && i.length) ? (Object.values(t).forEach((a) => {
11536
+ !!this._files.find(
11537
+ (r) => this.checkFileEquality(r, a)
11538
+ ) || e.push(a);
11539
+ }), e) : Object.values(t);
11540
+ }
11526
11541
  handleFileList(t) {
11527
11542
  var a;
11528
11543
  const e = [...this._files];
@@ -11539,19 +11554,39 @@ let X = class extends ge {
11539
11554
  onChange(t) {
11540
11555
  const i = (t == null ? void 0 : t.target).files;
11541
11556
  if (i) {
11542
- const a = this.validateFiles(i);
11543
- if (!a.isValid && a.errors) {
11544
- const o = a.errors.map((r) => r.file ? new qn(
11545
- r.message,
11546
- r.file,
11547
- r.type,
11548
- r.meta
11549
- ) : new Error(r.message));
11550
- this.emit("dds-upload-error", { errors: o });
11557
+ const d = this.validateFiles(i);
11558
+ if (!d.isValid && d.errors) {
11559
+ const l = d.errors.map((c) => c.file ? new qn(
11560
+ c.message,
11561
+ c.file,
11562
+ c.type,
11563
+ c.meta
11564
+ ) : new Error(c.message));
11565
+ this.emit("dds-upload-error", { errors: l });
11551
11566
  return;
11552
11567
  }
11553
11568
  }
11554
- this.value = this.input.value, this.handleFileList(i), this.emit("dds-file-change", { files: this._files }), this.setValidity();
11569
+ const a = i ? Array.from(i) : [], o = this.calculateNewFileList(i), r = /* @__PURE__ */ new Set();
11570
+ if (this.emit(
11571
+ "dds-file-change",
11572
+ { newFiles: a, files: o, canceledFiles: r },
11573
+ { cancelable: !0 }
11574
+ ).defaultPrevented) {
11575
+ this.input.value = "";
11576
+ return;
11577
+ }
11578
+ if (r.size > 0 && i) {
11579
+ const d = Array.from(i).filter(
11580
+ (c) => !r.has(c)
11581
+ );
11582
+ if (d.length === 0) {
11583
+ this.input.value = "";
11584
+ return;
11585
+ }
11586
+ const l = new DataTransfer();
11587
+ d.forEach((c) => l.items.add(c)), this.value = this.input.value, this.handleFileList(l.files), this.setValidity();
11588
+ } else
11589
+ this.value = this.input.value, this.handleFileList(i), this.setValidity();
11555
11590
  }
11556
11591
  onDragenter(t) {
11557
11592
  this.disabled || (t.preventDefault(), this._isDragOver = !0);
@@ -11563,24 +11598,39 @@ let X = class extends ge {
11563
11598
  this.disabled || (t.preventDefault(), this.contains(t.relatedTarget) || (this._isDragOver = !1));
11564
11599
  }
11565
11600
  onDrop(t) {
11566
- var i;
11601
+ var n;
11567
11602
  if (this.disabled) return;
11568
11603
  t.preventDefault(), this._isDragOver = !1;
11569
- const e = (i = t.dataTransfer) == null ? void 0 : i.files;
11604
+ const e = (n = t.dataTransfer) == null ? void 0 : n.files;
11570
11605
  if (e) {
11571
- const a = this.validateFiles(e);
11572
- if (!a.isValid && a.errors) {
11573
- const o = a.errors.map((r) => r.file ? new qn(
11574
- r.message,
11575
- r.file,
11576
- r.type,
11577
- r.meta
11578
- ) : new Error(r.message));
11579
- this.emit("dds-upload-error", { errors: o });
11606
+ const d = this.validateFiles(e);
11607
+ if (!d.isValid && d.errors) {
11608
+ const l = d.errors.map((c) => c.file ? new qn(
11609
+ c.message,
11610
+ c.file,
11611
+ c.type,
11612
+ c.meta
11613
+ ) : new Error(c.message));
11614
+ this.emit("dds-upload-error", { errors: l });
11580
11615
  return;
11581
11616
  }
11582
11617
  }
11583
- this.handleFileList(e != null ? e : null), this.emit("dds-file-change", { files: this._files }), this.setValidity();
11618
+ const i = e ? Array.from(e) : [], a = this.calculateNewFileList(e != null ? e : null), o = /* @__PURE__ */ new Set();
11619
+ if (!this.emit(
11620
+ "dds-file-change",
11621
+ { newFiles: i, files: a, canceledFiles: o },
11622
+ { cancelable: !0 }
11623
+ ).defaultPrevented)
11624
+ if (o.size > 0 && e) {
11625
+ const d = Array.from(e).filter(
11626
+ (c) => !o.has(c)
11627
+ );
11628
+ if (d.length === 0)
11629
+ return;
11630
+ const l = new DataTransfer();
11631
+ d.forEach((c) => l.items.add(c)), this.handleFileList(l.files), this.setValidity();
11632
+ } else
11633
+ this.handleFileList(e != null ? e : null), this.setValidity();
11584
11634
  }
11585
11635
  render() {
11586
11636
  var t, e;