hyalite 0.2.0 → 0.2.1

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
  SHA1:
3
- metadata.gz: 8ae6b1e6a2f77b3ca785171db8adcffcf67ec20a
4
- data.tar.gz: 522297bc892600075409e06fcaad2f4b83afd324
3
+ metadata.gz: d89b9e9e140202b8dadbe041cd0fd60eaf8a6df6
4
+ data.tar.gz: 4aa2d43c948f25716b9199184836b5aee1156293
5
5
  SHA512:
6
- metadata.gz: e91782a3f0991d6a0730ed4530d3528d8da93e52516d67b22b3135c4aaa77d478335a704af26e2240f5f1e86f9566688df947a83e18dc9378e56734e879dec4e
7
- data.tar.gz: e16dbeca13e13b18fc8bce24ee6aa09acaffc26a69c324c3d3cdc8b5bbc997f914c14f544d438315224fd3d66b09941835731cf39fd9bb00d104aab324b51082
6
+ metadata.gz: 45c0d50be1bf7a12aaf21c6c168ad66fb47a1e3053187dc030810a541e3821aa33715957c35ce431c56db906bf344f0d14cbb8377a730e40de4d08b54aaec23f
7
+ data.tar.gz: 509ba34af727a051ddede9b65c50f3fc1b2bc417029b98cd9f16adb63cf94984b1b300683f3be213bf6a1d54b0d674b3333ce2b497dbe8ef89a98ae6a38240a3
data/Gemfile.lock CHANGED
@@ -7,22 +7,22 @@ PATH
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- concurrent-ruby (1.0.4)
10
+ concurrent-ruby (1.0.5)
11
11
  hike (1.2.3)
12
- opal (0.10.3)
12
+ opal (0.10.5)
13
13
  hike (~> 1.2)
14
14
  sourcemap (~> 0.1.0)
15
15
  sprockets (~> 3.1)
16
16
  tilt (>= 1.4)
17
- opal-rspec (0.6.0)
18
- opal (>= 0.10.0, < 0.11)
19
- rack (2.0.1)
20
- rake (10.5.0)
17
+ opal-rspec (0.6.1)
18
+ opal (>= 0.10.0, < 0.12)
19
+ rack (2.0.3)
20
+ rake (12.0.0)
21
21
  sourcemap (0.1.1)
22
22
  sprockets (3.7.1)
23
23
  concurrent-ruby (~> 1.0)
24
24
  rack (> 1, < 3)
25
- tilt (2.0.5)
25
+ tilt (2.0.8)
26
26
 
27
27
  PLATFORMS
28
28
  ruby
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ Opal::Config.source_map_enabled = true
6
6
 
7
7
  Opal::RSpec::RakeTask.new(:default) do |server, task|
8
8
  task.files = [ENV['FILE']] if ENV['FILE']
9
- server.append_path File.expand_path('../client', __FILE__)
9
+ server.append_path File.expand_path('../lib', __FILE__)
10
10
  server.source_map = true
11
11
  server.debug = true
12
12
  end
@@ -31,10 +31,49 @@ module Hyalite
31
31
  end
32
32
 
33
33
  define_singleton_method(:initial_state) { @initial_state || {} }
34
+
35
+ define_singleton_method(:before_mount) do |&block|
36
+ if block
37
+ @before_mount = block
38
+ else
39
+ @before_mount
40
+ end
41
+ end
42
+
43
+ define_singleton_method(:after_mount) do |&block|
44
+ if block
45
+ @after_mount = block
46
+ else
47
+ @after_mount
48
+ end
49
+ end
50
+
51
+ define_singleton_method(:before_update) do |&block|
52
+ if block
53
+ @before_update = block
54
+ else
55
+ @before_update
56
+ end
57
+ end
58
+
59
+ define_singleton_method(:after_update) do |&block|
60
+ if block
61
+ @after_update = block
62
+ else
63
+ @after_update
64
+ end
65
+ end
34
66
  end
35
67
 
36
68
  TAGS.each do |tag|
37
- define_method(tag) do |props, *children|
69
+ define_method(tag) do |props, *children, &block|
70
+ if block
71
+ Hyalite.create_element_hook do |hook_setter|
72
+ renderer = ChildrenRenderer.new(self, hook_setter)
73
+ renderer.instance_eval(&block)
74
+ children << renderer.children
75
+ end
76
+ end
38
77
  Hyalite.create_element(tag, props, *children)
39
78
  end
40
79
  end
@@ -42,8 +81,33 @@ module Hyalite
42
81
  klass.extend ClassMethods
43
82
  end
44
83
 
84
+ class ChildrenRenderer
85
+ attr_reader :children
86
+
87
+ def initialize(component, hook_setter)
88
+ @component = component
89
+ @children = []
90
+ hook_setter.hook do |el|
91
+ @children << el
92
+ end
93
+ end
94
+
95
+ def method_missing(method_name, *args, &block)
96
+ if @component.respond_to?(method_name, true)
97
+ @component.send(method_name, *args, &block)
98
+ else
99
+ super
100
+ end
101
+ end
102
+
103
+ def respond_to_missing?(method_name, include_private = false)
104
+ @component.respond_to?(method_name, include_private) || super
105
+ end
106
+ end
107
+
45
108
  module ClassMethods
46
- def el(props, *children)
109
+ def el(props, *children, &block)
110
+ children << ChildrenRenderer.new(self).instance_eval(&block) if block
47
111
  Hyalite.create_element(self, props, *children)
48
112
  end
49
113
  end
@@ -64,22 +128,20 @@ module Hyalite
64
128
  {}
65
129
  end
66
130
 
67
- def component_did_mount
68
- end
69
-
70
131
  def component_will_mount
132
+ self.instance_eval(&self.class.before_mount) if self.class.before_mount
71
133
  end
72
134
 
73
135
  def component_did_mount
74
- end
75
-
76
- def component_will_unmount
136
+ self.instance_eval(&self.class.after_mount) if self.class.after_mount
77
137
  end
78
138
 
79
139
  def component_will_update(props, state, context)
140
+ self.instance_eval(&self.class.before_update) if self.class.before_update
80
141
  end
81
142
 
82
143
  def component_did_update(props, state, context)
144
+ self.instance_eval(&self.class.after_update) if self.class.after_update
83
145
  end
84
146
 
85
147
  def should_component_update(props, state, context)
@@ -99,6 +161,19 @@ module Hyalite
99
161
  @updator.enqueue_callback(self, &block)
100
162
  end
101
163
  end
164
+ alias :update_state :set_state
165
+
166
+ def method_missing(method_name, *args, &block)
167
+ if @props.has_key?(method_name)
168
+ @props[method_name]
169
+ else
170
+ super
171
+ end
172
+ end
173
+
174
+ def respond_to_missing?(method_name, include_private = false)
175
+ @props.has_key?(method_name) || super
176
+ end
102
177
 
103
178
  def render
104
179
  end
data/lib/hyalite/dom.rb CHANGED
@@ -4,8 +4,11 @@ module Hyalite
4
4
  end
5
5
 
6
6
  require 'native'
7
+ require_relative 'dom/event/mouse_event_interface'
8
+ require_relative 'dom/event/data_transfer'
7
9
  require_relative 'dom/event/keyboard_event'
8
10
  require_relative 'dom/event/mouse_event'
11
+ require_relative 'dom/event/drag_event'
9
12
  require_relative 'dom/event'
10
13
  require_relative 'dom/node'
11
14
  require_relative 'dom/collection'
@@ -2,8 +2,32 @@ module Hyalite
2
2
  module DOM
3
3
  module Event
4
4
  EVENT_CLASSES = {
5
+ # MouseEvent
5
6
  'click' => MouseEvent,
6
- 'keydown' => KeyboardEvent
7
+ 'dblclick' => MouseEvent,
8
+ 'mousedown' => MouseEvent,
9
+ 'mouseup' => MouseEvent,
10
+ 'mousemove' => MouseEvent,
11
+ 'mouseenter' => MouseEvent,
12
+ 'mouseleave' => MouseEvent,
13
+ 'mouseover' => MouseEvent,
14
+ 'mouseout' => MouseEvent,
15
+ 'contextmenu' => MouseEvent,
16
+
17
+ # DragEvent
18
+ 'drag' => DragEvent,
19
+ 'dragstart' => DragEvent,
20
+ 'dragend' => DragEvent,
21
+ 'dragenter' => DragEvent,
22
+ 'dragexit' => DragEvent,
23
+ 'dragleave' => DragEvent,
24
+ 'dragover' => DragEvent,
25
+ 'drop' => DragEvent,
26
+
27
+ # KeyboardEvent
28
+ 'keydown' => KeyboardEvent,
29
+ 'keyup' => KeyboardEvent,
30
+ 'keypress' => KeyboardEvent,
7
31
  }
8
32
 
9
33
  def self.create(event)
@@ -17,6 +41,10 @@ module Hyalite
17
41
  def target
18
42
  Node.create(`self.native.target`)
19
43
  end
44
+
45
+ def prevent_default
46
+ `self.native.preventDefault()`
47
+ end
20
48
  end
21
49
  end
22
50
  end
@@ -0,0 +1,24 @@
1
+ module Hyalite
2
+ module DOM
3
+ module Event
4
+ class DataTransfer
5
+ include Native
6
+
7
+ alias_native :clear, :createData
8
+ alias_native :drag_image=, :setDragImage
9
+
10
+ native_reader :files
11
+ native_reader :items
12
+ native_reader :types
13
+
14
+ def []=(name, value)
15
+ `self.native.setData(name, value)`
16
+ end
17
+
18
+ def [](name)
19
+ `self.native.getData(name)`
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,31 @@
1
+ module Hyalite
2
+ module DOM
3
+ module Event
4
+ class DragEvent
5
+ include Native
6
+ include Event
7
+ include MouseEventInterface
8
+
9
+ def drop_effect
10
+ `self.native.dataTransfer.dropEffect`
11
+ end
12
+
13
+ def drop_effect=(effect)
14
+ `self.native.dataTransfer.dropEffect = effect`
15
+ end
16
+
17
+ def effect_allowed
18
+ `self.native.dataTransfer.effectAllowed`
19
+ end
20
+
21
+ def effect_allowed=(effect)
22
+ `self.native.dataTransfer.effectAllowed = effect`
23
+ end
24
+
25
+ def data
26
+ DataTransfer.new `self.native.dataTransfer`
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -6,7 +6,18 @@ module Hyalite
6
6
  include Event
7
7
 
8
8
  alias_native :code
9
- alias_native :key_code, :keyCode
9
+ alias_native :key
10
+ alias_native :shift_key, :shiftKey
11
+ alias_native :alt_key, :altKey
12
+ alias_native :ctrl_key, :ctrlKey
13
+ alias_native :meta_key, :metaKey
14
+ alias_native :locale
15
+ alias_native :location
16
+ alias_native :repeat
17
+ alias_native :composing?, :isComposing
18
+ alias_native :modifierState, :getModifierState
19
+ alias_native :init_key_event, :initKeyEventg
20
+ alias_native :init_keyboard_event, :initKeyboardEventg
10
21
  end
11
22
  end
12
23
  end
@@ -4,6 +4,7 @@ module Hyalite
4
4
  class MouseEvent
5
5
  include Native
6
6
  include Event
7
+ include MouseEventInterface
7
8
  end
8
9
  end
9
10
  end
@@ -0,0 +1,84 @@
1
+ module Hyalite
2
+ module DOM
3
+ module Event
4
+ class AliasPosition
5
+ def initialize(native, name)
6
+ @native = native
7
+ @name = name
8
+ end
9
+
10
+ def x
11
+ name = @name + 'X'
12
+ `#@native[name]`
13
+ end
14
+
15
+ def y
16
+ name = @name + 'Y'
17
+ `#@native[name]`
18
+ end
19
+ end
20
+
21
+ module MouseEventInterface
22
+ def client
23
+ @client ||= AliasPosition.new(@native, :client)
24
+ end
25
+
26
+ def movement
27
+ @movement ||= AliasPosition.new(@native, :movement)
28
+ end
29
+
30
+ def offset
31
+ @offset ||= AliasPosition.new(@native, :offset)
32
+ end
33
+
34
+ def page
35
+ @page ||= AliasPosition.new(@native, :page)
36
+ end
37
+
38
+ def screen
39
+ @screen ||= AliasPosition.new(@native, :screen)
40
+ end
41
+
42
+ def shift_key
43
+ `#@native.shiftKey`
44
+ end
45
+
46
+ def ctrl_key
47
+ `#@native.ctrlKey`
48
+ end
49
+
50
+ def alt_key
51
+ `#@native.altKey`
52
+ end
53
+
54
+ def meta_key
55
+ `#@native.metaKey`
56
+ end
57
+
58
+ def button
59
+ `#@native.button`
60
+ end
61
+
62
+ def buttons
63
+ `#@native.buttons`
64
+ end
65
+
66
+ def region
67
+ `#@native.region`
68
+ end
69
+
70
+ def related_target
71
+ `#@native.relatedTarget`
72
+ end
73
+
74
+ def modifire_state
75
+ `#@native.getModifierState()`
76
+ end
77
+
78
+ def init_mouse_event
79
+ `#@native.initMouseEvent()`
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
data/lib/hyalite/main.rb CHANGED
@@ -38,7 +38,40 @@ module Hyalite
38
38
  children
39
39
  end
40
40
 
41
- ElementObject.new(type, key, ref, Hyalite.current_owner, props)
41
+ ElementObject.new(type, key, ref, Hyalite.current_owner, props).tap {|el| element_created(el) }
42
+ end
43
+
44
+ def element_created(element)
45
+ return unless @hooks
46
+ @hooks.each do |hook|
47
+ hook.call(element)
48
+ end
49
+ end
50
+
51
+ def create_element_hook(&block)
52
+ @hooks ||= []
53
+ hook_setter = HookSetter.new(@hooks)
54
+ yield hook_setter
55
+ ensure
56
+ hook_setter.destroy
57
+ end
58
+
59
+ class HookSetter
60
+ def initialize(hooks)
61
+ @hooks = hooks
62
+ @memo = []
63
+ end
64
+
65
+ def hook(&block)
66
+ @memo << block
67
+ @hooks << block
68
+ end
69
+
70
+ def destroy
71
+ @memo.each do |m|
72
+ @hooks.delete(m)
73
+ end
74
+ end
42
75
  end
43
76
 
44
77
  def fn(&block)
@@ -28,7 +28,6 @@ module Hyalite
28
28
  @rendered_children = next_children
29
29
  return if next_children.nil? && prev_children.nil?
30
30
 
31
-
32
31
  last_index = 0
33
32
  next_index = 0
34
33
  next_children.each do |name, next_child|
@@ -1,3 +1,3 @@
1
1
  module Hyalite
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyalite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - youchan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-28 00:00:00.000000000 Z
11
+ date: 2017-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -85,8 +85,11 @@ files:
85
85
  - lib/hyalite/dom/document.rb
86
86
  - lib/hyalite/dom/element.rb
87
87
  - lib/hyalite/dom/event.rb
88
+ - lib/hyalite/dom/event/data_transfer.rb
89
+ - lib/hyalite/dom/event/drag_event.rb
88
90
  - lib/hyalite/dom/event/keyboard_event.rb
89
91
  - lib/hyalite/dom/event/mouse_event.rb
92
+ - lib/hyalite/dom/event/mouse_event_interface.rb
90
93
  - lib/hyalite/dom/node.rb
91
94
  - lib/hyalite/dom/text.rb
92
95
  - lib/hyalite/dom_component.rb