@hellotext/hellotext 2.0.0 → 2.0.1
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/README.md +27 -2
- package/dist/hellotext.js +1 -1
- package/index.d.ts +61 -0
- package/lib/hellotext.cjs +1 -0
- package/lib/hellotext.js +1 -0
- package/lib/index.cjs +1 -2
- package/lib/index.js +1 -2
- package/lib/models/business.cjs +2 -5
- package/lib/models/business.js +18 -13
- package/lib/models/form_collection.cjs +4 -1
- package/lib/models/form_collection.js +4 -1
- package/package.json +11 -4
- package/src/hellotext.js +2 -0
- package/src/index.bundle.js +5 -0
- package/src/index.js +1 -3
- package/src/models/business.js +3 -6
- package/src/models/form_collection.js +10 -4
- package/styles/index.css +30 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Type definitions for @hellotext/hellotext
|
|
2
|
+
|
|
3
|
+
export interface HellotextConfig {
|
|
4
|
+
forms?: {
|
|
5
|
+
autoMount?: boolean
|
|
6
|
+
successMessage?: boolean | string
|
|
7
|
+
}
|
|
8
|
+
webchat?: {
|
|
9
|
+
id?: string
|
|
10
|
+
container?: string
|
|
11
|
+
placement?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
|
|
12
|
+
classes?: string | string[]
|
|
13
|
+
triggerClasses?: string | string[]
|
|
14
|
+
behaviour?: 'modal' | 'popover'
|
|
15
|
+
style?: {
|
|
16
|
+
primaryColor?: string
|
|
17
|
+
secondaryColor?: string
|
|
18
|
+
typography?: string
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
session?: string
|
|
22
|
+
autoGenerateSession?: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface TrackingParams {
|
|
26
|
+
amount?: number
|
|
27
|
+
currency?: string
|
|
28
|
+
metadata?: Record<string, any>
|
|
29
|
+
tracked_at?: number
|
|
30
|
+
url?: string
|
|
31
|
+
headers?: Record<string, string>
|
|
32
|
+
object?: string
|
|
33
|
+
object_parameters?: Record<string, any>
|
|
34
|
+
object_type?: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface Response {
|
|
38
|
+
data: any
|
|
39
|
+
succeeded: boolean
|
|
40
|
+
failed: boolean
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare class Hellotext {
|
|
44
|
+
static initialize(businessId: string, config?: HellotextConfig): Promise<void>
|
|
45
|
+
static track(action: string, params?: TrackingParams): Promise<Response>
|
|
46
|
+
static on(event: string, callback: (data: any) => void): void
|
|
47
|
+
static removeEventListener(event: string, callback: (data: any) => void): void
|
|
48
|
+
static get session(): string
|
|
49
|
+
static get isInitialized(): boolean
|
|
50
|
+
static forms: any
|
|
51
|
+
static business: any
|
|
52
|
+
static webchat: any
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default Hellotext
|
|
56
|
+
|
|
57
|
+
// Declare the CSS module
|
|
58
|
+
declare module '@hellotext/hellotext/styles/index.css' {
|
|
59
|
+
const styles: string
|
|
60
|
+
export default styles
|
|
61
|
+
}
|
package/lib/hellotext.cjs
CHANGED
package/lib/hellotext.js
CHANGED
package/lib/index.cjs
CHANGED
|
@@ -7,9 +7,8 @@ exports.default = void 0;
|
|
|
7
7
|
var _stimulus = require("@hotwired/stimulus");
|
|
8
8
|
var _hellotext = _interopRequireDefault(require("./hellotext"));
|
|
9
9
|
var _form_controller = _interopRequireDefault(require("./controllers/form_controller"));
|
|
10
|
-
var _webchat_controller = _interopRequireDefault(require("./controllers/webchat_controller"));
|
|
11
10
|
var _emoji_picker_controller = _interopRequireDefault(require("./controllers/webchat/emoji_picker_controller"));
|
|
12
|
-
require("
|
|
11
|
+
var _webchat_controller = _interopRequireDefault(require("./controllers/webchat_controller"));
|
|
13
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
13
|
const application = _stimulus.Application.start();
|
|
15
14
|
application.register('hellotext--form', _form_controller.default);
|
package/lib/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { Application } from '@hotwired/stimulus';
|
|
2
2
|
import Hellotext from './hellotext';
|
|
3
3
|
import FormController from './controllers/form_controller';
|
|
4
|
-
import WebchatController from './controllers/webchat_controller';
|
|
5
4
|
import WebChatEmojiController from './controllers/webchat/emoji_picker_controller';
|
|
5
|
+
import WebchatController from './controllers/webchat_controller';
|
|
6
6
|
var application = Application.start();
|
|
7
7
|
application.register('hellotext--form', FormController);
|
|
8
8
|
application.register('hellotext--webchat', WebchatController);
|
|
9
9
|
application.register('hellotext--webchat--emoji', WebChatEmojiController);
|
|
10
|
-
import '../styles/index.css';
|
|
11
10
|
window.Hellotext = Hellotext;
|
|
12
11
|
export default Hellotext;
|
package/lib/models/business.cjs
CHANGED
|
@@ -17,7 +17,6 @@ let Business = /*#__PURE__*/function () {
|
|
|
17
17
|
_classCallCheck(this, Business);
|
|
18
18
|
this.id = id;
|
|
19
19
|
this.data = {};
|
|
20
|
-
this.fetchPublicData();
|
|
21
20
|
}
|
|
22
21
|
_createClass(Business, [{
|
|
23
22
|
key: "subscription",
|
|
@@ -44,12 +43,10 @@ let Business = /*#__PURE__*/function () {
|
|
|
44
43
|
get: function () {
|
|
45
44
|
return this.data.features;
|
|
46
45
|
}
|
|
47
|
-
|
|
48
|
-
// private
|
|
49
46
|
}, {
|
|
50
47
|
key: "fetchPublicData",
|
|
51
|
-
value: function fetchPublicData() {
|
|
52
|
-
_businesses.default.get(this.id).then(response => response.json()).then(data => {
|
|
48
|
+
value: async function fetchPublicData() {
|
|
49
|
+
return _businesses.default.get(this.id).then(response => response.json()).then(data => {
|
|
53
50
|
this.data = data;
|
|
54
51
|
if (typeof document !== 'undefined') {
|
|
55
52
|
const linkTag = document.createElement('link');
|
package/lib/models/business.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
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); }); }; }
|
|
1
3
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2
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); } }
|
|
3
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; }
|
|
@@ -10,7 +12,6 @@ var Business = /*#__PURE__*/function () {
|
|
|
10
12
|
_classCallCheck(this, Business);
|
|
11
13
|
this.id = id;
|
|
12
14
|
this.data = {};
|
|
13
|
-
this.fetchPublicData();
|
|
14
15
|
}
|
|
15
16
|
_createClass(Business, [{
|
|
16
17
|
key: "subscription",
|
|
@@ -37,21 +38,25 @@ var Business = /*#__PURE__*/function () {
|
|
|
37
38
|
get: function get() {
|
|
38
39
|
return this.data.features;
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
-
// private
|
|
42
41
|
}, {
|
|
43
42
|
key: "fetchPublicData",
|
|
44
|
-
value: function
|
|
45
|
-
|
|
46
|
-
this.data
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
value: function () {
|
|
44
|
+
var _fetchPublicData = _asyncToGenerator(function* () {
|
|
45
|
+
return API.get(this.id).then(response => response.json()).then(data => {
|
|
46
|
+
this.data = data;
|
|
47
|
+
if (typeof document !== 'undefined') {
|
|
48
|
+
var linkTag = document.createElement('link');
|
|
49
|
+
linkTag.rel = 'stylesheet';
|
|
50
|
+
linkTag.href = data.style_url;
|
|
51
|
+
document.head.append(linkTag);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
53
54
|
});
|
|
54
|
-
|
|
55
|
+
function fetchPublicData() {
|
|
56
|
+
return _fetchPublicData.apply(this, arguments);
|
|
57
|
+
}
|
|
58
|
+
return fetchPublicData;
|
|
59
|
+
}()
|
|
55
60
|
}]);
|
|
56
61
|
return Business;
|
|
57
62
|
}();
|
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.FormCollection = void 0;
|
|
7
|
-
var _hellotext = _interopRequireDefault(require("../hellotext"));
|
|
8
7
|
var _forms = _interopRequireDefault(require("../api/forms"));
|
|
8
|
+
var _hellotext = _interopRequireDefault(require("../hellotext"));
|
|
9
9
|
var _core = require("../core");
|
|
10
10
|
var _form = require("./form");
|
|
11
11
|
var _errors = require("../errors");
|
|
@@ -55,6 +55,9 @@ let FormCollection = /*#__PURE__*/function () {
|
|
|
55
55
|
throw new _errors.NotInitializedError();
|
|
56
56
|
}
|
|
57
57
|
if (this.fetching) return;
|
|
58
|
+
if (typeof document === 'undefined' || !('querySelectorAll' in document)) {
|
|
59
|
+
return console.warn('Document is not defined, collection is not possible. Please make sure to initialize the library after the document is loaded.');
|
|
60
|
+
}
|
|
58
61
|
const formsIdsToFetch = _classPrivateFieldLooseBase(this, _formIdsToFetch)[_formIdsToFetch];
|
|
59
62
|
if (formsIdsToFetch.length === 0) return;
|
|
60
63
|
const promises = formsIdsToFetch.map(id => {
|
|
@@ -8,8 +8,8 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
|
|
|
8
8
|
function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
|
|
9
9
|
var id = 0;
|
|
10
10
|
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
11
|
-
import Hellotext from '../hellotext';
|
|
12
11
|
import API from '../api/forms';
|
|
12
|
+
import Hellotext from '../hellotext';
|
|
13
13
|
import { Configuration } from '../core';
|
|
14
14
|
import { Form } from './form';
|
|
15
15
|
import { NotInitializedError } from '../errors';
|
|
@@ -51,6 +51,9 @@ var FormCollection = /*#__PURE__*/function () {
|
|
|
51
51
|
throw new NotInitializedError();
|
|
52
52
|
}
|
|
53
53
|
if (this.fetching) return;
|
|
54
|
+
if (typeof document === 'undefined' || !('querySelectorAll' in document)) {
|
|
55
|
+
return console.warn('Document is not defined, collection is not possible. Please make sure to initialize the library after the document is loaded.');
|
|
56
|
+
}
|
|
54
57
|
var formsIdsToFetch = _classPrivateFieldLooseBase(this, _formIdsToFetch)[_formIdsToFetch];
|
|
55
58
|
if (formsIdsToFetch.length === 0) return;
|
|
56
59
|
var promises = formsIdsToFetch.map(id => {
|
package/package.json
CHANGED
|
@@ -1,30 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hellotext/hellotext",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Hellotext JavaScript Client",
|
|
5
5
|
"source": "src/index.js",
|
|
6
6
|
"main": "lib/index.cjs",
|
|
7
7
|
"module": "lib/index.js",
|
|
8
8
|
"browser": "dist/hellotext.js",
|
|
9
9
|
"unpkg": "dist/hellotext.js",
|
|
10
|
+
"types": "index.d.ts",
|
|
10
11
|
"author": "Hellotext",
|
|
11
12
|
"license": "MIT",
|
|
12
13
|
"homepage": "https://github.com/hellotext/hellotext.js",
|
|
13
14
|
"files": [
|
|
14
15
|
"lib",
|
|
15
16
|
"dist",
|
|
16
|
-
"src"
|
|
17
|
+
"src",
|
|
18
|
+
"styles",
|
|
19
|
+
"index.d.ts"
|
|
17
20
|
],
|
|
18
21
|
"exports": {
|
|
19
22
|
".": {
|
|
23
|
+
"types": "./index.d.ts",
|
|
20
24
|
"import": "./lib/index.js",
|
|
21
25
|
"require": "./lib/index.cjs",
|
|
22
26
|
"default": "./dist/hellotext.js"
|
|
23
27
|
},
|
|
24
28
|
"./vanilla": {
|
|
29
|
+
"types": "./index.d.ts",
|
|
25
30
|
"import": "./lib/vanilla.js",
|
|
26
31
|
"require": "./lib/vanilla.cjs"
|
|
27
32
|
},
|
|
33
|
+
"./styles/*": "./styles/*",
|
|
34
|
+
"./styles/index.css": "./styles/index.css",
|
|
28
35
|
"./package.json": "./package.json"
|
|
29
36
|
},
|
|
30
37
|
"sideEffects": [
|
|
@@ -63,8 +70,8 @@
|
|
|
63
70
|
"scripts": {
|
|
64
71
|
"test": "NODE_ENV=test jest",
|
|
65
72
|
"build": "npm run clean && npm run build:esm && npm run build:cjs && npm run build:bundle",
|
|
66
|
-
"build:esm": "babel src -d lib",
|
|
67
|
-
"build:cjs": "BABEL_ENV=cjs babel src -d lib --out-file-extension .cjs",
|
|
73
|
+
"build:esm": "babel src -d lib --ignore src/index.bundle.js",
|
|
74
|
+
"build:cjs": "BABEL_ENV=cjs babel src -d lib --out-file-extension .cjs --ignore src/index.bundle.js",
|
|
68
75
|
"build:bundle": "webpack",
|
|
69
76
|
"clean": "rm -rf lib dist",
|
|
70
77
|
"prepublishOnly": "npm test && npm run build"
|
package/src/hellotext.js
CHANGED
package/src/index.js
CHANGED
|
@@ -2,8 +2,8 @@ import { Application } from '@hotwired/stimulus'
|
|
|
2
2
|
import Hellotext from './hellotext'
|
|
3
3
|
|
|
4
4
|
import FormController from './controllers/form_controller'
|
|
5
|
-
import WebchatController from './controllers/webchat_controller'
|
|
6
5
|
import WebChatEmojiController from './controllers/webchat/emoji_picker_controller'
|
|
6
|
+
import WebchatController from './controllers/webchat_controller'
|
|
7
7
|
|
|
8
8
|
const application = Application.start()
|
|
9
9
|
|
|
@@ -11,8 +11,6 @@ application.register('hellotext--form', FormController)
|
|
|
11
11
|
application.register('hellotext--webchat', WebchatController)
|
|
12
12
|
application.register('hellotext--webchat--emoji', WebChatEmojiController)
|
|
13
13
|
|
|
14
|
-
import '../styles/index.css'
|
|
15
|
-
|
|
16
14
|
window.Hellotext = Hellotext
|
|
17
15
|
|
|
18
16
|
export default Hellotext
|
package/src/models/business.js
CHANGED
|
@@ -6,7 +6,6 @@ class Business {
|
|
|
6
6
|
constructor(id) {
|
|
7
7
|
this.id = id
|
|
8
8
|
this.data = {}
|
|
9
|
-
this.fetchPublicData()
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
get subscription() {
|
|
@@ -29,15 +28,13 @@ class Business {
|
|
|
29
28
|
return this.data.features
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
fetchPublicData() {
|
|
35
|
-
API.get(this.id)
|
|
31
|
+
async fetchPublicData() {
|
|
32
|
+
return API.get(this.id)
|
|
36
33
|
.then(response => response.json())
|
|
37
34
|
.then(data => {
|
|
38
35
|
this.data = data
|
|
39
36
|
|
|
40
|
-
if(typeof document !== 'undefined') {
|
|
37
|
+
if (typeof document !== 'undefined') {
|
|
41
38
|
const linkTag = document.createElement('link')
|
|
42
39
|
linkTag.rel = 'stylesheet'
|
|
43
40
|
linkTag.href = data.style_url
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Hellotext from '../hellotext'
|
|
2
1
|
import API from '../api/forms'
|
|
2
|
+
import Hellotext from '../hellotext'
|
|
3
3
|
|
|
4
4
|
import { Configuration } from '../core'
|
|
5
5
|
import { Form } from './form'
|
|
@@ -15,7 +15,7 @@ class FormCollection {
|
|
|
15
15
|
|
|
16
16
|
this.add = this.add.bind(this)
|
|
17
17
|
|
|
18
|
-
if(typeof MutationObserver !== 'undefined') {
|
|
18
|
+
if (typeof MutationObserver !== 'undefined') {
|
|
19
19
|
this.mutationObserver = new MutationObserver(this.formMutationObserver.bind(this))
|
|
20
20
|
this.mutationObserver.observe(document.body, { childList: true, subtree: true })
|
|
21
21
|
}
|
|
@@ -40,7 +40,13 @@ class FormCollection {
|
|
|
40
40
|
throw new NotInitializedError()
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
if(this.fetching) return
|
|
43
|
+
if (this.fetching) return
|
|
44
|
+
|
|
45
|
+
if (typeof document === 'undefined' || !('querySelectorAll' in document)) {
|
|
46
|
+
return console.warn(
|
|
47
|
+
'Document is not defined, collection is not possible. Please make sure to initialize the library after the document is loaded.',
|
|
48
|
+
)
|
|
49
|
+
}
|
|
44
50
|
|
|
45
51
|
const formsIdsToFetch = this.#formIdsToFetch
|
|
46
52
|
if (formsIdsToFetch.length === 0) return
|
|
@@ -60,7 +66,7 @@ class FormCollection {
|
|
|
60
66
|
await Promise.all(promises)
|
|
61
67
|
.then(forms => forms.forEach(this.add))
|
|
62
68
|
.then(() => Hellotext.eventEmitter.dispatch('forms:collected', this))
|
|
63
|
-
.then(() => this.fetching = false)
|
|
69
|
+
.then(() => (this.fetching = false))
|
|
64
70
|
|
|
65
71
|
if (Configuration.forms.autoMount) {
|
|
66
72
|
this.forms.forEach(form => form.mount())
|
package/styles/index.css
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
form[data-hello-form] {
|
|
2
|
+
position: relative;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
form[data-hello-form] article [data-error-container] {
|
|
6
|
+
font-size: 0.875rem;
|
|
7
|
+
line-height: 1.25rem;
|
|
8
|
+
display: none;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
form[data-hello-form] article:has(input:invalid) [data-error-container] {
|
|
12
|
+
display: block;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
form[data-hello-form] [data-logo-container] {
|
|
16
|
+
display: flex;
|
|
17
|
+
justify-content: center;
|
|
18
|
+
align-items: flex-end;
|
|
19
|
+
position: absolute;
|
|
20
|
+
right: 1rem;
|
|
21
|
+
bottom: 1rem;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
form[data-hello-form] [data-logo-container] small {
|
|
25
|
+
margin: 0 0.3rem;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
form[data-hello-form] [data-logo-container] [data-hello-brand] {
|
|
29
|
+
width: 4rem;
|
|
30
|
+
}
|