@hellotext/hellotext 2.5.6 → 2.5.8

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.
Files changed (113) hide show
  1. package/README.md +5 -26
  2. package/dist/hellotext.js +1 -1
  3. package/dist/hellotext.js.LICENSE.txt +1 -1
  4. package/index.d.ts +15 -6
  5. package/lib/api/acks.cjs +17 -31
  6. package/lib/api/acks.js +17 -42
  7. package/lib/api/businesses.cjs +14 -28
  8. package/lib/api/businesses.js +13 -36
  9. package/lib/api/events.cjs +26 -40
  10. package/lib/api/events.js +28 -52
  11. package/lib/api/forms.cjs +24 -40
  12. package/lib/api/forms.js +24 -57
  13. package/lib/api/identifications.cjs +15 -29
  14. package/lib/api/identifications.js +15 -40
  15. package/lib/api/index.cjs +26 -46
  16. package/lib/api/index.js +28 -49
  17. package/lib/api/push/identities.cjs +43 -0
  18. package/lib/api/push/identities.js +35 -0
  19. package/lib/api/response.cjs +30 -52
  20. package/lib/api/response.js +31 -60
  21. package/lib/api/submissions.cjs +18 -34
  22. package/lib/api/submissions.js +18 -48
  23. package/lib/api/webchat/messages.cjs +44 -64
  24. package/lib/api/webchat/messages.js +44 -80
  25. package/lib/api/webchats.cjs +37 -56
  26. package/lib/api/webchats.js +37 -65
  27. package/lib/api/whatsapp_widgets.cjs +49 -72
  28. package/lib/api/whatsapp_widgets.js +48 -91
  29. package/lib/builders/input_builder.cjs +36 -48
  30. package/lib/builders/input_builder.js +36 -48
  31. package/lib/builders/logo_builder.cjs +10 -29
  32. package/lib/builders/logo_builder.js +20 -28
  33. package/lib/channels/application_channel.cjs +136 -178
  34. package/lib/channels/application_channel.js +137 -180
  35. package/lib/channels/webchat_channel.cjs +125 -170
  36. package/lib/channels/webchat_channel.js +125 -170
  37. package/lib/controllers/form_controller.cjs +82 -121
  38. package/lib/controllers/form_controller.js +82 -130
  39. package/lib/controllers/message_controller.cjs +211 -282
  40. package/lib/controllers/message_controller.js +209 -284
  41. package/lib/controllers/mixins/usePopover.cjs +3 -6
  42. package/lib/controllers/mixins/usePopover.js +17 -22
  43. package/lib/controllers/webchat/emoji_picker_controller.cjs +106 -150
  44. package/lib/controllers/webchat/emoji_picker_controller.js +105 -170
  45. package/lib/controllers/webchat/useBehaviour.js +5 -5
  46. package/lib/controllers/webchat/useOpeningSequence.js +6 -6
  47. package/lib/controllers/webchat/useTeaser.js +9 -9
  48. package/lib/controllers/webchat_controller.cjs +916 -1088
  49. package/lib/controllers/webchat_controller.js +926 -1152
  50. package/lib/core/configuration/forms.cjs +21 -35
  51. package/lib/core/configuration/forms.js +20 -35
  52. package/lib/core/configuration/locale.cjs +36 -71
  53. package/lib/core/configuration/locale.js +36 -70
  54. package/lib/core/configuration/push.cjs +16 -0
  55. package/lib/core/configuration/push.js +10 -0
  56. package/lib/core/configuration/webchat.cjs +142 -182
  57. package/lib/core/configuration/webchat.js +145 -189
  58. package/lib/core/configuration/whatsapp.cjs +76 -102
  59. package/lib/core/configuration/whatsapp.js +76 -105
  60. package/lib/core/configuration.cjs +62 -75
  61. package/lib/core/configuration.js +61 -75
  62. package/lib/core/event.cjs +36 -59
  63. package/lib/core/event.js +35 -61
  64. package/lib/core/sanitize_html.js +4 -4
  65. package/lib/errors/invalid_event.cjs +5 -26
  66. package/lib/errors/invalid_event.js +5 -26
  67. package/lib/errors/not_initialized_error.cjs +5 -26
  68. package/lib/errors/not_initialized_error.js +5 -26
  69. package/lib/hellotext.cjs +186 -211
  70. package/lib/hellotext.js +189 -236
  71. package/lib/index.js +1 -1
  72. package/lib/models/business.cjs +115 -152
  73. package/lib/models/business.js +118 -162
  74. package/lib/models/cookies.cjs +34 -51
  75. package/lib/models/cookies.js +34 -51
  76. package/lib/models/fingerprint.cjs +8 -23
  77. package/lib/models/fingerprint.js +25 -58
  78. package/lib/models/form.cjs +106 -142
  79. package/lib/models/form.js +105 -153
  80. package/lib/models/form_collection.cjs +63 -101
  81. package/lib/models/form_collection.js +61 -107
  82. package/lib/models/index.cjs +7 -0
  83. package/lib/models/index.js +1 -0
  84. package/lib/models/page.cjs +106 -129
  85. package/lib/models/page.js +106 -131
  86. package/lib/models/push.cjs +345 -0
  87. package/lib/models/push.js +339 -0
  88. package/lib/models/query.cjs +21 -41
  89. package/lib/models/query.js +21 -41
  90. package/lib/models/session.cjs +33 -65
  91. package/lib/models/session.js +30 -63
  92. package/lib/models/user.cjs +29 -51
  93. package/lib/models/user.js +29 -51
  94. package/lib/models/utm.cjs +15 -27
  95. package/lib/models/utm.js +17 -32
  96. package/lib/models/webchat.cjs +52 -76
  97. package/lib/models/webchat.js +52 -90
  98. package/lib/models/whatsapp_widget.cjs +41 -59
  99. package/lib/models/whatsapp_widget.js +41 -73
  100. package/lib/vanilla.cjs +4 -7
  101. package/lib/vanilla.js +2 -1
  102. package/package.json +2 -10
  103. package/src/api/index.js +5 -0
  104. package/src/api/push/identities.js +42 -0
  105. package/src/core/configuration/push.js +12 -0
  106. package/src/core/configuration.js +5 -0
  107. package/src/hellotext.js +15 -1
  108. package/src/index.bundle.js +0 -1
  109. package/src/models/business.js +1 -0
  110. package/src/models/index.js +1 -0
  111. package/src/models/push.js +397 -0
  112. package/src/vanilla.js +2 -1
  113. package/styles/index.css +0 -30
@@ -9,157 +9,113 @@ var _stimulus = require("@hotwired/stimulus");
9
9
  var _usePopover = require("../mixins/usePopover");
10
10
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
11
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
12
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
14
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
15
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
16
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
17
- function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
18
- function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
19
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
20
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
21
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
22
- function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
23
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
24
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
25
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
26
- let _default = /*#__PURE__*/function (_Controller) {
27
- _inherits(_default, _Controller);
28
- var _super = _createSuper(_default);
29
- function _default() {
30
- _classCallCheck(this, _default);
31
- return _super.apply(this, arguments);
32
- }
33
- _createClass(_default, [{
34
- key: "initialize",
35
- value: function initialize() {
36
- this.onEmojiSelect = this.onEmojiSelect.bind(this);
37
- this.pickerLoaded = false;
38
- this.pickerLoadPromise = null;
39
- this.connected = false;
40
- _get(_getPrototypeOf(_default.prototype), "initialize", this).call(this);
41
- }
42
- }, {
43
- key: "connect",
44
- value: function connect() {
45
- this.connected = true;
46
- (0, _usePopover.usePopover)(this);
47
- this.setupFloatingUI({
48
- trigger: this.buttonTarget,
49
- popover: this.popoverTarget,
50
- strategy: 'absolute'
51
- });
52
- _get(_getPrototypeOf(_default.prototype), "connect", this).call(this);
53
- }
54
- }, {
55
- key: "disconnect",
56
- value: function disconnect() {
57
- this.connected = false;
58
- this.pickerLoadPromise = null;
59
- this.floatingUICleanup();
60
- _get(_getPrototypeOf(_default.prototype), "disconnect", this).call(this);
61
- }
62
- }, {
63
- key: "onEmojiSelect",
64
- value: function onEmojiSelect(emoji) {
65
- this.dispatch('selected', {
66
- detail: emoji.native
67
- });
68
- this.hide();
69
- }
70
- }, {
71
- key: "onClickOutside",
72
- value: function onClickOutside(event) {
73
- if (this.openValue && event.target.nodeType && this.element.contains(event.target) === false) {
74
- this.openValue = false;
75
- }
12
+ class _default extends _stimulus.Controller {
13
+ static targets = ['button', 'popover'];
14
+ static values = {
15
+ placement: {
16
+ type: String,
17
+ default: 'bottom-end'
18
+ },
19
+ open: {
20
+ type: Boolean,
21
+ default: false
22
+ },
23
+ autoPlacement: {
24
+ type: Boolean,
25
+ default: false
26
+ },
27
+ disabled: {
28
+ type: Boolean,
29
+ default: false
30
+ },
31
+ size: {
32
+ type: Number,
33
+ default: 24
34
+ },
35
+ perLine: {
36
+ type: Number,
37
+ default: 9
76
38
  }
77
- }, {
78
- key: "onPopoverOpened",
79
- value: async function onPopoverOpened() {
80
- await this.loadPicker();
81
- }
82
- }, {
83
- key: "loadPicker",
84
- value: async function loadPicker() {
85
- if (this.pickerLoaded) return;
86
- this.pickerLoadPromise || (this.pickerLoadPromise = this.loadPickerDependencies());
87
- const {
88
- Picker,
89
- i18n
90
- } = await this.pickerLoadPromise;
91
- if (!this.connected || this.pickerLoaded) return;
92
- this.popoverTarget.appendChild(this.buildPicker(Picker, i18n));
93
- this.pickerLoaded = true;
94
- }
95
- }, {
96
- key: "loadPickerDependencies",
97
- value: async function loadPickerDependencies() {
98
- const [pickerModule, i18nModule] = await Promise.all([Promise.resolve().then(() => _interopRequireWildcard(require( /* webpackChunkName: "webchat-emoji" */'emoji-mart'))), this.loadI18n()]);
99
- return {
100
- Picker: pickerModule.Picker,
101
- i18n: i18nModule.default || i18nModule
102
- };
103
- }
104
- }, {
105
- key: "loadI18n",
106
- value: function loadI18n() {
107
- if (Hellotext.business.locale === 'es') {
108
- return Promise.resolve().then(() => _interopRequireWildcard(require( /* webpackChunkName: "webchat-emoji-es" */'@emoji-mart/data/i18n/es.json')));
109
- }
110
- return Promise.resolve().then(() => _interopRequireWildcard(require( /* webpackChunkName: "webchat-emoji-en" */'@emoji-mart/data/i18n/en.json')));
111
- }
112
- }, {
113
- key: "buildPicker",
114
- value: function buildPicker(Picker, i18n) {
115
- return new Picker({
116
- onEmojiSelect: this.onEmojiSelect,
117
- theme: 'light',
118
- dynamicWidth: true,
119
- previewPosition: 'none',
120
- skinTonePosition: 'none',
121
- emojiSize: this.sizeValue,
122
- perLine: this.perLineValue,
123
- i18n
124
- });
39
+ };
40
+ initialize() {
41
+ this.onEmojiSelect = this.onEmojiSelect.bind(this);
42
+ this.pickerLoaded = false;
43
+ this.pickerLoadPromise = null;
44
+ this.connected = false;
45
+ super.initialize();
46
+ }
47
+ connect() {
48
+ this.connected = true;
49
+ (0, _usePopover.usePopover)(this);
50
+ this.setupFloatingUI({
51
+ trigger: this.buttonTarget,
52
+ popover: this.popoverTarget,
53
+ strategy: 'absolute'
54
+ });
55
+ super.connect();
56
+ }
57
+ disconnect() {
58
+ this.connected = false;
59
+ this.pickerLoadPromise = null;
60
+ this.floatingUICleanup();
61
+ super.disconnect();
62
+ }
63
+ onEmojiSelect(emoji) {
64
+ this.dispatch('selected', {
65
+ detail: emoji.native
66
+ });
67
+ this.hide();
68
+ }
69
+ onClickOutside(event) {
70
+ if (this.openValue && event.target.nodeType && this.element.contains(event.target) === false) {
71
+ this.openValue = false;
125
72
  }
126
- }, {
127
- key: "middlewares",
128
- get: function () {
129
- return [(0, _dom.offset)(5), (0, _dom.shift)({
130
- padding: 24
131
- }), (0, _dom.autoPlacement)({
132
- allowedPlacements: ['top', 'bottom']
133
- })];
73
+ }
74
+ async onPopoverOpened() {
75
+ await this.loadPicker();
76
+ }
77
+ async loadPicker() {
78
+ if (this.pickerLoaded) return;
79
+ this.pickerLoadPromise ||= this.loadPickerDependencies();
80
+ const {
81
+ Picker,
82
+ i18n
83
+ } = await this.pickerLoadPromise;
84
+ if (!this.connected || this.pickerLoaded) return;
85
+ this.popoverTarget.appendChild(this.buildPicker(Picker, i18n));
86
+ this.pickerLoaded = true;
87
+ }
88
+ async loadPickerDependencies() {
89
+ const [pickerModule, i18nModule] = await Promise.all([Promise.resolve().then(() => _interopRequireWildcard(require( /* webpackChunkName: "webchat-emoji" */'emoji-mart'))), this.loadI18n()]);
90
+ return {
91
+ Picker: pickerModule.Picker,
92
+ i18n: i18nModule.default || i18nModule
93
+ };
94
+ }
95
+ loadI18n() {
96
+ if (Hellotext.business.locale === 'es') {
97
+ return Promise.resolve().then(() => _interopRequireWildcard(require( /* webpackChunkName: "webchat-emoji-es" */'@emoji-mart/data/i18n/es.json')));
134
98
  }
135
- }]);
136
- return _default;
137
- }(_stimulus.Controller);
138
- exports.default = _default;
139
- _default.targets = ['button', 'popover'];
140
- _default.values = {
141
- placement: {
142
- type: String,
143
- default: 'bottom-end'
144
- },
145
- open: {
146
- type: Boolean,
147
- default: false
148
- },
149
- autoPlacement: {
150
- type: Boolean,
151
- default: false
152
- },
153
- disabled: {
154
- type: Boolean,
155
- default: false
156
- },
157
- size: {
158
- type: Number,
159
- default: 24
160
- },
161
- perLine: {
162
- type: Number,
163
- default: 9
99
+ return Promise.resolve().then(() => _interopRequireWildcard(require( /* webpackChunkName: "webchat-emoji-en" */'@emoji-mart/data/i18n/en.json')));
100
+ }
101
+ buildPicker(Picker, i18n) {
102
+ return new Picker({
103
+ onEmojiSelect: this.onEmojiSelect,
104
+ theme: 'light',
105
+ dynamicWidth: true,
106
+ previewPosition: 'none',
107
+ skinTonePosition: 'none',
108
+ emojiSize: this.sizeValue,
109
+ perLine: this.perLineValue,
110
+ i18n
111
+ });
112
+ }
113
+ get middlewares() {
114
+ return [(0, _dom.offset)(5), (0, _dom.shift)({
115
+ padding: 24
116
+ }), (0, _dom.autoPlacement)({
117
+ allowedPlacements: ['top', 'bottom']
118
+ })];
164
119
  }
165
- };
120
+ }
121
+ exports.default = _default;
@@ -1,177 +1,112 @@
1
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
2
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
3
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
5
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
7
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
- function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
9
- function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
10
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
11
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
12
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
13
- function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
14
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
15
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
16
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
17
1
  import { autoPlacement, offset, shift } from '@floating-ui/dom';
18
2
  import { Controller } from '@hotwired/stimulus';
19
3
  import { usePopover } from '../mixins/usePopover';
20
- var _default = /*#__PURE__*/function (_Controller) {
21
- _inherits(_default, _Controller);
22
- var _super = _createSuper(_default);
23
- function _default() {
24
- _classCallCheck(this, _default);
25
- return _super.apply(this, arguments);
26
- }
27
- _createClass(_default, [{
28
- key: "initialize",
29
- value: function initialize() {
30
- this.onEmojiSelect = this.onEmojiSelect.bind(this);
31
- this.pickerLoaded = false;
32
- this.pickerLoadPromise = null;
33
- this.connected = false;
34
- _get(_getPrototypeOf(_default.prototype), "initialize", this).call(this);
35
- }
36
- }, {
37
- key: "connect",
38
- value: function connect() {
39
- this.connected = true;
40
- usePopover(this);
41
- this.setupFloatingUI({
42
- trigger: this.buttonTarget,
43
- popover: this.popoverTarget,
44
- strategy: 'absolute'
45
- });
46
- _get(_getPrototypeOf(_default.prototype), "connect", this).call(this);
47
- }
48
- }, {
49
- key: "disconnect",
50
- value: function disconnect() {
51
- this.connected = false;
52
- this.pickerLoadPromise = null;
53
- this.floatingUICleanup();
54
- _get(_getPrototypeOf(_default.prototype), "disconnect", this).call(this);
55
- }
56
- }, {
57
- key: "onEmojiSelect",
58
- value: function onEmojiSelect(emoji) {
59
- this.dispatch('selected', {
60
- detail: emoji.native
61
- });
62
- this.hide();
4
+ export default class extends Controller {
5
+ static targets = ['button', 'popover'];
6
+ static values = {
7
+ placement: {
8
+ type: String,
9
+ default: 'bottom-end'
10
+ },
11
+ open: {
12
+ type: Boolean,
13
+ default: false
14
+ },
15
+ autoPlacement: {
16
+ type: Boolean,
17
+ default: false
18
+ },
19
+ disabled: {
20
+ type: Boolean,
21
+ default: false
22
+ },
23
+ size: {
24
+ type: Number,
25
+ default: 24
26
+ },
27
+ perLine: {
28
+ type: Number,
29
+ default: 9
63
30
  }
64
- }, {
65
- key: "onClickOutside",
66
- value: function onClickOutside(event) {
67
- if (this.openValue && event.target.nodeType && this.element.contains(event.target) === false) {
68
- this.openValue = false;
69
- }
70
- }
71
- }, {
72
- key: "onPopoverOpened",
73
- value: function () {
74
- var _onPopoverOpened = _asyncToGenerator(function* () {
75
- yield this.loadPicker();
76
- });
77
- function onPopoverOpened() {
78
- return _onPopoverOpened.apply(this, arguments);
79
- }
80
- return onPopoverOpened;
81
- }()
82
- }, {
83
- key: "loadPicker",
84
- value: function () {
85
- var _loadPicker = _asyncToGenerator(function* () {
86
- if (this.pickerLoaded) return;
87
- this.pickerLoadPromise || (this.pickerLoadPromise = this.loadPickerDependencies());
88
- var {
89
- Picker,
90
- i18n
91
- } = yield this.pickerLoadPromise;
92
- if (!this.connected || this.pickerLoaded) return;
93
- this.popoverTarget.appendChild(this.buildPicker(Picker, i18n));
94
- this.pickerLoaded = true;
95
- });
96
- function loadPicker() {
97
- return _loadPicker.apply(this, arguments);
98
- }
99
- return loadPicker;
100
- }()
101
- }, {
102
- key: "loadPickerDependencies",
103
- value: function () {
104
- var _loadPickerDependencies = _asyncToGenerator(function* () {
105
- var [pickerModule, i18nModule] = yield Promise.all([import( /* webpackChunkName: "webchat-emoji" */'emoji-mart'), this.loadI18n()]);
106
- return {
107
- Picker: pickerModule.Picker,
108
- i18n: i18nModule.default || i18nModule
109
- };
110
- });
111
- function loadPickerDependencies() {
112
- return _loadPickerDependencies.apply(this, arguments);
113
- }
114
- return loadPickerDependencies;
115
- }()
116
- }, {
117
- key: "loadI18n",
118
- value: function loadI18n() {
119
- if (Hellotext.business.locale === 'es') {
120
- return import( /* webpackChunkName: "webchat-emoji-es" */'@emoji-mart/data/i18n/es.json');
121
- }
122
- return import( /* webpackChunkName: "webchat-emoji-en" */'@emoji-mart/data/i18n/en.json');
123
- }
124
- }, {
125
- key: "buildPicker",
126
- value: function buildPicker(Picker, i18n) {
127
- return new Picker({
128
- onEmojiSelect: this.onEmojiSelect,
129
- theme: 'light',
130
- dynamicWidth: true,
131
- previewPosition: 'none',
132
- skinTonePosition: 'none',
133
- emojiSize: this.sizeValue,
134
- perLine: this.perLineValue,
135
- i18n
136
- });
31
+ };
32
+ initialize() {
33
+ this.onEmojiSelect = this.onEmojiSelect.bind(this);
34
+ this.pickerLoaded = false;
35
+ this.pickerLoadPromise = null;
36
+ this.connected = false;
37
+ super.initialize();
38
+ }
39
+ connect() {
40
+ this.connected = true;
41
+ usePopover(this);
42
+ this.setupFloatingUI({
43
+ trigger: this.buttonTarget,
44
+ popover: this.popoverTarget,
45
+ strategy: 'absolute'
46
+ });
47
+ super.connect();
48
+ }
49
+ disconnect() {
50
+ this.connected = false;
51
+ this.pickerLoadPromise = null;
52
+ this.floatingUICleanup();
53
+ super.disconnect();
54
+ }
55
+ onEmojiSelect(emoji) {
56
+ this.dispatch('selected', {
57
+ detail: emoji.native
58
+ });
59
+ this.hide();
60
+ }
61
+ onClickOutside(event) {
62
+ if (this.openValue && event.target.nodeType && this.element.contains(event.target) === false) {
63
+ this.openValue = false;
137
64
  }
138
- }, {
139
- key: "middlewares",
140
- get: function get() {
141
- return [offset(5), shift({
142
- padding: 24
143
- }), autoPlacement({
144
- allowedPlacements: ['top', 'bottom']
145
- })];
65
+ }
66
+ async onPopoverOpened() {
67
+ await this.loadPicker();
68
+ }
69
+ async loadPicker() {
70
+ if (this.pickerLoaded) return;
71
+ this.pickerLoadPromise ||= this.loadPickerDependencies();
72
+ const {
73
+ Picker,
74
+ i18n
75
+ } = await this.pickerLoadPromise;
76
+ if (!this.connected || this.pickerLoaded) return;
77
+ this.popoverTarget.appendChild(this.buildPicker(Picker, i18n));
78
+ this.pickerLoaded = true;
79
+ }
80
+ async loadPickerDependencies() {
81
+ const [pickerModule, i18nModule] = await Promise.all([import( /* webpackChunkName: "webchat-emoji" */'emoji-mart'), this.loadI18n()]);
82
+ return {
83
+ Picker: pickerModule.Picker,
84
+ i18n: i18nModule.default || i18nModule
85
+ };
86
+ }
87
+ loadI18n() {
88
+ if (Hellotext.business.locale === 'es') {
89
+ return import( /* webpackChunkName: "webchat-emoji-es" */'@emoji-mart/data/i18n/es.json');
146
90
  }
147
- }]);
148
- return _default;
149
- }(Controller);
150
- _default.targets = ['button', 'popover'];
151
- _default.values = {
152
- placement: {
153
- type: String,
154
- default: 'bottom-end'
155
- },
156
- open: {
157
- type: Boolean,
158
- default: false
159
- },
160
- autoPlacement: {
161
- type: Boolean,
162
- default: false
163
- },
164
- disabled: {
165
- type: Boolean,
166
- default: false
167
- },
168
- size: {
169
- type: Number,
170
- default: 24
171
- },
172
- perLine: {
173
- type: Number,
174
- default: 9
91
+ return import( /* webpackChunkName: "webchat-emoji-en" */'@emoji-mart/data/i18n/en.json');
92
+ }
93
+ buildPicker(Picker, i18n) {
94
+ return new Picker({
95
+ onEmojiSelect: this.onEmojiSelect,
96
+ theme: 'light',
97
+ dynamicWidth: true,
98
+ previewPosition: 'none',
99
+ skinTonePosition: 'none',
100
+ emojiSize: this.sizeValue,
101
+ perLine: this.perLineValue,
102
+ i18n
103
+ });
104
+ }
105
+ get middlewares() {
106
+ return [offset(5), shift({
107
+ padding: 24
108
+ }), autoPlacement({
109
+ allowedPlacements: ['top', 'bottom']
110
+ })];
175
111
  }
176
- };
177
- export { _default as default };
112
+ }
@@ -2,14 +2,14 @@
2
2
  // Stimulus lifecycle and `usePopover` still owns the mechanics of opening and
3
3
  // closing the popover. Keeping this policy here gives the configured behaviour
4
4
  // value one place to translate into timers, storage gates, and cleanup.
5
- export var useBehaviour = controller => {
5
+ export const useBehaviour = controller => {
6
6
  Object.assign(controller, {
7
7
  // Called from `connect` after the controller has wired channels, targets,
8
8
  // and popover state. Even a zero-second delay goes through a timeout so the
9
9
  // automatic open happens after the mount pass rather than during setup.
10
10
  scheduleBehaviourOpen() {
11
11
  if (!this.shouldAutoOpenFromBehaviour()) return;
12
- var delay = Number(this.behaviourValue.delay_seconds || 0) * 1000;
12
+ const delay = Number(this.behaviourValue.delay_seconds || 0) * 1000;
13
13
  this.behaviourOpenTimeout = window.setTimeout(() => {
14
14
  this.behaviourOpenTimeout = null;
15
15
  if (this.openValue) return;
@@ -30,7 +30,7 @@ export var useBehaviour = controller => {
30
30
  // that it would be allowed. That keeps blocked, cancelled, and manually
31
31
  // opened visits from being counted as behaviour-driven opens.
32
32
  shouldAutoOpenFromBehaviour() {
33
- var behaviour = this.behaviourValue;
33
+ const behaviour = this.behaviourValue;
34
34
  if (!behaviour || behaviour.trigger !== 'on_load') return false;
35
35
  if (behaviour.first_visit_only && localStorage.getItem(this.firstVisitKey())) {
36
36
  return false;
@@ -55,13 +55,13 @@ export var useBehaviour = controller => {
55
55
  // Records that this widget has already used its long-lived first-visit
56
56
  // automatic open. This is the durable gate behind `first_visit_only`.
57
57
  firstVisitKey() {
58
- return "hellotext--webchat--".concat(this.idValue, "--auto-opened");
58
+ return `hellotext--webchat--${this.idValue}--auto-opened`;
59
59
  },
60
60
  // Records that this widget has already used its automatic open during the
61
61
  // current browser session. This is the shorter-lived gate behind
62
62
  // `once_per_session`.
63
63
  sessionKey() {
64
- return "hellotext--webchat--".concat(this.idValue, "--auto-opened-session");
64
+ return `hellotext--webchat--${this.idValue}--auto-opened-session`;
65
65
  }
66
66
  });
67
67
  };
@@ -2,7 +2,7 @@
2
2
  // manages when those staged messages become visible and which ids should travel
3
3
  // with the first customer message. It never creates a conversation or posts the
4
4
  // staged messages by itself.
5
- export var useOpeningSequence = controller => {
5
+ export const useOpeningSequence = controller => {
6
6
  Object.assign(controller, {
7
7
  // Called from `connect` to prepare lifecycle state before the webchat opens.
8
8
  // The sequence may not exist on every widget, so the rest of the runtime can
@@ -37,9 +37,9 @@ export var useOpeningSequence = controller => {
37
37
  // still uses a timeout so reveal work stays outside the popover-open call
38
38
  // stack and cancellation has one consistent path.
39
39
  playOpeningSequenceMessageAt(index) {
40
- var message = this.openingSequenceMessages[index];
40
+ const message = this.openingSequenceMessages[index];
41
41
  if (!message) return;
42
- var delay = this.openingSequenceMessageDelay(message) * 1000;
42
+ const delay = this.openingSequenceMessageDelay(message) * 1000;
43
43
  this.openingSequenceTimeout = window.setTimeout(() => {
44
44
  this.openingSequenceTimeout = null;
45
45
  if (this.openingSequenceCancelled) return;
@@ -57,12 +57,12 @@ export var useOpeningSequence = controller => {
57
57
  this.scrollOpeningSequenceToBottom();
58
58
  },
59
59
  recordOpeningSequenceMessage(message) {
60
- var id = message.dataset.openingSequenceMessageId;
60
+ const id = message.dataset.openingSequenceMessageId;
61
61
  if (!id || this.revealedOpeningSequenceMessageIds.includes(id)) return;
62
62
  this.revealedOpeningSequenceMessageIds.push(id);
63
63
  },
64
64
  openingSequenceMessageDelay(message) {
65
- var delay = Number(message.dataset.delaySeconds || 0);
65
+ const delay = Number(message.dataset.delaySeconds || 0);
66
66
  return Number.isFinite(delay) ? delay : 0;
67
67
  },
68
68
  scrollOpeningSequenceToBottom() {
@@ -82,7 +82,7 @@ export var useOpeningSequence = controller => {
82
82
  // interrupts pending reveals so the payload cannot include later messages.
83
83
  appendOpeningSequenceMessageIds(formData) {
84
84
  this.cancelOpeningSequence();
85
- var ids = this.revealedOpeningSequenceMessageIds || [];
85
+ const ids = this.revealedOpeningSequenceMessageIds || [];
86
86
  ids.forEach(id => {
87
87
  formData.append('message[opening_sequence_message_ids][]', id);
88
88
  });