stimulus-rails 0.5.0 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Stimulus 3.0.0-beta.1
2
+ Stimulus 3.0.0-beta.2
3
3
  Copyright © 2021 Basecamp, LLC
4
4
  */
5
5
  class EventListener {
@@ -166,7 +166,7 @@ function dasherize(value) {
166
166
  return value.replace(/([A-Z])/g, (_, char) => `-${char.toLowerCase()}`);
167
167
  }
168
168
  function tokenize(value) {
169
- return value.trim().split(/\s+/).filter(content => content.length);
169
+ return value.match(/[^\s]+/g) || [];
170
170
  }
171
171
 
172
172
  class Action {
@@ -1210,12 +1210,6 @@ class Context {
1210
1210
  get parentElement() {
1211
1211
  return this.element.parentElement;
1212
1212
  }
1213
- dispatch(eventName, { target = this.element, detail = {}, prefix = this.identifier, bubbles = true, cancelable = true } = {}) {
1214
- const type = prefix ? `${prefix}:${eventName}` : eventName;
1215
- const event = new CustomEvent(type, { detail, bubbles, cancelable });
1216
- target.dispatchEvent(event);
1217
- return event;
1218
- }
1219
1213
  handleError(error, message, detail = {}) {
1220
1214
  const { identifier, controller, element } = this;
1221
1215
  detail = Object.assign({ identifier, controller, element }, detail);
@@ -2026,33 +2020,15 @@ class Controller {
2026
2020
  }
2027
2021
  disconnect() {
2028
2022
  }
2023
+ dispatch(eventName, { target = this.element, detail = {}, prefix = this.identifier, bubbles = true, cancelable = true } = {}) {
2024
+ const type = prefix ? `${prefix}:${eventName}` : eventName;
2025
+ const event = new CustomEvent(type, { detail, bubbles, cancelable });
2026
+ target.dispatchEvent(event);
2027
+ return event;
2028
+ }
2029
2029
  }
2030
2030
  Controller.blessings = [ClassPropertiesBlessing, TargetPropertiesBlessing, ValuePropertiesBlessing];
2031
2031
  Controller.targets = [];
2032
2032
  Controller.values = {};
2033
2033
 
2034
- function definitionsFromContext(context) {
2035
- return context.keys()
2036
- .map(key => definitionForModuleWithContextAndKey(context, key))
2037
- .filter(value => value);
2038
- }
2039
- function definitionForModuleWithContextAndKey(context, key) {
2040
- const identifier = identifierForContextKey(key);
2041
- if (identifier) {
2042
- return definitionForModuleAndIdentifier(context(key), identifier);
2043
- }
2044
- }
2045
- function definitionForModuleAndIdentifier(module, identifier) {
2046
- const controllerConstructor = module.default;
2047
- if (typeof controllerConstructor == "function") {
2048
- return { identifier, controllerConstructor };
2049
- }
2050
- }
2051
- function identifierForContextKey(key) {
2052
- const logicalName = (key.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/) || [])[1];
2053
- if (logicalName) {
2054
- return logicalName.replace(/_/g, "-").replace(/\//g, "--");
2055
- }
2056
- }
2057
-
2058
- export { Application, AttributeObserver, Context, Controller, ElementObserver, IndexedMultimap, Multimap, StringMapObserver, TokenListObserver, ValueListObserver, add, defaultSchema, definitionsFromContext, del, fetch, identifierForContextKey, prune };
2034
+ export { Application, AttributeObserver, Context, Controller, ElementObserver, IndexedMultimap, Multimap, StringMapObserver, TokenListObserver, ValueListObserver, add, defaultSchema, del, fetch, prune };
@@ -3,21 +3,25 @@ module Stimulus::Manifest
3
3
 
4
4
  def generate_from(controllers_path)
5
5
  extract_controllers_from(controllers_path).collect do |controller_path|
6
- module_path = controller_path.relative_path_from(controllers_path).to_s.remove(".js")
7
- controller_class_name = module_path.camelize.gsub(/::/, "__")
8
- tag_name = module_path.remove("_controller").gsub(/\//, "--")
9
-
10
- <<-JS
6
+ import_and_register_controller(controllers_path, controller_path)
7
+ end
8
+ end
9
+
10
+ def import_and_register_controller(controllers_path, controller_path)
11
+ module_path = controller_path.relative_path_from(controllers_path).to_s.remove(".js")
12
+ controller_class_name = module_path.camelize.gsub(/::/, "__")
13
+ tag_name = module_path.remove("_controller").gsub(/_/, "-").gsub(/\//, "--")
14
+
15
+ <<-JS
11
16
 
12
17
  import #{controller_class_name} from "./#{module_path}"
13
18
  application.register("#{tag_name}", #{controller_class_name})
14
- JS
15
- end
19
+ JS
16
20
  end
17
21
 
18
22
  def extract_controllers_from(directory)
19
23
  (directory.children.select { |e| e.to_s =~ /_controller.js$/ } +
20
24
  directory.children.select(&:directory?).collect { |d| extract_controllers_from(d) }
21
- ).flatten
25
+ ).flatten.sort
22
26
  end
23
27
  end
@@ -1,3 +1,3 @@
1
1
  module Stimulus
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stimulus-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Stephenson
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-09-10 00:00:00.000000000 Z
13
+ date: 2021-09-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -38,8 +38,7 @@ files:
38
38
  - app/assets/javascripts/stimulus-autoloader.js
39
39
  - app/assets/javascripts/stimulus-importmap-autoloader.js
40
40
  - app/assets/javascripts/stimulus.js
41
- - app/assets/javascripts/stimulus@2.js
42
- - app/assets/javascripts/stimulus@3.0.0-beta.1.js
41
+ - app/assets/javascripts/stimulus@3.0.0-beta.2.js
43
42
  - lib/generators/stimulus/USAGE
44
43
  - lib/generators/stimulus/stimulus_generator.rb
45
44
  - lib/generators/stimulus/templates/controller.js.tt