@subiz/widget-v4 4.1.125 → 4.1.129

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 (89) hide show
  1. package/assets/less/avatar.less +7 -3
  2. package/assets/less/chatbox.less +25 -2
  3. package/assets/less/form.less +77 -2
  4. package/assets/less/message.less +4 -0
  5. package/assets/less/widget.less +20 -0
  6. package/assets/less/widget_header.less +27 -7
  7. package/compiled_src/chatbox/ChatButton.js +22 -7
  8. package/compiled_src/chatbox/ConnectionStatus.js +58 -0
  9. package/compiled_src/chatbox/Event.js +10 -8
  10. package/compiled_src/chatbox/FormAttachment2.js +80 -0
  11. package/compiled_src/chatbox/Header.js +12 -1
  12. package/compiled_src/chatbox/Widget.js +5 -0
  13. package/compiled_src/form/Form.js +274 -0
  14. package/compiled_src/form/FormPage.js +131 -0
  15. package/compiled_src/form/index.js +72 -0
  16. package/compiled_src/store/api.js +3 -0
  17. package/compiled_src/store/realtime_fake.js +4 -0
  18. package/compiled_src/store/store.js +25 -0
  19. package/compiled_src/util/campaign.js +3 -5
  20. package/compiled_src/util/common.js +15 -0
  21. package/dist/127.js +273 -0
  22. package/dist/132.js +2575 -6434
  23. package/dist/185.js +1885 -0
  24. package/dist/1967c022bc1.127.js +1 -0
  25. package/dist/1967c022bc1.132.js +1 -0
  26. package/dist/1967c022bc1.185.js +1 -0
  27. package/dist/1967c022bc1.27.js +1 -0
  28. package/dist/1967c022bc1.278.js +1 -0
  29. package/dist/1967c022bc1.459.js +1 -0
  30. package/dist/1967c022bc1.490.js +1 -0
  31. package/dist/1967c022bc1.74.js +1 -0
  32. package/dist/1967c022bc1.997.js +1 -0
  33. package/dist/1967c022bc1.app.js +1 -0
  34. package/dist/1967c022bc1.form.html +1 -0
  35. package/dist/1967c022bc1.form.js +1 -0
  36. package/dist/{18a02a9c54e.index.html → 1967c022bc1.index.html} +28 -4
  37. package/dist/{18a02a9c54e.library.html → 1967c022bc1.library.html} +28 -4
  38. package/dist/1967c022bc1.library.js +1 -0
  39. package/dist/{18a02a9c54e.preview.html → 1967c022bc1.preview.html} +1 -1
  40. package/dist/1967c022bc1.preview.js +1 -0
  41. package/dist/1967c022bc1.webview.js +1 -0
  42. package/dist/27.js +107 -0
  43. package/dist/278.js +406 -0
  44. package/dist/459.js +107 -0
  45. package/dist/{605.js → 490.js} +82 -82
  46. package/dist/{335.js → 74.js} +35 -35
  47. package/dist/{678.js → 997.js} +6 -6
  48. package/dist/HASH +1 -1
  49. package/dist/assets/img/{subiz-mono.877e9f5.svg → subiz-mono.8fbc067.svg} +1 -1
  50. package/dist/malicious-app.js +6 -4
  51. package/dist/screenshoot.html +1 -1
  52. package/dist/screenshoot.js +10133 -5182
  53. package/form.html +10 -0
  54. package/package.json +5 -4
  55. package/src/chatbox/ChatButton.js +22 -9
  56. package/src/chatbox/ConnectionStatus.js +42 -0
  57. package/src/chatbox/Event.js +10 -10
  58. package/src/chatbox/FormAttachment2.js +58 -0
  59. package/src/chatbox/Header.js +15 -0
  60. package/src/chatbox/Widget.js +2 -0
  61. package/src/form/Form.js +293 -0
  62. package/src/form/FormPage.js +95 -0
  63. package/src/form/index.js +79 -0
  64. package/src/store/api.js +8 -0
  65. package/src/store/realtime_fake.js +8 -4
  66. package/src/store/store.js +29 -0
  67. package/src/util/campaign.js +3 -5
  68. package/src/util/common.js +16 -0
  69. package/webpack.dev.js +2 -0
  70. package/webpack.prod.js +7 -0
  71. package/dist/178.js +0 -406
  72. package/dist/18a02a9c54e.132.js +0 -1
  73. package/dist/18a02a9c54e.178.js +0 -1
  74. package/dist/18a02a9c54e.213.js +0 -1
  75. package/dist/18a02a9c54e.335.js +0 -1
  76. package/dist/18a02a9c54e.362.js +0 -1
  77. package/dist/18a02a9c54e.441.js +0 -1
  78. package/dist/18a02a9c54e.605.js +0 -1
  79. package/dist/18a02a9c54e.678.js +0 -1
  80. package/dist/18a02a9c54e.782.js +0 -1
  81. package/dist/18a02a9c54e.app.js +0 -1
  82. package/dist/18a02a9c54e.library.js +0 -1
  83. package/dist/18a02a9c54e.preview.js +0 -1
  84. package/dist/18a02a9c54e.screenshoot.js +0 -1
  85. package/dist/18a02a9c54e.webview.js +0 -1
  86. package/dist/213.js +0 -2780
  87. package/dist/362.js +0 -107
  88. package/dist/441.js +0 -2855
  89. package/dist/782.js +0 -107
@@ -0,0 +1,274 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _common = require("../common.js");
8
+ var _preact = require("preact");
9
+ var _index = _interopRequireDefault(require("../util/index.js"));
10
+ var _block = _interopRequireDefault(require("../chatbox/block.js"));
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
13
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
14
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
15
+ class Form2 extends _common.Com {
16
+ constructor(props) {
17
+ super(props);
18
+ _defineProperty(this, "state", {
19
+ errorFields: {},
20
+ submiting: false
21
+ });
22
+ _defineProperty(this, "renderFormComponent", (com, idx) => {
23
+ if (com.type === 'input') return this.renderField(com, idx);
24
+ if (com.type === 'button') return this.renderSubmitButton(com, idx);
25
+ if (this.props.isSubmited) return;
26
+ return (0, _preact.h)("div", {
27
+ class: "form-component form-component-block"
28
+ }, (0, _preact.h)(_block.default, {
29
+ block: com
30
+ }));
31
+ });
32
+ _defineProperty(this, "renderSubmitButton", (com, idx) => {
33
+ if (this.props.isSubmited) return;
34
+ return (0, _preact.h)("div", {
35
+ class: "form-component form-component-submit-button"
36
+ }, (0, _preact.h)("div", {
37
+ class: "form-control--valid-input--error"
38
+ }, this.props.errorMessage), (0, _preact.h)("div", null, (0, _preact.h)("button", {
39
+ class: "btn--start-convo",
40
+ disabled: this.props.submiting
41
+ }, com.label)));
42
+ });
43
+ _defineProperty(this, "renderField", (com, idx) => {
44
+ let errorMsg = this.state.errorFields[com.key];
45
+ if (this.props.isSubmited) {
46
+ let val = _index.default.find(this.props.submission.values, f => f.key === com.key) || {};
47
+ val = val.value || '""';
48
+ val = _index.default.parseJSON(val);
49
+ if (Array.isArray(val)) val = val.join(', ');
50
+ return (0, _preact.h)("div", {
51
+ class: "form-component submitted",
52
+ key: com.key
53
+ }, (0, _preact.h)("label", {
54
+ class: "label"
55
+ }, com.label), (0, _preact.h)("div", null, val || (0, _preact.h)("span", {
56
+ class: "text-muted text-italic"
57
+ }, this.props.t('no_info_input'))));
58
+ }
59
+ return (0, _preact.h)("div", {
60
+ class: "form-component",
61
+ key: com.key
62
+ }, (0, _preact.h)("label", {
63
+ class: "label"
64
+ }, com.label, " ", com.is_required && (0, _preact.h)("span", {
65
+ class: "red"
66
+ }, "*")), com.input_type === 'text' && this.renderFieldTextInput(com, idx), com.input_type === 'multiple' && this.renderFieldTextareaInput(com, idx), com.input_type === 'date' && this.renderFieldDateInput(com, idx), com.input_type === 'radio' && this.renderFieldRadioInput(com, idx), com.input_type === 'checkbox' && this.renderFieldCheckboxInput(com, idx), com.input_type === 'dropdown' && this.renderFieldDropdownInput(com, idx), errorMsg && (0, _preact.h)("div", {
67
+ class: "form-control--valid-input--error"
68
+ }, errorMsg));
69
+ });
70
+ _defineProperty(this, "renderFieldTextInput", (com, idx) => {
71
+ let cls = 'form-control';
72
+ if (this.state.errorFields[com.key]) cls = 'form-control input--error';
73
+ let val = _index.default.find(this.props.submission.values, f => f.key === com.key) || {};
74
+ val = val.value || '""';
75
+ val = _index.default.parseJSON(val);
76
+ return (0, _preact.h)("input", {
77
+ ref: this[`${com.key}_input`],
78
+ type: "text",
79
+ class: cls,
80
+ placeholder: com.placeholder,
81
+ value: val,
82
+ onInput: e => {
83
+ this.onChangeValue(com.key, e.target.value);
84
+ this.clearError(com.key);
85
+ }
86
+ });
87
+ });
88
+ _defineProperty(this, "renderFieldDateInput", (com, idx) => {
89
+ let val = _index.default.find(this.props.submission.values, f => f.key === com.key) || {};
90
+ val = val.value || '""';
91
+ val = _index.default.parseJSON(val);
92
+ return (0, _preact.h)("input", {
93
+ ref: this[`${com.key}_input`],
94
+ class: "form-control",
95
+ type: "date",
96
+ value: val,
97
+ onInput: e => {
98
+ this.onChangeValue(com.key, e.target.value);
99
+ this.clearError(com.key);
100
+ }
101
+ });
102
+ });
103
+ _defineProperty(this, "renderFieldRadioInput", (com, idx) => {
104
+ let val = _index.default.find(this.props.submission.values, f => f.key === com.key) || {};
105
+ val = val.value || '""';
106
+ val = _index.default.parseJSON(val);
107
+ return _index.default.map(com.input_options, (option, oidx) => {
108
+ let id = com.key + '_' + oidx;
109
+ return (0, _preact.h)("div", {
110
+ class: "radio"
111
+ }, (0, _preact.h)("input", {
112
+ type: "radio",
113
+ name: com.key,
114
+ id: id,
115
+ checked: option.value === val,
116
+ onChange: () => this.toggleRadioField(com.key, option.value)
117
+ }), (0, _preact.h)("label", {
118
+ class: "radio--label",
119
+ for: id
120
+ }, option.label), (0, _preact.h)("div", {
121
+ class: "radio--check"
122
+ }));
123
+ });
124
+ });
125
+ _defineProperty(this, "renderFieldCheckboxInput", (com, idx) => {
126
+ let val = _index.default.find(this.props.submission.values, f => f.key === com.key) || {};
127
+ val = val.value || '[]';
128
+ val = _index.default.parseJSON(val);
129
+ return _index.default.map(com.input_options, (option, oidx) => {
130
+ let id = com.key + '_' + oidx;
131
+ return (0, _preact.h)("div", {
132
+ class: "checkbox"
133
+ }, (0, _preact.h)("input", {
134
+ type: "checkbox",
135
+ name: com.key,
136
+ id: id,
137
+ checked: val.includes(option.value),
138
+ onChange: () => this.toggleCheckboxField(com.key, option.value)
139
+ }), (0, _preact.h)("label", {
140
+ class: "checkbox--label",
141
+ for: id
142
+ }, option.label), (0, _preact.h)("div", {
143
+ class: "checkbox--check"
144
+ }));
145
+ });
146
+ });
147
+ _defineProperty(this, "renderFieldDropdownInput", (com, idx) => {
148
+ let val = _index.default.find(this.props.submission.values, f => f.key === com.key) || {};
149
+ val = val.value || '""';
150
+ val = _index.default.parseJSON(val);
151
+ return (0, _preact.h)("select", {
152
+ class: "form-control",
153
+ ref: this[`${com.key}_input`],
154
+ onChange: e => {
155
+ this.onChangeValue(com.key, e.target.value);
156
+ this.clearError(com.key);
157
+ }
158
+ }, _index.default.map(com.input_options, option => {
159
+ return (0, _preact.h)("option", {
160
+ value: option.value
161
+ }, option.label);
162
+ }));
163
+ });
164
+ _defineProperty(this, "renderFieldTextareaInput", (com, idx) => {
165
+ let val = _index.default.find(this.props.submission.values, f => f.key === com.key) || {};
166
+ val = val.value || '""';
167
+ val = _index.default.parseJSON(val);
168
+ return (0, _preact.h)("textarea", {
169
+ onInput: e => {
170
+ this.onChangeValue(com.key, e.target.value);
171
+ this.clearError(com.key);
172
+ },
173
+ ref: this[`${com.key}_input`],
174
+ rows: "3",
175
+ class: "form-control",
176
+ placeholder: com.placeholder
177
+ });
178
+ });
179
+ _defineProperty(this, "onSubmit", e => {
180
+ e.preventDefault();
181
+ if (!this.validateForm()) return;
182
+ this.props.onSubmit();
183
+ });
184
+ _defineProperty(this, "validateForm", () => {
185
+ let result = true;
186
+ let ref = '';
187
+ let errors = {};
188
+ let components = _index.default.get(this.props.formSetting, 'components') || [];
189
+ _index.default.each(components, com => {
190
+ if (com.type === 'input') {
191
+ if (com.is_required) {
192
+ let val = _index.default.find(this.props.submission.values, f => f.key === com.key) || {};
193
+ val = val.value || '""';
194
+ val = _index.default.parseJSON(val);
195
+ if (typeof val === 'string' && !val.trim()) {
196
+ result = false;
197
+ errors[com.key] = this.props.t('cannot_be_empty');
198
+ if (!ref && com.input_type !== 'checkbox' && com.input_type !== 'radio') ref = `${com.key}_input`;
199
+ }
200
+ if (Array.isArray(val) && val.length === 0) {
201
+ result = false;
202
+ errors[com.key] = this.props.t('cannot_be_empty');
203
+ }
204
+ }
205
+ }
206
+ });
207
+ if (ref && this[ref] && this[ref].current) {
208
+ this[ref].current.focus();
209
+ }
210
+ this.setState({
211
+ errorFields: errors
212
+ });
213
+ return result;
214
+ });
215
+ _defineProperty(this, "onChangeValue", (key, v) => {
216
+ let formValues = _index.default.get(this.props.submission, 'values') || [];
217
+ let f = _index.default.find(formValues, field => field.key === key);
218
+ if (!f) {
219
+ formValues.push({
220
+ key,
221
+ value: JSON.stringify(v)
222
+ });
223
+ } else {
224
+ f.value = JSON.stringify(v);
225
+ }
226
+ this.props.onChangeFormValues(formValues);
227
+ });
228
+ _defineProperty(this, "clearError", key => {
229
+ let errors = this.state.errorFields;
230
+ errors[key] = '';
231
+ this.setState({
232
+ errorFields: errors
233
+ });
234
+ });
235
+ let _components = _index.default.get(this.props.formSetting, 'components') || [];
236
+ _index.default.each(_components, com => {
237
+ if (com.type === 'input' && com.input_type !== 'checkbox' && com.input_type !== 'radio') {
238
+ this[`${com.key}_input`] = (0, _preact.createRef)();
239
+ }
240
+ });
241
+ }
242
+ toggleRadioField(key, v) {
243
+ this.clearError(key);
244
+ this.onChangeValue(key, v);
245
+ }
246
+ toggleCheckboxField(key, v) {
247
+ let currentValues = _index.default.find(this.props.submission.values, f => f.key === key) || {};
248
+ currentValues = currentValues.value || '[]';
249
+ currentValues = _index.default.parseJSON(currentValues);
250
+ if (currentValues.includes(v)) {
251
+ currentValues = currentValues.filter(s => s !== v);
252
+ } else {
253
+ currentValues.push(v);
254
+ }
255
+ this.clearError(key);
256
+ this.onChangeValue(key, currentValues);
257
+ }
258
+ render() {
259
+ let components = _index.default.get(this.props.formSetting, 'components') || [];
260
+ let title = _index.default.get(this.props.formSetting, 'title') || '';
261
+ let cls = 'form-wrapper form';
262
+ if (this.props.mode === 'attachment') cls += ' form-wrapper-attachment';
263
+ return (0, _preact.h)("div", {
264
+ class: cls
265
+ }, this.props.isSubmited && (0, _preact.h)("div", {
266
+ class: "form-component"
267
+ }, this.props.t('you_have_submitted_info_successfully')), (0, _preact.h)("form", {
268
+ onSubmit: this.onSubmit
269
+ }, (0, _preact.h)("div", {
270
+ class: "form-component form-component-block"
271
+ }, title), _index.default.map(components, this.renderFormComponent)));
272
+ }
273
+ }
274
+ exports.default = Form2;
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _common = require("../common.js");
8
+ var _preact = require("preact");
9
+ var _Form = _interopRequireDefault(require("./Form.js"));
10
+ var _index = _interopRequireDefault(require("../util/index.js"));
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
13
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
14
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
15
+ class FormPage extends _common.Com {
16
+ constructor(props) {
17
+ super(props);
18
+ _defineProperty(this, "fetchFormSetting", async () => {
19
+ if (this.state.loading) return;
20
+ this.setState({
21
+ loading: true
22
+ });
23
+ let res = await this.props.store.checkFormToken(this.props.token);
24
+ if (res.error) {
25
+ this.setState({
26
+ loading: false,
27
+ loadError: true
28
+ });
29
+ return;
30
+ }
31
+ let formSetting = _index.default.get(res, 'body.form') || {};
32
+ let submission = _index.default.get(res, 'body.submission') || {};
33
+ let isSubmited = _index.default.size(submission) > 0;
34
+ this.setState({
35
+ loading: false,
36
+ loadError: false,
37
+ formSetting,
38
+ submission,
39
+ isSubmited
40
+ });
41
+ });
42
+ _defineProperty(this, "onChangeFormValues", values => {
43
+ this.setState({
44
+ submission: {
45
+ values
46
+ }
47
+ });
48
+ });
49
+ _defineProperty(this, "onSubmit", async () => {
50
+ this.setState({
51
+ errorMessage: ''
52
+ });
53
+ if (this.state.submiting) return;
54
+ this.setState({
55
+ submiting: true
56
+ });
57
+ let res = await this.props.store.submitForm2(this.props.token, this.state.submission);
58
+ if (res.error) {
59
+ this.setState({
60
+ submiting: false,
61
+ errorMessage: _index.default.get(res, 'error.code')
62
+ });
63
+ return;
64
+ }
65
+ this.setState({
66
+ submiting: false,
67
+ isSubmited: true
68
+ });
69
+ });
70
+ this.state = {
71
+ submission: {},
72
+ formSetting: {},
73
+ submiting: false,
74
+ errorMessage: '',
75
+ isSubmited: false,
76
+ loading: false,
77
+ loadError: ''
78
+ };
79
+ }
80
+ componentDidMount() {
81
+ this.fetchFormSetting();
82
+ }
83
+ render() {
84
+ const {
85
+ formSetting,
86
+ loading,
87
+ loadError,
88
+ submission,
89
+ errorMessage,
90
+ isSubmited,
91
+ submiting
92
+ } = this.state;
93
+ if (loading && !loadError) {
94
+ return (0, _preact.h)("div", {
95
+ class: "h-full w-full d-flex justify-content-center align-items-center"
96
+ }, (0, _preact.h)("div", {
97
+ class: "text-muted text-xl"
98
+ }, this.props.t('loading_data'), " ..."));
99
+ }
100
+ if (loadError) {
101
+ return (0, _preact.h)("div", {
102
+ class: "h-full w-full d-flex justify-content-center align-items-center"
103
+ }, (0, _preact.h)("div", {
104
+ class: "text-center"
105
+ }, (0, _preact.h)("div", {
106
+ class: "text-danger text-lg mb-2"
107
+ }, this.props.t('error_occurs_when_load_data')), (0, _preact.h)("br", null), (0, _preact.h)("button", {
108
+ disabled: loading,
109
+ type: "button",
110
+ class: "btn--start-convo",
111
+ onClick: this.fetchFormSetting
112
+ }, this.props.t('try_again'))));
113
+ }
114
+ return (0, _preact.h)("div", {
115
+ class: "form-page"
116
+ }, (0, _preact.h)("div", {
117
+ class: "form-page-header"
118
+ }, 'HEADER'), (0, _preact.h)(_Form.default, {
119
+ store: this.props.store,
120
+ formSetting: formSetting,
121
+ t: this.props.t,
122
+ submission: submission,
123
+ errorMessage: errorMessage,
124
+ isSubmited: isSubmited,
125
+ submiting: submiting,
126
+ onChangeFormValues: this.onChangeFormValues,
127
+ onSubmit: this.onSubmit
128
+ }));
129
+ }
130
+ }
131
+ exports.default = FormPage;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ var _store = _interopRequireDefault(require("../store/store.js"));
4
+ var common = _interopRequireWildcard(require("../common.js"));
5
+ var _index = _interopRequireDefault(require("../util/index.js"));
6
+ var _preact = require("preact");
7
+ var _FormPage = _interopRequireDefault(require("./FormPage.js"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
+ let promiseMainCSS = (() => Promise.resolve().then(() => _interopRequireWildcard(require('../chatbox/css.js'))))();
12
+ const config = require('../../config.js');
13
+ function findChatbox(store) {
14
+ let pluginM = store.matchPlugin();
15
+ let chatboxs = _index.default.filter(pluginM, plugin => plugin.type === 'chatbox');
16
+ if (_index.default.size(chatboxs) === 0) {
17
+ console.error('no chatbox found.');
18
+ return;
19
+ }
20
+ return chatboxs[0];
21
+ }
22
+ function getUrlParameter(name) {
23
+ name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
24
+ var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
25
+ var results = regex.exec(location.search);
26
+ return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
27
+ }
28
+ var $link = document.createElement('link');
29
+ $link.href = 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap';
30
+ $link.rel = 'stylesheet';
31
+ document.head.append($link);
32
+ _index.default.preloadWebfonts(['Inter'], [400, 500]);
33
+ async function load() {
34
+ let store = new _store.default(config.ApiURL, config.FileURL, config.RealtimeURL, true);
35
+ window.store = store;
36
+ let accid = getUrlParameter('id') || getUrlParameter('acc_id') || getUrlParameter('account_id') || 'acqsulrowbxiugvginhw';
37
+ let mask = accid + '@' + 'abcd';
38
+ let token = getUrlParameter('token');
39
+ await store.init(accid, mask);
40
+ let acc = store.matchAccount() || {};
41
+ let plugin = findChatbox(store) || {};
42
+ let css = (await promiseMainCSS).default.default.toString();
43
+ var outcss = _index.default.replaceCssVariable(css, plugin.chatbox);
44
+ let $cssStyleDiv = document.createElement('style');
45
+ document.head.appendChild($cssStyleDiv);
46
+ $cssStyleDiv.type = 'text/css';
47
+ $cssStyleDiv.id = 'subiz-style-for-order';
48
+ _index.default.setCss('form', $cssStyleDiv, outcss);
49
+ let t = key => {
50
+ if (_locale === 'debug') return `{{${key}}}`;
51
+ let messages = _index.default.get(common.langMessages, _locale, []);
52
+ let message = _index.default.find(messages, message => message.key === key);
53
+ return _index.default.get(message, 'message', key);
54
+ };
55
+ let _locale = plugin.locale || acc.locale || 'vi-VN';
56
+ t.i18n = i18nText => {
57
+ if (!i18nText) return '';
58
+ let fallbackLocale = plugin.locale || acc.locale || 'vi-VN';
59
+ fallbackLocale = fallbackLocale.replace('-', '_');
60
+ let locale = _locale.replace('-', '_');
61
+ return i18nText[locale] || i18nText[fallbackLocale];
62
+ };
63
+ t.locale = () => _locale;
64
+ common.downloadLanguage(store, _locale).then(() => {
65
+ (0, _preact.render)((0, _preact.h)(_FormPage.default, {
66
+ store: store,
67
+ t: t,
68
+ token: token
69
+ }), document.getElementById('form'));
70
+ });
71
+ }
72
+ load();
@@ -110,6 +110,8 @@ class _default {
110
110
  _defineProperty(this, "list_provinces", () => this.apireq.get(`/accounts/${this.accid}/provinces`));
111
111
  _defineProperty(this, "list_districts", p => this.apireq.setQuery(p).get(`/accounts/${this.accid}/districts`));
112
112
  _defineProperty(this, "list_wards", p => this.apireq.setQuery(p).get(`/accounts/${this.accid}/wards`));
113
+ _defineProperty(this, "checkFormToken", token => this.api41.get(`/submissions/${token}`));
114
+ _defineProperty(this, "submitForm2", (token, data) => this.api41.post(`/submissions/${token}`, data));
113
115
  _defineProperty(this, "suggest_address", keyword => this.apireq.setQuery({
114
116
  keyword: keyword
115
117
  }).get(`/accounts/${this.accid}/addresses`));
@@ -117,6 +119,7 @@ class _default {
117
119
  this.refreshLock = new _index.default.Mutex();
118
120
  this.FileURL = FileURL;
119
121
  this.ApiURL = ApiURL;
122
+ this.api41 = ajax.setBaseUrl('https://api5.subiz.com.vn/4.1').withCredentials(true).setContentType('text/plain').beforeHook(jsonifyTextPlain).setParser('json');
120
123
  this.apireq = ajax.setBaseUrl(ApiURL).withCredentials(true).addQuery('v', '6').setContentType('text/plain').beforeHook(jsonifyTextPlain).setParser('json').beforeHook((param, done) => {
121
124
  if (this.token_generator) {
122
125
  let user_id = this.profile_id;
@@ -9,5 +9,9 @@ class _default {
9
9
  onInterrupted() {}
10
10
  subscribe() {}
11
11
  stop() {}
12
+ getStatus() {
13
+ return 'active';
14
+ }
15
+ reconnect() {}
12
16
  }
13
17
  exports.default = _default;
@@ -27,6 +27,7 @@ class Store {
27
27
  constructor(ApiURL, FileURL, RealtimeURL, inmem, fakeapi) {
28
28
  _defineProperty(this, "inmem", false);
29
29
  _defineProperty(this, "cookie", cookie);
30
+ _defineProperty(this, "getConnectionStatus", () => this.connectionStatus);
30
31
  _defineProperty(this, "_currentViewingProduct", {});
31
32
  _defineProperty(this, "new_visitor", true);
32
33
  _defineProperty(this, "matchUser", () => {
@@ -134,6 +135,8 @@ class Store {
134
135
  _defineProperty(this, "matchIsOpen", () => !!this.kv.match('isopen'));
135
136
  _defineProperty(this, "matchHasManuallyClosed", () => !!this.kv.match('hasManuallyClosed'));
136
137
  _defineProperty(this, "matchClosePreviewAt", () => this.kv.match('close_preview_at') || 0);
138
+ _defineProperty(this, "checkFormToken", token => this.api.checkFormToken(token));
139
+ _defineProperty(this, "submitForm2", (token, data) => this.api.submitForm2(token, data));
137
140
  _defineProperty(this, "sendPresence", _index.default.throttle(async () => {
138
141
  if (this._die) return dieErr;
139
142
  await this.readyGate.entry();
@@ -160,6 +163,7 @@ class Store {
160
163
  this.seenQueue.push(id);
161
164
  });
162
165
  _defineProperty(this, "onUpdate", (o, cb) => this.pubsub.on2(o, 'account', cb));
166
+ _defineProperty(this, "onConnection", (o, cb) => this.pubsub.on2(o, 'connection', cb));
163
167
  _defineProperty(this, "onResetCSS", (o, cb) => this.pubsub.on2(o, 'resetCSS', cb));
164
168
  _defineProperty(this, "onHighlight", (o, cb) => this.pubsub.on2(o, 'highlight', cb));
165
169
  _defineProperty(this, "setHasManuallyClosed", () => this.kv.put('hasManuallyClosed', true));
@@ -181,6 +185,9 @@ class Store {
181
185
  });
182
186
  });
183
187
  _defineProperty(this, "timeDiff", 0);
188
+ this.connectionStatus = 'active';
189
+ this.CONNECTION_CHECK_INTERVAL = 3000;
190
+ this.reconnectTimestamp = 0;
184
191
  this.g_sync = {};
185
192
  this._die = false;
186
193
  this.forceDevice = null;
@@ -267,6 +274,23 @@ class Store {
267
274
  }
268
275
  }, 2000);
269
276
  }
277
+ async loopCheckConnectionStatus() {
278
+ while (true) {
279
+ if (this._die) break;
280
+ await _index.default.sleep(this.CONNECTION_CHECK_INTERVAL);
281
+ if (!this.realtime) continue;
282
+ if (!this.realtime.getStatus || !this.realtime.reconnect) continue;
283
+ if (this.connectionStatus === 'dead') {
284
+ await this.realtime.reconnect();
285
+ }
286
+ let currentStatus = this.connectionStatus;
287
+ this.connectionStatus = this.realtime.getStatus();
288
+ if (currentStatus !== this.connectionStatus) {
289
+ console.log('publish connectionStatus', this.connectionStatus);
290
+ this.pubsub.publish('connection');
291
+ }
292
+ }
293
+ }
270
294
  linkProduct(p) {
271
295
  if (!p) {
272
296
  this._currentViewingProduct = {};
@@ -445,6 +469,7 @@ class Store {
445
469
  });
446
470
  this.readyGate.open();
447
471
  this.reconnectWs(accid, user.id);
472
+ this.loopCheckConnectionStatus();
448
473
  return user;
449
474
  }
450
475
  async login(accid, user_id, tokenGenerator) {
@@ -56,10 +56,7 @@ function trackInactivity(seconds = 0, cb) {
56
56
  document.addEventListener(ev, resetTime, false);
57
57
  }
58
58
  }
59
- let timeOnPage = 0;
60
- common.setInterval(() => {
61
- timeOnPage += 5;
62
- }, 5000);
59
+ let _pageLoaded = common.Date.now();
63
60
  function trackTimeOnPage(seconds = 0, cb) {
64
61
  if (seconds < 1) {
65
62
  return common.setTimeout(function () {
@@ -67,10 +64,11 @@ function trackTimeOnPage(seconds = 0, cb) {
67
64
  }, 100);
68
65
  }
69
66
  let timer = common.setInterval(() => {
67
+ let timeOnPage = (common.Date.now() - _pageLoaded) / 1000;
70
68
  if (timeOnPage < seconds) return;
71
69
  if (cb) cb(timeOnPage);
72
70
  common.clearInterval(timer);
73
- }, 1000);
71
+ }, 200);
74
72
  }
75
73
  function on(eventName, selector, fn) {
76
74
  document.addEventListener(eventName, function (event) {
@@ -31,6 +31,7 @@ exports.getUrlParameter = getUrlParameter;
31
31
  exports.getUserAttr = getUserAttr;
32
32
  exports.hslToRgb = hslToRgb;
33
33
  exports.includes = includes;
34
+ exports.isBlockEmpty = isBlockEmpty;
34
35
  exports.isConvoSeen = isConvoSeen;
35
36
  exports.isEmail = isEmail;
36
37
  exports.isNumber = isNumber;
@@ -1214,6 +1215,20 @@ const ALL_CURRENCIES = [{
1214
1215
  function blockToText(block) {
1215
1216
  return _blockToText(block).trim();
1216
1217
  }
1218
+ function isBlockEmpty(block) {
1219
+ return _isBlockEmpty(block);
1220
+ }
1221
+ function _isBlockEmpty(block = {}) {
1222
+ if (!size(block.content)) {
1223
+ if ((block.text || '').trim()) return false;
1224
+ return true;
1225
+ }
1226
+ let result = true;
1227
+ map(block.content, content => {
1228
+ result = result && _isBlockEmpty(content);
1229
+ });
1230
+ return result;
1231
+ }
1217
1232
  function _blockToText(block) {
1218
1233
  if (!block || !block.type) return '';
1219
1234
  let out = '';