select7 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/select7.esm.min.js +1 -0
- data/app/assets/javascripts/select7.min.js +1 -0
- data/lib/install/select7.rb +4 -9
- data/lib/select7/engine.rb +1 -6
- data/lib/select7/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5cbea4cef32560542f42d0715ee25b429e199cb30b11b7ae071a0c0203bd0157
|
4
|
+
data.tar.gz: 239250b63f2155268ce24afd753afe1adcd348d8a8ba05d2e5ae19e555a4fb6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffcac75631f362ceb52ec3fd3ec118fd0c43d140ac11b72b4eeb0180f746de3bd68187decebcac1b451ffb18e8460199facc73997b1c475447e044530fb0099f
|
7
|
+
data.tar.gz: b42c44b626e068b9b9ecf97ad0b05a7d81602db5b266e31078e83b0e8aaa01f96723fc3a4806b9fe5caeff8070d29ff2afafbd903e6e47500b8ad84603ec2adf
|
@@ -0,0 +1 @@
|
|
1
|
+
var r=(c,u)=>class extends c{static targets=["selected","input","suggestion","template"];static values={scope:String,field:String,valueAttr:String,textAttr:String,suggest:Object,inputName:String,multiple:Boolean,nested:Boolean,items:Array,selectedItems:Array};static formats={json:"application/json",html:"text/html",turbo_stream:"text/vnd.turbo-stream.html"};connect(){this.count=0,this.timeoutId=null,this.element.addEventListener("turbo:submit-end",this.clearForm.bind(this)),this.hasInputTarget&&this.inputTarget.setAttribute("autocomplete","off"),this.debounceSuggest=u(this.suggest.bind(this),500,{leading:!0}),this.selectedItems=this.hasSelectedItemsValue?this.selectedItemsValue.map((t,s,i)=>[t,s]):[],document.addEventListener("click",this.outsideClick.bind(this))}disconnect(){document.removeEventListener("click",this.outsideClick.bind(this))}suggest(){this.suggestValue.url?this.remoteSuggest():this.hasItemsValue&&this.localSuggest()}localSuggest(){let t=this.inputTarget.value.toLowerCase();if(t!=""){this.suggestionTarget.innerHTML="";let s=this.itemsValue.filter(([i,e,n])=>n.includes(t));s.length>0&&(s.forEach(([i,e,n])=>this.insertSuggestItem(i,e)),this.showSuggestion())}else this.hideSuggestion()}remoteSuggest(){let t=this.inputTarget.value.replaceAll(/[^\w]/g,"");if(t.length<=0)return;let s=document.querySelector("[name='csrf-token']")?.content,i=this.suggestValue.format||"html",e=this.suggestValue["content-type"]||this.constructor.formats[i],n=new URL(this.suggestValue.url);n.searchParams.append(this.textAttrValue,t),fetch(n,{method:this.suggestValue.method||"get",mode:"cors",cache:"no-cache",credentials:"same-origin",headers:{Accept:e,"Content-Type":e,"X-CSRF-Token":s}}).then(a=>a.text()).then(a=>{if(a)if(this.suggestionTarget.innerHTML="",this.suggestValue.format=="json"){let l=JSON.parse(a);l.length>0&&(l.forEach(o=>{this.insertSuggestItem(o[this.valueAttrValue],o[this.textAttrValue])}),this.showSuggestion())}else this.suggestionTarget.innerHTML=a,this.showSuggestion();else this.hideSuggestion()})}insertSuggestItem(t,s){let i=this.selectedItems.find(n=>n[0]==t)?`\u2713 ${s}`:s,e=document.createElement("div");e.setAttribute("value",t),e.setAttribute("data-action","click->select7#selectTag"),e.setAttribute("class","select7-option-item"),e.innerText=i,this.suggestionTarget.appendChild(e)}selectTag(t){let s=t.target,i=s.getAttribute("value"),e=this.inputNameValue.replace("[?]",`[${this.count++}]`);if(!this.selectedItems.find(n=>n[0]==i)){this.selectedItems.push([i,e]);let n=document.createElement("input");n.setAttribute("type","hidden"),n.setAttribute("value",i),n.setAttribute("name",e);let a=this.templateTarget.cloneNode(!0);a.appendChild(n),a.insertAdjacentHTML("afterbegin",s.innerHTML),a.classList.remove("select7-hidden"),this.selectedTarget.appendChild(a),this.emitChangedEvent("add",e,i)}this.hideSuggestion(),this.inputTarget.value="",this.multipleValue||this.inputTarget.classList.add("select7-invisible"),this.inputTarget.focus()}removeTag(t){let s=t.target.parentElement,i=s.getAttribute("data-remove-id"),e=s.getAttribute("data-remove-value");if(this.selectedItems=this.selectedItems.filter((a,l)=>l==i&&e==a),s.hasAttribute("data-remove-id")){let a=document.createElement("input");a.setAttribute("type","hidden"),a.setAttribute("name",i),a.setAttribute("value",e),this.selectedTarget.appendChild(a),s.querySelectorAll("input").forEach(l=>this.selectedTarget.appendChild(l))}let n=s.querySelector("input");this.emitChangedEvent("remove",i,e),this.selectedTarget.removeChild(s),this.inputTarget.classList.remove("select7-invisible")}showSuggestion(){this.suggestionTarget.classList.remove("select7-hidden"),this.suggestionTarget.scrollTo(0,0)}hideSuggestion(){this.suggestionTarget.classList.add("select7-hidden")}clearForm(){this.selectedTarget.innerHTML=""}emitChangedEvent(t,s,i){let e=new CustomEvent("select7-changed",{detail:{scope:this.scopeValue,field:this.fieldValue,action:t,change_value:i,values:this.selectedItems.map(n=>n[0])}});window.dispatchEvent(e)}handleKeyUp(t){t.code=="Escape"&&this.hideSuggestion()}outsideClick(t){t.composedPath().includes(this.element)||this.hideSuggestion()}};export{r as Select7Controller};
|
@@ -0,0 +1 @@
|
|
1
|
+
const Select7Controller=(c,u)=>class extends c{static targets=["selected","input","suggestion","template"];static values={scope:String,field:String,valueAttr:String,textAttr:String,suggest:Object,inputName:String,multiple:Boolean,nested:Boolean,items:Array,selectedItems:Array};static formats={json:"application/json",html:"text/html",turbo_stream:"text/vnd.turbo-stream.html"};connect(){this.count=0,this.timeoutId=null,this.element.addEventListener("turbo:submit-end",this.clearForm.bind(this)),this.hasInputTarget&&this.inputTarget.setAttribute("autocomplete","off"),this.debounceSuggest=u(this.suggest.bind(this),500,{leading:!0}),this.selectedItems=this.hasSelectedItemsValue?this.selectedItemsValue.map((t,s,i)=>[t,s]):[],document.addEventListener("click",this.outsideClick.bind(this))}disconnect(){document.removeEventListener("click",this.outsideClick.bind(this))}suggest(){this.suggestValue.url?this.remoteSuggest():this.hasItemsValue&&this.localSuggest()}localSuggest(){const t=this.inputTarget.value.toLowerCase();if(t!=""){this.suggestionTarget.innerHTML="";const s=this.itemsValue.filter(([i,e,n])=>n.includes(t));s.length>0&&(s.forEach(([i,e,n])=>this.insertSuggestItem(i,e)),this.showSuggestion())}else this.hideSuggestion()}remoteSuggest(){const t=this.inputTarget.value.replaceAll(/[^\w]/g,"");if(t.length<=0)return;const s=document.querySelector("[name='csrf-token']")?.content,i=this.suggestValue.format||"html",e=this.suggestValue["content-type"]||this.constructor.formats[i],n=new URL(this.suggestValue.url);n.searchParams.append(this.textAttrValue,t),fetch(n,{method:this.suggestValue.method||"get",mode:"cors",cache:"no-cache",credentials:"same-origin",headers:{Accept:e,"Content-Type":e,"X-CSRF-Token":s}}).then(a=>a.text()).then(a=>{if(a)if(this.suggestionTarget.innerHTML="",this.suggestValue.format=="json"){const l=JSON.parse(a);l.length>0&&(l.forEach(o=>{this.insertSuggestItem(o[this.valueAttrValue],o[this.textAttrValue])}),this.showSuggestion())}else this.suggestionTarget.innerHTML=a,this.showSuggestion();else this.hideSuggestion()})}insertSuggestItem(t,s){const i=this.selectedItems.find(n=>n[0]==t)?`\u2713 ${s}`:s,e=document.createElement("div");e.setAttribute("value",t),e.setAttribute("data-action","click->select7#selectTag"),e.setAttribute("class","select7-option-item"),e.innerText=i,this.suggestionTarget.appendChild(e)}selectTag(t){const s=t.target,i=s.getAttribute("value"),e=this.inputNameValue.replace("[?]",`[${this.count++}]`);if(!this.selectedItems.find(n=>n[0]==i)){this.selectedItems.push([i,e]);const n=document.createElement("input");n.setAttribute("type","hidden"),n.setAttribute("value",i),n.setAttribute("name",e);const a=this.templateTarget.cloneNode(!0);a.appendChild(n),a.insertAdjacentHTML("afterbegin",s.innerHTML),a.classList.remove("select7-hidden"),this.selectedTarget.appendChild(a),this.emitChangedEvent("add",e,i)}this.hideSuggestion(),this.inputTarget.value="",this.multipleValue||this.inputTarget.classList.add("select7-invisible"),this.inputTarget.focus()}removeTag(t){const s=t.target.parentElement,i=s.getAttribute("data-remove-id"),e=s.getAttribute("data-remove-value");if(this.selectedItems=this.selectedItems.filter((a,l)=>l==i&&e==a),s.hasAttribute("data-remove-id")){const a=document.createElement("input");a.setAttribute("type","hidden"),a.setAttribute("name",i),a.setAttribute("value",e),this.selectedTarget.appendChild(a),s.querySelectorAll("input").forEach(l=>this.selectedTarget.appendChild(l))}const n=s.querySelector("input");this.emitChangedEvent("remove",i,e),this.selectedTarget.removeChild(s),this.inputTarget.classList.remove("select7-invisible")}showSuggestion(){this.suggestionTarget.classList.remove("select7-hidden"),this.suggestionTarget.scrollTo(0,0)}hideSuggestion(){this.suggestionTarget.classList.add("select7-hidden")}clearForm(){this.selectedTarget.innerHTML=""}emitChangedEvent(t,s,i){const e=new CustomEvent("select7-changed",{detail:{scope:this.scopeValue,field:this.fieldValue,action:t,change_value:i,values:this.selectedItems.map(n=>n[0])}});window.dispatchEvent(e)}handleKeyUp(t){t.code=="Escape"&&this.hideSuggestion()}outsideClick(t){t.composedPath().includes(this.element)||this.hideSuggestion()}};
|
data/lib/install/select7.rb
CHANGED
@@ -5,7 +5,7 @@ say "Import Select7 Js"
|
|
5
5
|
|
6
6
|
if IMPORTMAP_PATH.exist?
|
7
7
|
append_to_file IMPORTMAP_PATH, %(\npin "lodash.debounce", to: "https://cdn.jsdelivr.net/npm/lodash.debounce@4.0.8/+esm", preload: true\n)
|
8
|
-
append_to_file IMPORTMAP_PATH, %(pin "select7", to: "select7.esm.js", preload: true\n)
|
8
|
+
append_to_file IMPORTMAP_PATH, %(pin "select7", to: "select7.esm.min.js", preload: true\n)
|
9
9
|
|
10
10
|
copy_file "#{__dir__}/app/javascript/controllers/select7_esm_controller.js", "app/javascript/controllers/select7_controller.js"
|
11
11
|
|
@@ -14,7 +14,7 @@ elsif Rails.root.join("package.json").exist?
|
|
14
14
|
run "yarn add lodash.debounce"
|
15
15
|
|
16
16
|
insert_into_file APPLICATION_LAYOUT_PATH.to_s, <<~ERB.indent(4), before: /\s*<\/head/
|
17
|
-
\n<%= javascript_include_tag "select7", "data-turbo-track": "reload", rel: :preload, async: true %>
|
17
|
+
\n<%= javascript_include_tag "select7.min.js", "data-turbo-track": "reload", rel: :preload, async: true %>
|
18
18
|
ERB
|
19
19
|
|
20
20
|
append_to_file Rails.root.join("app/javascript/controllers/index.js"), <<~ERB
|
@@ -22,9 +22,6 @@ elsif Rails.root.join("package.json").exist?
|
|
22
22
|
application.register("select7", Select7Controller)
|
23
23
|
ERB
|
24
24
|
|
25
|
-
append_to_file Rails.root.join("app/javascript/application.js"), <<~ERB
|
26
|
-
ERB
|
27
|
-
|
28
25
|
copy_file "#{__dir__}/app/javascript/controllers/select7_controller.js", "app/javascript/controllers/select7_controller.js"
|
29
26
|
else
|
30
27
|
say %(Couldn't Import Select7 Js), :red
|
@@ -37,11 +34,9 @@ end
|
|
37
34
|
# ==============
|
38
35
|
|
39
36
|
say "Import Select7 Css"
|
40
|
-
if
|
41
|
-
append_to_file "app/assets/stylesheets/application.css", %(\n@import "select7.css"\n)
|
42
|
-
elsif APPLICATION_LAYOUT_PATH.exist?
|
37
|
+
if APPLICATION_LAYOUT_PATH.exist?
|
43
38
|
insert_into_file APPLICATION_LAYOUT_PATH.to_s, <<~ERB.indent(4), before: /^\s*<%= stylesheet_link_tag/
|
44
|
-
<%= stylesheet_link_tag "select7", "
|
39
|
+
<%= stylesheet_link_tag "select7", "data-turbo-track": "reload" %>
|
45
40
|
ERB
|
46
41
|
else
|
47
42
|
say %(Couldn't Import Select7 Css), :red
|
data/lib/select7/engine.rb
CHANGED
@@ -2,21 +2,16 @@ module Select7
|
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
isolate_namespace Select7
|
4
4
|
|
5
|
-
config.eager_load_namespaces << Select7
|
6
5
|
config.autoload_once_paths = %W(
|
7
6
|
#{root}/app/helpers
|
8
7
|
)
|
9
8
|
|
10
9
|
initializer "select7.assets" do |app|
|
11
10
|
if app.config.respond_to?(:assets)
|
12
|
-
Rails.application.config.assets.precompile += %w( select7.js select7.esm.js select7.css )
|
11
|
+
Rails.application.config.assets.precompile += %w( select7.min.js select7.esm.min.js select7.css )
|
13
12
|
end
|
14
13
|
end
|
15
14
|
|
16
|
-
# initializer "select7.importmap", after: "importmap" do |app|
|
17
|
-
# app.config.importmap.paths << Engine.root.join("config/importmap.rb")
|
18
|
-
# end
|
19
|
-
|
20
15
|
initializer "select7.helpers", before: :load_config_initializers do
|
21
16
|
ActiveSupport.on_load(:action_controller_base) do
|
22
17
|
helper Select7::Engine.helpers
|
data/lib/select7/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: select7
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lam Phan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -119,7 +119,9 @@ files:
|
|
119
119
|
- README.md
|
120
120
|
- Rakefile
|
121
121
|
- app/assets/javascripts/select7.esm.js
|
122
|
+
- app/assets/javascripts/select7.esm.min.js
|
122
123
|
- app/assets/javascripts/select7.js
|
124
|
+
- app/assets/javascripts/select7.min.js
|
123
125
|
- app/assets/stylesheets/select7.css
|
124
126
|
- app/helpers/select7/form_helper.rb
|
125
127
|
- app/helpers/select7/tag_helper.rb
|