pushfeedback 0.0.10 → 0.0.11

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.
@@ -1,5 +1,5 @@
1
1
  import { h } from '@stencil/core';
2
- import html2canvas from 'html2canvas';
2
+ import domtoimage from 'dom-to-image';
3
3
  export class FeedbackModal {
4
4
  constructor() {
5
5
  this.handleSubmit = async (event) => {
@@ -8,6 +8,14 @@ export class FeedbackModal {
8
8
  this.showScreenshotMode = false;
9
9
  this.showModal = false;
10
10
  this.sending = true;
11
+ let encodedScreenshot = "";
12
+ if (this.encodedScreenshot) {
13
+ await this.encodedScreenshot.then((data) => {
14
+ encodedScreenshot = data;
15
+ }).catch((error) => {
16
+ console.log(error);
17
+ });
18
+ }
11
19
  try {
12
20
  const res = await fetch('https://app.pushfeedback.com/api/feedback/', {
13
21
  method: 'POST',
@@ -16,7 +24,7 @@ export class FeedbackModal {
16
24
  message: this.formMessage,
17
25
  email: this.formEmail,
18
26
  project: this.project,
19
- screenshot: this.encodedScreenshot
27
+ screenshot: encodedScreenshot
20
28
  }),
21
29
  headers: {
22
30
  'Content-Type': 'application/json'
@@ -122,26 +130,27 @@ export class FeedbackModal {
122
130
  };
123
131
  this.handleMouseClickedSelectedElement = (event) => {
124
132
  event.preventDefault();
125
- if (this.elementSelected) {
133
+ if (this.elementSelected)
126
134
  this.elementSelected.classList.add('feedback-modal-element-selected');
127
- }
128
135
  let top = this.elementSelected.getBoundingClientRect().top;
129
- this.elementSelected.style.top = `${top + window.scrollY}px`;
136
+ this.elementSelected.style.top = `${top + window.pageYOffset}px`;
130
137
  const clonedElementSelected = this.elementSelected.cloneNode(true);
131
138
  document.body.appendChild(clonedElementSelected);
132
139
  this.elementSelected.style.top = `${top}px`;
133
- html2canvas(document.body).then((canvas) => {
134
- this.encodedScreenshot = canvas.toDataURL();
140
+ this.encodedScreenshot = domtoimage.toPng(document.body, { cacheBust: true })
141
+ .then(function (dataUrl) {
135
142
  document.body.removeChild(clonedElementSelected);
136
- const page = document.getElementsByTagName('html')[0];
137
- page.style.overflow = 'hidden';
138
- this.hasSelectedElement = true;
139
- this.overlay.style.display = 'block';
140
- this.showModal = true;
141
- }).catch((error) => {
142
- console.log(error);
143
+ return dataUrl;
144
+ })
145
+ .catch(function (error) {
146
+ console.error('Oops, something went wrong!', error);
143
147
  return "";
144
148
  });
149
+ const page = document.getElementsByTagName('html')[0];
150
+ page.style.overflow = 'hidden';
151
+ this.hasSelectedElement = true;
152
+ this.overlay.style.display = 'block';
153
+ this.showModal = true;
145
154
  };
146
155
  this.sending = false;
147
156
  this.formMessage = '';