beyond-rails 0.0.251 → 0.0.256

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/src/js/components/TagInput.js +47 -20
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7c25c8becf8350b03ce7b3be5e10d7aa6a5e7c748609be8c6004066dfb1b4e2
4
- data.tar.gz: 60db926a555eecbd5ab96f3d7018909eb071c35e5415da248c0b8265812fb6f9
3
+ metadata.gz: c3e85d9b4c8f791f8ed1eb1bac8a68f71ca189301734451410d1da2628cf49e9
4
+ data.tar.gz: fb6e1b6de1b7703918a39e5f426bcfad2cc743fbb5c9534878e86ba3f635586d
5
5
  SHA512:
6
- metadata.gz: f1d4b5d3497fb25c8fe860f73d8cc0428253d05621e110acbbe4a5099ecb96c17c96ba5628d31f272056c336d86db5fa28622efd2ca0d549cdf55509b271d4f1
7
- data.tar.gz: d84d78e047382a8c69af7fa8f8826103ae1a3b4bc8705b5ca070015e0b90fbd408a61d2fc8e558bd4629bb36584f74e1d62352bd2bde6e4dd2ed78e776da3d48
6
+ metadata.gz: 7408a3297619f390240197b29e768e9a37ad7c3377072470edafdbc29762d8bbd3b146f14808417ea1f16258c79e0cf30d2b09f0581ff4f755beb2c20422a5b0
7
+ data.tar.gz: 90c1d93650ecdfa61be3ea6e4d37c8bbe81804748fb9233cb5bf48fbfa6fde4ff555f2a5ffcd2f9d5409c3dd0f142dd2a944fa2ddede8cb5780400bd75eaa029
@@ -75,26 +75,41 @@ export default class TagInput {
75
75
  }, 500)
76
76
  }
77
77
 
78
- setTag(id, options = {}) {
78
+ setTagAttrs(id, rows = [], options = {}) {
79
79
  const tag = this.tags.find(tag => tag.id === id)
80
80
  if (! tag) {
81
81
  return
82
82
  }
83
- if (options.classname) {
84
- const originalClassname = tag.elem.className
85
- tag.elem.className = options.classname
86
- if (options.classnameTimeout) {
87
- setTimeout(() => {
88
- if (document.body.contains(tag.elem)) {
89
- tag.elem.className = originalClassname
90
- }
91
- }, options.classnameTimeout)
92
- }
83
+ const { elem } = tag
84
+ const { timeout } = options
85
+
86
+ if (this.timer) {
87
+ clearTimeout(this.timer)
88
+ this.timer = null
89
+ }
90
+ else {
91
+ this.oldAttrs = rows.map(row => elem.getAttribute(row.name))
92
+ }
93
+
94
+ rows.forEach(row => {
95
+ elem.setAttribute(row.name, row.value)
96
+ })
97
+
98
+ if (timeout) {
99
+ this.timer = setTimeout(() => {
100
+ if (document.body.contains(elem)) {
101
+ const { oldAttrs } = this
102
+ rows.forEach((row, i) => {
103
+ elem.setAttribute(row.name, oldAttrs[i])
104
+ })
105
+ }
106
+ }, timeout)
93
107
  }
94
108
  }
95
109
 
96
- addTag(inputValue, res) {
97
- const classname = res.classname ? ` ${res.classname}` : ''
110
+ getTag(inputValue, options = {}) {
111
+
112
+ const classname = options.classname ? ` ${options.classname}` : ''
98
113
  const tag = document.createElement('div')
99
114
 
100
115
  tag.className = 'tag' + classname
@@ -113,10 +128,25 @@ export default class TagInput {
113
128
  }
114
129
  btn.addEventListener('click', handleBtnClick)
115
130
  tag.appendChild(btn)
116
-
117
131
  this.id += 1
118
- this.tags.push({ id: this.id, elem: tag, remove: handleBtnClick, res })
119
- this.dom.insertBefore(tag, this.inputDiv)
132
+
133
+ return { id: this.id, elem: tag, remove: handleBtnClick, options }
134
+ }
135
+
136
+ setTags(rows) {
137
+ const { dom, inputDiv } = this
138
+ const tags = rows.map(row => this.getTag(row.text, row))
139
+ tags.forEach(tag => {
140
+ dom.insertBefore(tag.elem, inputDiv)
141
+ })
142
+ this.tags = tags
143
+ }
144
+
145
+ addTag(inputValue, options = {}) {
146
+ const tag = this.getTag(inputValue, options)
147
+ this.tags.push(tag)
148
+ this.dom.insertBefore(tag.elem, this.inputDiv)
149
+ this.change(this.tags.slice())
120
150
  }
121
151
 
122
152
  async addTagIfNeeded() {
@@ -126,12 +156,9 @@ export default class TagInput {
126
156
  if (! res.isTag) {
127
157
  return this.shake()
128
158
  }
129
- this.addTag(inputValue, res)
130
-
131
159
  input.value = ''
132
160
  suggestInput.value = ''
133
-
134
- this.change(this.tags.slice())
161
+ this.addTag(inputValue, res)
135
162
  }
136
163
 
137
164
  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.251
4
+ version: 0.0.256
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-11-24 00:00:00.000000000 Z
12
+ date: 2020-11-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sassc