atv-rails 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/app/assets/javascripts/atv.js +23 -18
- data/app/assets/javascripts/atv.min.js +4 -0
- data/lib/atv/engine.rb +13 -0
- data/lib/atv/version.rb +3 -0
- data/lib/atv-rails.rb +5 -0
- data/lib/generators/atv/USAGE +14 -0
- data/lib/generators/atv/atv_generator.rb +19 -0
- data/lib/generators/atv/templates/controller.js.tt +13 -0
- data/lib/tasks/atv.rake +37 -0
- metadata +40 -10
- data/app/assets/atv-min.js +0 -1
- data/lib/atv/rails/railtie.rb +0 -6
- data/lib/atv/rails/version.rb +0 -5
- data/lib/atv/rails.rb +0 -8
- data/lib/install/importmap.rb +0 -8
- data/lib/tasks/atv/rails_tasks.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90eed2550de006c017a7e04a41aa89ffe9d3d0e34740c9cb6d9fc5c17c418537
|
4
|
+
data.tar.gz: d4c9e9bb798ee12cd2eda572d1300deb897fad1eee53bfb949d28cd9f341f2c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 020f55905f8884bb5268f14d82a027a9c06aca7aaa71d652cf869f6d752779093183c489d0161565f575b79b08a496d44fd5a28f6142df4d8ac82ab541637714
|
7
|
+
data.tar.gz: fb0b1c821179e7f0a1588288d3be1be9ca1056c42ea65fdeacfb8e1e7617693a3a9c1183e8cfec2683fd17d90c3c0aca11408f2b8dfd7e7cc4b8022e976a36df
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@
|
|
32
32
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
33
33
|
// THE SOFTWARE.
|
34
34
|
|
35
|
-
const version = "0.1.
|
35
|
+
const version = "0.1.9";
|
36
36
|
|
37
37
|
// To dynamically load up the ATV javascripts if needed
|
38
38
|
function importMap() {
|
@@ -231,7 +231,6 @@ function attributesFor(element, type) {
|
|
231
231
|
}
|
232
232
|
|
233
233
|
const allControllerNames = new Set();
|
234
|
-
const allEventListeners = new Map();
|
235
234
|
const allTargets = new Map();
|
236
235
|
let allControllers = new Map();
|
237
236
|
|
@@ -370,9 +369,15 @@ function activate(prefix = "atv") {
|
|
370
369
|
) {
|
371
370
|
const callbacks = controllers.get(action.controller).getActions();
|
372
371
|
const callback = callbacks[action.method];
|
372
|
+
let result;
|
373
373
|
if (callback) {
|
374
|
-
|
374
|
+
try {
|
375
|
+
result = callback(event.target, event, action.parameters);
|
376
|
+
} catch (error) {
|
377
|
+
console.error(`ATV ${prefix}: ${eventName}->${name}`, error);
|
378
|
+
}
|
375
379
|
if (result === false) {
|
380
|
+
event.stopPropagation();
|
376
381
|
return;
|
377
382
|
}
|
378
383
|
}
|
@@ -381,14 +386,9 @@ function activate(prefix = "atv") {
|
|
381
386
|
return invokeNext(event, actions.slice(1));
|
382
387
|
}
|
383
388
|
}
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
if (events.get(eventName)) {
|
388
|
-
return;
|
389
|
-
}
|
390
|
-
element.addEventListener(eventName, handler);
|
391
|
-
events.set(eventName, handler);
|
389
|
+
element.addEventListener(eventName, (event) =>
|
390
|
+
invokeNext(event, list)
|
391
|
+
);
|
392
392
|
});
|
393
393
|
});
|
394
394
|
}
|
@@ -532,7 +532,10 @@ function activate(prefix = "atv") {
|
|
532
532
|
}
|
533
533
|
|
534
534
|
function updateControllers(root) {
|
535
|
-
let initialCount =
|
535
|
+
let initialCount = 0;
|
536
|
+
if (allControllers?.has(prefix)) {
|
537
|
+
initialCount = Number(allControllers.get(prefix).size);
|
538
|
+
}
|
536
539
|
const elements = new Set();
|
537
540
|
if (root.matches(controllersSelector)) {
|
538
541
|
elements.add(root);
|
@@ -542,11 +545,13 @@ function activate(prefix = "atv") {
|
|
542
545
|
.forEach((element) => elements.add(element));
|
543
546
|
elements.forEach(registerControllers);
|
544
547
|
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
548
|
+
if (allControllers.has(prefix)) {
|
549
|
+
report(
|
550
|
+
allControllers.get(prefix).size - initialCount,
|
551
|
+
"controllers",
|
552
|
+
"found"
|
553
|
+
);
|
554
|
+
}
|
550
555
|
}
|
551
556
|
|
552
557
|
updateControllers(root);
|
@@ -656,4 +661,4 @@ function activate(prefix = "atv") {
|
|
656
661
|
observer.observe(document, config);
|
657
662
|
}
|
658
663
|
|
659
|
-
export { activate, version };
|
664
|
+
export { activate, version };
|
@@ -0,0 +1,4 @@
|
|
1
|
+
// @sbrew.com/atv@0.1.9 downloaded from https://ga.jspm.io/npm:@sbrew.com/atv@0.1.9/atv.js
|
2
|
+
|
3
|
+
const t="0.1.9";function importMap(){return JSON.parse(document.querySelector("script[type='importmap']").innerText).imports}const e=/[\-_]/;function pascalize(t){return t.split(e).map((t=>t.charAt(0).toUpperCase()+t.slice(1))).join("")}function dasherize(t){return t.replace(/_/g,"-")}const n=/,[\s+]/;function allVariants(...t){const e=t.filter((t=>Boolean(t)));return e.length===0?[]:dashVariants(...e).flatMap((t=>[t,`${t}s`]))}function dashVariants(t,...n){function dashOrUnderscore(t){const n=t||"";return e.test(n)?[dasherize(n),n.replace(/-/g,"_")]:[n]}const r=dashOrUnderscore(t);return n.length<1?r:dashVariants(...n).flatMap((t=>r.flatMap((e=>[`${e}-${t}`,`${e}_${t}`]))))}function variantSelectors(t,...e){return allVariants("data",...e).flatMap((e=>Array.from(t.querySelectorAll(`[${e}]`)).map((t=>[t,e]))))}function errorReport(t){t?.message?.includes("JSON")||console.error(`ATV: ${t}`)}function actionsFor(t,e,r=null){let o=[];const c=/[()]/;function parseAction(t,e){let i;let a=[];let[s,l]=t.split(/[\s]*[\-=]>[\s]*/);if(l){let[t,n]=l.split("#");n?e=t:n=t;i=n}else i=s;const[f,u]=i.split(c);if(u){i=f;a=u.split(n);try{a=JSON.parse(`[${u}]`)}catch(t){errorReport(t)}s=s.split("(")[0]}if(!r||s===r){if(!e){e=i;i=s}o.push({controller:dasherize(e),event:s,method:i,parameters:a})}}function actionSplit(t,e){let n=0;let r=[];Array.from(t).forEach((function(t){if(t!==","||n!==0){r.push(t);t==="("?n+=1:t===")"&&(n-=1)}else{e(r.join("").trim());r=[]}}));const o=r.join("").trim();n!==0&&console.error(`badly formed parameters: ${t}`);o&&e(o)}e.getAttributeNames().forEach((function(n){const r=new RegExp(`^data[_-]${t}[_-]?action[s]?`);const o=new RegExp(`^data[_-]${t}[_-]?(.*[^-_])[_-]?action[s]?`);let c;let i=n.match(o);if(i)c=i[1];else{c=null;i=n.match(r)}if(!i)return;let a=e.getAttribute(n);if(a){try{a=JSON.parse(a).join(",")}catch(t){errorReport(t)}actionSplit(a,(t=>parseAction(t,c)))}}));return o}function attributeKeysFor(t,e){if(!t||!t.getAttributeNames)return[];const n=new RegExp(`${e}s?$`,"i");return t.getAttributeNames().filter((t=>n.test(t)))}function attributesFor(t,e){return attributeKeysFor(t,e).map((e=>t.getAttribute(e)))}const r=new Set;const o=new Map;let c=new Map;function findOrInitalize(t,e,n,r=null){t.has(e)||t.set(e,new Map);t.get(e).has(n)||t.get(e).set(n,r??new Map);return t.get(e).get(n)}function withModule(t,e){let n=`${t}_atv`;const r=importMap();Object.keys(r).forEach((function(e){dasherize(e).includes(`/${t}-atv`)&&(n=r[e])}));import(n).then((function(t){e(t)})).catch((function(t){console.error(`Loading ${n} failed:`,t)}))}function activate(e="atv"){if(c.has(e))return;const i=document.body;const a=allVariants("data",e,"controller").map((t=>`[${t}]`)).join(",");function outOfScope(t,e,r){if(!t||t.nodeType==="BODY")return true;const o=t.closest(a);if(!o)return true;let c=false;attributesFor(o,"controller").forEach((function(t){const i=t.split(n).map((t=>dasherize(t)));c=i.includes(r)?!(o===e):outOfScope(o.parentNode,e,r)}));return c}const s=!document.querySelector(`[data-${e}-report="true"]`);function report(n,r,o){s||n<1||console.log([["ATV:",`(${e})`,r,`[${Number(c.get(e)?.size)}]`].join(" "),`${o}: ${n}`,`v${t}`].join(" / "))}function createController(t,i){let a;let s={};let l={};r.add(i);function getActions(){return a}function registerActions(t){const n=findOrInitalize(c,e,t);let r=new Set;function collectElements(t){const[e]=t;r.add(e)}variantSelectors(t,e,i,"action").forEach(collectElements);variantSelectors(t,e,"action").forEach(collectElements);Array.from(r).forEach((function(r){const o=actionsFor(e,r);const c=new Set(o.map((t=>t.event)));c.forEach((function(c){const a=o.find((t=>t.event===c));a?.controller===i&&r.addEventListener(c,(t=>invokeNext(t,o)));function invokeNext(o,a){if(a.length<1)return;const s=a[0];if(s.event===c&&!outOfScope(r,t,s.controller)){const t=n.get(s.controller).getActions();const r=t[s.method];let a;if(r){try{a=r(o.target,o,s.parameters)}catch(t){console.error(`ATV ${e}: ${c}->${i}`,t)}if(a===false){o.stopPropagation();return}}}return a.length>1?invokeNext(o,a.slice(1)):void 0}}))}))}function refresh(){function refreshTargets(t,r){const c={};function collectionKeys(t){return[`all${pascalize(t)}`,`${t}s`]}variantSelectors(t.parentNode,e,i,"target").forEach((function(e){const[r,o]=e;r.getAttribute(o).split(n).forEach((function(e){const[n,o]=collectionKeys(e);if(!(s[e]===r||s[n]&&s[n].includes(r)||outOfScope(r,t,i))){if(s[n]){s[n].push(r);s[o].push(r)}else if(s[e]){s[n]=[s[e],r];s[o]=[s[e],r]}else s[e]=r;c[e]||(c[e]=[]);c[e].push(r)}}))}));r();Object.keys(c).forEach((function(t){const n=a[`${t}TargetConnected`];n&&c[t].forEach(n);const r=a[`${t}TargetDisconnected`];r&&c[t].forEach((function(n){findOrInitalize(o,e,n,[]).push((function(){const[e,o]=collectionKeys(t);let c=s[e]?.indexOf(n);c&&s[e].splice(c,1);c=s[o]?.indexOf(n);c&&s[o].splice(c,1);s[t]===n&&(s[e]?s[t]=s[e][0]:delete s[e]);r(n)}))}))}))}function refreshValues(t){allVariants("data",e,i,"value").forEach((function(e){const n=t.getAttribute(e);n&&[n,`{${n}}`].forEach((function(t){try{Object.assign(l,JSON.parse(t))}catch(t){errorReport(t)}}))}))}withModule(i,(function(e){refreshTargets(t,(function(){refreshValues(t);const n=e.connect(s,l,t,controllerBySelectorAndName);a=typeof n==="function"?n():n;registerActions(t)}))}))}const f=Object.freeze({getActions:getActions,refresh:refresh});return f}function registerControllers(t){findOrInitalize(c,e,t);attributesFor(t,"controller").forEach((function(r){r.split(n).forEach((function(n){const r=dasherize(n);const o=c.get(e).get(t).get(r)||createController(t,r);o.refresh();c.get(e).get(t).set(r,o)}))}))}function updateControllers(t){let n=0;c?.has(e)&&(n=Number(c.get(e).size));const r=new Set;t.matches(a)&&r.add(t);t.querySelectorAll(a).forEach((t=>r.add(t)));r.forEach(registerControllers);c.has(e)&&report(c.get(e).size-n,"controllers","found")}updateControllers(i);const l=new MutationObserver(domWatcher);function controllerBySelectorAndName(t,n,r){document.querySelectorAll(t).forEach((function(t){let o=findOrInitalize(c,e,t)?.get(n);o&&r({actions:o.getActions()})}))}function domWatcher(t,n){function cleanup(t){if(t.nodeName!=="BODY"&&t.nodeName!=="HTML"&&t.nodeName!=="#document"){cleanTargets(t);t.querySelectorAll(a).forEach(cleanActions);cleanActions(t)}else{n.disconnect();c=new Map}function cleanTargets(t){t&&t.children.length>0&&Array.from(t.children).forEach(cleanTargets);const n=o.get(e)?.get(t);if(n){n.forEach((t=>t()));n.splice(0,n.length)}}function cleanActions(t){const n=findOrInitalize(c,e,t);if(n){n.forEach((function(t){const e=t.getActions().disconnect;e&&e()}));c.get(e).delete(t)}}}function controllerFor(t,n){if(t&&t!==document.body)return findOrInitalize(c,e,t)?.get(n)||controllerFor(t.parentNode,n)}function updateTargets(t){Array.from(r).forEach((function(n){controllerFor(t,n)?.refresh();variantSelectors(t,e,n,"target").forEach((function(t){controllerFor(t[0],n)?.refresh()}))}))}function HTMLElements(t){return Boolean(t.classList)}t.forEach((function(t){t.type==="childList"&&Array.from(t.removedNodes).filter(HTMLElements).forEach((t=>cleanup(t)))}));t.forEach((function(t){t.type==="childList"&&Array.from(t.addedNodes).filter(HTMLElements).forEach((function(t){updateTargets(t);updateControllers(t)}))}))}const f={childList:true,subtree:true};l.observe(document,f)}export{activate,t as version};
|
4
|
+
|
data/lib/atv/engine.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ATV
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
JAVASCRIPTS = %w[atv.js atv.min.js].freeze
|
6
|
+
|
7
|
+
initializer "ATV.configure_rails_initialization" do
|
8
|
+
if Rails.application.config.respond_to?(:assets)
|
9
|
+
Rails.application.config.assets.precompile += JAVASCRIPTS
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/atv/version.rb
ADDED
data/lib/atv-rails.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Description:
|
2
|
+
============
|
3
|
+
Generates a new ATV controller at the passed path.
|
4
|
+
|
5
|
+
Examples:
|
6
|
+
=========
|
7
|
+
bin/rails generate atv chat
|
8
|
+
|
9
|
+
creates: app/javascript/controllers/chat_atv.js
|
10
|
+
|
11
|
+
|
12
|
+
bin/rails generate stimulus nested/chat
|
13
|
+
|
14
|
+
creates: app/javascript/controllers/nested/chat_atv.js
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "rails/generators/named_base"
|
2
|
+
|
3
|
+
class AtvGenerator < Rails::Generators::NamedBase # :nodoc:
|
4
|
+
source_root File.expand_path("templates", __dir__)
|
5
|
+
|
6
|
+
def copy_view_files
|
7
|
+
@attribute = attribute_value(controller_name)
|
8
|
+
template "controller.js", "app/javascript/controllers/#{controller_name}_atv.js"
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def controller_name
|
13
|
+
name.underscore.gsub(/_atv$/, "")
|
14
|
+
end
|
15
|
+
|
16
|
+
def attribute_value(controller_name)
|
17
|
+
controller_name.gsub(/\//, "--").gsub("_", "-")
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
function connect(targets, values, element, controllers) {
|
2
|
+
return (function() {
|
3
|
+
// Object contains named methods plus disconnect, and target backs.
|
4
|
+
return {
|
5
|
+
click: function(actor, event, params) {
|
6
|
+
},
|
7
|
+
disconnect: function() {
|
8
|
+
}
|
9
|
+
}
|
10
|
+
});
|
11
|
+
};
|
12
|
+
|
13
|
+
export { connect };
|
data/lib/tasks/atv.rake
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
namespace :atv do
|
2
|
+
desc "Install ATV into this rails app"
|
3
|
+
task :install do
|
4
|
+
importmap_file = "config/importmap.rb"
|
5
|
+
pin_command = %(pin "@sbrew.com/atv", to: "atv.min.js")
|
6
|
+
installed = false
|
7
|
+
|
8
|
+
# Add importmap
|
9
|
+
if File.exist?(importmap_file)
|
10
|
+
if File.read(importmap_file).include?(pin_command)
|
11
|
+
puts "Importmap already pinned, no change"
|
12
|
+
installed = true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
unless installed
|
16
|
+
File.open(importmap_file, "a") do |file|
|
17
|
+
file.puts(pin_command)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Add to application.js
|
22
|
+
application_js_file = "app/javascript/application.js"
|
23
|
+
included = false
|
24
|
+
|
25
|
+
if File.exist?(application_js_file)
|
26
|
+
if File.read(application_js_file).match?(/import.*activate.*sbrew.*atv/)
|
27
|
+
puts "Javascript already included, no change"
|
28
|
+
included = true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
unless included
|
32
|
+
File.open(application_js_file, "a") do |file|
|
33
|
+
file.puts %[import { activate } from "@sbrew.com/atv"; activate("atv");]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atv-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timothy Breitkreutz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -16,14 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 7.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 7.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: stimulus-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.3.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: importmap-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.0.0
|
27
55
|
description:
|
28
56
|
email:
|
29
57
|
- tim@sbrew.com
|
@@ -34,13 +62,15 @@ files:
|
|
34
62
|
- MIT-LICENSE
|
35
63
|
- README.md
|
36
64
|
- Rakefile
|
37
|
-
- app/assets/atv-min.js
|
38
65
|
- app/assets/javascripts/atv.js
|
39
|
-
-
|
40
|
-
- lib/atv
|
41
|
-
- lib/atv/
|
42
|
-
- lib/
|
43
|
-
- lib/
|
66
|
+
- app/assets/javascripts/atv.min.js
|
67
|
+
- lib/atv-rails.rb
|
68
|
+
- lib/atv/engine.rb
|
69
|
+
- lib/atv/version.rb
|
70
|
+
- lib/generators/atv/USAGE
|
71
|
+
- lib/generators/atv/atv_generator.rb
|
72
|
+
- lib/generators/atv/templates/controller.js.tt
|
73
|
+
- lib/tasks/atv.rake
|
44
74
|
homepage: https://www.sbrew.com/atv
|
45
75
|
licenses:
|
46
76
|
- MIT
|
data/app/assets/atv-min.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
const t="0.1.8";function importMap(){return JSON.parse(document.querySelector("script[type='importmap']").innerText).imports}const e=/[\-_]/;function pascalize(t){return t.split(e).map((t=>t.charAt(0).toUpperCase()+t.slice(1))).join("")}function dasherize(t){return t.replace(/_/g,"-")}const n=/,[\s+]/;function allVariants(...t){const e=t.filter((t=>Boolean(t)));return e.length===0?[]:dashVariants(...e).flatMap((t=>[t,`${t}s`]))}function dashVariants(t,...n){function dashOrUnderscore(t){const n=t||"";return e.test(n)?[dasherize(n),n.replace(/-/g,"_")]:[n]}const r=dashOrUnderscore(t);return n.length<1?r:dashVariants(...n).flatMap((t=>r.flatMap((e=>[`${e}-${t}`,`${e}_${t}`]))))}function variantSelectors(t,...e){return allVariants("data",...e).flatMap((e=>Array.from(t.querySelectorAll(`[${e}]`)).map((t=>[t,e]))))}function errorReport(t){t?.message?.includes("JSON")||console.error(`ATV: ${t}`)}function actionsFor(t,e,r=null){let o=[];const c=/[()]/;function parseAction(t,e){let i;let a=[];let[s,l]=t.split(/[\s]*[\-=]>[\s]*/);if(l){let[t,n]=l.split("#");n?e=t:n=t;i=n}else i=s;const[f,u]=i.split(c);if(u){i=f;a=u.split(n);try{a=JSON.parse(`[${u}]`)}catch(t){errorReport(t)}s=s.split("(")[0]}if(!r||s===r){if(!e){e=i;i=s}o.push({controller:dasherize(e),event:s,method:i,parameters:a})}}function actionSplit(t,e){let n=0;let r=[];Array.from(t).forEach((function(t){if(t!==","||n!==0){r.push(t);t==="("?n+=1:t===")"&&(n-=1)}else{e(r.join("").trim());r=[]}}));const o=r.join("").trim();n!==0&&console.error(`badly formed parameters: ${t}`);o&&e(o)}e.getAttributeNames().forEach((function(n){const r=new RegExp(`^data[_-]${t}[_-]?action[s]?`);const o=new RegExp(`^data[_-]${t}[_-]?(.*[^-_])[_-]?action[s]?`);let c;let i=n.match(o);if(i)c=i[1];else{c=null;i=n.match(r)}if(!i)return;let a=e.getAttribute(n);if(a){try{a=JSON.parse(a).join(",")}catch(t){errorReport(t)}actionSplit(a,(t=>parseAction(t,c)))}}));return o}function attributeKeysFor(t,e){if(!t||!t.getAttributeNames)return[];const n=new RegExp(`${e}s?$`,"i");return t.getAttributeNames().filter((t=>n.test(t)))}function attributesFor(t,e){return attributeKeysFor(t,e).map((e=>t.getAttribute(e)))}const r=new Set;const o=new Map;const c=new Map;let i=new Map;function findOrInitalize(t,e,n,r=null){t.has(e)||t.set(e,new Map);t.get(e).has(n)||t.get(e).set(n,r??new Map);return t.get(e).get(n)}function withModule(t,e){let n=`${t}_atv`;const r=importMap();Object.keys(r).forEach((function(e){dasherize(e).includes(`/${t}-atv`)&&(n=r[e])}));import(n).then((function(t){e(t)})).catch((function(t){console.error(`Loading ${n} failed:`,t)}))}function activate(e="atv"){if(i.has(e))return;const a=document.body;const s=allVariants("data",e,"controller").map((t=>`[${t}]`)).join(",");function outOfScope(t,e,r){if(!t||t.nodeType==="BODY")return true;const o=t.closest(s);if(!o)return true;let c=false;attributesFor(o,"controller").forEach((function(t){const i=t.split(n).map((t=>dasherize(t)));c=i.includes(r)?!(o===e):outOfScope(o.parentNode,e,r)}));return c}const l=!document.querySelector(`[data-${e}-report="true"]`);function report(n,r,o){l||n<1||console.log([["ATV:",`(${e})`,r,`[${Number(i.get(e)?.size)}]`].join(" "),`${o}: ${n}`,`v${t}`].join(" / "))}function createController(t,a){let s;let l={};let f={};r.add(a);function getActions(){return s}function registerActions(t){const n=findOrInitalize(i,e,t);let r=new Set;function collectElements(t){const[e]=t;r.add(e)}variantSelectors(t,e,a,"action").forEach(collectElements);variantSelectors(t,e,"action").forEach(collectElements);Array.from(r).forEach((function(r){const c=actionsFor(e,r);const i=new Set(c.map((t=>t.event)));i.forEach((function(i){const s=c.find((t=>t.event===i));if(s?.controller!==a)return;function invokeNext(e,o){if(o.length<1)return;const c=o[0];if(c.event===i&&!outOfScope(r,t,c.controller)){const t=n.get(c.controller).getActions();const r=t[c.method];if(r){const t=r(e.target,e,c.parameters);if(t===false)return}}return o.length>1?invokeNext(e,o.slice(1)):void 0}const handler=t=>invokeNext(t,c);const l=findOrInitalize(o,e,r);if(!l.get(i)){r.addEventListener(i,handler);l.set(i,handler)}}))}))}function refresh(){function refreshTargets(t,r){const o={};function collectionKeys(t){return[`all${pascalize(t)}`,`${t}s`]}variantSelectors(t.parentNode,e,a,"target").forEach((function(e){const[r,c]=e;r.getAttribute(c).split(n).forEach((function(e){const[n,c]=collectionKeys(e);if(!(l[e]===r||l[n]&&l[n].includes(r)||outOfScope(r,t,a))){if(l[n]){l[n].push(r);l[c].push(r)}else if(l[e]){l[n]=[l[e],r];l[c]=[l[e],r]}else l[e]=r;o[e]||(o[e]=[]);o[e].push(r)}}))}));r();Object.keys(o).forEach((function(t){const n=s[`${t}TargetConnected`];n&&o[t].forEach(n);const r=s[`${t}TargetDisconnected`];r&&o[t].forEach((function(n){findOrInitalize(c,e,n,[]).push((function(){const[e,o]=collectionKeys(t);let c=l[e]?.indexOf(n);c&&l[e].splice(c,1);c=l[o]?.indexOf(n);c&&l[o].splice(c,1);l[t]===n&&(l[e]?l[t]=l[e][0]:delete l[e]);r(n)}))}))}))}function refreshValues(t){allVariants("data",e,a,"value").forEach((function(e){const n=t.getAttribute(e);n&&[n,`{${n}}`].forEach((function(t){try{Object.assign(f,JSON.parse(t))}catch(t){errorReport(t)}}))}))}withModule(a,(function(e){refreshTargets(t,(function(){refreshValues(t);const n=e.connect(l,f,t,controllerBySelectorAndName);s=typeof n==="function"?n():n;registerActions(t)}))}))}const u=Object.freeze({getActions:getActions,refresh:refresh});return u}function registerControllers(t){findOrInitalize(i,e,t);attributesFor(t,"controller").forEach((function(r){r.split(n).forEach((function(n){const r=dasherize(n);const o=i.get(e).get(t).get(r)||createController(t,r);o.refresh();i.get(e).get(t).set(r,o)}))}))}function updateControllers(t){let n=Number(i.get(e)?.size);const r=new Set;t.matches(s)&&r.add(t);t.querySelectorAll(s).forEach((t=>r.add(t)));r.forEach(registerControllers);report(i.get(e).size-n,"controllers","found")}updateControllers(a);const f=new MutationObserver(domWatcher);function controllerBySelectorAndName(t,n,r){document.querySelectorAll(t).forEach((function(t){let o=findOrInitalize(i,e,t)?.get(n);o&&r({actions:o.getActions()})}))}function domWatcher(t,n){function cleanup(t){if(t.nodeName!=="BODY"&&t.nodeName!=="HTML"&&t.nodeName!=="#document"){cleanTargets(t);t.querySelectorAll(s).forEach(cleanActions);cleanActions(t)}else{n.disconnect();i=new Map}function cleanTargets(t){t&&t.children.length>0&&Array.from(t.children).forEach(cleanTargets);const n=c.get(e)?.get(t);if(n){n.forEach((t=>t()));n.splice(0,n.length)}}function cleanActions(t){const n=findOrInitalize(i,e,t);if(n){n.forEach((function(t){const e=t.getActions().disconnect;e&&e()}));i.get(e).delete(t)}}}function controllerFor(t,n){if(t&&t!==document.body)return findOrInitalize(i,e,t)?.get(n)||controllerFor(t.parentNode,n)}function updateTargets(t){Array.from(r).forEach((function(n){controllerFor(t,n)?.refresh();variantSelectors(t,e,n,"target").forEach((function(t){controllerFor(t[0],n)?.refresh()}))}))}function HTMLElements(t){return Boolean(t.classList)}t.forEach((function(t){t.type==="childList"&&Array.from(t.removedNodes).filter(HTMLElements).forEach((t=>cleanup(t)))}));t.forEach((function(t){t.type==="childList"&&Array.from(t.addedNodes).filter(HTMLElements).forEach((function(t){updateTargets(t);updateControllers(t)}))}))}const u={childList:true,subtree:true};f.observe(document,u)}export{activate,t as version};
|
data/lib/atv/rails/railtie.rb
DELETED
data/lib/atv/rails/version.rb
DELETED
data/lib/atv/rails.rb
DELETED
data/lib/install/importmap.rb
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
# Assumes stimulus is already installed
|
2
|
-
|
3
|
-
say "Copying ATV Rails JavaScript"
|
4
|
-
copy_file "#{__dir__}/app/javascript/controllers/atv-rails.js", "app/javascript/controllers/atv-rails.js"
|
5
|
-
|
6
|
-
say "Pin ATV"
|
7
|
-
say %(Appending: pin "@sbrew.com/atv")
|
8
|
-
append_to_file "config/importmap.rb", %(pin "atv", to: "@sbrew.com--atv.js"\n)
|