abyme 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29bd9abd9bf5c46d2c23b9c53cbe38990d03078c87fd6face66bb865493aa5a5
4
- data.tar.gz: d118f6af056ca064e405c4c8a4c6df2c4fbe52864387cd45bee8f558f1990018
3
+ metadata.gz: a97e238f55a532fe8c8539fc6a7362b77ba79f0a13475a8bac7241b26e15a668
4
+ data.tar.gz: 4ebbc1a9ec8cccbf8cbf028e70013c9538493c650852ee5d26ec05183542576b
5
5
  SHA512:
6
- metadata.gz: 43692f0d91e0afe0f20ad57b6e89d914eb359efe175c1ff2649f362d8b6e275084067d1ed219152fead5f6782374498644c372a74c2d4f163b60696c495c8995
7
- data.tar.gz: 007b9b1df96b8de5690c54c4b4083176641af8980e464b35d83b2bfcc4e84a9f53ecc9d5d41540c8131cfd134f2931bebc9f08f7cce83b94d0fee4f766dca7d8
6
+ metadata.gz: a768126195e684dc1c9de9c16c776ea4588d5b841a3927ec0f1ba224cbc96bbc8f199667221a2dc05b8c75764c187418859f89fc890ec4a8f3b064b6339f5fa3
7
+ data.tar.gz: 6a2aab308d72d41616fa6445a58c53ba3fa67c7ce143014371506412afdddd0380aece8874dbbdc00ea70f47d6fc61568ce0b6e086b47f26ac6ab7f61cef5f58
data/.DS_Store CHANGED
Binary file
data/.babelrc ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "presets": ["@babel/env"],
3
+ "plugins": [
4
+ "@babel/plugin-proposal-class-properties"
5
+ ]
6
+ }
data/Gemfile.lock CHANGED
@@ -1,61 +1,61 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- abyme (0.5.1)
4
+ abyme (0.6.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- actioncable (6.0.3.4)
10
- actionpack (= 6.0.3.4)
9
+ actioncable (6.0.3.7)
10
+ actionpack (= 6.0.3.7)
11
11
  nio4r (~> 2.0)
12
12
  websocket-driver (>= 0.6.1)
13
- actionmailbox (6.0.3.4)
14
- actionpack (= 6.0.3.4)
15
- activejob (= 6.0.3.4)
16
- activerecord (= 6.0.3.4)
17
- activestorage (= 6.0.3.4)
18
- activesupport (= 6.0.3.4)
13
+ actionmailbox (6.0.3.7)
14
+ actionpack (= 6.0.3.7)
15
+ activejob (= 6.0.3.7)
16
+ activerecord (= 6.0.3.7)
17
+ activestorage (= 6.0.3.7)
18
+ activesupport (= 6.0.3.7)
19
19
  mail (>= 2.7.1)
20
- actionmailer (6.0.3.4)
21
- actionpack (= 6.0.3.4)
22
- actionview (= 6.0.3.4)
23
- activejob (= 6.0.3.4)
20
+ actionmailer (6.0.3.7)
21
+ actionpack (= 6.0.3.7)
22
+ actionview (= 6.0.3.7)
23
+ activejob (= 6.0.3.7)
24
24
  mail (~> 2.5, >= 2.5.4)
25
25
  rails-dom-testing (~> 2.0)
26
- actionpack (6.0.3.4)
27
- actionview (= 6.0.3.4)
28
- activesupport (= 6.0.3.4)
26
+ actionpack (6.0.3.7)
27
+ actionview (= 6.0.3.7)
28
+ activesupport (= 6.0.3.7)
29
29
  rack (~> 2.0, >= 2.0.8)
30
30
  rack-test (>= 0.6.3)
31
31
  rails-dom-testing (~> 2.0)
32
32
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
33
- actiontext (6.0.3.4)
34
- actionpack (= 6.0.3.4)
35
- activerecord (= 6.0.3.4)
36
- activestorage (= 6.0.3.4)
37
- activesupport (= 6.0.3.4)
33
+ actiontext (6.0.3.7)
34
+ actionpack (= 6.0.3.7)
35
+ activerecord (= 6.0.3.7)
36
+ activestorage (= 6.0.3.7)
37
+ activesupport (= 6.0.3.7)
38
38
  nokogiri (>= 1.8.5)
39
- actionview (6.0.3.4)
40
- activesupport (= 6.0.3.4)
39
+ actionview (6.0.3.7)
40
+ activesupport (= 6.0.3.7)
41
41
  builder (~> 3.1)
42
42
  erubi (~> 1.4)
43
43
  rails-dom-testing (~> 2.0)
44
44
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
45
- activejob (6.0.3.4)
46
- activesupport (= 6.0.3.4)
45
+ activejob (6.0.3.7)
46
+ activesupport (= 6.0.3.7)
47
47
  globalid (>= 0.3.6)
48
- activemodel (6.0.3.4)
49
- activesupport (= 6.0.3.4)
50
- activerecord (6.0.3.4)
51
- activemodel (= 6.0.3.4)
52
- activesupport (= 6.0.3.4)
53
- activestorage (6.0.3.4)
54
- actionpack (= 6.0.3.4)
55
- activejob (= 6.0.3.4)
56
- activerecord (= 6.0.3.4)
57
- marcel (~> 0.3.1)
58
- activesupport (6.0.3.4)
48
+ activemodel (6.0.3.7)
49
+ activesupport (= 6.0.3.7)
50
+ activerecord (6.0.3.7)
51
+ activemodel (= 6.0.3.7)
52
+ activesupport (= 6.0.3.7)
53
+ activestorage (6.0.3.7)
54
+ actionpack (= 6.0.3.7)
55
+ activejob (= 6.0.3.7)
56
+ activerecord (= 6.0.3.7)
57
+ marcel (~> 1.0.0)
58
+ activesupport (6.0.3.7)
59
59
  concurrent-ruby (~> 1.0, >= 1.0.2)
60
60
  i18n (>= 0.7, < 2)
61
61
  minitest (~> 5.1)
@@ -65,74 +65,74 @@ GEM
65
65
  public_suffix (>= 2.0.2, < 5.0)
66
66
  bindex (0.8.1)
67
67
  builder (3.2.4)
68
- capybara (3.33.0)
68
+ byebug (11.1.3)
69
+ capybara (3.35.3)
69
70
  addressable
70
71
  mini_mime (>= 0.1.3)
71
72
  nokogiri (~> 1.8)
72
73
  rack (>= 1.6.0)
73
74
  rack-test (>= 0.6.3)
74
- regexp_parser (~> 1.5)
75
+ regexp_parser (>= 1.5, < 3.0)
75
76
  xpath (~> 3.2)
76
77
  childprocess (3.0.0)
77
78
  coderay (1.1.3)
78
- concurrent-ruby (1.1.8)
79
+ concurrent-ruby (1.1.9)
79
80
  crass (1.0.6)
80
- database_cleaner (1.8.5)
81
- database_cleaner-active_record (1.8.0)
82
- activerecord
83
- database_cleaner (~> 1.8.0)
81
+ database_cleaner-active_record (2.0.1)
82
+ activerecord (>= 5.a)
83
+ database_cleaner-core (~> 2.0.0)
84
+ database_cleaner-core (2.0.1)
84
85
  diff-lcs (1.4.4)
85
- docile (1.3.2)
86
+ docile (1.4.0)
86
87
  erubi (1.10.0)
87
88
  generator_spec (0.9.4)
88
89
  activesupport (>= 3.0.0)
89
90
  railties (>= 3.0.0)
90
91
  globalid (0.4.2)
91
92
  activesupport (>= 4.2.0)
92
- i18n (1.8.8)
93
+ i18n (1.8.10)
93
94
  concurrent-ruby (~> 1.0)
94
- loofah (2.9.0)
95
+ loofah (2.10.0)
95
96
  crass (~> 1.0.2)
96
97
  nokogiri (>= 1.5.9)
97
98
  mail (2.7.1)
98
99
  mini_mime (>= 0.1.1)
99
- marcel (0.3.3)
100
- mimemagic (~> 0.3.2)
100
+ marcel (1.0.1)
101
101
  method_source (1.0.0)
102
- mimemagic (0.3.5)
103
- mini_mime (1.0.2)
104
- mini_portile2 (2.5.0)
105
- minitest (5.14.3)
106
- nio4r (2.5.4)
107
- nokogiri (1.11.1)
102
+ mini_mime (1.1.0)
103
+ mini_portile2 (2.5.3)
104
+ minitest (5.14.4)
105
+ nio4r (2.5.7)
106
+ nokogiri (1.11.7)
108
107
  mini_portile2 (~> 2.5.0)
109
108
  racc (~> 1.4)
110
109
  pry (0.13.1)
111
110
  coderay (~> 1.1)
112
111
  method_source (~> 1.0)
113
- pry-rails (0.3.9)
114
- pry (>= 0.10.4)
112
+ pry-byebug (3.9.0)
113
+ byebug (~> 11.0)
114
+ pry (~> 0.13.0)
115
115
  public_suffix (4.0.6)
116
- puma (5.0.4)
116
+ puma (5.3.2)
117
117
  nio4r (~> 2.0)
118
118
  racc (1.5.2)
119
119
  rack (2.2.3)
120
120
  rack-test (1.1.0)
121
121
  rack (>= 1.0, < 3)
122
- rails (6.0.3.4)
123
- actioncable (= 6.0.3.4)
124
- actionmailbox (= 6.0.3.4)
125
- actionmailer (= 6.0.3.4)
126
- actionpack (= 6.0.3.4)
127
- actiontext (= 6.0.3.4)
128
- actionview (= 6.0.3.4)
129
- activejob (= 6.0.3.4)
130
- activemodel (= 6.0.3.4)
131
- activerecord (= 6.0.3.4)
132
- activestorage (= 6.0.3.4)
133
- activesupport (= 6.0.3.4)
122
+ rails (6.0.3.7)
123
+ actioncable (= 6.0.3.7)
124
+ actionmailbox (= 6.0.3.7)
125
+ actionmailer (= 6.0.3.7)
126
+ actionpack (= 6.0.3.7)
127
+ actiontext (= 6.0.3.7)
128
+ actionview (= 6.0.3.7)
129
+ activejob (= 6.0.3.7)
130
+ activemodel (= 6.0.3.7)
131
+ activerecord (= 6.0.3.7)
132
+ activestorage (= 6.0.3.7)
133
+ activesupport (= 6.0.3.7)
134
134
  bundler (>= 1.3.0)
135
- railties (= 6.0.3.4)
135
+ railties (= 6.0.3.7)
136
136
  sprockets-rails (>= 2.0.0)
137
137
  rails-controller-testing (1.0.5)
138
138
  actionpack (>= 5.0.1.rc1)
@@ -143,14 +143,14 @@ GEM
143
143
  nokogiri (>= 1.6)
144
144
  rails-html-sanitizer (1.3.0)
145
145
  loofah (~> 2.3)
146
- railties (6.0.3.4)
147
- actionpack (= 6.0.3.4)
148
- activesupport (= 6.0.3.4)
146
+ railties (6.0.3.7)
147
+ actionpack (= 6.0.3.7)
148
+ activesupport (= 6.0.3.7)
149
149
  method_source
150
150
  rake (>= 0.8.7)
151
151
  thor (>= 0.20.3, < 2.0)
152
152
  rake (13.0.3)
153
- regexp_parser (1.8.2)
153
+ regexp_parser (2.1.1)
154
154
  rspec-core (3.10.1)
155
155
  rspec-support (~> 3.10.0)
156
156
  rspec-expectations (3.10.1)
@@ -159,10 +159,10 @@ GEM
159
159
  rspec-mocks (3.10.2)
160
160
  diff-lcs (>= 1.2.0, < 2.0)
161
161
  rspec-support (~> 3.10.0)
162
- rspec-rails (4.0.2)
163
- actionpack (>= 4.2)
164
- activesupport (>= 4.2)
165
- railties (>= 4.2)
162
+ rspec-rails (5.0.1)
163
+ actionpack (>= 5.2)
164
+ activesupport (>= 5.2)
165
+ railties (>= 5.2)
166
166
  rspec-core (~> 3.10)
167
167
  rspec-expectations (~> 3.10)
168
168
  rspec-mocks (~> 3.10)
@@ -172,11 +172,16 @@ GEM
172
172
  selenium-webdriver (3.142.7)
173
173
  childprocess (>= 0.5, < 4.0)
174
174
  rubyzip (>= 1.2.2)
175
- simplecov (0.19.1)
175
+ simple_form (5.1.0)
176
+ actionpack (>= 5.2)
177
+ activemodel (>= 5.2)
178
+ simplecov (0.21.2)
176
179
  docile (~> 1.1)
177
180
  simplecov-html (~> 0.11)
181
+ simplecov_json_formatter (~> 0.1)
178
182
  simplecov-html (0.12.3)
179
183
  simplecov-lcov (0.8.0)
184
+ simplecov_json_formatter (0.1.3)
180
185
  sprockets (4.0.2)
181
186
  concurrent-ruby (~> 1.0)
182
187
  rack (> 1, < 3)
@@ -194,11 +199,11 @@ GEM
194
199
  activemodel (>= 6.0.0)
195
200
  bindex (>= 0.4.0)
196
201
  railties (>= 6.0.0)
197
- webdrivers (4.4.1)
202
+ webdrivers (4.6.0)
198
203
  nokogiri (~> 1.6)
199
204
  rubyzip (>= 1.3.0)
200
205
  selenium-webdriver (>= 3.0, < 4.0)
201
- websocket-driver (0.7.3)
206
+ websocket-driver (0.7.5)
202
207
  websocket-extensions (>= 0.1.0)
203
208
  websocket-extensions (0.1.5)
204
209
  xpath (3.2.0)
@@ -211,15 +216,17 @@ PLATFORMS
211
216
  DEPENDENCIES
212
217
  abyme!
213
218
  bundler (~> 2.0)
219
+ byebug
214
220
  capybara
215
221
  database_cleaner-active_record
216
222
  generator_spec
217
- pry-rails
223
+ pry-byebug
218
224
  puma
219
- rails
225
+ rails (~> 6.0.3.6)
220
226
  rails-controller-testing
221
227
  rake (~> 13.0)
222
228
  rspec-rails
229
+ simple_form
223
230
  simplecov
224
231
  simplecov-lcov
225
232
  sqlite3
@@ -227,4 +234,4 @@ DEPENDENCIES
227
234
  webdrivers
228
235
 
229
236
  BUNDLED WITH
230
- 2.1.4
237
+ 2.2.13
data/README.md CHANGED
@@ -76,8 +76,8 @@ application.register('abyme', AbymeController)
76
76
 
77
77
  To learn more about the *why* of this gem, check out our [wiki](https://github.com/bear-in-mind/abyme/wiki/What-are-nested-forms-and-why-a-new-gem-%3F)
78
78
 
79
- You may also check out our [step by step tutorial](https://github.com/bear-in-mind/abyme/wiki/Step-by-step-Tutorial)
80
-
79
+ You may also check out our [step by step tutorial](https://github.com/bear-in-mind/abyme/wiki/Step-by-step-Tutorial) and our [advanced configuration guide](https://github.com/bear-in-mind/abyme/wiki/Step-by-step-:-Advanced-configuration) (currently in construction).
80
+ ## Documentation
81
81
 
82
82
  ### Model
83
83
 
@@ -136,7 +136,7 @@ This is the container for all your nested fields. It takes the symbolized associ
136
136
  <%= f.abyme_for(:tasks, partial: 'projects/task_fields') do |abyme| %>
137
137
  <%= abyme.records %>
138
138
  <%= abyme.new_records %>
139
- <%= add_association %>
139
+ <%= add_associated_record %>
140
140
  <% end %>
141
141
  ```
142
142
  * `limit: ` : allows you to limit the number of new fields that can be created through JS. If you need to limit the number of associations in database, you will need to add validations. You can also pass an option [in your model as well](https://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html#method-i-accepts_nested_attributes_for).
@@ -145,7 +145,7 @@ This is the container for all your nested fields. It takes the symbolized associ
145
145
  # Beyond 5 tasks, the add button won't add any more fields. See events section below to see how to handle the 'abyme:limit-reached' event
146
146
  <%= abyme.records %>
147
147
  <%= abyme.new_records %>
148
- <%= add_association %>
148
+ <%= add_associated_record %>
149
149
  <% end %>
150
150
  ```
151
151
  * `min_count: ` by default, there won't be any blank fields added on page load. By passing a `min_count` option, you can set how many empty fields should appear in the form.
@@ -154,7 +154,7 @@ This is the container for all your nested fields. It takes the symbolized associ
154
154
  # 1 blank task will automatically be added to the form.
155
155
  <%= abyme.records %>
156
156
  <%= abyme.new_records %>
157
- <%= add_association %>
157
+ <%= add_associated_record %>
158
158
  <% end %>
159
159
  ```
160
160
 
data/abyme.gemspec CHANGED
@@ -38,9 +38,11 @@ Gem::Specification.new do |spec|
38
38
 
39
39
  # Dummy app
40
40
  spec.add_development_dependency "sqlite3"
41
- spec.add_development_dependency 'rails'
42
- spec.add_development_dependency 'pry-rails'
41
+ spec.add_development_dependency 'rails', "~> 6.0.3.6"
42
+ spec.add_development_dependency 'pry-byebug'
43
+ spec.add_development_dependency 'byebug'
43
44
  spec.add_development_dependency 'web-console'
45
+ spec.add_development_dependency 'simple_form'
44
46
 
45
47
  spec.add_development_dependency 'puma'
46
48
  spec.add_development_dependency 'simplecov'
data/dist/abyme.js ADDED
@@ -0,0 +1,2 @@
1
+ function e(t,n){return(e=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(t,n)}function t(e,n,i){if(!e.s){if(i instanceof r){if(!i.s)return void(i.o=t.bind(null,e,n));1&n&&(n=i.s),i=i.v}if(i&&i.then)return void i.then(t.bind(null,e,n),t.bind(null,e,2));e.s=n,e.v=i;var o=e.o;o&&o(e)}}var n=function(n){var o,a;function s(){return n.apply(this,arguments)||this}a=n,(o=s).prototype=Object.create(a.prototype),o.prototype.constructor=o,e(o,a);var c,u=s.prototype;return u.connect=function(){console.log("Abyme Connected"),this.count&&this.add_default_associations()},u.add_association=function(e){if(e&&e.preventDefault(),this.element.dataset.limit&&this.limit_check())return this.create_event("limit-reached"),!1;var t=this.build_html();this.create_event("before-add"),this.associationsTarget.insertAdjacentHTML(this.position,t),this.create_event("after-add")},u.remove_association=function(e){e.preventDefault(),this.create_event("before-remove"),this.mark_for_destroy(e),this.create_event("after-remove")},u.create_event=function(e,t){void 0===t&&(t=null);var n=new CustomEvent("abyme:"+e,{detail:{controller:this,content:t}});this.element.dispatchEvent(n),this.dispatch(n,e)},u.dispatch=function(e,t){"before-add"===t&&this.abymeBeforeAdd&&this.abymeBeforeAdd(e),"after-add"===t&&this.abymeAfterAdd&&this.abymeAfterAdd(e),"before-remove"===t&&this.abymeBeforeRemove&&this.abymeBeforeAdd(e),"after-remove"===t&&this.abymeAfterRemove&&this.abymeAfterRemove(e)},u.abymeBeforeAdd=function(e){},u.abymeAfterAdd=function(e){},u.abymeBeforeRemove=function(e){},u.abymeAfterRemove=function(e){},u.build_html=function(){var e=this.templateTarget.innerHTML.replace(/NEW_RECORD/g,(new Date).getTime());if(e.match(/<template[\s\S]+<\/template>/)){var t=e.match(/<template[\s\S]+<\/template>/)[0].replace(/(\[\d{12,}\])(\[[^\[\]]+\]"){1}/g,"[NEW_RECORD]$2");e=e.replace(/<template[\s\S]+<\/template>/g,t)}return e},u.mark_for_destroy=function(e){var t=e.target.closest(".abyme--fields");t.querySelector("input[name*='_destroy']").value=1,t.style.display="none",t.classList.add("abyme--marked-for-destroy")},u.limit_check=function(){return this.newFieldsTargets.filter(function(e){return!e.classList.contains("abyme--marked-for-destroy")}).length>=parseInt(this.element.dataset.limit)},u.add_default_associations=function(){try{var e=this,n=0,o=function(e,n,o){for(var a;;){var s=e();if(i(s)&&(s=s.v),!s)return c;if(s.then){a=0;break}var c=o();if(c&&c.then){if(!i(c)){a=1;break}c=c.s}}var u=new r,f=t.bind(null,u,2);return(0===a?s.then(h):1===a?c.then(d):(void 0).then(function(){(s=e())?s.then?s.then(h).then(void 0,f):h(s):t(u,1,c)})).then(void 0,f),u;function d(n){c=n;do{if(!(s=e())||i(s)&&!s.v)return void t(u,1,c);if(s.then)return void s.then(h).then(void 0,f);i(c=o())&&(c=c.v)}while(!c||!c.then);c.then(d).then(void 0,f)}function h(e){e?(c=o())&&c.then?c.then(d).then(void 0,f):d(c):t(u,1,c)}}(function(){return n<e.count},0,function(){return e.add_association(),n++,Promise.resolve(e.sleep(1)).then(function(){})});return Promise.resolve(o&&o.then?o.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},u.sleep=function(e){return new Promise(function(t){return setTimeout(t,e)})},(c=[{key:"count",get:function(){return this.element.dataset.minCount||0}},{key:"position",get:function(){return"end"===this.associationsTarget.dataset.abymePosition?"beforeend":"afterbegin"}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(s.prototype,c),s}(require("stimulus").Controller),r=function(){function e(){}return e.prototype.then=function(n,r){var i=new e,o=this.s;if(o){var a=1&o?n:r;if(a){try{t(i,1,a(this.v))}catch(e){t(i,2,e)}return i}return this}return this.o=function(e){try{var o=e.v;1&e.s?t(i,1,n?n(o):o):r?t(i,1,r(o)):t(i,2,o)}catch(e){t(i,2,e)}},i},e}();function i(e){return e instanceof r&&1&e.s}n.targets=["template","associations","fields","newFields"],exports.AbymeController=n;
2
+ //# sourceMappingURL=abyme.js.map
data/dist/abyme.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abyme.js","sources":["../src/abyme_controller.js"],"sourcesContent":["import { Controller } from 'stimulus';\n\nexport default class extends Controller {\n // static targets = ['template', 'associations', 'fields', 'newFields'];\n // Some applications don't compile correctly with the usual static syntax. \n // Thus implementing targets with standard getters below\n\n static targets = ['template', 'associations', 'fields', 'newFields']\n\n connect() {\n console.log(\"Abyme Connected\")\n\n if (this.count) {\n // If data-count is present,\n // add n default fields on page load\n\n this.add_default_associations();\n }\n }\n\n // return the value of the data-count attribute\n\n get count() {\n return this.element.dataset.minCount || 0;\n }\n \n // return the value of the data-position attribute\n // if there is no position specified set end as default\n\n get position() {\n return this.associationsTarget.dataset.abymePosition === 'end' ? 'beforeend' : 'afterbegin';\n }\n\n // ADD_ASSOCIATION\n\n // this function is call whenever a click occurs\n // on the element with the click->abyme#add_association\n // <button> element by default\n\n // if a data-count is present the add_association\n // will be call without an event so we have to check\n // this case\n\n // check for limit reached \n // dispatch an event if the limit is reached\n\n // - call the function build_html that take care\n // for building the correct html to be inserted in the DOM\n // - dispatch an event before insert\n // - insert html into the dom\n // - dispatch an event after insert\n\n add_association(event) {\n if (event) {\n event.preventDefault();\n }\n\n if (this.element.dataset.limit && this.limit_check()) {\n this.create_event('limit-reached')\n return false\n }\n\n const html = this.build_html();\n this.create_event('before-add');\n this.associationsTarget.insertAdjacentHTML(this.position, html);\n this.create_event('after-add');\n }\n\n // REMOVE_ASSOCIATION\n\n // this function is call whenever a click occurs\n // on the element with the click->abyme#remove_association\n // <button> element by default\n\n // - call the function mark_for_destroy that takes care\n // of marking the element for destruction and hiding it\n // - dispatch an event before mark & hide\n // - mark for descrution + hide the element\n // - dispatch an event after mark and hide\n\n remove_association(event) {\n event.preventDefault();\n\n this.create_event('before-remove');\n this.mark_for_destroy(event);\n this.create_event('after-remove');\n }\n\n // LIFECYCLE EVENTS RELATED\n\n // CREATE_EVENT\n\n // take a stage (String) => before-add, after-add...\n // create a new custom event \n // and dispatch at at the controller level\n\n create_event(stage, html = null) {\n const event = new CustomEvent(`abyme:${stage}`, { detail: {controller: this, content: html} });\n this.element.dispatchEvent(event);\n // WIP\n this.dispatch(event, stage);\n }\n\n // WIP : Trying to integrate event handling through controller inheritance\n dispatch(event, stage) {\n if (stage === 'before-add' && this.abymeBeforeAdd) this.abymeBeforeAdd(event);\n if (stage === 'after-add' && this.abymeAfterAdd) this.abymeAfterAdd(event);\n if (stage === 'before-remove' && this.abymeBeforeRemove) this.abymeBeforeAdd(event);\n if (stage === 'after-remove' && this.abymeAfterRemove) this.abymeAfterRemove(event);\n }\n\n abymeBeforeAdd(event) {\n }\n\n abymeAfterAdd(event) {\n }\n\n abymeBeforeRemove(event) {\n }\n\n abymeAfterRemove(event) {\n }\n\n // BUILD HTML\n\n // takes the html template and substitutes the sub-string\n // NEW_RECORD for a generated timestamp\n // then if there is a sub template in the html (multiple nested level)\n // set all the sub timestamps back as NEW_RECORD\n // finally returns the html \n\n build_html() {\n let html = this.templateTarget.innerHTML.replace(\n /NEW_RECORD/g,\n new Date().getTime()\n );\n \n if (html.match(/<template[\\s\\S]+<\\/template>/)) {\n const template = html\n .match(/<template[\\s\\S]+<\\/template>/)[0]\n .replace(/(\\[\\d{12,}\\])(\\[[^\\[\\]]+\\]\"){1}/g, `[NEW_RECORD]$2`);\n \n html = html.replace(/<template[\\s\\S]+<\\/template>/g, template);\n }\n\n return html;\n }\n \n // MARK_FOR_DESTROY\n\n // mark association for destruction\n // get the closest abyme--fields from the remove_association button\n // set the _destroy input value as 1\n // hide the element\n // add the class of abyme--marked-for-destroy to the element\n\n mark_for_destroy(event) {\n let item = event.target.closest('.abyme--fields');\n item.querySelector(\"input[name*='_destroy']\").value = 1;\n item.style.display = 'none';\n item.classList.add('abyme--marked-for-destroy')\n }\n\n\n // LIMIT_CHECK\n\n // Check if associations limit is reached\n // based on newFieldsTargets only\n // persisted fields are ignored\n\n limit_check() {\n return (this.newFieldsTargets\n .filter(item => !item.classList.contains('abyme--marked-for-destroy'))).length \n >= parseInt(this.element.dataset.limit)\n }\n\n // ADD_DEFAULT_ASSOCIATION\n\n // Add n default blank associations at page load\n // call sleep function to ensure uniqueness of timestamp\n\n async add_default_associations() {\n let i = 0\n while (i < this.count) {\n this.add_association()\n i++\n await this.sleep(1);\n }\n }\n\n sleep(ms) {\n return new Promise(resolve => setTimeout(resolve, ms));\n }\n}\n"],"names":["_settle","pact","state","value","s","_Pact","o","bind","v","then","observer","connect","console","log","this","count","add_default_associations","add_association","event","preventDefault","element","dataset","limit","limit_check","create_event","html","build_html","associationsTarget","insertAdjacentHTML","position","remove_association","mark_for_destroy","stage","CustomEvent","detail","controller","content","dispatchEvent","dispatch","abymeBeforeAdd","abymeAfterAdd","abymeBeforeRemove","abymeAfterRemove","templateTarget","innerHTML","replace","Date","getTime","match","template","item","target","closest","querySelector","style","display","classList","add","newFieldsTargets","filter","contains","length","parseInt","i","test","update","body","shouldContinue","_isSettledPact","result","reject","_resumeAfterTest","_resumeAfterBody","updateValue","_this2","sleep","ms","Promise","resolve","setTimeout","minCount","abymePosition","prototype","onFulfilled","onRejected","callback","e","_this","thenable","targets"],"mappings":"4FAuCO,SAASA,EAAQC,EAAMC,EAAOC,GACpC,IAAKF,EAAKG,EAAG,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QqE,EAAQ,EAAGc,EAAcA,EAAYhF,GAASA,GAC5CiF,EACVpF,EAAQqE,EAAQ,EAAGe,EAAWjF,IAE9BH,EAAQqE,EAAQ,EAAGlE,GAEnB,MAAOmF,GACRtF,EAAQqE,EAAQ,EAAGiB,KAGdjB,KAhC0B,GAgE5B,WAAwBmB,GAC9B,OAAOA,gBAA0C,EAAbA,EAASpF,IA3DrCqF,QAAU,CAAC,WAAY,eAAgB,SAAU"}
@@ -0,0 +1,2 @@
1
+ import{Controller as e}from"stimulus";class t extends e{connect(){console.log("Abyme Connected"),this.count&&this.add_default_associations()}get count(){return this.element.dataset.minCount||0}get position(){return"end"===this.associationsTarget.dataset.abymePosition?"beforeend":"afterbegin"}add_association(e){if(e&&e.preventDefault(),this.element.dataset.limit&&this.limit_check())return this.create_event("limit-reached"),!1;const t=this.build_html();this.create_event("before-add"),this.associationsTarget.insertAdjacentHTML(this.position,t),this.create_event("after-add")}remove_association(e){e.preventDefault(),this.create_event("before-remove"),this.mark_for_destroy(e),this.create_event("after-remove")}create_event(e,t=null){const a=new CustomEvent(`abyme:${e}`,{detail:{controller:this,content:t}});this.element.dispatchEvent(a),this.dispatch(a,e)}dispatch(e,t){"before-add"===t&&this.abymeBeforeAdd&&this.abymeBeforeAdd(e),"after-add"===t&&this.abymeAfterAdd&&this.abymeAfterAdd(e),"before-remove"===t&&this.abymeBeforeRemove&&this.abymeBeforeAdd(e),"after-remove"===t&&this.abymeAfterRemove&&this.abymeAfterRemove(e)}abymeBeforeAdd(e){}abymeAfterAdd(e){}abymeBeforeRemove(e){}abymeAfterRemove(e){}build_html(){let e=this.templateTarget.innerHTML.replace(/NEW_RECORD/g,(new Date).getTime());if(e.match(/<template[\s\S]+<\/template>/)){const t=e.match(/<template[\s\S]+<\/template>/)[0].replace(/(\[\d{12,}\])(\[[^\[\]]+\]"){1}/g,"[NEW_RECORD]$2");e=e.replace(/<template[\s\S]+<\/template>/g,t)}return e}mark_for_destroy(e){let t=e.target.closest(".abyme--fields");t.querySelector("input[name*='_destroy']").value=1,t.style.display="none",t.classList.add("abyme--marked-for-destroy")}limit_check(){return this.newFieldsTargets.filter(e=>!e.classList.contains("abyme--marked-for-destroy")).length>=parseInt(this.element.dataset.limit)}async add_default_associations(){let e=0;for(;e<this.count;)this.add_association(),e++,await this.sleep(1)}sleep(e){return new Promise(t=>setTimeout(t,e))}}t.targets=["template","associations","fields","newFields"];export{t as AbymeController};
2
+ //# sourceMappingURL=abyme.modern.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abyme.modern.js","sources":["../src/abyme_controller.js"],"sourcesContent":["import { Controller } from 'stimulus';\n\nexport default class extends Controller {\n // static targets = ['template', 'associations', 'fields', 'newFields'];\n // Some applications don't compile correctly with the usual static syntax. \n // Thus implementing targets with standard getters below\n\n static targets = ['template', 'associations', 'fields', 'newFields']\n\n connect() {\n console.log(\"Abyme Connected\")\n\n if (this.count) {\n // If data-count is present,\n // add n default fields on page load\n\n this.add_default_associations();\n }\n }\n\n // return the value of the data-count attribute\n\n get count() {\n return this.element.dataset.minCount || 0;\n }\n \n // return the value of the data-position attribute\n // if there is no position specified set end as default\n\n get position() {\n return this.associationsTarget.dataset.abymePosition === 'end' ? 'beforeend' : 'afterbegin';\n }\n\n // ADD_ASSOCIATION\n\n // this function is call whenever a click occurs\n // on the element with the click->abyme#add_association\n // <button> element by default\n\n // if a data-count is present the add_association\n // will be call without an event so we have to check\n // this case\n\n // check for limit reached \n // dispatch an event if the limit is reached\n\n // - call the function build_html that take care\n // for building the correct html to be inserted in the DOM\n // - dispatch an event before insert\n // - insert html into the dom\n // - dispatch an event after insert\n\n add_association(event) {\n if (event) {\n event.preventDefault();\n }\n\n if (this.element.dataset.limit && this.limit_check()) {\n this.create_event('limit-reached')\n return false\n }\n\n const html = this.build_html();\n this.create_event('before-add');\n this.associationsTarget.insertAdjacentHTML(this.position, html);\n this.create_event('after-add');\n }\n\n // REMOVE_ASSOCIATION\n\n // this function is call whenever a click occurs\n // on the element with the click->abyme#remove_association\n // <button> element by default\n\n // - call the function mark_for_destroy that takes care\n // of marking the element for destruction and hiding it\n // - dispatch an event before mark & hide\n // - mark for descrution + hide the element\n // - dispatch an event after mark and hide\n\n remove_association(event) {\n event.preventDefault();\n\n this.create_event('before-remove');\n this.mark_for_destroy(event);\n this.create_event('after-remove');\n }\n\n // LIFECYCLE EVENTS RELATED\n\n // CREATE_EVENT\n\n // take a stage (String) => before-add, after-add...\n // create a new custom event \n // and dispatch at at the controller level\n\n create_event(stage, html = null) {\n const event = new CustomEvent(`abyme:${stage}`, { detail: {controller: this, content: html} });\n this.element.dispatchEvent(event);\n // WIP\n this.dispatch(event, stage);\n }\n\n // WIP : Trying to integrate event handling through controller inheritance\n dispatch(event, stage) {\n if (stage === 'before-add' && this.abymeBeforeAdd) this.abymeBeforeAdd(event);\n if (stage === 'after-add' && this.abymeAfterAdd) this.abymeAfterAdd(event);\n if (stage === 'before-remove' && this.abymeBeforeRemove) this.abymeBeforeAdd(event);\n if (stage === 'after-remove' && this.abymeAfterRemove) this.abymeAfterRemove(event);\n }\n\n abymeBeforeAdd(event) {\n }\n\n abymeAfterAdd(event) {\n }\n\n abymeBeforeRemove(event) {\n }\n\n abymeAfterRemove(event) {\n }\n\n // BUILD HTML\n\n // takes the html template and substitutes the sub-string\n // NEW_RECORD for a generated timestamp\n // then if there is a sub template in the html (multiple nested level)\n // set all the sub timestamps back as NEW_RECORD\n // finally returns the html \n\n build_html() {\n let html = this.templateTarget.innerHTML.replace(\n /NEW_RECORD/g,\n new Date().getTime()\n );\n \n if (html.match(/<template[\\s\\S]+<\\/template>/)) {\n const template = html\n .match(/<template[\\s\\S]+<\\/template>/)[0]\n .replace(/(\\[\\d{12,}\\])(\\[[^\\[\\]]+\\]\"){1}/g, `[NEW_RECORD]$2`);\n \n html = html.replace(/<template[\\s\\S]+<\\/template>/g, template);\n }\n\n return html;\n }\n \n // MARK_FOR_DESTROY\n\n // mark association for destruction\n // get the closest abyme--fields from the remove_association button\n // set the _destroy input value as 1\n // hide the element\n // add the class of abyme--marked-for-destroy to the element\n\n mark_for_destroy(event) {\n let item = event.target.closest('.abyme--fields');\n item.querySelector(\"input[name*='_destroy']\").value = 1;\n item.style.display = 'none';\n item.classList.add('abyme--marked-for-destroy')\n }\n\n\n // LIMIT_CHECK\n\n // Check if associations limit is reached\n // based on newFieldsTargets only\n // persisted fields are ignored\n\n limit_check() {\n return (this.newFieldsTargets\n .filter(item => !item.classList.contains('abyme--marked-for-destroy'))).length \n >= parseInt(this.element.dataset.limit)\n }\n\n // ADD_DEFAULT_ASSOCIATION\n\n // Add n default blank associations at page load\n // call sleep function to ensure uniqueness of timestamp\n\n async add_default_associations() {\n let i = 0\n while (i < this.count) {\n this.add_association()\n i++\n await this.sleep(1);\n }\n }\n\n sleep(ms) {\n return new Promise(resolve => setTimeout(resolve, ms));\n }\n}\n"],"names":["Controller","connect","console","log","this","count","add_default_associations","element","dataset","minCount","position","associationsTarget","abymePosition","add_association","event","preventDefault","limit","limit_check","create_event","html","build_html","insertAdjacentHTML","remove_association","mark_for_destroy","stage","CustomEvent","detail","controller","content","dispatchEvent","dispatch","abymeBeforeAdd","abymeAfterAdd","abymeBeforeRemove","abymeAfterRemove","templateTarget","innerHTML","replace","Date","getTime","match","template","item","target","closest","querySelector","value","style","display","classList","add","newFieldsTargets","filter","contains","length","parseInt","[object Object]","i","sleep","ms","Promise","resolve","setTimeout","targets"],"mappings":"sDAE6BA,EAO3BC,UACEC,QAAQC,IAAI,mBAERC,KAAKC,OAIPD,KAAKE,2BAMAD,YACP,YAAYE,QAAQC,QAAQC,UAAY,EAM9BC,eACV,MAAyD,aAA7CC,mBAAmBH,QAAQI,cAA0B,YAAc,aAsBjFC,gBAAgBC,GAKd,GAJIA,GACFA,EAAMC,iBAGJX,KAAKG,QAAQC,QAAQQ,OAASZ,KAAKa,cAErC,OADAb,KAAKc,aAAa,oBAIpB,MAAMC,EAAOf,KAAKgB,aAClBhB,KAAKc,aAAa,cAClBd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KAAKC,OACdD,KAAKS,kBACL4C,eACWC,MAAM,GAIrBA,MAAMC,GACJ,WAAWC,QAAQC,GAAWC,WAAWD,EAASF,OAxL7CI,QAAU,CAAC,WAAY,eAAgB,SAAU"}
@@ -0,0 +1,2 @@
1
+ import{Controller as e}from"stimulus";function t(e,n){return(t=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,n)}function n(e,t,r){if(!e.s){if(r instanceof i){if(!r.s)return void(r.o=n.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(n.bind(null,e,t),n.bind(null,e,2));e.s=t,e.v=r;var o=e.o;o&&o(e)}}var r=function(e){var r,a;function s(){return e.apply(this,arguments)||this}a=e,(r=s).prototype=Object.create(a.prototype),r.prototype.constructor=r,t(r,a);var c,f=s.prototype;return f.connect=function(){console.log("Abyme Connected"),this.count&&this.add_default_associations()},f.add_association=function(e){if(e&&e.preventDefault(),this.element.dataset.limit&&this.limit_check())return this.create_event("limit-reached"),!1;var t=this.build_html();this.create_event("before-add"),this.associationsTarget.insertAdjacentHTML(this.position,t),this.create_event("after-add")},f.remove_association=function(e){e.preventDefault(),this.create_event("before-remove"),this.mark_for_destroy(e),this.create_event("after-remove")},f.create_event=function(e,t){void 0===t&&(t=null);var n=new CustomEvent("abyme:"+e,{detail:{controller:this,content:t}});this.element.dispatchEvent(n),this.dispatch(n,e)},f.dispatch=function(e,t){"before-add"===t&&this.abymeBeforeAdd&&this.abymeBeforeAdd(e),"after-add"===t&&this.abymeAfterAdd&&this.abymeAfterAdd(e),"before-remove"===t&&this.abymeBeforeRemove&&this.abymeBeforeAdd(e),"after-remove"===t&&this.abymeAfterRemove&&this.abymeAfterRemove(e)},f.abymeBeforeAdd=function(e){},f.abymeAfterAdd=function(e){},f.abymeBeforeRemove=function(e){},f.abymeAfterRemove=function(e){},f.build_html=function(){var e=this.templateTarget.innerHTML.replace(/NEW_RECORD/g,(new Date).getTime());if(e.match(/<template[\s\S]+<\/template>/)){var t=e.match(/<template[\s\S]+<\/template>/)[0].replace(/(\[\d{12,}\])(\[[^\[\]]+\]"){1}/g,"[NEW_RECORD]$2");e=e.replace(/<template[\s\S]+<\/template>/g,t)}return e},f.mark_for_destroy=function(e){var t=e.target.closest(".abyme--fields");t.querySelector("input[name*='_destroy']").value=1,t.style.display="none",t.classList.add("abyme--marked-for-destroy")},f.limit_check=function(){return this.newFieldsTargets.filter(function(e){return!e.classList.contains("abyme--marked-for-destroy")}).length>=parseInt(this.element.dataset.limit)},f.add_default_associations=function(){try{var e=this,t=0,r=function(e,t,r){for(var a;;){var s=e();if(o(s)&&(s=s.v),!s)return c;if(s.then){a=0;break}var c=r();if(c&&c.then){if(!o(c)){a=1;break}c=c.s}}var f=new i,u=n.bind(null,f,2);return(0===a?s.then(h):1===a?c.then(d):(void 0).then(function(){(s=e())?s.then?s.then(h).then(void 0,u):h(s):n(f,1,c)})).then(void 0,u),f;function d(t){c=t;do{if(!(s=e())||o(s)&&!s.v)return void n(f,1,c);if(s.then)return void s.then(h).then(void 0,u);o(c=r())&&(c=c.v)}while(!c||!c.then);c.then(d).then(void 0,u)}function h(e){e?(c=r())&&c.then?c.then(d).then(void 0,u):d(c):n(f,1,c)}}(function(){return t<e.count},0,function(){return e.add_association(),t++,Promise.resolve(e.sleep(1)).then(function(){})});return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},f.sleep=function(e){return new Promise(function(t){return setTimeout(t,e)})},(c=[{key:"count",get:function(){return this.element.dataset.minCount||0}},{key:"position",get:function(){return"end"===this.associationsTarget.dataset.abymePosition?"beforeend":"afterbegin"}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(s.prototype,c),s}(e),i=function(){function e(){}return e.prototype.then=function(t,r){var i=new e,o=this.s;if(o){var a=1&o?t:r;if(a){try{n(i,1,a(this.v))}catch(e){n(i,2,e)}return i}return this}return this.o=function(e){try{var o=e.v;1&e.s?n(i,1,t?t(o):o):r?n(i,1,r(o)):n(i,2,o)}catch(e){n(i,2,e)}},i},e}();function o(e){return e instanceof i&&1&e.s}r.targets=["template","associations","fields","newFields"];export{r as AbymeController};
2
+ //# sourceMappingURL=abyme.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abyme.module.js","sources":["../src/abyme_controller.js"],"sourcesContent":["import { Controller } from 'stimulus';\n\nexport default class extends Controller {\n // static targets = ['template', 'associations', 'fields', 'newFields'];\n // Some applications don't compile correctly with the usual static syntax. \n // Thus implementing targets with standard getters below\n\n static targets = ['template', 'associations', 'fields', 'newFields']\n\n connect() {\n console.log(\"Abyme Connected\")\n\n if (this.count) {\n // If data-count is present,\n // add n default fields on page load\n\n this.add_default_associations();\n }\n }\n\n // return the value of the data-count attribute\n\n get count() {\n return this.element.dataset.minCount || 0;\n }\n \n // return the value of the data-position attribute\n // if there is no position specified set end as default\n\n get position() {\n return this.associationsTarget.dataset.abymePosition === 'end' ? 'beforeend' : 'afterbegin';\n }\n\n // ADD_ASSOCIATION\n\n // this function is call whenever a click occurs\n // on the element with the click->abyme#add_association\n // <button> element by default\n\n // if a data-count is present the add_association\n // will be call without an event so we have to check\n // this case\n\n // check for limit reached \n // dispatch an event if the limit is reached\n\n // - call the function build_html that take care\n // for building the correct html to be inserted in the DOM\n // - dispatch an event before insert\n // - insert html into the dom\n // - dispatch an event after insert\n\n add_association(event) {\n if (event) {\n event.preventDefault();\n }\n\n if (this.element.dataset.limit && this.limit_check()) {\n this.create_event('limit-reached')\n return false\n }\n\n const html = this.build_html();\n this.create_event('before-add');\n this.associationsTarget.insertAdjacentHTML(this.position, html);\n this.create_event('after-add');\n }\n\n // REMOVE_ASSOCIATION\n\n // this function is call whenever a click occurs\n // on the element with the click->abyme#remove_association\n // <button> element by default\n\n // - call the function mark_for_destroy that takes care\n // of marking the element for destruction and hiding it\n // - dispatch an event before mark & hide\n // - mark for descrution + hide the element\n // - dispatch an event after mark and hide\n\n remove_association(event) {\n event.preventDefault();\n\n this.create_event('before-remove');\n this.mark_for_destroy(event);\n this.create_event('after-remove');\n }\n\n // LIFECYCLE EVENTS RELATED\n\n // CREATE_EVENT\n\n // take a stage (String) => before-add, after-add...\n // create a new custom event \n // and dispatch at at the controller level\n\n create_event(stage, html = null) {\n const event = new CustomEvent(`abyme:${stage}`, { detail: {controller: this, content: html} });\n this.element.dispatchEvent(event);\n // WIP\n this.dispatch(event, stage);\n }\n\n // WIP : Trying to integrate event handling through controller inheritance\n dispatch(event, stage) {\n if (stage === 'before-add' && this.abymeBeforeAdd) this.abymeBeforeAdd(event);\n if (stage === 'after-add' && this.abymeAfterAdd) this.abymeAfterAdd(event);\n if (stage === 'before-remove' && this.abymeBeforeRemove) this.abymeBeforeAdd(event);\n if (stage === 'after-remove' && this.abymeAfterRemove) this.abymeAfterRemove(event);\n }\n\n abymeBeforeAdd(event) {\n }\n\n abymeAfterAdd(event) {\n }\n\n abymeBeforeRemove(event) {\n }\n\n abymeAfterRemove(event) {\n }\n\n // BUILD HTML\n\n // takes the html template and substitutes the sub-string\n // NEW_RECORD for a generated timestamp\n // then if there is a sub template in the html (multiple nested level)\n // set all the sub timestamps back as NEW_RECORD\n // finally returns the html \n\n build_html() {\n let html = this.templateTarget.innerHTML.replace(\n /NEW_RECORD/g,\n new Date().getTime()\n );\n \n if (html.match(/<template[\\s\\S]+<\\/template>/)) {\n const template = html\n .match(/<template[\\s\\S]+<\\/template>/)[0]\n .replace(/(\\[\\d{12,}\\])(\\[[^\\[\\]]+\\]\"){1}/g, `[NEW_RECORD]$2`);\n \n html = html.replace(/<template[\\s\\S]+<\\/template>/g, template);\n }\n\n return html;\n }\n \n // MARK_FOR_DESTROY\n\n // mark association for destruction\n // get the closest abyme--fields from the remove_association button\n // set the _destroy input value as 1\n // hide the element\n // add the class of abyme--marked-for-destroy to the element\n\n mark_for_destroy(event) {\n let item = event.target.closest('.abyme--fields');\n item.querySelector(\"input[name*='_destroy']\").value = 1;\n item.style.display = 'none';\n item.classList.add('abyme--marked-for-destroy')\n }\n\n\n // LIMIT_CHECK\n\n // Check if associations limit is reached\n // based on newFieldsTargets only\n // persisted fields are ignored\n\n limit_check() {\n return (this.newFieldsTargets\n .filter(item => !item.classList.contains('abyme--marked-for-destroy'))).length \n >= parseInt(this.element.dataset.limit)\n }\n\n // ADD_DEFAULT_ASSOCIATION\n\n // Add n default blank associations at page load\n // call sleep function to ensure uniqueness of timestamp\n\n async add_default_associations() {\n let i = 0\n while (i < this.count) {\n this.add_association()\n i++\n await this.sleep(1);\n }\n }\n\n sleep(ms) {\n return new Promise(resolve => setTimeout(resolve, ms));\n }\n}\n"],"names":["_settle","pact","state","value","s","_Pact","o","bind","v","then","observer","connect","console","log","this","count","add_default_associations","add_association","event","preventDefault","element","dataset","limit","limit_check","create_event","html","build_html","associationsTarget","insertAdjacentHTML","position","remove_association","mark_for_destroy","stage","CustomEvent","detail","controller","content","dispatchEvent","dispatch","abymeBeforeAdd","abymeAfterAdd","abymeBeforeRemove","abymeAfterRemove","templateTarget","innerHTML","replace","Date","getTime","match","template","item","target","closest","querySelector","style","display","classList","add","newFieldsTargets","filter","contains","length","parseInt","i","test","update","body","shouldContinue","_isSettledPact","result","reject","_resumeAfterTest","_resumeAfterBody","updateValue","_this2","sleep","ms","Promise","resolve","setTimeout","minCount","abymePosition","Controller","prototype","onFulfilled","onRejected","callback","e","_this","thenable","targets"],"mappings":"kIAuCO,SAASA,EAAQC,EAAMC,EAAOC,GACpC,IAAKF,EAAKG,EAAG,CACZ,GAAID,aAAiBE,EAAO,CAC3B,IAAIF,EAAMC,EAOT,YADAD,EAAMG,EAAIN,EAAQO,KAAK,KAAMN,EAAMC,IALvB,EAARA,IACHA,EAAQC,EAAMC,GAEfD,EAAQA,EAAMK,EAMhB,GAAIL,GAASA,EAAMM,KAElB,YADAN,EAAMM,KAAKT,EAAQO,KAAK,KAAMN,EAAMC,GAAQF,EAAQO,KAAK,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,QAAU,CAAC,WAAY,eAAgB,SAAU"}
data/dist/abyme.umd.js ADDED
@@ -0,0 +1,2 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("stimulus")):"function"==typeof define&&define.amd?define(["exports","stimulus"],t):t((e||self).abyme={},e.Stimulus)}(this,function(e,t){function n(e,t){return(n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function i(e,t,n){if(!e.s){if(n instanceof o){if(!n.s)return void(n.o=i.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(i.bind(null,e,t),i.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var r=function(e){var t,r;function s(){return e.apply(this,arguments)||this}r=e,(t=s).prototype=Object.create(r.prototype),t.prototype.constructor=t,n(t,r);var f,u=s.prototype;return u.connect=function(){console.log("Abyme Connected"),this.count&&this.add_default_associations()},u.add_association=function(e){if(e&&e.preventDefault(),this.element.dataset.limit&&this.limit_check())return this.create_event("limit-reached"),!1;var t=this.build_html();this.create_event("before-add"),this.associationsTarget.insertAdjacentHTML(this.position,t),this.create_event("after-add")},u.remove_association=function(e){e.preventDefault(),this.create_event("before-remove"),this.mark_for_destroy(e),this.create_event("after-remove")},u.create_event=function(e,t){void 0===t&&(t=null);var n=new CustomEvent("abyme:"+e,{detail:{controller:this,content:t}});this.element.dispatchEvent(n),this.dispatch(n,e)},u.dispatch=function(e,t){"before-add"===t&&this.abymeBeforeAdd&&this.abymeBeforeAdd(e),"after-add"===t&&this.abymeAfterAdd&&this.abymeAfterAdd(e),"before-remove"===t&&this.abymeBeforeRemove&&this.abymeBeforeAdd(e),"after-remove"===t&&this.abymeAfterRemove&&this.abymeAfterRemove(e)},u.abymeBeforeAdd=function(e){},u.abymeAfterAdd=function(e){},u.abymeBeforeRemove=function(e){},u.abymeAfterRemove=function(e){},u.build_html=function(){var e=this.templateTarget.innerHTML.replace(/NEW_RECORD/g,(new Date).getTime());if(e.match(/<template[\s\S]+<\/template>/)){var t=e.match(/<template[\s\S]+<\/template>/)[0].replace(/(\[\d{12,}\])(\[[^\[\]]+\]"){1}/g,"[NEW_RECORD]$2");e=e.replace(/<template[\s\S]+<\/template>/g,t)}return e},u.mark_for_destroy=function(e){var t=e.target.closest(".abyme--fields");t.querySelector("input[name*='_destroy']").value=1,t.style.display="none",t.classList.add("abyme--marked-for-destroy")},u.limit_check=function(){return this.newFieldsTargets.filter(function(e){return!e.classList.contains("abyme--marked-for-destroy")}).length>=parseInt(this.element.dataset.limit)},u.add_default_associations=function(){try{var e=this,t=0,n=function(e,t,n){for(var r;;){var s=e();if(a(s)&&(s=s.v),!s)return f;if(s.then){r=0;break}var f=n();if(f&&f.then){if(!a(f)){r=1;break}f=f.s}}var u=new o,c=i.bind(null,u,2);return(0===r?s.then(l):1===r?f.then(d):(void 0).then(function(){(s=e())?s.then?s.then(l).then(void 0,c):l(s):i(u,1,f)})).then(void 0,c),u;function d(t){f=t;do{if(!(s=e())||a(s)&&!s.v)return void i(u,1,f);if(s.then)return void s.then(l).then(void 0,c);a(f=n())&&(f=f.v)}while(!f||!f.then);f.then(d).then(void 0,c)}function l(e){e?(f=n())&&f.then?f.then(d).then(void 0,c):d(f):i(u,1,f)}}(function(){return t<e.count},0,function(){return e.add_association(),t++,Promise.resolve(e.sleep(1)).then(function(){})});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},u.sleep=function(e){return new Promise(function(t){return setTimeout(t,e)})},(f=[{key:"count",get:function(){return this.element.dataset.minCount||0}},{key:"position",get:function(){return"end"===this.associationsTarget.dataset.abymePosition?"beforeend":"afterbegin"}}])&&function(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}(s.prototype,f),s}(t.Controller),o=function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var a=1&o?t:n;if(a){try{i(r,1,a(this.v))}catch(e){i(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?i(r,1,t?t(o):o):n?i(r,1,n(o)):i(r,2,o)}catch(e){i(r,2,e)}},r},e}();function a(e){return e instanceof o&&1&e.s}r.targets=["template","associations","fields","newFields"],e.AbymeController=r});
2
+ //# sourceMappingURL=abyme.umd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abyme.umd.js","sources":["../src/abyme_controller.js"],"sourcesContent":["import { Controller } from 'stimulus';\n\nexport default class extends Controller {\n // static targets = ['template', 'associations', 'fields', 'newFields'];\n // Some applications don't compile correctly with the usual static syntax. \n // Thus implementing targets with standard getters below\n\n static targets = ['template', 'associations', 'fields', 'newFields']\n\n connect() {\n console.log(\"Abyme Connected\")\n\n if (this.count) {\n // If data-count is present,\n // add n default fields on page load\n\n this.add_default_associations();\n }\n }\n\n // return the value of the data-count attribute\n\n get count() {\n return this.element.dataset.minCount || 0;\n }\n \n // return the value of the data-position attribute\n // if there is no position specified set end as default\n\n get position() {\n return this.associationsTarget.dataset.abymePosition === 'end' ? 'beforeend' : 'afterbegin';\n }\n\n // ADD_ASSOCIATION\n\n // this function is call whenever a click occurs\n // on the element with the click->abyme#add_association\n // <button> element by default\n\n // if a data-count is present the add_association\n // will be call without an event so we have to check\n // this case\n\n // check for limit reached \n // dispatch an event if the limit is reached\n\n // - call the function build_html that take care\n // for building the correct html to be inserted in the DOM\n // - dispatch an event before insert\n // - insert html into the dom\n // - dispatch an event after insert\n\n add_association(event) {\n if (event) {\n event.preventDefault();\n }\n\n if (this.element.dataset.limit && this.limit_check()) {\n this.create_event('limit-reached')\n return false\n }\n\n const html = this.build_html();\n this.create_event('before-add');\n this.associationsTarget.insertAdjacentHTML(this.position, html);\n this.create_event('after-add');\n }\n\n // REMOVE_ASSOCIATION\n\n // this function is call whenever a click occurs\n // on the element with the click->abyme#remove_association\n // <button> element by default\n\n // - call the function mark_for_destroy that takes care\n // of marking the element for destruction and hiding it\n // - dispatch an event before mark & hide\n // - mark for descrution + hide the element\n // - dispatch an event after mark and hide\n\n remove_association(event) {\n event.preventDefault();\n\n this.create_event('before-remove');\n this.mark_for_destroy(event);\n this.create_event('after-remove');\n }\n\n // LIFECYCLE EVENTS RELATED\n\n // CREATE_EVENT\n\n // take a stage (String) => before-add, after-add...\n // create a new custom event \n // and dispatch at at the controller level\n\n create_event(stage, html = null) {\n const event = new CustomEvent(`abyme:${stage}`, { detail: {controller: this, content: html} });\n this.element.dispatchEvent(event);\n // WIP\n this.dispatch(event, stage);\n }\n\n // WIP : Trying to integrate event handling through controller inheritance\n dispatch(event, stage) {\n if (stage === 'before-add' && this.abymeBeforeAdd) this.abymeBeforeAdd(event);\n if (stage === 'after-add' && this.abymeAfterAdd) this.abymeAfterAdd(event);\n if (stage === 'before-remove' && this.abymeBeforeRemove) this.abymeBeforeAdd(event);\n if (stage === 'after-remove' && this.abymeAfterRemove) this.abymeAfterRemove(event);\n }\n\n abymeBeforeAdd(event) {\n }\n\n abymeAfterAdd(event) {\n }\n\n abymeBeforeRemove(event) {\n }\n\n abymeAfterRemove(event) {\n }\n\n // BUILD HTML\n\n // takes the html template and substitutes the sub-string\n // NEW_RECORD for a generated timestamp\n // then if there is a sub template in the html (multiple nested level)\n // set all the sub timestamps back as NEW_RECORD\n // finally returns the html \n\n build_html() {\n let html = this.templateTarget.innerHTML.replace(\n /NEW_RECORD/g,\n new Date().getTime()\n );\n \n if (html.match(/<template[\\s\\S]+<\\/template>/)) {\n const template = html\n .match(/<template[\\s\\S]+<\\/template>/)[0]\n .replace(/(\\[\\d{12,}\\])(\\[[^\\[\\]]+\\]\"){1}/g, `[NEW_RECORD]$2`);\n \n html = html.replace(/<template[\\s\\S]+<\\/template>/g, template);\n }\n\n return html;\n }\n \n // MARK_FOR_DESTROY\n\n // mark association for destruction\n // get the closest abyme--fields from the remove_association button\n // set the _destroy input value as 1\n // hide the element\n // add the class of abyme--marked-for-destroy to the element\n\n mark_for_destroy(event) {\n let item = event.target.closest('.abyme--fields');\n item.querySelector(\"input[name*='_destroy']\").value = 1;\n item.style.display = 'none';\n item.classList.add('abyme--marked-for-destroy')\n }\n\n\n // LIMIT_CHECK\n\n // Check if associations limit is reached\n // based on newFieldsTargets only\n // persisted fields are ignored\n\n limit_check() {\n return (this.newFieldsTargets\n .filter(item => !item.classList.contains('abyme--marked-for-destroy'))).length \n >= parseInt(this.element.dataset.limit)\n }\n\n // ADD_DEFAULT_ASSOCIATION\n\n // Add n default blank associations at page load\n // call sleep function to ensure uniqueness of timestamp\n\n async add_default_associations() {\n let i = 0\n while (i < this.count) {\n this.add_association()\n i++\n await this.sleep(1);\n }\n }\n\n sleep(ms) {\n return new Promise(resolve => setTimeout(resolve, ms));\n }\n}\n"],"names":["_settle","pact","state","value","s","_Pact","o","bind","v","then","observer","connect","console","log","this","count","add_default_associations","add_association","event","preventDefault","element","dataset","limit","limit_check","create_event","html","build_html","associationsTarget","insertAdjacentHTML","position","remove_association","mark_for_destroy","stage","CustomEvent","detail","controller","content","dispatchEvent","dispatch","abymeBeforeAdd","abymeAfterAdd","abymeBeforeRemove","abymeAfterRemove","templateTarget","innerHTML","replace","Date","getTime","match","template","item","target","closest","querySelector","style","display","classList","add","newFieldsTargets","filter","contains","length","parseInt","i","test","update","body","shouldContinue","_isSettledPact","result","reject","_resumeAfterTest","_resumeAfterBody","updateValue","_this2","sleep","ms","Promise","resolve","setTimeout","minCount","abymePosition","Controller","prototype","onFulfilled","onRejected","callback","e","_this","thenable","targets"],"mappings":"uWAuCO,SAASA,EAAQC,EAAMC,EAAOC,GACpC,IAAKF,EAAKG,EAAG,CACZ,GAAID,aAAiBE,EAAO,CAC3B,IAAIF,EAAMC,EAOT,YADAD,EAAMG,EAAIN,EAAQO,KAAK,KAAMN,EAAMC,IALvB,EAARA,IACHA,EAAQC,EAAMC,GAEfD,EAAQA,EAAMK,EAMhB,GAAIL,GAASA,EAAMM,KAElB,YADAN,EAAMM,KAAKT,EAAQO,KAAK,KAAMN,E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0C,EAAbA,EAASrF,IA3DrCsF,QAAU,CAAC,WAAY,eAAgB,SAAU"}
@@ -0,0 +1,2 @@
1
+ import '@babel/polyfill'
2
+ import 'mutationobserver-shim'
@@ -2,11 +2,11 @@ module Abyme
2
2
  class AbymeBuilder < ActionView::Base
3
3
  include ActionView
4
4
 
5
- # If a block is given to the #abymize helper
6
- # it will instanciate a new AbymeBuilder
5
+ # If a block is given to the #abymize helper
6
+ # it will instanciate a new AbymeBuilder
7
7
  # and pass to it the association name (Symbol)
8
8
  # the form object, lookup_context optionaly a partial path
9
- # then yield itself to the block
9
+ # then yield itself to the block
10
10
 
11
11
  def initialize(association:, form:, context:, partial:, &block)
12
12
  @association = association
@@ -14,14 +14,14 @@ module Abyme
14
14
  @context = context
15
15
  @lookup_context = context.lookup_context
16
16
  @partial = partial
17
- yield(self) if block_given?
17
+ yield(self) if block
18
18
  end
19
19
 
20
20
  # RECORDS
21
21
 
22
22
  # calls the #persisted_records_for helper method
23
23
  # passing association, form and options to it
24
-
24
+
25
25
  def records(options = {})
26
26
  persisted_records_for(@association, @form, options) do |fields_for_association|
27
27
  render_association_partial(@association, fields_for_association, @partial, @context)
@@ -32,12 +32,10 @@ module Abyme
32
32
 
33
33
  # calls the #new_records_for helper method
34
34
  # passing association, form and options to it
35
-
36
35
  def new_records(options = {}, &block)
37
36
  new_records_for(@association, @form, options) do |fields_for_association|
38
37
  render_association_partial(@association, fields_for_association, @partial, @context)
39
38
  end
40
39
  end
41
-
42
40
  end
43
- end
41
+ end