@verdocs/web-sdk 5.0.23 → 5.0.24

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.
@@ -108,7 +108,7 @@ const doneIcon = '<svg focusable="false" aria-hidden="true" viewBox="0 0 24 24"
108
108
  const VerdocsSend = class {
109
109
  constructor(hostRef) {
110
110
  index$1.registerInstance(this, hostRef);
111
- this.sendingEnvelope = index$1.createEvent(this, "sendingEnvelope", 7);
111
+ this.beforeSend = index$1.createEvent(this, "beforeSend", 7);
112
112
  this.send = index$1.createEvent(this, "send", 7);
113
113
  this.exit = index$1.createEvent(this, "exit", 7);
114
114
  this.sdkError = index$1.createEvent(this, "sdkError", 7);
@@ -250,7 +250,7 @@ const VerdocsSend = class {
250
250
  this.showPickerForId = role.id;
251
251
  }
252
252
  handleSend(e) {
253
- var _a, _b;
253
+ var _a;
254
254
  if (this.sending) {
255
255
  console.log('[SEND] Skipping duplicate send', e);
256
256
  return;
@@ -259,10 +259,9 @@ const VerdocsSend = class {
259
259
  e.preventDefault();
260
260
  e.stopPropagation();
261
261
  this.sending = true;
262
- (_a = this.sendingEnvelope) === null || _a === void 0 ? void 0 : _a.emit({ sending: true });
263
262
  const details = {
264
263
  template_id: this.templateId,
265
- name: ((_b = this.template) === null || _b === void 0 ? void 0 : _b.name) || 'New Envelope',
264
+ name: ((_a = this.template) === null || _a === void 0 ? void 0 : _a.name) || 'New Envelope',
266
265
  environment: this.environment,
267
266
  initial_reminder: 0,
268
267
  followup_reminders: 0,
@@ -270,22 +269,27 @@ const VerdocsSend = class {
270
269
  // TODO: Pre-filled fields support
271
270
  fields: [],
272
271
  };
272
+ const beforeSendResult = this.beforeSend.emit({ ...details, name: details.name });
273
+ if (beforeSendResult.defaultPrevented) {
274
+ console.log('[SEND] Send cancelled by parent', details);
275
+ this.sending = false;
276
+ return;
277
+ }
273
278
  console.log('[SEND] Creating envelope', details);
274
279
  jsSdk.createEnvelope(this.endpoint, details)
275
280
  .then(r => {
276
- var _a, _b;
281
+ var _a;
277
282
  console.log('[SEND] Send envelope', r);
278
283
  this.reset().catch((e) => console.log('Unknown Error', e));
279
284
  this.sending = false;
280
- (_a = this.sendingEnvelope) === null || _a === void 0 ? void 0 : _a.emit({ sending: false });
281
- (_b = this.send) === null || _b === void 0 ? void 0 : _b.emit({ ...details, name: details.name, envelope_id: r.id, envelope: r });
285
+ (_a = this.send) === null || _a === void 0 ? void 0 : _a.emit({ ...details, name: details.name, envelope_id: r.id, envelope: r });
282
286
  })
283
287
  .catch(e => {
284
288
  var _a, _b, _c;
285
- console.log('Send error', e);
289
+ console.log('[SEND] Send error', e);
286
290
  Toast.VerdocsToast(((_b = (_a = e.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) || 'Error creating envelope, please try again later.');
287
291
  this.sending = false;
288
- (_c = this.sendingEnvelope) === null || _c === void 0 ? void 0 : _c.emit({ sending: false });
292
+ (_c = this.sdkError) === null || _c === void 0 ? void 0 : _c.emit(e);
289
293
  });
290
294
  }
291
295
  handleCancel(e) {