glimmer-dsl-opal 0.0.4 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +35 -0
  3. data/README.md +983 -34
  4. data/VERSION +1 -1
  5. data/lib/glimmer-dsl-opal.rb +5 -2
  6. data/lib/glimmer/data_binding/ext/observable_model.rb +40 -0
  7. data/lib/glimmer/data_binding/table_items_binding.rb +70 -0
  8. data/lib/glimmer/dsl/opal/async_exec_expression.rb +17 -0
  9. data/lib/glimmer/dsl/opal/browser_expression.rb +17 -0
  10. data/lib/glimmer/dsl/opal/column_properties_expression.rb +22 -0
  11. data/lib/glimmer/dsl/opal/dsl.rb +11 -0
  12. data/lib/glimmer/dsl/opal/message_box_expression.rb +20 -0
  13. data/lib/glimmer/dsl/opal/observe_expression.rb +32 -0
  14. data/lib/glimmer/dsl/opal/tab_folder_expression.rb +17 -0
  15. data/lib/glimmer/dsl/opal/tab_item_expression.rb +17 -0
  16. data/lib/glimmer/dsl/opal/table_column_expression.rb +17 -0
  17. data/lib/glimmer/dsl/opal/table_expression.rb +17 -0
  18. data/lib/glimmer/dsl/opal/table_items_data_binding_expression.rb +29 -0
  19. data/lib/glimmer/opal/display_proxy.rb +23 -0
  20. data/lib/glimmer/opal/div_proxy.rb +11 -2
  21. data/lib/glimmer/opal/document_proxy.rb +124 -4
  22. data/lib/glimmer/opal/element_proxy.rb +45 -14
  23. data/lib/glimmer/opal/grid_layout_proxy.rb +3 -1
  24. data/lib/glimmer/opal/iframe_proxy.rb +23 -0
  25. data/lib/glimmer/opal/input_proxy.rb +8 -4
  26. data/lib/glimmer/opal/label_proxy.rb +1 -1
  27. data/lib/glimmer/opal/layout_data_proxy.rb +23 -2
  28. data/lib/glimmer/opal/list_proxy.rb +2 -2
  29. data/lib/glimmer/opal/modal.rb +94 -0
  30. data/lib/glimmer/opal/point.rb +5 -0
  31. data/lib/glimmer/opal/select_proxy.rb +1 -1
  32. data/lib/glimmer/opal/tab_folder.rb +53 -0
  33. data/lib/glimmer/opal/tab_item.rb +98 -0
  34. data/lib/glimmer/opal/table_column.rb +50 -0
  35. data/lib/glimmer/opal/table_item.rb +136 -0
  36. data/lib/glimmer/opal/table_proxy.rb +149 -0
  37. data/lib/samples/elaborate/contact_manager.rb +1 -2
  38. data/lib/samples/elaborate/login.rb +0 -1
  39. data/lib/samples/elaborate/tic_tac_toe.rb +5 -5
  40. data/lib/samples/hello/hello_tab.rb +2 -2
  41. metadata +28 -16
  42. data/lib/glimmer/config.rb +0 -22
  43. data/lib/glimmer/dsl/engine.rb +0 -193
  44. data/lib/glimmer/dsl/expression.rb +0 -42
  45. data/lib/glimmer/dsl/expression_handler.rb +0 -48
  46. data/lib/glimmer/dsl/parent_expression.rb +0 -12
  47. data/lib/glimmer/dsl/static_expression.rb +0 -36
  48. data/lib/glimmer/dsl/top_level_expression.rb +0 -7
  49. data/lib/glimmer/error.rb +0 -6
  50. data/lib/glimmer/invalid_keyword_error.rb +0 -6
@@ -0,0 +1,50 @@
1
+ require 'glimmer/opal/element_proxy'
2
+
3
+ module Glimmer
4
+ module Opal
5
+ class TableColumn < ElementProxy
6
+ include Glimmer
7
+ attr_reader :text, :width
8
+
9
+ def text=(value)
10
+ @text = value
11
+ redraw
12
+ end
13
+
14
+ def width=(value)
15
+ @width = value
16
+ redraw
17
+ end
18
+
19
+ def css
20
+ <<~CSS
21
+ width: #{width};
22
+ CSS
23
+ end
24
+
25
+ def name
26
+ 'th'
27
+ end
28
+
29
+ def observation_request_to_event_mapping
30
+ {
31
+ 'on_widget_selected' => {
32
+ event: 'click'
33
+ },
34
+ }
35
+ end
36
+
37
+ def dom
38
+ table_column_text = text
39
+ table_column_id = id
40
+ table_column_id_style = css
41
+ table_column_css_classes = css_classes
42
+ @dom ||= DOM {
43
+ th(id: table_column_id, style: table_column_id_style, class: table_column_css_classes.to_a.join(' ')) {
44
+ table_column_text
45
+ }
46
+ }
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,136 @@
1
+ require 'glimmer/opal/element_proxy'
2
+
3
+ module Glimmer
4
+ module Opal
5
+ class TableItem < ElementProxy
6
+ attr_reader :data
7
+
8
+ def initialize(parent, args)
9
+ super(parent, args)
10
+ on_widget_selected { |event|
11
+ parent.select(parent.index_of(self), event.meta?)
12
+ }
13
+ end
14
+
15
+ def get_text(index)
16
+ text_array[index]
17
+ end
18
+
19
+ def set_text(index, text_value)
20
+ text_array[index] = text_value
21
+ redraw
22
+ end
23
+
24
+ def text_array
25
+ @text_array ||= []
26
+ end
27
+
28
+ def get_data(key = nil)
29
+ if key.nil?
30
+ @data
31
+ else
32
+ data_hash[key]
33
+ end
34
+ end
35
+
36
+ def set_data(key = nil, data_value)
37
+ if key.nil?
38
+ @data = data_value
39
+ else
40
+ data_hash[key] = data_value
41
+ end
42
+ end
43
+
44
+ def data_hash
45
+ @data_hash ||= {}
46
+ end
47
+
48
+ def name
49
+ 'tr'
50
+ end
51
+
52
+ def edit(column_index)
53
+ return if @edit_column_index == column_index.to_i
54
+ parent.select(parent.index_of(self), false)
55
+ @edit_column_index = column_index.to_i
56
+ redraw
57
+ end
58
+
59
+ def on_widget_selected(&block)
60
+ event = 'click'
61
+ delegate = $document.on(event, selector, &block)
62
+ EventListenerProxy.new(element_proxy: self, event: event, selector: selector, delegate: delegate)
63
+ end
64
+
65
+ def max_column_width(column_index)
66
+ parent.dom.css("tr td:nth-child(#{column_index + 1})").first.width
67
+ end
68
+
69
+ def dom
70
+ table_item_id = id
71
+ table_item_id_style = css
72
+ table_item_css_classes = css_classes
73
+ table_item_selection = parent.selection.include?(self)
74
+ if table_item_selection
75
+ table_item_css_classes << 'selected'
76
+ else
77
+ table_item_css_classes.delete('selected')
78
+ end
79
+ table_item_text_array = text_array
80
+ table_item_edit_column_index = @edit_column_index
81
+ table_item_max_width = max_column_width(table_item_edit_column_index) if table_item_edit_column_index
82
+ table_item_edit_handler = lambda do |event, cancel = false|
83
+ Async::Task.new do
84
+ text_value = event.target.value
85
+ edit_property = parent.column_properties[table_item_edit_column_index]
86
+ edit_model = get_data
87
+ if !cancel && edit_model.send(edit_property) != text_value
88
+ edit_model.send("#{edit_property}=", text_value)
89
+ set_text(table_item_edit_column_index, text_value)
90
+ end
91
+ @edit_column_index = nil
92
+ redraw
93
+ end
94
+ end
95
+ table_item_edit_cancel_handler = lambda do |event|
96
+ Async::Task.new do
97
+ table_item_edit_handler.call(event, true)
98
+ end
99
+ end
100
+ table_item_edit_key_handler = lambda do |event|
101
+ Async::Task.new do
102
+ if event.code == 13
103
+ table_item_edit_handler.call(event)
104
+ elsif event.code == 27
105
+ table_item_edit_cancel_handler.call(event)
106
+ end
107
+ end
108
+ end
109
+ @dom ||= DOM {
110
+ tr(id: table_item_id, style: table_item_id_style, class: table_item_css_classes.to_a.join(' ')) {
111
+ table_item_text_array.each_with_index do |table_item_text, column_index|
112
+ td('data-column-index' => column_index) {
113
+ if table_item_edit_column_index == column_index
114
+ input(type: 'text', value: table_item_text, style: "max-width: #{table_item_max_width - 11}px;")
115
+ else
116
+ table_item_text
117
+ end
118
+ }
119
+ end
120
+ }
121
+ }.tap do |the_dom|
122
+ if table_item_edit_column_index
123
+ table_item_input = the_dom.css("td:nth-child(#{table_item_edit_column_index + 1}) input").first
124
+ if table_item_input
125
+ Async::Task.new do
126
+ table_item_input.focus
127
+ table_item_input.on('keyup', &table_item_edit_key_handler)
128
+ table_item_input.on('focusout', &table_item_edit_cancel_handler)
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,149 @@
1
+ require 'glimmer/opal/element_proxy'
2
+ require 'glimmer/opal/table_column'
3
+
4
+ module Glimmer
5
+ module Opal
6
+ class TableProxy < ElementProxy
7
+ attr_reader :columns, :selection
8
+ attr_accessor :column_properties
9
+ alias items children
10
+
11
+ def initialize(parent, args)
12
+ super(parent, args)
13
+ @columns = []
14
+ @children = []
15
+ @selection = []
16
+ end
17
+
18
+ # Only table_columns may be added as children
19
+ def add_child(child)
20
+ if child.is_a?(TableColumn)
21
+ @columns << child
22
+ columns_dom << child.dom
23
+ else
24
+ @children << child
25
+ items_dom << child.dom
26
+ end
27
+ end
28
+
29
+ def remove_all
30
+ items.clear
31
+ @items_dom = nil
32
+ end
33
+
34
+ def selection=(new_selection)
35
+ changed = (@selection + new_selection) - (@selection & new_selection)
36
+ @selection = new_selection
37
+ changed.each(&:redraw)
38
+ end
39
+
40
+ def items=(new_items)
41
+ @children = new_items
42
+ redraw
43
+ end
44
+
45
+ def search(&condition)
46
+ items.select {|item| condition.nil? || condition.call(item)}
47
+ end
48
+
49
+ def index_of(item)
50
+ items.index(item)
51
+ end
52
+
53
+ def select(index, meta = false)
54
+ new_selection = @selection.clone
55
+ selected_item = items[index]
56
+ if @selection.include?(selected_item)
57
+ new_selection.delete(selected_item) if meta
58
+ else
59
+ new_selection = [] if !meta || (!has_style?(:multi) && @selection.to_a.size >= 1)
60
+ new_selection << selected_item
61
+ end
62
+ self.selection = new_selection
63
+ end
64
+
65
+ def edit_table_item(table_item, column_index)
66
+ table_item.edit(column_index)
67
+ end
68
+
69
+ def selector
70
+ super + ' tbody'
71
+ end
72
+
73
+ def observation_request_to_event_mapping
74
+ {
75
+ 'on_mouse_down' => {
76
+ event: 'mousedown',
77
+ event_handler: -> (event_listener) {
78
+ -> (event) {
79
+ event.singleton_class.send(:define_method, :table_item=) do |item|
80
+ @table_item = item
81
+ end
82
+ event.singleton_class.send(:define_method, :table_item) do
83
+ @table_item
84
+ end
85
+ table_row = event.target.ancestors('tr').first
86
+ table_data = event.target.ancestors('td').first
87
+ event.table_item = items.detect {|item| item.id == table_row.attributes['id']}
88
+ event.singleton_class.send(:define_method, :column_index) do
89
+ (table_data || event.target).attributes['data-column-index']
90
+ end
91
+ event_listener.call(event)
92
+ }
93
+ }
94
+ }
95
+ }
96
+ end
97
+
98
+ def redraw
99
+ if @dom
100
+ old_dom = @dom
101
+ @dom = nil
102
+ old_dom.replace dom
103
+ else
104
+ dom
105
+ end
106
+ if @last_redrawn_children != @children
107
+ items_dom.clear
108
+ @last_redrawn_children = @children
109
+ @children = []
110
+ @last_redrawn_children.each do |child|
111
+ add_child(child)
112
+ end
113
+ end
114
+ end
115
+
116
+ def columns_dom
117
+ @columns_dom ||= DOM {
118
+ tr {
119
+ }
120
+ }
121
+ end
122
+
123
+ def thead_dom
124
+ @thead_dom ||= DOM {
125
+ thead {
126
+ }
127
+ }.tap {|the_dom| the_dom << columns_dom }
128
+ end
129
+
130
+ def items_dom
131
+ @items_dom ||= DOM {
132
+ tbody {
133
+ }
134
+ }
135
+ end
136
+
137
+ def dom
138
+ table_id = id
139
+ table_id_style = css
140
+ table_id_css_classes = css_classes
141
+ table_id_css_classes_string = table_id_css_classes.to_a.join(' ')
142
+ @dom ||= DOM {
143
+ table(id: table_id, style: table_id_style, class: table_id_css_classes_string) {
144
+ }
145
+ }.tap {|the_dom| the_dom >> thead_dom }.tap {|the_dom| the_dom << items_dom }
146
+ end
147
+ end
148
+ end
149
+ end
@@ -81,8 +81,7 @@ class ContactManager
81
81
  @contact_manager_presenter.toggle_sort(:email)
82
82
  }
83
83
  }
84
- items bind(@contact_manager_presenter, :results),
85
- column_properties(:first_name, :last_name, :email)
84
+ items bind(@contact_manager_presenter, :results), column_properties(:first_name, :last_name, :email)
86
85
  on_mouse_down { |event|
87
86
  table_proxy.edit_table_item(event.table_item, event.column_index)
88
87
  }
@@ -1,4 +1,3 @@
1
- require "java"
2
1
  require "observer"
3
2
 
4
3
  #Presents login screen data
@@ -37,11 +37,11 @@ class TicTacToe
37
37
  display_game_over_message("Draw!")
38
38
  end
39
39
 
40
- def display_game_over_message(message)
41
- message_box = MessageBox.new(@shell.swt_widget)
42
- message_box.setText("Game Over")
43
- message_box.setMessage(message)
44
- message_box.open
40
+ def display_game_over_message(message_text)
41
+ message_box(@shell) {
42
+ text 'Game Over'
43
+ message message_text
44
+ }.open
45
45
  @tic_tac_toe_board.reset
46
46
  end
47
47
 
@@ -2,7 +2,7 @@ class HelloTab
2
2
  include Glimmer
3
3
  def launch
4
4
  shell {
5
- text "Hello Tab"
5
+ text "Hello, Tab!"
6
6
  tab_folder {
7
7
  tab_item {
8
8
  text "English"
@@ -13,7 +13,7 @@ class HelloTab
13
13
  tab_item {
14
14
  text "French"
15
15
  label {
16
- text "Bonjour Univers!"
16
+ text "Bonjour, Univers!"
17
17
  }
18
18
  }
19
19
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-opal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-18 00:00:00.000000000 Z
11
+ date: 2020-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.9.2
19
+ version: 0.9.3
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: 0.9.2
26
+ version: 0.9.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec-mocks
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -168,15 +168,16 @@ files:
168
168
  - README.md
169
169
  - VERSION
170
170
  - lib/glimmer-dsl-opal.rb
171
- - lib/glimmer/config.rb
172
171
  - lib/glimmer/data_binding/element_binding.rb
172
+ - lib/glimmer/data_binding/ext/observable_model.rb
173
173
  - lib/glimmer/data_binding/list_selection_binding.rb
174
174
  - lib/glimmer/data_binding/observable_element.rb
175
- - lib/glimmer/dsl/engine.rb
176
- - lib/glimmer/dsl/expression.rb
177
- - lib/glimmer/dsl/expression_handler.rb
175
+ - lib/glimmer/data_binding/table_items_binding.rb
176
+ - lib/glimmer/dsl/opal/async_exec_expression.rb
178
177
  - lib/glimmer/dsl/opal/bind_expression.rb
178
+ - lib/glimmer/dsl/opal/browser_expression.rb
179
179
  - lib/glimmer/dsl/opal/button_expression.rb
180
+ - lib/glimmer/dsl/opal/column_properties_expression.rb
180
181
  - lib/glimmer/dsl/opal/combo_expression.rb
181
182
  - lib/glimmer/dsl/opal/combo_selection_data_binding_expression.rb
182
183
  - lib/glimmer/dsl/opal/composite_expression.rb
@@ -187,26 +188,37 @@ files:
187
188
  - lib/glimmer/dsl/opal/layout_data_expression.rb
188
189
  - lib/glimmer/dsl/opal/list_expression.rb
189
190
  - lib/glimmer/dsl/opal/list_selection_data_binding_expression.rb
191
+ - lib/glimmer/dsl/opal/message_box_expression.rb
192
+ - lib/glimmer/dsl/opal/observe_expression.rb
190
193
  - lib/glimmer/dsl/opal/property_expression.rb
191
194
  - lib/glimmer/dsl/opal/shell_expression.rb
195
+ - lib/glimmer/dsl/opal/tab_folder_expression.rb
196
+ - lib/glimmer/dsl/opal/tab_item_expression.rb
197
+ - lib/glimmer/dsl/opal/table_column_expression.rb
198
+ - lib/glimmer/dsl/opal/table_expression.rb
199
+ - lib/glimmer/dsl/opal/table_items_data_binding_expression.rb
192
200
  - lib/glimmer/dsl/opal/text_expression.rb
193
201
  - lib/glimmer/dsl/opal/widget_listener_expression.rb
194
- - lib/glimmer/dsl/parent_expression.rb
195
- - lib/glimmer/dsl/static_expression.rb
196
- - lib/glimmer/dsl/top_level_expression.rb
197
- - lib/glimmer/error.rb
198
- - lib/glimmer/invalid_keyword_error.rb
202
+ - lib/glimmer/opal/display_proxy.rb
199
203
  - lib/glimmer/opal/div_proxy.rb
200
204
  - lib/glimmer/opal/document_proxy.rb
201
205
  - lib/glimmer/opal/element_proxy.rb
202
206
  - lib/glimmer/opal/event_listener_proxy.rb
203
207
  - lib/glimmer/opal/grid_layout_proxy.rb
208
+ - lib/glimmer/opal/iframe_proxy.rb
204
209
  - lib/glimmer/opal/input_proxy.rb
205
210
  - lib/glimmer/opal/label_proxy.rb
206
211
  - lib/glimmer/opal/layout_data_proxy.rb
207
212
  - lib/glimmer/opal/list_proxy.rb
213
+ - lib/glimmer/opal/modal.rb
214
+ - lib/glimmer/opal/point.rb
208
215
  - lib/glimmer/opal/property_owner.rb
209
216
  - lib/glimmer/opal/select_proxy.rb
217
+ - lib/glimmer/opal/tab_folder.rb
218
+ - lib/glimmer/opal/tab_item.rb
219
+ - lib/glimmer/opal/table_column.rb
220
+ - lib/glimmer/opal/table_item.rb
221
+ - lib/glimmer/opal/table_proxy.rb
210
222
  - lib/samples/elaborate/contact_manager.rb
211
223
  - lib/samples/elaborate/contact_manager/contact.rb
212
224
  - lib/samples/elaborate/contact_manager/contact_manager_presenter.rb
@@ -230,7 +242,7 @@ homepage: http://github.com/AndyObtiva/glimmer-dsl-opal
230
242
  licenses:
231
243
  - MIT
232
244
  metadata: {}
233
- post_install_message:
245
+ post_install_message:
234
246
  rdoc_options: []
235
247
  require_paths:
236
248
  - lib
@@ -246,7 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
258
  version: '0'
247
259
  requirements: []
248
260
  rubygems_version: 3.1.2
249
- signing_key:
261
+ signing_key:
250
262
  specification_version: 4
251
263
  summary: Glimmer DSL for Opal
252
264
  test_files: []