@subiz/widget-v4 4.1.136 → 4.1.138

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.
@@ -41,9 +41,6 @@ body div#sbz92 {
41
41
  @import 'base.less';
42
42
 
43
43
  * {
44
- -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
45
- -webkit-tap-highlight-color: transparent;
46
-
47
44
  font-family: @font-family-sans-serif;
48
45
  font-size: @font-size-base;
49
46
 
@@ -302,5 +299,20 @@ body div#sbz92 {
302
299
  pointer-events: none;
303
300
  }
304
301
 
302
+ .form-wrapper.form select.form-control {
303
+ height: 40px;
304
+ }
305
+
306
+ .form-page-preview-noti {
307
+ background: #fef7e0;
308
+ text-align: center;
309
+ border-radius: 6px;
310
+ margin-top: 10px;
311
+ margin-left: 15px;
312
+ margin-right: 15px;
313
+ padding: 8px 12px;
314
+ color: #202122;
315
+ }
316
+
305
317
  @import 'form.less';
306
318
  }
@@ -480,3 +480,7 @@ select {
480
480
  height: 36px;
481
481
  }
482
482
  }
483
+
484
+ select.form-control.form-control--empty {
485
+ .color(@text-muted);
486
+ }
@@ -150,14 +150,19 @@ class Form2 extends _common.Com {
150
150
  let val = _index.default.find(this.props.submission.values, f => f.key === com.key) || {};
151
151
  val = val.value || '""';
152
152
  val = _index.default.parseJSON(val);
153
+ let cls = 'form-control';
154
+ if (this.state.errorFields[com.key]) cls += ' input--error';
155
+ if (!val) cls += ' form-control--empty';
153
156
  return (0, _preact.h)("select", {
154
- class: "form-control",
157
+ class: cls,
155
158
  ref: this[`${com.key}_input`],
156
159
  onChange: e => {
157
160
  this.onChangeValue(com.key, e.target.value);
158
161
  this.clearError(com.key);
159
162
  }
160
- }, _index.default.map(com.input_options, option => {
163
+ }, (0, _preact.h)("option", {
164
+ value: ""
165
+ }, "-- ", this.props.t('no_select'), " --"), _index.default.map(com.input_options, option => {
161
166
  return (0, _preact.h)("option", {
162
167
  value: option.value
163
168
  }, option.label);
@@ -27,7 +27,6 @@ class FormPage extends _common.Com {
27
27
  if (document.fonts.check('normal 16px ' + fonts[i])) {
28
28
  ready[fonts[i]] = true;
29
29
  }
30
- console.log('ready', ready, Object.keys(ready), fonts.length, Object.keys(ready) === fonts.length);
31
30
  if (_index.default.size(Object.keys(ready)) === fonts.length) {
32
31
  return;
33
32
  }
@@ -79,12 +78,16 @@ class FormPage extends _common.Com {
79
78
  let chatbox = _index.default.find(this.props.store.matchPlugin(), plugin => plugin.type === 'chatbox') || {};
80
79
  chatbox = chatbox.chatbox || {};
81
80
  if (this.props.previewJson) {
81
+ this.setState({
82
+ loading: true
83
+ });
82
84
  let json = atob(this.props.previewJson);
83
85
  json = decodeURIComponent(json);
84
86
  json = _index.default.parseJSON(json);
85
87
  await this.insertCss(chatbox, json);
86
88
  this.setState({
87
- formSetting: json
89
+ formSetting: json,
90
+ loading: false
88
91
  });
89
92
  return;
90
93
  }
@@ -172,14 +175,16 @@ class FormPage extends _common.Com {
172
175
  } = this.state;
173
176
  if (loading && !loadError) {
174
177
  return (0, _preact.h)("div", {
175
- class: "h-full w-full d-flex justify-content-center align-items-center"
178
+ class: "h-full w-full d-flex justify-content-center align-items-center",
179
+ key: "loading"
176
180
  }, (0, _preact.h)("div", {
177
181
  class: "text-muted text-xl"
178
182
  }, this.props.t('loading_data'), " ..."));
179
183
  }
180
184
  if (loadError) {
181
185
  return (0, _preact.h)("div", {
182
- class: "h-full w-full d-flex justify-content-center align-items-center"
186
+ class: "h-full w-full d-flex justify-content-center align-items-center",
187
+ key: "error"
183
188
  }, (0, _preact.h)("div", {
184
189
  class: "text-center"
185
190
  }, (0, _preact.h)("div", {
@@ -193,8 +198,11 @@ class FormPage extends _common.Com {
193
198
  }
194
199
  let brandLogo = _index.default.get(formSetting, 'logo.url');
195
200
  return (0, _preact.h)("div", {
196
- class: "form-page-body"
197
- }, (0, _preact.h)("div", {
201
+ class: "form-page-body",
202
+ key: "form"
203
+ }, this.props.previewJson && (0, _preact.h)("div", {
204
+ class: "form-page-preview-noti"
205
+ }, 'Form ở trạng thái xem thử, không ghi nhận phản hồi'), (0, _preact.h)("div", {
198
206
  class: "form-page"
199
207
  }, (0, _preact.h)("div", {
200
208
  class: "form-page-logo-wrapper"
@@ -18,13 +18,21 @@ async function renderForm(form, chatbox, $div) {
18
18
  (0, _preact.render)((0, _preact.h)("div", null, "Loading"), $div);
19
19
  return;
20
20
  }
21
+ const LANG = {
22
+ no_select: 'Chưa chọn',
23
+ cannot_be_empty: 'không thể để trống',
24
+ you_have_submitted_info_successfully: 'Form được gửi thành công',
25
+ no_info_input: 'Chưa nhập'
26
+ };
21
27
  (0, _preact.render)((0, _preact.h)(_Form.default, {
22
28
  mode: "attachment",
29
+ onChangeFormValues: () => {},
30
+ onSubmit: () => {},
23
31
  formSetting: form,
24
32
  submission: {
25
33
  values: []
26
34
  },
27
- t: () => ''
35
+ t: key => LANG[key]
28
36
  }), $div);
29
37
  }
30
38
  async function initCss(chatbox) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subiz/widget-v4",
3
- "version": "4.1.136",
3
+ "version": "4.1.138",
4
4
  "main": "./compiled_src/lib.js",
5
5
  "scripts": {
6
6
  "dev": "npx webpack serve --config webpack.dev.js",
package/src/form/Form.js CHANGED
@@ -169,15 +169,19 @@ export default class Form2 extends Com {
169
169
  let val = sb.find(this.props.submission.values, (f) => f.key === com.key) || {}
170
170
  val = val.value || '""'
171
171
  val = sb.parseJSON(val)
172
+ let cls = 'form-control'
173
+ if (this.state.errorFields[com.key]) cls += ' input--error'
174
+ if (!val) cls += ' form-control--empty'
172
175
  return (
173
176
  <select
174
- class='form-control'
177
+ class={cls}
175
178
  ref={this[`${com.key}_input`]}
176
179
  onChange={(e) => {
177
180
  this.onChangeValue(com.key, e.target.value)
178
181
  this.clearError(com.key)
179
182
  }}
180
183
  >
184
+ <option value=''>-- {this.props.t('no_select')} --</option>
181
185
  {sb.map(com.input_options, (option) => {
182
186
  return <option value={option.value}>{option.label}</option>
183
187
  })}
@@ -35,7 +35,6 @@ export default class FormPage extends Com {
35
35
  if (document.fonts.check('normal 16px ' + fonts[i])) {
36
36
  ready[fonts[i]] = true
37
37
  }
38
- console.log('ready', ready, Object.keys(ready), fonts.length, Object.keys(ready) === fonts.length)
39
38
  if (sb.size(Object.keys(ready)) === fonts.length) {
40
39
  return
41
40
  }
@@ -95,11 +94,12 @@ export default class FormPage extends Com {
95
94
  chatbox = chatbox.chatbox || {}
96
95
 
97
96
  if (this.props.previewJson) {
97
+ this.setState({loading: true})
98
98
  let json = atob(this.props.previewJson)
99
99
  json = decodeURIComponent(json)
100
100
  json = sb.parseJSON(json)
101
101
  await this.insertCss(chatbox, json)
102
- this.setState({formSetting: json})
102
+ this.setState({formSetting: json, loading: false})
103
103
  return
104
104
  }
105
105
  if (this.state.loading) return
@@ -148,14 +148,14 @@ export default class FormPage extends Com {
148
148
  const {formSetting, loading, loadError, submission, errorMessage, isSubmited, submiting} = this.state
149
149
  if (loading && !loadError) {
150
150
  return (
151
- <div class='h-full w-full d-flex justify-content-center align-items-center'>
151
+ <div class='h-full w-full d-flex justify-content-center align-items-center' key='loading'>
152
152
  <div class='text-muted text-xl'>{this.props.t('loading_data')} ...</div>
153
153
  </div>
154
154
  )
155
155
  }
156
156
  if (loadError) {
157
157
  return (
158
- <div class='h-full w-full d-flex justify-content-center align-items-center'>
158
+ <div class='h-full w-full d-flex justify-content-center align-items-center' key='error'>
159
159
  <div class='text-center'>
160
160
  <div class='text-danger text-lg mb-2'>{this.props.t('error_occurs_when_load_data')}</div>
161
161
  <br />
@@ -169,7 +169,10 @@ export default class FormPage extends Com {
169
169
 
170
170
  let brandLogo = sb.get(formSetting, 'logo.url')
171
171
  return (
172
- <div class='form-page-body'>
172
+ <div class='form-page-body' key='form'>
173
+ {this.props.previewJson && (
174
+ <div class='form-page-preview-noti'>{'Form ở trạng thái xem thử, không ghi nhận phản hồi'}</div>
175
+ )}
173
176
  <div class='form-page'>
174
177
  <div class='form-page-logo-wrapper'>
175
178
  <a href={formSetting.brand_url || 'javascript:;'}>
package/src/form.js CHANGED
@@ -5,18 +5,33 @@ import sb from './util/index.js'
5
5
 
6
6
  let loadStatus = ''
7
7
  export default async function renderForm(form, chatbox, $div) {
8
- initCss(chatbox)
9
- if (loadStatus !== 'done') {
10
- render(<div>Loading</div>, $div)
11
- return
12
-
13
- }
14
- render(<Form mode='attachment' formSetting={form} submission={{values: []}} t={() => ''} />, $div)
8
+ initCss(chatbox)
9
+ if (loadStatus !== 'done') {
10
+ render(<div>Loading</div>, $div)
11
+ return
12
+ }
13
+ const LANG = {
14
+ no_select: 'Chưa chọn',
15
+ cannot_be_empty: 'không thể để trống',
16
+ you_have_submitted_info_successfully: 'Form được gửi thành công',
17
+ no_info_input: 'Chưa nhập',
18
+ }
19
+ render(
20
+ <Form
21
+ mode='attachment'
22
+ onChangeFormValues={() => {}}
23
+ onSubmit={() => {}}
24
+ formSetting={form}
25
+ submission={{values: []}}
26
+ t={(key) => LANG[key]}
27
+ />,
28
+ $div,
29
+ )
15
30
  }
16
31
 
17
32
  async function initCss(chatbox) {
18
- if (loadStatus) return
19
- loadStatus = 'loadiing'
33
+ if (loadStatus) return
34
+ loadStatus = 'loadiing'
20
35
  let css = (await promiseMainCSS).default.default.toString()
21
36
  let outcss = sb.replaceCssVariable(css, chatbox)
22
37
 
@@ -26,5 +41,5 @@ async function initCss(chatbox) {
26
41
  $cssStyleDiv.id = 'subiz-style-for-form'
27
42
 
28
43
  sb.setCss('form', $cssStyleDiv, outcss)
29
- loadStatus = 'done'
44
+ loadStatus = 'done'
30
45
  }