beyond-rails 0.0.263 → 0.0.264

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/src/js/components/TagInput.js +30 -16
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c68a62a7a7cb119c6c0b31ec428dca33fd34fafd15f78a57351a5f504c39bb54
4
- data.tar.gz: 936f0f2f04b0340ac662e096688d517165628bbcd8bcd97d31c37c935f06a844
3
+ metadata.gz: c50569e664c1fcbed09ffbded0db57abcf311f9a04254dbd772cefbaafe04c2e
4
+ data.tar.gz: e2dc759c9069a62eb43b65864469b865f6812c7447772fc91e20531058746c25
5
5
  SHA512:
6
- metadata.gz: 4540fa5e0475f803440896c5506207749ed03c85d84422a3640e1511fc1bec599b8f1914d7d0d1f678dee1aecf0b017870074f240ec61854d030871e3dc364cc
7
- data.tar.gz: f5e971151429d2113f35ec0fcc7c89250d16571470a8ca534a8d0729f29016caa859556fe2b2555840755e900e3797f5cc0a5241e7ad6177baa169d34c3fa173
6
+ metadata.gz: 0b84f7ff5b00eb96a30fd9baf13b91be6e22dd10e3f521d89b33ba6e2b2dd403dceec22db65cf730bf78800a8596b15fdf9f69a7e1f79606e02e3aa551156cb8
7
+ data.tar.gz: 9bc478bdf05fe67768bddea72550587d0b5964ef2b20078a0779bd57a7c3bf239ad807cd361bb5dc2c71ce6fa7b25f5ac1ea18af26fea211d74a742649512314
@@ -12,7 +12,6 @@ export default class TagInput {
12
12
  this.validate = options.validate || (() => ({ isTag: true }))
13
13
  this.suggest = options.suggest || noop
14
14
  this.change = options.change || noop
15
- this.remove = options.remove || noop
16
15
  this.isComposing = false
17
16
  this.raf = raf
18
17
  this.id = 0
@@ -69,11 +68,11 @@ export default class TagInput {
69
68
  return nextWidth
70
69
  }
71
70
 
72
- shake() {
71
+ shake(duration = 500) {
73
72
  this.dom.classList.add('shake')
74
73
  setTimeout(() => {
75
74
  this.dom.classList.remove('shake')
76
- }, 500)
75
+ }, duration)
77
76
  }
78
77
 
79
78
  setTagAttrs(id, rows = [], options = {}) {
@@ -108,50 +107,63 @@ export default class TagInput {
108
107
  }
109
108
  }
110
109
 
111
- getTag(inputValue, options = {}) {
110
+ getTag(row) {
112
111
 
113
112
  this.id += 1
114
113
 
115
114
  const id = this.id
116
- const classname = options.classname ? ` ${options.classname}` : ''
115
+ const classname = row.classname ? ` ${row.classname}` : ''
117
116
  const tag = document.createElement('div')
118
117
 
119
118
  tag.className = 'tag' + classname
120
- tag.textContent = inputValue
119
+ tag.textContent = row.text
121
120
 
122
121
  const btn = document.createElement('button')
123
122
  btn.type = 'button'
124
123
 
125
124
  // https://wesbos.com/times-html-entity-close-button
126
125
  btn.textContent = '×'
127
- const handleBtnClick = () => {
126
+ const handleBtnClick = event => {
128
127
  this.tags = this.tags.filter(row => row.elem !== tag)
129
128
  btn.removeEventListener('click', handleBtnClick)
130
129
  tag.remove()
131
- this.remove(id)
132
- this.change(this.tags.slice())
130
+
131
+ if (event) {
132
+ this.change({
133
+ type: 'remove',
134
+ removedId: id,
135
+ tags: this.tags.slice()
136
+ })
137
+ }
133
138
  }
134
139
  btn.addEventListener('click', handleBtnClick)
135
140
  tag.appendChild(btn)
136
141
 
137
- return { id, elem: tag, remove: handleBtnClick, options }
142
+ return { id, elem: tag, remove: handleBtnClick, ...row }
138
143
  }
139
144
 
140
145
  setTags(rows) {
146
+ this.tags.forEach(tag => tag.remove())
141
147
  const { dom, inputDiv } = this
142
- const tags = rows.map(row => this.getTag(row.text, row))
148
+ const tags = rows.map(row => this.getTag(row))
143
149
  tags.forEach(tag => {
144
150
  dom.insertBefore(tag.elem, inputDiv)
145
151
  })
146
152
  this.tags = tags
147
- this.change(this.tags.slice())
153
+ this.change({
154
+ type: 'set',
155
+ tags: this.tags.slice()
156
+ })
148
157
  }
149
158
 
150
- addTag(inputValue, options = {}) {
151
- const tag = this.getTag(inputValue, options)
159
+ addTag(row, type = 'add') {
160
+ const tag = this.getTag(row)
152
161
  this.tags.push(tag)
153
162
  this.dom.insertBefore(tag.elem, this.inputDiv)
154
- this.change(this.tags.slice())
163
+ this.change({
164
+ type,
165
+ tags: this.tags.slice()
166
+ })
155
167
  }
156
168
 
157
169
  async addTagIfNeeded() {
@@ -163,7 +175,9 @@ export default class TagInput {
163
175
  }
164
176
  input.value = ''
165
177
  suggestInput.value = ''
166
- this.addTag(inputValue, res)
178
+
179
+ const row = Object.assign({}, res, { text: inputValue })
180
+ this.addTag(row, 'input')
167
181
  }
168
182
 
169
183
  removeTagIfNeeded() {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beyond-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.263
4
+ version: 0.0.264
5
5
  platform: ruby
6
6
  authors:
7
7
  - kmsheng
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-12-03 00:00:00.000000000 Z
12
+ date: 2020-12-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sassc