pushfeedback 0.1.37 → 0.1.39

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.
@@ -2,110 +2,112 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const index = require('./index-d64bfb06.js');
5
+ const index = require('./index-a717311c.js');
6
6
 
7
7
  const feedbackButtonCss = ".feedback-button-content{cursor:pointer;max-width:fit-content;z-index:var(--feedback-button-z-index)}.feedback-button-content--light{align-items:center;background-color:var(--feedback-button-light-bg-color);border-radius:var(--feedback-button-border-radius);box-shadow:rgba(60, 64, 67, 0.3) 0px 1px 2px 0px, rgba(60, 64, 67, 0.15) 0px 2px 6px 2px;box-sizing:border-box;color:var(--feedback-button-light-text-color);display:flex;font-family:var(--feedback-font-family);font-size:var(--feedback-button-text-font-size);font-weight:var(--feedback-button-text-font-weight);padding:8px 15px}.feedback-button-content--dark{align-items:center;background-color:var(--feedback-button-dark-bg-color);border-radius:var(--feedback-button-border-radius);box-shadow:rgba(60, 64, 67, 0.3) 0px 1px 2px 0px, rgba(60, 64, 67, 0.15) 0px 2px 6px 2px;box-sizing:border-box;color:var(--feedback-button-dark-text-color);display:flex;font-family:var(--feedback-font-family);font-weight:var(--feedback-button-text-font-weight);font-size:var(--feedback-button-text-font-size);padding:8px 15px}.feedback-button-content--bottom-right{bottom:10px;position:fixed;right:10px}.feedback-button-content--center-right{position:fixed;transform:rotate(-90deg) translateY(-50%);top:50%}.feedback-button-content--center-right.feedback-button-content--dark,.feedback-button-content--center-right.feedback-button-content--light{border-radius:4px;border-bottom-left-radius:0px;border-bottom-right-radius:0px}.feedback-button-content-icon{height:16px;margin-right:5px;width:16px}.feedback-button-content--center-right .feedback-button-content-icon{rotate:90deg}";
8
8
 
9
- const FeedbackButton = class {
10
- constructor(hostRef) {
11
- index.registerInstance(this, hostRef);
12
- this.customFont = false;
13
- this.errorMessage = "Please try again later.";
14
- this.errorMessage403 = "The request URL does not match the one defined in PushFeedback for this project.";
15
- this.errorMessage404 = "We could not find the provided project id in PushFeedback.";
16
- this.modalTitle = 'Share your feedback';
17
- this.modalTitleSuccess = 'Thanks for your feedback!';
18
- this.modalTitleError = "Oops!";
19
- this.modalPosition = 'center';
20
- this.sendButtonText = 'Send';
21
- this.successMessage = "";
22
- this.project = '';
23
- this.screenshotButtonText = 'Add a screenshot';
24
- this.screenshotTopbarText = 'Select an element on this page';
25
- this.hideEmail = false;
26
- this.emailAddress = '';
27
- this.emailPlaceholder = 'Email address (optional)';
28
- this.messagePlaceholder = 'Comments';
29
- this.hideRating = false;
30
- this.ratingMode = 'thumbs';
31
- this.ratingPlaceholder = 'Was this page helpful?';
32
- this.ratingStarsPlaceholder = 'How would you rate this page?';
33
- this.buttonStyle = 'default';
34
- this.buttonPosition = 'default';
35
- this.hideIcon = false;
36
- this.hideScreenshotButton = false;
37
- this.hidePrivacyPolicy = true;
38
- this.privacyPolicyText = "I have read and expressly consent to the terms of the <a href='https://pushfeedback.com/privacy'>Privacy Policy</a>.";
39
- this.fetchData = true;
40
- }
41
- connectedCallback() {
42
- this.feedbackModal = document.createElement('feedback-modal');
43
- const props = [
44
- 'customFont',
45
- 'errorMessage',
46
- 'errorMessage403',
47
- 'errorMessage404',
48
- 'modalTitle',
49
- 'modalTitleSuccess',
50
- 'modalTitleError',
51
- 'modalPosition',
52
- 'sendButtonText',
53
- 'successMessage',
54
- 'project',
55
- 'screenshotButtonText',
56
- 'screenshotTopbarText',
57
- 'hideEmail',
58
- 'emailAddress',
59
- 'emailPlaceholder',
60
- 'messagePlaceholder',
61
- 'hideRating',
62
- 'ratingMode',
63
- 'ratingPlaceholder',
64
- 'ratingStarsPlaceholder',
65
- 'hideScreenshotButton',
66
- 'hidePrivacyPolicy',
67
- 'privacyPolicyText',
68
- 'fetchData'
69
- ];
70
- props.forEach(prop => {
71
- this.feedbackModal[prop] = this[prop];
72
- });
73
- document.body.appendChild(this.feedbackModal);
74
- }
75
- disconnectedCallback() {
76
- document.body.removeChild(this.feedbackModal);
77
- }
78
- isSafariBrowser() {
79
- const isSafari = /safari/i.test(navigator.userAgent) && !/chrome/i.test(navigator.userAgent);
80
- return isSafari;
81
- }
82
- componentDidLoad() {
83
- if (this.buttonPosition === 'center-right') {
84
- const buttonContent = this.el.shadowRoot.querySelector('.feedback-button-content');
85
- let adjustement = 0;
86
- if (this.isSafariBrowser()) {
87
- adjustement = 10;
88
- }
89
- buttonContent.style.right = `${(buttonContent.offsetWidth + adjustement) / 2 * -1}px`;
90
- }
91
- if (!this.customFont) {
92
- this.loadInterFont();
93
- }
94
- }
95
- loadInterFont() {
96
- const link = document.createElement('link');
97
- link.href = 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap';
98
- link.rel = 'stylesheet';
99
- document.head.appendChild(link);
100
- }
101
- showModal() {
102
- this.feedbackModal.showModal = true;
103
- }
104
- render() {
105
- return (index.h(index.Host, null, index.h("a", { class: `feedback-button-content feedback-button-content--${this.buttonStyle} feedback-button-content--${this.buttonPosition}`, onClick: () => this.showModal() }, !this.hideIcon && this.buttonStyle === 'dark' && (index.h("span", { class: "feedback-button-content-icon" }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "#fff", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", class: "feather feather-edit-3" }, index.h("path", { d: "M12 20h9" }), index.h("path", { d: "M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z" })))), !this.hideIcon && this.buttonStyle === 'light' && (index.h("span", { class: "feedback-button-content-icon" }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "#0070F4", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", class: "feather feather-edit-3" }, index.h("path", { d: "M12 20h9" }), index.h("path", { d: "M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z" })))), index.h("slot", null))));
106
- }
107
- get el() { return index.getElement(this); }
108
- };
9
+ const FeedbackButton = class {
10
+ constructor(hostRef) {
11
+ index.registerInstance(this, hostRef);
12
+ this.customFont = false;
13
+ this.errorMessage = "Please try again later.";
14
+ this.errorMessage403 = "The request URL does not match the one defined in PushFeedback for this project.";
15
+ this.errorMessage404 = "We could not find the provided project id in PushFeedback.";
16
+ this.modalTitle = 'Share your feedback';
17
+ this.modalTitleSuccess = 'Thanks for your feedback!';
18
+ this.modalTitleError = "Oops!";
19
+ this.modalPosition = 'center';
20
+ this.sendButtonText = 'Send';
21
+ this.successMessage = "";
22
+ this.project = '';
23
+ this.screenshotButtonText = 'Add a screenshot';
24
+ this.screenshotTopbarText = 'Select an element on this page';
25
+ this.hideEmail = false;
26
+ this.emailAddress = '';
27
+ this.emailPlaceholder = 'Email address (optional)';
28
+ this.messagePlaceholder = 'Comments';
29
+ this.hideRating = false;
30
+ this.rating = undefined;
31
+ this.ratingMode = 'thumbs';
32
+ this.ratingPlaceholder = 'Was this page helpful?';
33
+ this.ratingStarsPlaceholder = 'How would you rate this page?';
34
+ this.buttonStyle = 'default';
35
+ this.buttonPosition = 'default';
36
+ this.hideIcon = false;
37
+ this.hideScreenshotButton = false;
38
+ this.hidePrivacyPolicy = true;
39
+ this.privacyPolicyText = "I have read and expressly consent to the terms of the <a href='https://pushfeedback.com/privacy'>Privacy Policy</a>.";
40
+ this.fetchData = true;
41
+ }
42
+ connectedCallback() {
43
+ this.feedbackModal = document.createElement('feedback-modal');
44
+ const props = [
45
+ 'customFont',
46
+ 'errorMessage',
47
+ 'errorMessage403',
48
+ 'errorMessage404',
49
+ 'modalTitle',
50
+ 'modalTitleSuccess',
51
+ 'modalTitleError',
52
+ 'modalPosition',
53
+ 'sendButtonText',
54
+ 'successMessage',
55
+ 'project',
56
+ 'screenshotButtonText',
57
+ 'screenshotTopbarText',
58
+ 'hideEmail',
59
+ 'emailAddress',
60
+ 'emailPlaceholder',
61
+ 'messagePlaceholder',
62
+ 'hideRating',
63
+ 'rating',
64
+ 'ratingMode',
65
+ 'ratingPlaceholder',
66
+ 'ratingStarsPlaceholder',
67
+ 'hideScreenshotButton',
68
+ 'hidePrivacyPolicy',
69
+ 'privacyPolicyText',
70
+ 'fetchData'
71
+ ];
72
+ props.forEach(prop => {
73
+ this.feedbackModal[prop] = this[prop];
74
+ });
75
+ document.body.appendChild(this.feedbackModal);
76
+ }
77
+ disconnectedCallback() {
78
+ document.body.removeChild(this.feedbackModal);
79
+ }
80
+ isSafariBrowser() {
81
+ const isSafari = /safari/i.test(navigator.userAgent) && !/chrome/i.test(navigator.userAgent);
82
+ return isSafari;
83
+ }
84
+ componentDidLoad() {
85
+ if (this.buttonPosition === 'center-right') {
86
+ const buttonContent = this.el.shadowRoot.querySelector('.feedback-button-content');
87
+ let adjustement = 0;
88
+ if (this.isSafariBrowser()) {
89
+ adjustement = 10;
90
+ }
91
+ buttonContent.style.right = `${(buttonContent.offsetWidth + adjustement) / 2 * -1}px`;
92
+ }
93
+ if (!this.customFont) {
94
+ this.loadInterFont();
95
+ }
96
+ }
97
+ loadInterFont() {
98
+ const link = document.createElement('link');
99
+ link.href = 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap';
100
+ link.rel = 'stylesheet';
101
+ document.head.appendChild(link);
102
+ }
103
+ showModal() {
104
+ this.feedbackModal.showModal = true;
105
+ }
106
+ render() {
107
+ return (index.h(index.Host, null, index.h("a", { class: `feedback-button-content feedback-button-content--${this.buttonStyle} feedback-button-content--${this.buttonPosition}`, onClick: () => this.showModal() }, !this.hideIcon && this.buttonStyle === 'dark' && (index.h("span", { class: "feedback-button-content-icon" }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "#fff", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", class: "feather feather-edit-3" }, index.h("path", { d: "M12 20h9" }), index.h("path", { d: "M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z" })))), !this.hideIcon && this.buttonStyle === 'light' && (index.h("span", { class: "feedback-button-content-icon" }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "#0070F4", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", class: "feather feather-edit-3" }, index.h("path", { d: "M12 20h9" }), index.h("path", { d: "M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z" })))), index.h("slot", null))));
108
+ }
109
+ get el() { return index.getElement(this); }
110
+ };
109
111
  FeedbackButton.style = feedbackButtonCss;
110
112
 
111
113
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
@@ -7954,284 +7956,291 @@ var html2canvas = createCommonjsModule(function (module, exports) {
7954
7956
 
7955
7957
  const feedbackModalCss = ".text-center{flex-grow:1;text-align:center}.feedback-modal-wrapper{position:absolute;z-index:var(--feedback-modal-wrapper-z-index)}.feedback-overlay{background-color:var(--feedback-modal-screenshot-bg-color);height:100%;left:0;position:fixed;top:0;width:100%;z-index:var(--feedback-modal-screnshot-z-index)}.feedback-modal{display:inline-block;position:relative}.feedback-modal-content{background-color:var(--feedback-modal-content-bg-color);border-color:1px solid var(--feedback-modal-header-text-color);border-radius:var(--feedback-modal-content-border-radius);box-shadow:0px 1px 2px 0px rgba(60, 64, 67, .30), 0px 2px 6px 2px rgba(60, 64, 67, .15);box-sizing:border-box;color:var(--feedback-modal-content-text-color);display:flex;flex-direction:column;font-family:var(--feedback-modal-content-font-family);left:50%;max-width:90%;padding:20px;position:fixed;top:50%;transform:translate(-50%, -50%);width:100%;z-index:var(--feedback-modal-content-z-index)}.feedback-modal-header{align-items:center;color:var(--feedback-modal-header-text-color);display:flex;font-family:var(--feedback-modal-header-font-family);font-size:var(--feedback-header-font-size);font-weight:var(--feedback-modal-header-font-weight);justify-content:space-between;margin-bottom:20px}.feedback-modal-rating-buttons{width:100%;margin-bottom:20px}.feedback-modal-rating-button{padding:0;background-color:transparent;border:transparent;margin-right:5px;cursor:pointer}.feedback-modal-rating-buttons--thumbs .feedback-modal-rating-button{border:1px solid var(--feedback-modal-button-border-color);border-radius:var(--feedback-modal-button-border-radius);color:var(--feedback-modal-button-text-color);font-size:var(--feedback-modal-button-font-size);font-family:var(--feedback-modal-content-font-family);font-weight:500;margin-right:10px;justify-content:center;padding:5px 10px}.feedback-modal-rating-buttons--thumbs .feedback-modal-rating-button:hover,.feedback-modal-rating-buttons--thumbs .feedback-modal-rating-button--selected{background-color:var(--feedback-modal-button-bg-color-active);border:1px solid var(--feedback-modal-button-border-color-active);color:var(--feedback-modal-button-text-color-active)}.feedback-modal-rating-buttons--thumbs .feedback-modal-rating-button:hover svg,.feedback-modal-rating-buttons--thumbs .feedback-modal-rating-button--selected svg{stroke:var(--feedback-modal-rating-button-selected-color)}.feedback-modal-rating-buttons svg{stroke:var(--feedback-modal-rating-button-color);cursor:pointer}.feedback-modal-rating-buttons--stars .feedback-modal-rating-button--selected svg{fill:var(--feedback-modal-rating-button-stars-selected-color);stroke:var(--feedback-modal-rating-button-stars-selected-color)}.feedback-modal-text textarea{background-color:var(--feedback-modal-input-bg-color);border:1px solid var(--feedback-modal-input-border-color);border-radius:var(--feedback-modal-input-border-radius);box-sizing:border-box;color:var(--feedback-modal-input-text-color);font-family:var(--feedback-modal-content-font-family);font-size:var(--feedback-modal-input-font-size);margin-bottom:20px;height:100px;min-height:100px;padding:10px;resize:vertical;width:100%}.feedback-modal-email input{background-color:var(--feedback-modal-input-bg-color);border:1px solid var(--feedback-modal-input-border-color);border-radius:var(--feedback-modal-input-border-radius);box-sizing:border-box;color:var(--feedback-modal-input-text-color);font-family:var(--feedback-modal-content-font-family);font-size:var(--feedback-modal-input-font-size);margin-bottom:20px;height:40px;padding:10px;width:100%;margin-bottom:20px}.feedback-modal-privacy{font-family:var(--feedback-modal-content-font-family);font-size:var(--feedback-modal-input-font-size);margin-bottom:20px}.feedback-modal-text textarea:focus,.feedback-modal-email input:focus{border:1px solid var(--feedback-modal-input-border-color-focused);outline:none}.feedback-modal-buttons{display:flex;flex-direction:column}.feedback-modal-buttons .feedback-modal-button{margin-bottom:20px}.feedback-modal-button{align-items:center;background-color:transparent;border:1px solid var(--feedback-modal-button-border-color);border-radius:var(--feedback-modal-button-border-radius);color:var(--feedback-modal-button-text-color);cursor:pointer;display:flex;font-size:var(--feedback-modal-button-font-size);font-family:var(--feedback-modal-content-font-family);font-weight:500;justify-content:center;min-height:40px;padding:5px 10px}.feedback-modal-button svg{margin-right:6px}.feedback-modal-button path{fill:var(--feedback-modal-button-icon-color)}.feedback-modal-button:hover path,.feedback-modal-button--active path{fill:var(--feedback-modal-button-icon-color-active)}.feedback-modal-button--submit{background-color:var(--feedback-modal-button-submit-bg-color);border:1px solid var(--feedback-modal-button-border-color-active);color:var(--feedback-modal-button-submit-text-color)}.feedback-modal-button:hover,.feedback-modal-button--active{background-color:var(--feedback-modal-button-bg-color-active);border:1px solid var(--feedback-modal-button-border-color-active);color:var(--feedback-modal-button-text-color-active)}.feedback-modal-button--submit:hover{background-color:var(--feedback-modal-button-submit-bg-color-hover);border:1px solid var(--feedback-modal-button-submit-border-color-hover);color:var(--feedback-modal-button-submit-text-color-hover)}.feedback-modal-input-heading{display:block;font-size:14px;font-weight:300;padding-bottom:10px;font-family:var(--feedback-modal-content-font-family)}.feedback-modal-footer{font-size:12px;text-align:center}.feedback-modal-footer a{color:var(--feedback-modal-footer-link);font-weight:500;text-decoration:none}.feedback-logo{align-items:center;display:flex;justify-content:center;margin-top:5px}.feedback-logo a{margin-left:3px}.feedback-modal-close{background-color:var(--feedback-modal-close-bg-color);border:0;border-radius:50%;cursor:pointer;height:22px;margin-left:auto;padding:0;width:22px}.feedback-modal-close svg{stroke:var(--feedback-modal-close-color)}.feedback-modal-screenshot{background-color:var(--feedback-modal-screenshot-bg-color);height:100%;left:0;position:fixed;top:0;width:100%;z-index:var(--feedback-modal-screnshot-z-index)}.feedback-modal-screenshot-header{align-items:center;background-color:var(--feedback-modal-screenshot-header-bg-color);border-radius:var(--feedback-modal-content-border-radius);box-shadow:0px 1px 2px 0px rgba(60, 64, 67, .30), 0px 2px 6px 2px rgba(60, 64, 67, .15);box-sizing:border-box;color:var(--feedback-modal-screenshot-header-text-color);cursor:pointer;display:flex;font-family:var(--feedback-modal-content-font-family);left:50%;top:20px;transform:translateX(-50%);padding:10px;position:fixed;width:max-content;z-index:var(--feedback-modal-screenshot-header-z-index)}.feedback-modal-screenshot-close{height:24px;padding-left:10px;width:24px}.feedback-modal-screenshot-close svg{stroke:var(--feedback-modal-close-color)}.feedback-modal-message{font-size:var(--feedback-modal-message-font-size);margin-top:0}.feedback-modal-element-hover{background-color:transparent;cursor:pointer;border:1px solid var(--feedback-modal-element-hover-border-color)}.feedback-modal-element-selected{background-color:transparent;border:1px solid var(--feedback-modal-element-selected-border-color)}@media screen and (min-width: 768px){.feedback-modal-content{max-width:600px}.feedback-modal-content.feedback-modal-content--bottom-right{bottom:var(--feedback-modal-content-position-bottom);left:initial;right:var(--feedback-modal-content-position-right);top:initial;transform:initial}.feedback-modal-content.feedback-modal-content--bottom-left{bottom:var(--feedback-modal-content-position-bottom);left:var(--feedback-modal-content-position-left);top:initial;transform:initial}.feedback-modal-content.feedback-modal-content--top-right{right:var(--feedback-modal-content-position-right);top:var(--feedback-modal-content-position-top);transform:initial}.feedback-modal-content.feedback-modal-content--top-left{left:var(--feedback-modal-content-position-left);top:var(--feedback-modal-content-position-top);transform:initial}.feedback-modal-content.feedback-modal-content--center-left{left:5px;right:auto;top:50%;transform:translateY(-50%)}.feedback-modal-content.feedback-modal-content--center-right{left:auto;right:5px;top:50%;transform:translateY(-50%)}.feedback-modal-content.feedback-modal-content--sidebar-left.feedback-modal-content--open,.feedback-modal-content.feedback-modal-content--sidebar-right.feedback-modal-content--open{transform:translateX(0)}.feedback-modal-content.feedback-modal-content--sidebar-left{max-width:300px;left:0;right:auto;height:100vh;top:0;transform:translateX(-100%);transition:transform 0.5s ease-in-out;border-radius:0}.feedback-modal-content.feedback-modal-content--sidebar-right{max-width:300px;left:auto;right:0;height:100vh;top:0;transform:translateX(100%);transition:transform 0.5s ease-in-out;border-radius:0}.feedback-modal-text textarea{height:150px;min-height:150px}}";
7956
7958
 
7957
- const FeedbackModal = class {
7958
- constructor(hostRef) {
7959
- index.registerInstance(this, hostRef);
7960
- this.onScrollDebounced = () => {
7961
- clearTimeout(this.scrollTimeout);
7962
- this.scrollTimeout = setTimeout(() => {
7963
- document.documentElement.classList.remove('feedback-modal-screenshot-closing');
7964
- document.documentElement.style.top = "";
7965
- window.removeEventListener('scroll', this.onScrollDebounced);
7966
- }, 200);
7967
- };
7968
- this.handleSubmit = async (event) => {
7969
- event.preventDefault();
7970
- this.resetOverflow();
7971
- this.showScreenshotMode = false;
7972
- this.showScreenshotTopBar = false;
7973
- this.showModal = false;
7974
- this.sending = true;
7975
- try {
7976
- const res = await fetch('https://app.pushfeedback.com/api/feedback/', {
7977
- method: 'POST',
7978
- body: JSON.stringify({
7979
- url: window.location.href,
7980
- message: this.formMessage,
7981
- email: this.formEmail,
7982
- project: this.project,
7983
- screenshot: this.encodedScreenshot,
7984
- rating: this.selectedRating,
7985
- ratingMode: this.ratingMode,
7986
- }),
7987
- headers: {
7988
- 'Content-Type': 'application/json'
7989
- }
7990
- });
7991
- if (res.status === 201) {
7992
- this.formSuccess = true;
7993
- this.formError = false;
7994
- }
7995
- else {
7996
- this.formSuccess = false;
7997
- this.formError = true;
7998
- this.formErrorStatus = res.status;
7999
- }
8000
- }
8001
- catch (error) {
8002
- console.log(error);
8003
- this.formSuccess = false;
8004
- this.formError = true;
8005
- this.formErrorStatus = 500;
8006
- }
8007
- finally {
8008
- this.sending = false;
8009
- this.showModal = true;
8010
- }
8011
- };
8012
- this.close = () => {
8013
- this.sending = false;
8014
- this.showModal = false;
8015
- this.showScreenshotMode = false;
8016
- this.showScreenshotTopBar = false;
8017
- this.hasSelectedElement = false;
8018
- this.encodedScreenshot = null;
8019
- this.formSuccess = false;
8020
- this.formError = false;
8021
- this.formErrorStatus = 500;
8022
- this.formMessage = '';
8023
- this.formEmail = '';
8024
- this.resetOverflow();
8025
- };
8026
- this.openScreenShot = () => {
8027
- this.hasSelectedElement = false;
8028
- this.showModal = false;
8029
- this.showScreenshotMode = true;
8030
- this.showScreenshotTopBar = true;
8031
- this.encodedScreenshot = null;
8032
- if (window.innerWidth > document.documentElement.clientWidth) {
8033
- document.documentElement.classList.add('feedback-modal-screenshot-open--scroll');
8034
- }
8035
- const scrollY = window.scrollY;
8036
- document.documentElement.style.top = `-${scrollY}px`;
8037
- window.scrollTo(0, parseInt(document.documentElement.style.top || '0') * -1);
8038
- document.documentElement.classList.add('feedback-modal-screenshot-open');
8039
- };
8040
- this.closeScreenShot = () => {
8041
- this.showModal = false;
8042
- this.showScreenshotMode = false;
8043
- this.showScreenshotTopBar = false;
8044
- this.hasSelectedElement = false;
8045
- this.encodedScreenshot = null;
8046
- this.resetOverflow();
8047
- };
8048
- this.handleMouseOverScreenShot = (event) => {
8049
- event.preventDefault();
8050
- if (this.hasSelectedElement)
8051
- return;
8052
- const borderOffset = 2;
8053
- this.screenshotModal.style.display = 'none';
8054
- const elementUnder = document.elementFromPoint(event.clientX, event.clientY);
8055
- const rect = elementUnder.getBoundingClientRect();
8056
- this.screenshotModal.style.display = '';
8057
- // Get the bounding box of the element selected
8058
- this.elementSelected.style.position = "absolute";
8059
- this.elementSelected.style.left = `${rect.left}px`;
8060
- this.elementSelected.style.top = `${rect.top}px`;
8061
- this.elementSelected.style.width = `${rect.width}px`;
8062
- this.elementSelected.style.height = `${rect.height}px`;
8063
- this.elementSelected.classList.add('feedback-modal-element-hover');
8064
- // Set the background color of nonselected areas
8065
- // Top
8066
- this.topSide.style.position = "absolute";
8067
- this.topSide.style.left = `${rect.left}px`;
8068
- this.topSide.style.top = '0px';
8069
- this.topSide.style.width = `${rect.width + borderOffset}px`;
8070
- this.topSide.style.height = `${rect.top}px`;
8071
- this.topSide.style.backgroundColor = "rgba(0, 0, 0, 0.4)";
8072
- // Left
8073
- this.leftSide.style.position = "absolute";
8074
- this.leftSide.style.left = '0px';
8075
- this.leftSide.style.top = '0px';
8076
- this.leftSide.style.width = `${rect.left}px`;
8077
- this.leftSide.style.height = '100vh';
8078
- this.leftSide.style.backgroundColor = "rgba(0, 0, 0, 0.4)";
8079
- // Bottom
8080
- this.bottomSide.style.position = "absolute";
8081
- this.bottomSide.style.left = `${rect.left}px`;
8082
- this.bottomSide.style.top = `${rect.bottom + borderOffset}px`;
8083
- this.bottomSide.style.width = `${rect.width + borderOffset}px`;
8084
- this.bottomSide.style.height = '100vh';
8085
- this.bottomSide.style.backgroundColor = "rgba(0, 0, 0, 0.4)";
8086
- // Right
8087
- this.rightSide.style.position = "absolute";
8088
- this.rightSide.style.left = `${rect.right + borderOffset}px`;
8089
- this.rightSide.style.top = '0px';
8090
- this.rightSide.style.width = '100%';
8091
- this.rightSide.style.height = '100vh';
8092
- this.rightSide.style.backgroundColor = "rgba(0, 0, 0, 0.4)";
8093
- // Restore the visibility of the screenshot-modal
8094
- this.screenshotModal.style.backgroundColor = 'transparent';
8095
- };
8096
- this.handleMouseClickedSelectedElement = async (event) => {
8097
- event.preventDefault();
8098
- if (!this.elementSelected) {
8099
- return;
8100
- }
8101
- this.hasSelectedElement = true;
8102
- this.elementSelected.classList.add('feedback-modal-element-selected');
8103
- // Get the top position including the scroll offset
8104
- const rectTop = this.elementSelected.getBoundingClientRect().top;
8105
- const topWithScroll = rectTop + window.scrollY;
8106
- // Move the element with the scroll offset
8107
- this.elementSelected.style.top = `${topWithScroll}px`;
8108
- // Clone the selected element and append it to the body
8109
- const clonedElementSelected = this.elementSelected.cloneNode(true);
8110
- document.body.appendChild(clonedElementSelected);
8111
- // Reset the top position of the original element
8112
- this.elementSelected.style.top = `${rectTop}px`;
8113
- this.showScreenshotTopBar = false;
8114
- this.showModal = false;
8115
- try {
8116
- const dataUrl = await this.captureScreenshot();
8117
- console.log('Screenshot captured');
8118
- this.encodedScreenshot = dataUrl;
8119
- }
8120
- catch (error) {
8121
- console.error('Failed to capture screenshot:', error);
8122
- this.hasSelectedElement = false;
8123
- }
8124
- finally {
8125
- // Remove the cloned element and show the modal again
8126
- document.body.removeChild(clonedElementSelected);
8127
- this.showModal = true;
8128
- }
8129
- };
8130
- this.sending = false;
8131
- this.formMessage = '';
8132
- this.formEmail = '';
8133
- this.formSuccess = false;
8134
- this.formError = false;
8135
- this.formErrorStatus = 500;
8136
- this.encodedScreenshot = undefined;
8137
- this.isPrivacyChecked = false;
8138
- this.whitelabel = false;
8139
- this.selectedRating = 0;
8140
- this.errorMessage = "Please try again later.";
8141
- this.errorMessage403 = "The request URL does not match the one defined in PushFeedback for this project.";
8142
- this.errorMessage404 = "We could not find the provided project ID in PushFeedback.";
8143
- this.modalTitle = 'Share your feedback';
8144
- this.modalTitleSuccess = 'Thanks for your feedback!';
8145
- this.modalTitleError = "Oops!";
8146
- this.modalPosition = 'center';
8147
- this.sendButtonText = 'Send';
8148
- this.successMessage = "";
8149
- this.project = '';
8150
- this.screenshotButtonText = 'Add a screenshot';
8151
- this.screenshotTopbarText = 'Select an element on this page';
8152
- this.hideEmail = false;
8153
- this.emailAddress = '';
8154
- this.emailPlaceholder = 'Email address (optional)';
8155
- this.messagePlaceholder = 'Comments';
8156
- this.hideRating = false;
8157
- this.ratingMode = 'thumbs';
8158
- this.ratingPlaceholder = 'Was this page helpful?';
8159
- this.ratingStarsPlaceholder = 'How would you rate this page?';
8160
- this.showModal = false;
8161
- this.showScreenshotMode = false;
8162
- this.showScreenshotTopBar = false;
8163
- this.hasSelectedElement = false;
8164
- this.hideScreenshotButton = false;
8165
- this.hidePrivacyPolicy = true;
8166
- this.privacyPolicyText = "I have read and expressly consent to the terms of the <a href='https://pushfeedback.com/privacy'>Privacy Policy</a>.";
8167
- this.fetchData = true;
8168
- }
8169
- componentWillLoad() {
8170
- if (this.fetchData)
8171
- this.fetchProjectData();
8172
- this.formEmail = this.emailAddress;
8173
- }
8174
- async fetchProjectData() {
8175
- try {
8176
- const response = await fetch('https://app.pushfeedback.com/api/projects/' + this.project + '/');
8177
- const data = await response.json();
8178
- this.whitelabel = data.whitelabel;
8179
- }
8180
- catch (error) {
8181
- console.log(error);
8182
- }
8183
- }
8184
- resetOverflow() {
8185
- document.documentElement.classList.remove('feedback-modal-screenshot-open');
8186
- document.documentElement.classList.remove('feedback-modal-screenshot-open--scroll');
8187
- document.documentElement.classList.add('feedback-modal-screenshot-closing');
8188
- window.scrollTo(0, parseInt(document.documentElement.style.top || '0') * -1);
8189
- window.addEventListener('scroll', this.onScrollDebounced);
8190
- }
8191
- handleMessageInput(event) {
8192
- this.formMessage = event.target.value;
8193
- }
8194
- handleEmailInput(event) {
8195
- this.formEmail = event.target.value;
8196
- }
8197
- captureScreenshot() {
8198
- return new Promise((resolve, reject) => {
8199
- requestAnimationFrame(() => {
8200
- html2canvas(document.body, {
8201
- x: window.scrollX,
8202
- y: window.scrollY,
8203
- width: window.innerWidth,
8204
- height: window.innerHeight,
8205
- }).then(canvas => {
8206
- const dataUrl = canvas.toDataURL();
8207
- resolve(dataUrl);
8208
- })
8209
- .catch(error => {
8210
- console.error(error);
8211
- reject(error);
8212
- });
8213
- });
8214
- });
8215
- }
8216
- handleCheckboxChange(event) {
8217
- this.isPrivacyChecked = event.target.checked;
8218
- }
8219
- handleRatingChange(newRating) {
8220
- this.selectedRating = newRating;
8221
- }
8222
- render() {
8223
- return (index.h("div", { class: 'feedback-modal-wrapper' }, this.showScreenshotMode && (index.h("div", { class: "feedback-modal-screenshot", ref: el => (this.screenshotModal = el), onMouseMove: this.handleMouseOverScreenShot }, index.h("div", { class: "feedback-modal-screenshot-element-selected", ref: el => (this.elementSelected = el), onClick: this.handleMouseClickedSelectedElement }), index.h("div", { class: "top-side", ref: el => (this.topSide = el) }), index.h("div", { class: "left-side", ref: el => (this.leftSide = el) }), index.h("div", { class: "bottom-side", ref: el => (this.bottomSide = el) }), index.h("div", { class: "right-side", ref: el => (this.rightSide = el) }), this.showScreenshotTopBar && (index.h("div", { class: "feedback-modal-screenshot-header", onClick: this.closeScreenShot }, index.h("span", null, this.screenshotTopbarText), index.h("span", { class: "feedback-modal-screenshot-close" }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "22", height: "22", viewBox: "0 0 24 24", fill: "none", stroke: "#191919", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", class: "feather feather-x" }, index.h("line", { x1: "18", y1: "6", x2: "6", y2: "18" }), index.h("line", { x1: "6", y1: "6", x2: "18", y2: "18" }))))))), this.showModal && (index.h("div", { class: "feedback-overlay" })), this.showModal && (index.h("div", { class: `feedback-modal-content feedback-modal-content--${this.modalPosition} ${this.showModal ? 'feedback-modal-content--open' : ''}`, ref: el => (this.modalContent = el) }, index.h("div", { class: "feedback-modal-header" }, !this.formSuccess && !this.formError ? (index.h("span", null, this.modalTitle)) : this.formSuccess ? (index.h("span", null, this.modalTitleSuccess)) : index.h("span", null, this.modalTitleError), index.h("button", { class: "feedback-modal-close", onClick: this.close }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "22", height: "22", viewBox: "0 0 24 24", fill: "none", stroke: "#191919", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", class: "feather feather-x" }, index.h("line", { x1: "18", y1: "6", x2: "6", y2: "18" }), index.h("line", { x1: "6", y1: "6", x2: "18", y2: "18" })))), index.h("div", { class: "feedback-modal-body" }, !this.formSuccess && !this.formError ? (index.h("form", { onSubmit: this.handleSubmit }, !this.hideRating && (index.h("div", { class: "feedback-modal-rating" }, this.ratingMode === 'thumbs' ? (index.h("div", { class: "feedback-modal-rating-content" }, index.h("span", { class: "feedback-modal-input-heading" }, this.ratingPlaceholder), index.h("div", { class: "feedback-modal-rating-buttons feedback-modal-rating-buttons--thumbs" }, index.h("button", { title: "Yes", class: `feedback-modal-rating-button ${this.selectedRating === 1 ? 'feedback-modal-rating-button--selected' : ''}`, onClick: (event) => {
8224
- event.preventDefault();
8225
- this.handleRatingChange(1);
8226
- } }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "#5F6368", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round" }, index.h("path", { d: "M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3" }))), index.h("button", { title: "No", class: `feedback-modal-rating-button ${this.selectedRating === 5 ? 'feedback-modal-rating-button--selected' : ''}`, onClick: (event) => {
8227
- event.preventDefault();
8228
- this.handleRatingChange(5);
8229
- } }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "#5F6368", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round" }, index.h("path", { d: "M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17" })))))) : (index.h("div", { class: "feedback-modal-rating-content" }, index.h("span", { class: "feedback-modal-input-heading" }, this.ratingStarsPlaceholder), index.h("div", { class: "feedback-modal-rating-buttons feedback-modal-rating-buttons--stars" }, [1, 2, 3, 4, 5].map((rating) => (index.h("button", { key: rating, class: `feedback-modal-rating-button ${this.selectedRating >= rating ? 'feedback-modal-rating-button--selected' : ''}`, onClick: (event) => {
8230
- event.preventDefault();
8231
- this.handleRatingChange(rating);
8232
- } }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "28", height: "28", viewBox: "0 0 24 24", fill: "none", stroke: "#5F6368", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round" }, index.h("polygon", { points: "12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" })))))))))), index.h("div", { class: "feedback-modal-text" }, index.h("textarea", { placeholder: this.messagePlaceholder, value: this.formMessage, onInput: (event) => this.handleMessageInput(event) })), !this.hideEmail && (index.h("div", { class: "feedback-modal-email" }, index.h("input", { placeholder: this.emailPlaceholder, type: "email", onInput: (event) => this.handleEmailInput(event), value: this.formEmail }))), !this.hidePrivacyPolicy && (index.h("div", { class: "feedback-modal-privacy" }, index.h("input", { type: "checkbox", id: "privacyPolicy", onChange: (ev) => this.handleCheckboxChange(ev), required: true }), index.h("span", { innerHTML: this.privacyPolicyText }))), index.h("div", { class: `feedback-modal-buttons ${this.hideScreenshotButton ? 'single' : ''}` }, !this.hideScreenshotButton && (index.h("button", { type: "button", class: `feedback-modal-button feedback-modal-button--screenshot ${this.encodedScreenshot ? "feedback-modal-button--active" : ""}`, onClick: this.openScreenShot, disabled: this.sending }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", height: "24", viewBox: "0 -960 960 960", width: "24" }, index.h("path", { d: "M680-80v-120H560v-80h120v-120h80v120h120v80H760v120h-80ZM200-200v-200h80v120h120v80H200Zm0-360v-200h200v80H280v120h-80Zm480 0v-120H560v-80h200v200h-80Z" })), this.screenshotButtonText)), index.h("button", { class: "feedback-modal-button feedback-modal-button--submit", type: "submit", disabled: this.sending }, this.sendButtonText)))) : this.formSuccess && !this.formError ? (index.h("p", { class: "feedback-modal-message" }, this.successMessage)) : this.formError && this.formErrorStatus == 404 ? (index.h("p", { class: "feedback-modal-message" }, this.errorMessage404)) : this.formError && this.formErrorStatus == 403 ? (index.h("p", { class: "feedback-modal-message" }, this.errorMessage403)) : this.formError ? (index.h("p", { class: "feedback-modal-message" }, this.errorMessage)) : index.h("span", null)), index.h("div", { class: "feedback-modal-footer", style: { display: this.whitelabel ? 'none' : 'block' } }, index.h("div", { class: "feedback-logo" }, "Powered by ", index.h("a", { target: "_blank", href: "https://pushfeedback.com" }, "PushFeedback.com")))))));
8233
- }
8234
- };
7959
+ const FeedbackModal = class {
7960
+ constructor(hostRef) {
7961
+ index.registerInstance(this, hostRef);
7962
+ this.onScrollDebounced = () => {
7963
+ clearTimeout(this.scrollTimeout);
7964
+ this.scrollTimeout = setTimeout(() => {
7965
+ document.documentElement.classList.remove('feedback-modal-screenshot-closing');
7966
+ document.documentElement.style.top = "";
7967
+ window.removeEventListener('scroll', this.onScrollDebounced);
7968
+ }, 200);
7969
+ };
7970
+ this.handleSubmit = async (event) => {
7971
+ event.preventDefault();
7972
+ this.resetOverflow();
7973
+ this.showScreenshotMode = false;
7974
+ this.showScreenshotTopBar = false;
7975
+ this.showModal = false;
7976
+ this.sending = true;
7977
+ try {
7978
+ const res = await fetch('https://app.pushfeedback.com/api/feedback/', {
7979
+ method: 'POST',
7980
+ body: JSON.stringify({
7981
+ url: window.location.href,
7982
+ message: this.formMessage,
7983
+ email: this.formEmail,
7984
+ project: this.project,
7985
+ screenshot: this.encodedScreenshot,
7986
+ rating: this.selectedRating,
7987
+ ratingMode: this.ratingMode,
7988
+ }),
7989
+ headers: {
7990
+ 'Content-Type': 'application/json'
7991
+ }
7992
+ });
7993
+ if (res.status === 201) {
7994
+ this.formSuccess = true;
7995
+ this.formError = false;
7996
+ }
7997
+ else {
7998
+ this.formSuccess = false;
7999
+ this.formError = true;
8000
+ this.formErrorStatus = res.status;
8001
+ }
8002
+ }
8003
+ catch (error) {
8004
+ console.log(error);
8005
+ this.formSuccess = false;
8006
+ this.formError = true;
8007
+ this.formErrorStatus = 500;
8008
+ }
8009
+ finally {
8010
+ this.sending = false;
8011
+ this.showModal = true;
8012
+ }
8013
+ };
8014
+ this.close = () => {
8015
+ this.sending = false;
8016
+ this.showModal = false;
8017
+ this.showScreenshotMode = false;
8018
+ this.showScreenshotTopBar = false;
8019
+ this.hasSelectedElement = false;
8020
+ this.encodedScreenshot = null;
8021
+ this.formSuccess = false;
8022
+ this.formError = false;
8023
+ this.formErrorStatus = 500;
8024
+ this.formMessage = '';
8025
+ this.formEmail = '';
8026
+ this.resetOverflow();
8027
+ };
8028
+ this.openScreenShot = () => {
8029
+ this.hasSelectedElement = false;
8030
+ this.showModal = false;
8031
+ this.showScreenshotMode = true;
8032
+ this.showScreenshotTopBar = true;
8033
+ this.encodedScreenshot = null;
8034
+ if (window.innerWidth > document.documentElement.clientWidth) {
8035
+ document.documentElement.classList.add('feedback-modal-screenshot-open--scroll');
8036
+ }
8037
+ const scrollY = window.scrollY;
8038
+ document.documentElement.style.top = `-${scrollY}px`;
8039
+ window.scrollTo(0, parseInt(document.documentElement.style.top || '0') * -1);
8040
+ document.documentElement.classList.add('feedback-modal-screenshot-open');
8041
+ };
8042
+ this.closeScreenShot = () => {
8043
+ this.showModal = false;
8044
+ this.showScreenshotMode = false;
8045
+ this.showScreenshotTopBar = false;
8046
+ this.hasSelectedElement = false;
8047
+ this.encodedScreenshot = null;
8048
+ this.resetOverflow();
8049
+ };
8050
+ this.handleMouseOverScreenShot = (event) => {
8051
+ event.preventDefault();
8052
+ if (this.hasSelectedElement)
8053
+ return;
8054
+ const borderOffset = 2;
8055
+ this.screenshotModal.style.display = 'none';
8056
+ const elementUnder = document.elementFromPoint(event.clientX, event.clientY);
8057
+ const rect = elementUnder.getBoundingClientRect();
8058
+ this.screenshotModal.style.display = '';
8059
+ // Get the bounding box of the element selected
8060
+ this.elementSelected.style.position = "absolute";
8061
+ this.elementSelected.style.left = `${rect.left}px`;
8062
+ this.elementSelected.style.top = `${rect.top}px`;
8063
+ this.elementSelected.style.width = `${rect.width}px`;
8064
+ this.elementSelected.style.height = `${rect.height}px`;
8065
+ this.elementSelected.classList.add('feedback-modal-element-hover');
8066
+ // Set the background color of nonselected areas
8067
+ // Top
8068
+ this.topSide.style.position = "absolute";
8069
+ this.topSide.style.left = `${rect.left}px`;
8070
+ this.topSide.style.top = '0px';
8071
+ this.topSide.style.width = `${rect.width + borderOffset}px`;
8072
+ this.topSide.style.height = `${rect.top}px`;
8073
+ this.topSide.style.backgroundColor = "rgba(0, 0, 0, 0.4)";
8074
+ // Left
8075
+ this.leftSide.style.position = "absolute";
8076
+ this.leftSide.style.left = '0px';
8077
+ this.leftSide.style.top = '0px';
8078
+ this.leftSide.style.width = `${rect.left}px`;
8079
+ this.leftSide.style.height = '100vh';
8080
+ this.leftSide.style.backgroundColor = "rgba(0, 0, 0, 0.4)";
8081
+ // Bottom
8082
+ this.bottomSide.style.position = "absolute";
8083
+ this.bottomSide.style.left = `${rect.left}px`;
8084
+ this.bottomSide.style.top = `${rect.bottom + borderOffset}px`;
8085
+ this.bottomSide.style.width = `${rect.width + borderOffset}px`;
8086
+ this.bottomSide.style.height = '100vh';
8087
+ this.bottomSide.style.backgroundColor = "rgba(0, 0, 0, 0.4)";
8088
+ // Right
8089
+ this.rightSide.style.position = "absolute";
8090
+ this.rightSide.style.left = `${rect.right + borderOffset}px`;
8091
+ this.rightSide.style.top = '0px';
8092
+ this.rightSide.style.width = '100%';
8093
+ this.rightSide.style.height = '100vh';
8094
+ this.rightSide.style.backgroundColor = "rgba(0, 0, 0, 0.4)";
8095
+ // Restore the visibility of the screenshot-modal
8096
+ this.screenshotModal.style.backgroundColor = 'transparent';
8097
+ };
8098
+ this.handleMouseClickedSelectedElement = async (event) => {
8099
+ event.preventDefault();
8100
+ if (!this.elementSelected) {
8101
+ return;
8102
+ }
8103
+ this.hasSelectedElement = true;
8104
+ this.elementSelected.classList.add('feedback-modal-element-selected');
8105
+ // Get the top position including the scroll offset
8106
+ const rectTop = this.elementSelected.getBoundingClientRect().top;
8107
+ const topWithScroll = rectTop + window.scrollY;
8108
+ // Move the element with the scroll offset
8109
+ this.elementSelected.style.top = `${topWithScroll}px`;
8110
+ // Clone the selected element and append it to the body
8111
+ const clonedElementSelected = this.elementSelected.cloneNode(true);
8112
+ document.body.appendChild(clonedElementSelected);
8113
+ // Reset the top position of the original element
8114
+ this.elementSelected.style.top = `${rectTop}px`;
8115
+ this.showScreenshotTopBar = false;
8116
+ this.showModal = false;
8117
+ try {
8118
+ const dataUrl = await this.captureScreenshot();
8119
+ console.log('Screenshot captured');
8120
+ this.encodedScreenshot = dataUrl;
8121
+ }
8122
+ catch (error) {
8123
+ console.error('Failed to capture screenshot:', error);
8124
+ this.hasSelectedElement = false;
8125
+ }
8126
+ finally {
8127
+ // Remove the cloned element and show the modal again
8128
+ document.body.removeChild(clonedElementSelected);
8129
+ this.showModal = true;
8130
+ }
8131
+ };
8132
+ this.sending = false;
8133
+ this.formMessage = '';
8134
+ this.formEmail = '';
8135
+ this.formSuccess = false;
8136
+ this.formError = false;
8137
+ this.formErrorStatus = 500;
8138
+ this.encodedScreenshot = undefined;
8139
+ this.isPrivacyChecked = false;
8140
+ this.whitelabel = false;
8141
+ this.selectedRating = 0;
8142
+ this.errorMessage = "Please try again later.";
8143
+ this.errorMessage403 = "The request URL does not match the one defined in PushFeedback for this project.";
8144
+ this.errorMessage404 = "We could not find the provided project ID in PushFeedback.";
8145
+ this.modalTitle = 'Share your feedback';
8146
+ this.modalTitleSuccess = 'Thanks for your feedback!';
8147
+ this.modalTitleError = "Oops!";
8148
+ this.modalPosition = 'center';
8149
+ this.sendButtonText = 'Send';
8150
+ this.successMessage = "";
8151
+ this.project = '';
8152
+ this.screenshotButtonText = 'Add a screenshot';
8153
+ this.screenshotTopbarText = 'Select an element on this page';
8154
+ this.hideEmail = false;
8155
+ this.emailAddress = '';
8156
+ this.emailPlaceholder = 'Email address (optional)';
8157
+ this.messagePlaceholder = 'Comments';
8158
+ this.hideRating = false;
8159
+ this.rating = undefined;
8160
+ this.ratingMode = 'thumbs';
8161
+ this.ratingPlaceholder = 'Was this page helpful?';
8162
+ this.ratingStarsPlaceholder = 'How would you rate this page?';
8163
+ this.showModal = false;
8164
+ this.showScreenshotMode = false;
8165
+ this.showScreenshotTopBar = false;
8166
+ this.hasSelectedElement = false;
8167
+ this.hideScreenshotButton = false;
8168
+ this.hidePrivacyPolicy = true;
8169
+ this.privacyPolicyText = "I have read and expressly consent to the terms of the <a href='https://pushfeedback.com/privacy'>Privacy Policy</a>.";
8170
+ this.fetchData = true;
8171
+ }
8172
+ componentWillLoad() {
8173
+ if (this.fetchData)
8174
+ this.fetchProjectData();
8175
+ this.formEmail = this.emailAddress;
8176
+ if (this.rating) {
8177
+ this.selectedRating = this.rating;
8178
+ }
8179
+ if (this.ratingMode == "thumbs" && this.rating == 0) {
8180
+ this.selectedRating = 5;
8181
+ }
8182
+ }
8183
+ async fetchProjectData() {
8184
+ try {
8185
+ const response = await fetch('https://app.pushfeedback.com/api/projects/' + this.project + '/');
8186
+ const data = await response.json();
8187
+ this.whitelabel = data.whitelabel;
8188
+ }
8189
+ catch (error) {
8190
+ console.log(error);
8191
+ }
8192
+ }
8193
+ resetOverflow() {
8194
+ document.documentElement.classList.remove('feedback-modal-screenshot-open');
8195
+ document.documentElement.classList.remove('feedback-modal-screenshot-open--scroll');
8196
+ document.documentElement.classList.add('feedback-modal-screenshot-closing');
8197
+ window.scrollTo(0, parseInt(document.documentElement.style.top || '0') * -1);
8198
+ window.addEventListener('scroll', this.onScrollDebounced);
8199
+ }
8200
+ handleMessageInput(event) {
8201
+ this.formMessage = event.target.value;
8202
+ }
8203
+ handleEmailInput(event) {
8204
+ this.formEmail = event.target.value;
8205
+ }
8206
+ captureScreenshot() {
8207
+ return new Promise((resolve, reject) => {
8208
+ requestAnimationFrame(() => {
8209
+ html2canvas(document.body, {
8210
+ x: window.scrollX,
8211
+ y: window.scrollY,
8212
+ width: window.innerWidth,
8213
+ height: window.innerHeight,
8214
+ }).then(canvas => {
8215
+ const dataUrl = canvas.toDataURL();
8216
+ resolve(dataUrl);
8217
+ })
8218
+ .catch(error => {
8219
+ console.error(error);
8220
+ reject(error);
8221
+ });
8222
+ });
8223
+ });
8224
+ }
8225
+ handleCheckboxChange(event) {
8226
+ this.isPrivacyChecked = event.target.checked;
8227
+ }
8228
+ handleRatingChange(newRating) {
8229
+ this.selectedRating = newRating;
8230
+ }
8231
+ render() {
8232
+ return (index.h("div", { class: 'feedback-modal-wrapper' }, this.showScreenshotMode && (index.h("div", { class: "feedback-modal-screenshot", ref: el => (this.screenshotModal = el), onMouseMove: this.handleMouseOverScreenShot }, index.h("div", { class: "feedback-modal-screenshot-element-selected", ref: el => (this.elementSelected = el), onClick: this.handleMouseClickedSelectedElement }), index.h("div", { class: "top-side", ref: el => (this.topSide = el) }), index.h("div", { class: "left-side", ref: el => (this.leftSide = el) }), index.h("div", { class: "bottom-side", ref: el => (this.bottomSide = el) }), index.h("div", { class: "right-side", ref: el => (this.rightSide = el) }), this.showScreenshotTopBar && (index.h("div", { class: "feedback-modal-screenshot-header", onClick: this.closeScreenShot }, index.h("span", null, this.screenshotTopbarText), index.h("span", { class: "feedback-modal-screenshot-close" }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "22", height: "22", viewBox: "0 0 24 24", fill: "none", stroke: "#191919", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", class: "feather feather-x" }, index.h("line", { x1: "18", y1: "6", x2: "6", y2: "18" }), index.h("line", { x1: "6", y1: "6", x2: "18", y2: "18" }))))))), this.showModal && (index.h("div", { class: "feedback-overlay" })), this.showModal && (index.h("div", { class: `feedback-modal-content feedback-modal-content--${this.modalPosition} ${this.showModal ? 'feedback-modal-content--open' : ''}`, ref: el => (this.modalContent = el) }, index.h("div", { class: "feedback-modal-header" }, !this.formSuccess && !this.formError ? (index.h("span", null, this.modalTitle)) : this.formSuccess ? (index.h("span", null, this.modalTitleSuccess)) : index.h("span", null, this.modalTitleError), index.h("button", { class: "feedback-modal-close", onClick: this.close }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "22", height: "22", viewBox: "0 0 24 24", fill: "none", stroke: "#191919", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round", class: "feather feather-x" }, index.h("line", { x1: "18", y1: "6", x2: "6", y2: "18" }), index.h("line", { x1: "6", y1: "6", x2: "18", y2: "18" })))), index.h("div", { class: "feedback-modal-body" }, !this.formSuccess && !this.formError ? (index.h("form", { onSubmit: this.handleSubmit }, !this.hideRating && (index.h("div", { class: "feedback-modal-rating" }, this.ratingMode === 'thumbs' ? (index.h("div", { class: "feedback-modal-rating-content" }, index.h("span", { class: "feedback-modal-input-heading" }, this.ratingPlaceholder), index.h("div", { class: "feedback-modal-rating-buttons feedback-modal-rating-buttons--thumbs" }, index.h("button", { title: "Yes", class: `feedback-modal-rating-button ${this.selectedRating === 1 ? 'feedback-modal-rating-button--selected' : ''}`, onClick: (event) => {
8233
+ event.preventDefault();
8234
+ this.handleRatingChange(1);
8235
+ } }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "#5F6368", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round" }, index.h("path", { d: "M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3" }))), index.h("button", { title: "No", class: `feedback-modal-rating-button ${this.selectedRating === 5 ? 'feedback-modal-rating-button--selected' : ''}`, onClick: (event) => {
8236
+ event.preventDefault();
8237
+ this.handleRatingChange(5);
8238
+ } }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "#5F6368", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round" }, index.h("path", { d: "M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17" })))))) : (index.h("div", { class: "feedback-modal-rating-content" }, index.h("span", { class: "feedback-modal-input-heading" }, this.ratingStarsPlaceholder), index.h("div", { class: "feedback-modal-rating-buttons feedback-modal-rating-buttons--stars" }, [1, 2, 3, 4, 5].map((rating) => (index.h("button", { key: rating, class: `feedback-modal-rating-button ${this.selectedRating >= rating ? 'feedback-modal-rating-button--selected' : ''}`, onClick: (event) => {
8239
+ event.preventDefault();
8240
+ this.handleRatingChange(rating);
8241
+ } }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", width: "28", height: "28", viewBox: "0 0 24 24", fill: "none", stroke: "#5F6368", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round" }, index.h("polygon", { points: "12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" })))))))))), index.h("div", { class: "feedback-modal-text" }, index.h("textarea", { placeholder: this.messagePlaceholder, value: this.formMessage, onInput: (event) => this.handleMessageInput(event) })), !this.hideEmail && (index.h("div", { class: "feedback-modal-email" }, index.h("input", { placeholder: this.emailPlaceholder, type: "email", onInput: (event) => this.handleEmailInput(event), value: this.formEmail }))), !this.hidePrivacyPolicy && (index.h("div", { class: "feedback-modal-privacy" }, index.h("input", { type: "checkbox", id: "privacyPolicy", onChange: (ev) => this.handleCheckboxChange(ev), required: true }), index.h("span", { innerHTML: this.privacyPolicyText }))), index.h("div", { class: `feedback-modal-buttons ${this.hideScreenshotButton ? 'single' : ''}` }, !this.hideScreenshotButton && (index.h("button", { type: "button", class: `feedback-modal-button feedback-modal-button--screenshot ${this.encodedScreenshot ? "feedback-modal-button--active" : ""}`, onClick: this.openScreenShot, disabled: this.sending }, index.h("svg", { xmlns: "http://www.w3.org/2000/svg", height: "24", viewBox: "0 -960 960 960", width: "24" }, index.h("path", { d: "M680-80v-120H560v-80h120v-120h80v120h120v80H760v120h-80ZM200-200v-200h80v120h120v80H200Zm0-360v-200h200v80H280v120h-80Zm480 0v-120H560v-80h200v200h-80Z" })), this.screenshotButtonText)), index.h("button", { class: "feedback-modal-button feedback-modal-button--submit", type: "submit", disabled: this.sending }, this.sendButtonText)))) : this.formSuccess && !this.formError ? (index.h("p", { class: "feedback-modal-message" }, this.successMessage)) : this.formError && this.formErrorStatus == 404 ? (index.h("p", { class: "feedback-modal-message" }, this.errorMessage404)) : this.formError && this.formErrorStatus == 403 ? (index.h("p", { class: "feedback-modal-message" }, this.errorMessage403)) : this.formError ? (index.h("p", { class: "feedback-modal-message" }, this.errorMessage)) : index.h("span", null)), index.h("div", { class: "feedback-modal-footer", style: { display: this.whitelabel ? 'none' : 'block' } }, index.h("div", { class: "feedback-logo" }, "Powered by ", index.h("a", { target: "_blank", href: "https://pushfeedback.com" }, "PushFeedback.com")))))));
8242
+ }
8243
+ };
8235
8244
  FeedbackModal.style = feedbackModalCss;
8236
8245
 
8237
8246
  exports.feedback_button = FeedbackButton;