@lvble/core 2.0.30 → 2.0.32
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 +2 -2
- package/dist/_bundles/core.js +1 -1
- package/dist/_bundles/core.js.map +1 -1
- package/dist/_bundles/core.min.js +1 -1
- package/dist/_bundles/core.min.js.map +1 -1
- package/dist/lib/lvble.d.ts +9 -19
- package/dist/lib/lvble.d.ts.map +1 -1
- package/dist/lib/lvble.js +83 -58
- package/dist/lib/lvble.js.map +1 -1
- package/dist/lib-esm/lvble.d.ts +9 -19
- package/dist/lib-esm/lvble.d.ts.map +1 -1
- package/dist/lib-esm/lvble.js +84 -59
- package/dist/lib-esm/lvble.js.map +1 -1
- package/package.json +5 -6
package/dist/lib/lvble.d.ts
CHANGED
|
@@ -32,14 +32,10 @@ declare enum EventType {
|
|
|
32
32
|
export interface InitOptions {
|
|
33
33
|
environment: Environment;
|
|
34
34
|
token: string;
|
|
35
|
+
onEvent: (eventType: string, data: any) => void;
|
|
35
36
|
}
|
|
36
37
|
export interface OpenOptions {
|
|
37
38
|
mode?: Mode;
|
|
38
|
-
onEvent: (eventType: string, data: any) => void;
|
|
39
|
-
}
|
|
40
|
-
export interface CreateWidgetOptions extends OpenOptions {
|
|
41
|
-
mode?: Extract<Mode, "onboarding" | "repay">;
|
|
42
|
-
onEvent: (eventType: string, data: any) => void;
|
|
43
39
|
}
|
|
44
40
|
declare class LvbleWidget extends HTMLElement {
|
|
45
41
|
_typeToEvent: {
|
|
@@ -50,8 +46,6 @@ declare class LvbleWidget extends HTMLElement {
|
|
|
50
46
|
};
|
|
51
47
|
_iframe?: HTMLIFrameElement;
|
|
52
48
|
constructor();
|
|
53
|
-
get mode(): Mode;
|
|
54
|
-
set mode(val: Mode | undefined);
|
|
55
49
|
get environment(): Environment;
|
|
56
50
|
set environment(val: Environment);
|
|
57
51
|
get token(): string;
|
|
@@ -63,14 +57,12 @@ declare const lvble: (initOptions: InitOptions) => {
|
|
|
63
57
|
/**
|
|
64
58
|
* This function creates a widget that can be embedded in your website.
|
|
65
59
|
*
|
|
66
|
-
* @
|
|
67
|
-
* @returns The widget.
|
|
60
|
+
* @returns A lvble widget. Note that it detects mode automagically.
|
|
68
61
|
*/
|
|
69
|
-
createWidget: (
|
|
62
|
+
createWidget: () => LvbleWidget;
|
|
70
63
|
/**
|
|
71
|
-
* This function opens a
|
|
72
|
-
* @param openOptions The options for opening the
|
|
73
|
-
* @returns undefined.
|
|
64
|
+
* This function opens a modal with the relevant mode.
|
|
65
|
+
* @param openOptions The options for opening the modal. See `OpenOptions` for more information.
|
|
74
66
|
*/
|
|
75
67
|
open: (openOptions: OpenOptions) => void;
|
|
76
68
|
};
|
|
@@ -79,14 +71,12 @@ export declare const Lvble: (initOptions: InitOptions) => {
|
|
|
79
71
|
/**
|
|
80
72
|
* This function creates a widget that can be embedded in your website.
|
|
81
73
|
*
|
|
82
|
-
* @
|
|
83
|
-
* @returns The widget.
|
|
74
|
+
* @returns A lvble widget. Note that it detects mode automagically.
|
|
84
75
|
*/
|
|
85
|
-
createWidget: (
|
|
76
|
+
createWidget: () => LvbleWidget;
|
|
86
77
|
/**
|
|
87
|
-
* This function opens a
|
|
88
|
-
* @param openOptions The options for opening the
|
|
89
|
-
* @returns undefined.
|
|
78
|
+
* This function opens a modal with the relevant mode.
|
|
79
|
+
* @param openOptions The options for opening the modal. See `OpenOptions` for more information.
|
|
90
80
|
*/
|
|
91
81
|
open: (openOptions: OpenOptions) => void;
|
|
92
82
|
};
|
package/dist/lib/lvble.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lvble.d.ts","sourceRoot":"","sources":["../../src/lib/lvble.ts"],"names":[],"mappings":"AAEA,oBAAY,WAAW;IACrB,KAAK,UAAU;IACf,GAAG,gBAAgB;IACnB,OAAO,YAAY;IACnB,UAAU,eAAe;CAC1B;AAeD,MAAM,MAAM,IAAI,GAAG,YAAY,GAAG,aAAa,G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SAAS,GAAG,cAAc,GAAG,SAAS,GAAG,SAAS,CAAC;AAE/D,aAAK,SAAS;IACZ,gBAAgB,qBAAqB;IACrC,iBAAiB,sBAAsB;IACvC,WAAW,gBAAgB;IAC3B,WAAW,gBAAgB;CAC5B;AASD,MAAM,WAAW,WAAW;IAE1B,WAAW,EAAE,WAAW,CAAC;IAEzB,KAAK,EAAE,MAAM,CAAC;IAEd,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;CACjD;AAED,MAAM,WAAW,WAAW;IAE1B,IAAI,CAAC,EAAE,IAAI,CAAC;CACb;AAED,cAAM,WAAY,SAAQ,WAAW;IACnC,YAAY;;;;;MAKV;IACF,OAAO,CAAC,EAAE,iBAAiB,CAAC;;IAO5B,IAAI,WAAW,IAAI,WAAW,CAE7B;IAED,IAAI,WAAW,CAAC,GAAG,EAJA,WAIA,EAMlB;IAED,IAAI,KAAK,IAIM,MAAM,CAFpB;IAED,IAAI,KAAK,CAAC,GAAG,EAAE,MAAM,EAMpB;IAED,iBAAiB;IAiBjB,oBAAoB;CAGrB;AAyCD,QAAA,MAAM,KAAK,gBAAiB,WAAW;IA+BnC;;;;OAIG;;IAuCH;;;OAGG;wBACiB,WAAW;CAyDlC,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC;AAEjD,eAAO,MAAM,KAAK,gBA3IU,WAAW;IA+BnC;;;;OAIG;;IAuCH;;;OAGG;wBACiB,WAAW;CA6DT,CAAC"}
|
package/dist/lib/lvble.js
CHANGED
|
@@ -16,7 +16,7 @@ const envToBaseUrlMapWidget = {
|
|
|
16
16
|
[Environment.Production]: "https://widget.pms.production.nowlvble.com",
|
|
17
17
|
};
|
|
18
18
|
const envToBaseUrlMapExperience = {
|
|
19
|
-
[Environment.Local]: "http://localhost:
|
|
19
|
+
[Environment.Local]: "http://localhost:3001",
|
|
20
20
|
[Environment.Dev]: "https://experience.pms.development.nowlvble.com",
|
|
21
21
|
[Environment.Sandbox]: "https://experience.pms.sandbox.nowlvble.com",
|
|
22
22
|
[Environment.Production]: "https://experience.pms.production.nowlvble.com",
|
|
@@ -56,17 +56,6 @@ class LvbleWidget extends HTMLElement {
|
|
|
56
56
|
});
|
|
57
57
|
this.attachShadow({ mode: "open" });
|
|
58
58
|
}
|
|
59
|
-
get mode() {
|
|
60
|
-
return this.getAttribute("mode");
|
|
61
|
-
}
|
|
62
|
-
set mode(val) {
|
|
63
|
-
if (val) {
|
|
64
|
-
this.setAttribute("mode", val);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
this.removeAttribute("mode");
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
59
|
get environment() {
|
|
71
60
|
return this.getAttribute("environment");
|
|
72
61
|
}
|
|
@@ -108,94 +97,130 @@ class LvbleWidget extends HTMLElement {
|
|
|
108
97
|
}
|
|
109
98
|
}
|
|
110
99
|
customElements.define("lvble-widget", LvbleWidget);
|
|
111
|
-
const modeWidgetMap = {
|
|
112
|
-
onboarding: customElements.get("lvble-widget"),
|
|
113
|
-
repay: customElements.get("lvble-widget"),
|
|
114
|
-
};
|
|
115
|
-
let _popup;
|
|
116
100
|
let eventListenerLvbleAdded = false;
|
|
117
101
|
let eventListenerOpenAdded = false;
|
|
102
|
+
const createModal = () => {
|
|
103
|
+
const modalIframe = document.createElement("iframe");
|
|
104
|
+
const w = 360;
|
|
105
|
+
const h = 95;
|
|
106
|
+
const t = `calc(50vh + 10px)`;
|
|
107
|
+
const l = `50vw`;
|
|
108
|
+
modalIframe.style.position = "absolute";
|
|
109
|
+
modalIframe.style.top = t;
|
|
110
|
+
modalIframe.style.left = l;
|
|
111
|
+
modalIframe.style.transform = `translate(-50%, -50%)`;
|
|
112
|
+
modalIframe.style.width = `min(95vw, ${w}px)`;
|
|
113
|
+
modalIframe.style.height = `min(${h}vh, 750px)`;
|
|
114
|
+
modalIframe.style.backgroundColor = "white";
|
|
115
|
+
modalIframe.style.borderRadius = "10px";
|
|
116
|
+
modalIframe.style.borderStyle = "solid";
|
|
117
|
+
modalIframe.style.borderColor = "transparent";
|
|
118
|
+
modalIframe.style.borderWidth = "1px";
|
|
119
|
+
// modalIframe.style.padding = "1.5rem";
|
|
120
|
+
const modalBackground = document.createElement("div");
|
|
121
|
+
modalBackground.style.position = "fixed";
|
|
122
|
+
modalBackground.style.top = "0";
|
|
123
|
+
modalBackground.style.left = "0";
|
|
124
|
+
modalBackground.style.height = "100%";
|
|
125
|
+
modalBackground.style.width = "100%";
|
|
126
|
+
modalBackground.style.zIndex = "100";
|
|
127
|
+
modalBackground.style.backgroundColor = "rgba(0, 0, 0, 0.5)";
|
|
128
|
+
return { modalBackground, modalIframe };
|
|
129
|
+
};
|
|
118
130
|
const lvble = (initOptions) => {
|
|
119
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Note: you can only register for onEvent once.
|
|
133
|
+
*/
|
|
134
|
+
if (!initOptions.onEvent) {
|
|
135
|
+
throw new Error("onEvent callback is required");
|
|
136
|
+
}
|
|
137
|
+
if (!initOptions.token) {
|
|
138
|
+
throw new Error("token is required");
|
|
139
|
+
}
|
|
140
|
+
if (!initOptions.environment) {
|
|
141
|
+
throw new Error("environment is required");
|
|
142
|
+
}
|
|
143
|
+
const modeUrlMap = {
|
|
144
|
+
onboarding: `${envToBaseUrlMapExperience[initOptions.environment]}?token=${initOptions.token}`,
|
|
145
|
+
offboarding: `${envToBaseUrlMapExperience[initOptions.environment]}?token=${initOptions.token}`,
|
|
146
|
+
split: `${envToBaseUrlMapExperience[initOptions.environment]}?token=${initOptions.token}`,
|
|
147
|
+
repay: `${envToBaseUrlMapExperience[initOptions.environment]}?token=${initOptions.token}`,
|
|
148
|
+
};
|
|
149
|
+
const { modalBackground, modalIframe } = createModal();
|
|
150
|
+
const l = {
|
|
120
151
|
/**
|
|
121
152
|
* This function creates a widget that can be embedded in your website.
|
|
122
153
|
*
|
|
123
|
-
* @
|
|
124
|
-
* @returns The widget.
|
|
154
|
+
* @returns A lvble widget. Note that it detects mode automagically.
|
|
125
155
|
*/
|
|
126
|
-
|
|
127
|
-
createWidget: (createOptions) => {
|
|
156
|
+
createWidget: () => {
|
|
128
157
|
const widget = new LvbleWidget();
|
|
129
|
-
// (
|
|
130
|
-
// createOptions.mode
|
|
131
|
-
// ? new modeWidgetMap[createOptions.mode]!()
|
|
132
|
-
// : new (customElements.get(
|
|
133
|
-
// "lvble-widget"
|
|
134
|
-
// ) as CustomElementConstructor)()
|
|
135
|
-
// ) as LvbleWidget;
|
|
136
158
|
widget.environment = initOptions.environment;
|
|
137
159
|
widget.token = initOptions.token;
|
|
138
|
-
|
|
160
|
+
modalBackground.appendChild(modalIframe);
|
|
139
161
|
const messageListener = (message) => {
|
|
140
162
|
if (message.origin != envToBaseUrlMapWidget[initOptions.environment]) {
|
|
141
163
|
console.debug(`Received message from unknown origin: ${message.origin}`);
|
|
142
164
|
return;
|
|
143
165
|
}
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
166
|
+
const eventData = message.data;
|
|
167
|
+
if (eventData.eventType === "OPEN_EXPERIENCE_REQUEST") {
|
|
168
|
+
modalIframe.src = `${envToBaseUrlMapExperience[initOptions.environment]}?token=${initOptions.token}`;
|
|
169
|
+
const openOptions = {
|
|
170
|
+
mode: "onboarding", // Replace with the desired mode
|
|
171
|
+
};
|
|
172
|
+
l.open(openOptions);
|
|
173
|
+
}
|
|
148
174
|
};
|
|
149
175
|
if (!eventListenerLvbleAdded) {
|
|
150
176
|
window.addEventListener("message", messageListener);
|
|
151
177
|
eventListenerLvbleAdded = true;
|
|
152
|
-
mixpanel_browser_1.default.init(
|
|
178
|
+
mixpanel_browser_1.default.init("9ad1530a57a977ab9d4005e2ba11ab4a", { debug: true });
|
|
153
179
|
}
|
|
154
180
|
return widget;
|
|
155
181
|
},
|
|
156
182
|
/**
|
|
157
|
-
* This function opens a
|
|
158
|
-
* @param openOptions The options for opening the
|
|
159
|
-
* @returns undefined.
|
|
183
|
+
* This function opens a modal with the relevant mode.
|
|
184
|
+
* @param openOptions The options for opening the modal. See `OpenOptions` for more information.
|
|
160
185
|
*/
|
|
161
186
|
open: (openOptions) => {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const w = 450;
|
|
172
|
-
const h = 800;
|
|
173
|
-
const l = screen.width / 2 - w / 2;
|
|
174
|
-
const t = screen.height / 2 - h / 2;
|
|
175
|
-
_popup = window.open(modeUrl, "LvblePopup", "width=" + w + ",height=" + h + ",location=no,left=" + l + ",top=" + t);
|
|
187
|
+
if (!openOptions.mode) {
|
|
188
|
+
throw new Error("mode is required");
|
|
189
|
+
}
|
|
190
|
+
const modeUrl = openOptions.mode
|
|
191
|
+
? modeUrlMap[openOptions.mode]
|
|
192
|
+
: `${envToBaseUrlMapExperience[initOptions.environment]}?token=${initOptions.token}`;
|
|
193
|
+
modalIframe.src = modeUrl;
|
|
194
|
+
modalBackground.appendChild(modalIframe);
|
|
195
|
+
document.body.appendChild(modalBackground);
|
|
176
196
|
const messageListener = (message) => {
|
|
177
197
|
if (message.origin != envToBaseUrlMapExperience[initOptions.environment]) {
|
|
178
|
-
console.debug(`Received message from unknown origin: ${message.origin}`);
|
|
198
|
+
console.debug(`Received message from unknown origin: ${message.origin} Expecting only ${envToBaseUrlMapExperience[initOptions.environment]}`);
|
|
179
199
|
return;
|
|
180
200
|
}
|
|
181
201
|
const eventData = message.data;
|
|
202
|
+
if (eventData.eventType === "CLOSE_EXPERIENCE_REQUEST") {
|
|
203
|
+
document.body.removeChild(modalBackground);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
// TODO: Consider using websocket in iframes instead of posting messages to them.
|
|
182
207
|
const iframes = document.querySelectorAll("lvble-widget");
|
|
183
|
-
message = JSON.parse(JSON.stringify(message));
|
|
184
208
|
iframes.forEach((w) => {
|
|
185
209
|
var _a, _b;
|
|
186
210
|
(_b = ((_a = w.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector("iframe")).contentWindow) === null || _b === void 0 ? void 0 : _b.postMessage(eventData, "*");
|
|
187
211
|
});
|
|
188
|
-
mixpanel_browser_1.default.track(
|
|
189
|
-
|
|
190
|
-
mixpanel_browser_1.default.track(
|
|
212
|
+
mixpanel_browser_1.default.track("BEFORE_INVOKE_ON_EVENT", eventData);
|
|
213
|
+
initOptions.onEvent(eventData.eventType, eventData.data);
|
|
214
|
+
mixpanel_browser_1.default.track("AFTER_INVOKE_ON_EVENT", eventData);
|
|
191
215
|
};
|
|
192
216
|
if (!eventListenerOpenAdded) {
|
|
193
217
|
window.addEventListener("message", messageListener);
|
|
194
218
|
eventListenerOpenAdded = true;
|
|
195
|
-
mixpanel_browser_1.default.init(
|
|
219
|
+
mixpanel_browser_1.default.init("9ad1530a57a977ab9d4005e2ba11ab4a", { debug: true });
|
|
196
220
|
}
|
|
197
221
|
},
|
|
198
222
|
};
|
|
223
|
+
return l;
|
|
199
224
|
};
|
|
200
225
|
exports.Lvble = lvble;
|
|
201
226
|
//# sourceMappingURL=lvble.js.map
|
package/dist/lib/lvble.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lvble.js","sourceRoot":"","sources":["../../src/lib/lvble.ts"],"names":[],"mappings":";;;AAAA,uDAAwC;AAExC,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,8BAAe,CAAA;IACf,kCAAmB,CAAA;IACnB,kCAAmB,CAAA;IACnB,wCAAyB,CAAA;AAC3B,CAAC,EALW,WAAW,2BAAX,WAAW,QAKtB;AACD,MAAM,qBAAqB,GAAgC;IACzD,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,uBAAuB;IAC5C,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,6CAA6C;IAChE,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,yCAAy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,KAAK,0BAA0B,EAAE;oBACtD,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;oBAC3C,OAAO;iBACR;gBAED,iFAAiF;gBACjF,MAAM,OAAO,GAAG,QAAQ,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC;gBAE1D,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;;oBACpB,MAAA,CACE,MAAA,CAAC,CAAC,UAAU,0CAAE,aAAa,CAAC,QAAQ,CACrC,CAAA,CAAC,aAAa,0CAAE,WAAW,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;gBAC/C,CAAC,CAAC,CAAC;gBAEH,0BAAQ,CAAC,KAAK,CAAC,wBAAwB,EAAE,SAAS,CAAC,CAAC;gBACpD,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;gBACzD,0BAAQ,CAAC,KAAK,CAAC,uBAAuB,EAAE,SAAS,CAAC,CAAC;YACrD,CAAC,CAAC;YAEF,IAAI,CAAC,sBAAsB,EAAE;gBAC3B,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;gBACpD,sBAAsB,GAAG,IAAI,CAAC;gBAC9B,0BAAQ,CAAC,IAAI,CAAC,kCAAkC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;aACpE;QACH,CAAC;KACF,CAAC;IAEF,OAAO,CAAC,CAAC;AACX,CAAC,CAAC;AAIW,QAAA,KAAK,GAAG,KAAK,CAAC"}
|
package/dist/lib-esm/lvble.d.ts
CHANGED
|
@@ -32,14 +32,10 @@ declare enum EventType {
|
|
|
32
32
|
export interface InitOptions {
|
|
33
33
|
environment: Environment;
|
|
34
34
|
token: string;
|
|
35
|
+
onEvent: (eventType: string, data: any) => void;
|
|
35
36
|
}
|
|
36
37
|
export interface OpenOptions {
|
|
37
38
|
mode?: Mode;
|
|
38
|
-
onEvent: (eventType: string, data: any) => void;
|
|
39
|
-
}
|
|
40
|
-
export interface CreateWidgetOptions extends OpenOptions {
|
|
41
|
-
mode?: Extract<Mode, "onboarding" | "repay">;
|
|
42
|
-
onEvent: (eventType: string, data: any) => void;
|
|
43
39
|
}
|
|
44
40
|
declare class LvbleWidget extends HTMLElement {
|
|
45
41
|
_typeToEvent: {
|
|
@@ -50,8 +46,6 @@ declare class LvbleWidget extends HTMLElement {
|
|
|
50
46
|
};
|
|
51
47
|
_iframe?: HTMLIFrameElement;
|
|
52
48
|
constructor();
|
|
53
|
-
get mode(): Mode;
|
|
54
|
-
set mode(val: Mode | undefined);
|
|
55
49
|
get environment(): Environment;
|
|
56
50
|
set environment(val: Environment);
|
|
57
51
|
get token(): string;
|
|
@@ -63,14 +57,12 @@ declare const lvble: (initOptions: InitOptions) => {
|
|
|
63
57
|
/**
|
|
64
58
|
* This function creates a widget that can be embedded in your website.
|
|
65
59
|
*
|
|
66
|
-
* @
|
|
67
|
-
* @returns The widget.
|
|
60
|
+
* @returns A lvble widget. Note that it detects mode automagically.
|
|
68
61
|
*/
|
|
69
|
-
createWidget: (
|
|
62
|
+
createWidget: () => LvbleWidget;
|
|
70
63
|
/**
|
|
71
|
-
* This function opens a
|
|
72
|
-
* @param openOptions The options for opening the
|
|
73
|
-
* @returns undefined.
|
|
64
|
+
* This function opens a modal with the relevant mode.
|
|
65
|
+
* @param openOptions The options for opening the modal. See `OpenOptions` for more information.
|
|
74
66
|
*/
|
|
75
67
|
open: (openOptions: OpenOptions) => void;
|
|
76
68
|
};
|
|
@@ -79,14 +71,12 @@ export declare const Lvble: (initOptions: InitOptions) => {
|
|
|
79
71
|
/**
|
|
80
72
|
* This function creates a widget that can be embedded in your website.
|
|
81
73
|
*
|
|
82
|
-
* @
|
|
83
|
-
* @returns The widget.
|
|
74
|
+
* @returns A lvble widget. Note that it detects mode automagically.
|
|
84
75
|
*/
|
|
85
|
-
createWidget: (
|
|
76
|
+
createWidget: () => LvbleWidget;
|
|
86
77
|
/**
|
|
87
|
-
* This function opens a
|
|
88
|
-
* @param openOptions The options for opening the
|
|
89
|
-
* @returns undefined.
|
|
78
|
+
* This function opens a modal with the relevant mode.
|
|
79
|
+
* @param openOptions The options for opening the modal. See `OpenOptions` for more information.
|
|
90
80
|
*/
|
|
91
81
|
open: (openOptions: OpenOptions) => void;
|
|
92
82
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lvble.d.ts","sourceRoot":"","sources":["../../src/lib/lvble.ts"],"names":[],"mappings":"AAEA,oBAAY,WAAW;IACrB,KAAK,UAAU;IACf,GAAG,gBAAgB;IACnB,OAAO,YAAY;IACnB,UAAU,eAAe;CAC1B;AAeD,MAAM,MAAM,IAAI,GAAG,YAAY,GAAG,aAAa,GAAG,OAAO,GAAG,OAAO,CAAC;AACpE,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AACF,MAAM,MAAM,cAAc,GACtB,SAAS,GACT;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AACN,MAAM,MAAM,SAAS,GACjB,SAAS,GACT;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AACN,MAAM,MAAM,SAAS,GACjB,SAAS,GACT;IACE,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;
|
|
1
|
+
{"version":3,"file":"lvble.d.ts","sourceRoot":"","sources":["../../src/lib/lvble.ts"],"names":[],"mappings":"AAEA,oBAAY,WAAW;IACrB,KAAK,UAAU;IACf,GAAG,gBAAgB;IACnB,OAAO,YAAY;IACnB,UAAU,eAAe;CAC1B;AAeD,MAAM,MAAM,IAAI,GAAG,YAAY,GAAG,aAAa,GAAG,OAAO,GAAG,OAAO,CA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C;;;;OAIG;;IAuCH;;;OAGG;wBACiB,WAAW;CAyDlC,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC;AAEjD,eAAO,MAAM,KAAK,gBA3IU,WAAW;IA+BnC;;;;OAIG;;IAuCH;;;OAGG;wBACiB,WAAW;CA6DT,CAAC"}
|
package/dist/lib-esm/lvble.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import mixpanel from
|
|
1
|
+
import mixpanel from "mixpanel-browser";
|
|
2
2
|
export var Environment;
|
|
3
3
|
(function (Environment) {
|
|
4
4
|
Environment["Local"] = "local";
|
|
@@ -13,7 +13,7 @@ const envToBaseUrlMapWidget = {
|
|
|
13
13
|
[Environment.Production]: "https://widget.pms.production.nowlvble.com",
|
|
14
14
|
};
|
|
15
15
|
const envToBaseUrlMapExperience = {
|
|
16
|
-
[Environment.Local]: "http://localhost:
|
|
16
|
+
[Environment.Local]: "http://localhost:3001",
|
|
17
17
|
[Environment.Dev]: "https://experience.pms.development.nowlvble.com",
|
|
18
18
|
[Environment.Sandbox]: "https://experience.pms.sandbox.nowlvble.com",
|
|
19
19
|
[Environment.Production]: "https://experience.pms.production.nowlvble.com",
|
|
@@ -53,17 +53,6 @@ class LvbleWidget extends HTMLElement {
|
|
|
53
53
|
});
|
|
54
54
|
this.attachShadow({ mode: "open" });
|
|
55
55
|
}
|
|
56
|
-
get mode() {
|
|
57
|
-
return this.getAttribute("mode");
|
|
58
|
-
}
|
|
59
|
-
set mode(val) {
|
|
60
|
-
if (val) {
|
|
61
|
-
this.setAttribute("mode", val);
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
this.removeAttribute("mode");
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
56
|
get environment() {
|
|
68
57
|
return this.getAttribute("environment");
|
|
69
58
|
}
|
|
@@ -105,94 +94,130 @@ class LvbleWidget extends HTMLElement {
|
|
|
105
94
|
}
|
|
106
95
|
}
|
|
107
96
|
customElements.define("lvble-widget", LvbleWidget);
|
|
108
|
-
const modeWidgetMap = {
|
|
109
|
-
onboarding: customElements.get("lvble-widget"),
|
|
110
|
-
repay: customElements.get("lvble-widget"),
|
|
111
|
-
};
|
|
112
|
-
let _popup;
|
|
113
97
|
let eventListenerLvbleAdded = false;
|
|
114
98
|
let eventListenerOpenAdded = false;
|
|
99
|
+
const createModal = () => {
|
|
100
|
+
const modalIframe = document.createElement("iframe");
|
|
101
|
+
const w = 360;
|
|
102
|
+
const h = 95;
|
|
103
|
+
const t = `calc(50vh + 10px)`;
|
|
104
|
+
const l = `50vw`;
|
|
105
|
+
modalIframe.style.position = "absolute";
|
|
106
|
+
modalIframe.style.top = t;
|
|
107
|
+
modalIframe.style.left = l;
|
|
108
|
+
modalIframe.style.transform = `translate(-50%, -50%)`;
|
|
109
|
+
modalIframe.style.width = `min(95vw, ${w}px)`;
|
|
110
|
+
modalIframe.style.height = `min(${h}vh, 750px)`;
|
|
111
|
+
modalIframe.style.backgroundColor = "white";
|
|
112
|
+
modalIframe.style.borderRadius = "10px";
|
|
113
|
+
modalIframe.style.borderStyle = "solid";
|
|
114
|
+
modalIframe.style.borderColor = "transparent";
|
|
115
|
+
modalIframe.style.borderWidth = "1px";
|
|
116
|
+
// modalIframe.style.padding = "1.5rem";
|
|
117
|
+
const modalBackground = document.createElement("div");
|
|
118
|
+
modalBackground.style.position = "fixed";
|
|
119
|
+
modalBackground.style.top = "0";
|
|
120
|
+
modalBackground.style.left = "0";
|
|
121
|
+
modalBackground.style.height = "100%";
|
|
122
|
+
modalBackground.style.width = "100%";
|
|
123
|
+
modalBackground.style.zIndex = "100";
|
|
124
|
+
modalBackground.style.backgroundColor = "rgba(0, 0, 0, 0.5)";
|
|
125
|
+
return { modalBackground, modalIframe };
|
|
126
|
+
};
|
|
115
127
|
const lvble = (initOptions) => {
|
|
116
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Note: you can only register for onEvent once.
|
|
130
|
+
*/
|
|
131
|
+
if (!initOptions.onEvent) {
|
|
132
|
+
throw new Error("onEvent callback is required");
|
|
133
|
+
}
|
|
134
|
+
if (!initOptions.token) {
|
|
135
|
+
throw new Error("token is required");
|
|
136
|
+
}
|
|
137
|
+
if (!initOptions.environment) {
|
|
138
|
+
throw new Error("environment is required");
|
|
139
|
+
}
|
|
140
|
+
const modeUrlMap = {
|
|
141
|
+
onboarding: `${envToBaseUrlMapExperience[initOptions.environment]}?token=${initOptions.token}`,
|
|
142
|
+
offboarding: `${envToBaseUrlMapExperience[initOptions.environment]}?token=${initOptions.token}`,
|
|
143
|
+
split: `${envToBaseUrlMapExperience[initOptions.environment]}?token=${initOptions.token}`,
|
|
144
|
+
repay: `${envToBaseUrlMapExperience[initOptions.environment]}?token=${initOptions.token}`,
|
|
145
|
+
};
|
|
146
|
+
const { modalBackground, modalIframe } = createModal();
|
|
147
|
+
const l = {
|
|
117
148
|
/**
|
|
118
149
|
* This function creates a widget that can be embedded in your website.
|
|
119
150
|
*
|
|
120
|
-
* @
|
|
121
|
-
* @returns The widget.
|
|
151
|
+
* @returns A lvble widget. Note that it detects mode automagically.
|
|
122
152
|
*/
|
|
123
|
-
|
|
124
|
-
createWidget: (createOptions) => {
|
|
153
|
+
createWidget: () => {
|
|
125
154
|
const widget = new LvbleWidget();
|
|
126
|
-
// (
|
|
127
|
-
// createOptions.mode
|
|
128
|
-
// ? new modeWidgetMap[createOptions.mode]!()
|
|
129
|
-
// : new (customElements.get(
|
|
130
|
-
// "lvble-widget"
|
|
131
|
-
// ) as CustomElementConstructor)()
|
|
132
|
-
// ) as LvbleWidget;
|
|
133
155
|
widget.environment = initOptions.environment;
|
|
134
156
|
widget.token = initOptions.token;
|
|
135
|
-
|
|
157
|
+
modalBackground.appendChild(modalIframe);
|
|
136
158
|
const messageListener = (message) => {
|
|
137
159
|
if (message.origin != envToBaseUrlMapWidget[initOptions.environment]) {
|
|
138
160
|
console.debug(`Received message from unknown origin: ${message.origin}`);
|
|
139
161
|
return;
|
|
140
162
|
}
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
163
|
+
const eventData = message.data;
|
|
164
|
+
if (eventData.eventType === "OPEN_EXPERIENCE_REQUEST") {
|
|
165
|
+
modalIframe.src = `${envToBaseUrlMapExperience[initOptions.environment]}?token=${initOptions.token}`;
|
|
166
|
+
const openOptions = {
|
|
167
|
+
mode: "onboarding", // Replace with the desired mode
|
|
168
|
+
};
|
|
169
|
+
l.open(openOptions);
|
|
170
|
+
}
|
|
145
171
|
};
|
|
146
172
|
if (!eventListenerLvbleAdded) {
|
|
147
173
|
window.addEventListener("message", messageListener);
|
|
148
174
|
eventListenerLvbleAdded = true;
|
|
149
|
-
mixpanel.init(
|
|
175
|
+
mixpanel.init("9ad1530a57a977ab9d4005e2ba11ab4a", { debug: true });
|
|
150
176
|
}
|
|
151
177
|
return widget;
|
|
152
178
|
},
|
|
153
179
|
/**
|
|
154
|
-
* This function opens a
|
|
155
|
-
* @param openOptions The options for opening the
|
|
156
|
-
* @returns undefined.
|
|
180
|
+
* This function opens a modal with the relevant mode.
|
|
181
|
+
* @param openOptions The options for opening the modal. See `OpenOptions` for more information.
|
|
157
182
|
*/
|
|
158
183
|
open: (openOptions) => {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const w = 450;
|
|
169
|
-
const h = 800;
|
|
170
|
-
const l = screen.width / 2 - w / 2;
|
|
171
|
-
const t = screen.height / 2 - h / 2;
|
|
172
|
-
_popup = window.open(modeUrl, "LvblePopup", "width=" + w + ",height=" + h + ",location=no,left=" + l + ",top=" + t);
|
|
184
|
+
if (!openOptions.mode) {
|
|
185
|
+
throw new Error("mode is required");
|
|
186
|
+
}
|
|
187
|
+
const modeUrl = openOptions.mode
|
|
188
|
+
? modeUrlMap[openOptions.mode]
|
|
189
|
+
: `${envToBaseUrlMapExperience[initOptions.environment]}?token=${initOptions.token}`;
|
|
190
|
+
modalIframe.src = modeUrl;
|
|
191
|
+
modalBackground.appendChild(modalIframe);
|
|
192
|
+
document.body.appendChild(modalBackground);
|
|
173
193
|
const messageListener = (message) => {
|
|
174
194
|
if (message.origin != envToBaseUrlMapExperience[initOptions.environment]) {
|
|
175
|
-
console.debug(`Received message from unknown origin: ${message.origin}`);
|
|
195
|
+
console.debug(`Received message from unknown origin: ${message.origin} Expecting only ${envToBaseUrlMapExperience[initOptions.environment]}`);
|
|
176
196
|
return;
|
|
177
197
|
}
|
|
178
198
|
const eventData = message.data;
|
|
199
|
+
if (eventData.eventType === "CLOSE_EXPERIENCE_REQUEST") {
|
|
200
|
+
document.body.removeChild(modalBackground);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
// TODO: Consider using websocket in iframes instead of posting messages to them.
|
|
179
204
|
const iframes = document.querySelectorAll("lvble-widget");
|
|
180
|
-
message = JSON.parse(JSON.stringify(message));
|
|
181
205
|
iframes.forEach((w) => {
|
|
182
206
|
var _a, _b;
|
|
183
207
|
(_b = ((_a = w.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector("iframe")).contentWindow) === null || _b === void 0 ? void 0 : _b.postMessage(eventData, "*");
|
|
184
208
|
});
|
|
185
|
-
mixpanel.track(
|
|
186
|
-
|
|
187
|
-
mixpanel.track(
|
|
209
|
+
mixpanel.track("BEFORE_INVOKE_ON_EVENT", eventData);
|
|
210
|
+
initOptions.onEvent(eventData.eventType, eventData.data);
|
|
211
|
+
mixpanel.track("AFTER_INVOKE_ON_EVENT", eventData);
|
|
188
212
|
};
|
|
189
213
|
if (!eventListenerOpenAdded) {
|
|
190
214
|
window.addEventListener("message", messageListener);
|
|
191
215
|
eventListenerOpenAdded = true;
|
|
192
|
-
mixpanel.init(
|
|
216
|
+
mixpanel.init("9ad1530a57a977ab9d4005e2ba11ab4a", { debug: true });
|
|
193
217
|
}
|
|
194
218
|
},
|
|
195
219
|
};
|
|
220
|
+
return l;
|
|
196
221
|
};
|
|
197
222
|
export const Lvble = lvble;
|
|
198
223
|
//# sourceMappingURL=lvble.js.map
|