@product7/feedback-sdk 1.2.2 → 1.2.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@product7/feedback-sdk",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "JavaScript SDK for integrating Product7 feedback widgets into any website",
5
5
  "main": "dist/feedback-sdk.js",
6
6
  "module": "src/index.js",
@@ -283,6 +283,25 @@ export class FeedbackSDK {
283
283
  this.eventBus.emit('sdk:destroyed');
284
284
  }
285
285
 
286
+ _detectEnvironment() {
287
+ if (typeof window === 'undefined') {
288
+ return 'production';
289
+ }
290
+
291
+ const hostname = window.location.hostname.toLowerCase();
292
+
293
+ if (
294
+ hostname.includes('staging') ||
295
+ hostname.includes('localhost') ||
296
+ hostname.includes('127.0.0.1') ||
297
+ hostname.includes('.local')
298
+ ) {
299
+ return 'staging';
300
+ }
301
+
302
+ return 'production';
303
+ }
304
+
286
305
  _validateAndMergeConfig(newConfig, existingConfig = {}) {
287
306
  const defaultConfig = {
288
307
  apiUrl: null,
@@ -294,7 +313,7 @@ export class FeedbackSDK {
294
313
  autoShow: true,
295
314
  debug: false,
296
315
  mock: false,
297
- env: 'production', // 'production' or 'staging'
316
+ env: this._detectEnvironment(),
298
317
  };
299
318
 
300
319
  const mergedConfig = deepMerge(
@@ -302,6 +321,10 @@ export class FeedbackSDK {
302
321
  newConfig
303
322
  );
304
323
 
324
+ if (!newConfig.env && !existingConfig.env) {
325
+ mergedConfig.env = this._detectEnvironment();
326
+ }
327
+
305
328
  if (!mergedConfig.workspace) {
306
329
  throw new ConfigError('Missing required configuration: workspace');
307
330
  }
@@ -375,4 +398,4 @@ export class FeedbackSDK {
375
398
  : undefined,
376
399
  };
377
400
  }
378
- }
401
+ }
@@ -1,11 +1,12 @@
1
1
  import { BaseWidget } from './BaseWidget.js';
2
+
2
3
  export class ButtonWidget extends BaseWidget {
3
4
  constructor(options) {
4
5
  super({ ...options, type: 'button' });
5
6
  this.isMinimized = false;
6
7
  }
7
8
 
8
- _render() {
9
+ render() {
9
10
  const button = document.createElement('div');
10
11
  button.className = `feedback-widget feedback-widget-button theme-${this.options.theme} position-${this.options.position}`;
11
12
  button.innerHTML = `
@@ -36,25 +37,34 @@ export class ButtonWidget extends BaseWidget {
36
37
  return button;
37
38
  }
38
39
 
39
- _attachEvents() {
40
+ attachEvents() {
40
41
  const button = this.element.querySelector('.feedback-trigger-btn');
41
42
  const minimizeIcon = this.element.querySelector('.feedback-minimize-icon');
42
43
  const expandIcon = this.element.querySelector('.feedback-expand-icon');
43
44
 
45
+ // Add click handlers directly to the icons
46
+ minimizeIcon.addEventListener('click', (e) => {
47
+ e.stopPropagation();
48
+ e.preventDefault();
49
+ this.minimize();
50
+ });
51
+
52
+ expandIcon.addEventListener('click', (e) => {
53
+ e.stopPropagation();
54
+ e.preventDefault();
55
+ this.restore();
56
+ });
57
+
58
+ // Main button click handler
44
59
  button.addEventListener('click', (e) => {
45
- const clickedMinimize = e.target.closest('.feedback-minimize-icon');
46
- const clickedExpand = e.target.closest('.feedback-expand-icon');
60
+ // Check if the click originated from an icon
61
+ if (e.target.closest('.feedback-minimize-icon') ||
62
+ e.target.closest('.feedback-expand-icon')) {
63
+ return; // Let the icon handlers deal with it
64
+ }
47
65
 
48
- if (clickedMinimize) {
49
- e.stopPropagation();
50
- this.minimize();
51
- } else if (clickedExpand) {
52
- e.stopPropagation();
53
- this.restore();
54
- } else {
55
- if (!this.isMinimized) {
56
- this.openPanel();
57
- }
66
+ if (!this.isMinimized) {
67
+ this.openPanel();
58
68
  }
59
69
  });
60
70