glimmer-dsl-opal 0.7.1 → 0.7.2

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: b4e81c8aae870295468f5c0e573da962daa58837efda4742c9855313ae29f42a
4
- data.tar.gz: 40df246c27977d3fa862a452cdfb2dd99ad0b506374408c69e25666b3fc7fa50
3
+ metadata.gz: 8a9e35ef70d7e6aae911e0b4be468617f0efd5c5ee2b31ad9b6aef191b52681f
4
+ data.tar.gz: 3a7624376ee038d5419b993911d6f0ec59f94780425c10306f5c7928572ad4de
5
5
  SHA512:
6
- metadata.gz: c46c3bdfcc129557ac54640d2d905cb7495f010ff1b81422c5b55529a01ecb67c698b4724029b62b9cbc6bcb46727763185ba1b4469c0355259d16acd1f228f1
7
- data.tar.gz: 803c487121b4092f024fabca666e359fcdfeca87482b95a391e6b857b19dca28f46a845fc46e6c189e73254c1aa3a1f53d8cbe51c113f425be5019544a353913
6
+ metadata.gz: 8a98ce6e0b97501d3f78b5e589ada5e65d31c94d75ddcfa7e7f1abee3aa15e03bd51d7c3167f395778b458fd1a55e6fb630704aae33ea7ef633d1a7e603f952a
7
+ data.tar.gz: 9c602827b6d2da600ac68ad77b2f9d5faa01f29f9b7f0a0b843878950579836de0f2eb1f35a6e7d8681b63dc14afc429cdd0c0420d01a561683b600d13e07e4a
@@ -1,5 +1,16 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.7.2
4
+
5
+ - `date_drop_down` `table_column` `editor`
6
+ - `date` `table_column` `editor`
7
+ - `time` `table_column` `editor`
8
+ - Implement `on_focus_gained`, `on_focus_lost` universally on all widgets
9
+ - Add support for Struct keyword_init to Opal
10
+ - Fix issue with hello_table button/combo not being centered (yet stretched)
11
+ - Fix issue with table item selection for booking not working after editing has been added
12
+ - Fix escape keyboard event handling for combo table editor
13
+
3
14
  ## 0.7.1
4
15
 
5
16
  - Combo table editor (enabled in Hello, Table! sample)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for Opal 0.7.1 (Pure Ruby Web GUI)
1
+ # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for Opal 0.7.2 (Pure Ruby Web GUI)
2
2
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-opal.svg)](http://badge.fury.io/rb/glimmer-dsl-opal)
3
3
  [![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
4
 
@@ -12,7 +12,53 @@ Use in one of two ways:
12
12
 
13
13
  Glimmer DSL for Opal successfully reuses the entire [Glimmer](https://github.com/AndyObtiva/glimmer) core DSL engine in [Opal Ruby](https://opalrb.com/) inside a web browser, and as such inherits the full range of powerful Glimmer desktop [data-binding](https://github.com/AndyObtiva/glimmer#data-binding) capabilities for the web.
14
14
 
15
- NOTE: Alpha Version 0.7.1 only supports bare-minimum capabilities for the following [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt) [samples](https://github.com/AndyObtiva/glimmer#samples):
15
+ #### Tic Tac Toe Sample
16
+
17
+ Add the following require statement to `app/assets/javascripts/application.rb` in a [Glimmer setup](#setup) Rails app:
18
+
19
+ ```ruby
20
+ require 'glimmer-dsl-opal/samples/elaborate/tic_tac_toe'
21
+ ```
22
+
23
+ Glimmer GUI code from [glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb](glimmer-dsl-opal/samples/elaborate/tic_tac_toe.rb):
24
+
25
+ ```ruby
26
+ # ...
27
+ @shell = shell {
28
+ text "Tic-Tac-Toe"
29
+ minimum_size 150, 178
30
+ composite {
31
+ grid_layout 3, true
32
+ (1..3).each { |row|
33
+ (1..3).each { |column|
34
+ button {
35
+ layout_data :fill, :fill, true, true
36
+ text bind(@tic_tac_toe_board[row, column], :sign)
37
+ enabled bind(@tic_tac_toe_board[row, column], :empty)
38
+ font style: :bold, height: 20
39
+ on_widget_selected {
40
+ @tic_tac_toe_board.mark(row, column)
41
+ }
42
+ }
43
+ }
44
+ }
45
+ }
46
+ }
47
+ # ...
48
+ ```
49
+ Tic Tac Toe on the web (using the [glimmer-dsl-opal](https://rubygems.org/gems/glimmer-dsl-opal) gem):
50
+
51
+ ![Glimmer DSL for Opal Tic Tac Toe](images/glimmer-dsl-opal-tic-tac-toe.png)
52
+ ![Glimmer DSL for Opal Tic Tac Toe In Progress](images/glimmer-dsl-opal-tic-tac-toe-in-progress.png)
53
+ ![Glimmer DSL for Opal Tic Tac Toe Game Over](images/glimmer-dsl-opal-tic-tac-toe-game-over.png)
54
+
55
+ Tic Tac Toe on the desktop with the same exact code (using the [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
56
+
57
+ ![Glimmer DSL for SWT Tic Tac Toe](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-tic-tac-toe.png)
58
+ ![Glimmer DSL for SWT Tic Tac Toe In Progress](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-tic-tac-toe-in-progress.png)
59
+ ![Glimmer DSL for SWT Tic Tac Toe Game Over](https://github.com/AndyObtiva/glimmer-dsl-swt/raw/master/images/glimmer-tic-tac-toe-game-over.png)
60
+
61
+ NOTE: Alpha Version 0.7.2 only supports bare-minimum capabilities for the following [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt) [samples](https://github.com/AndyObtiva/glimmer#samples):
16
62
 
17
63
  Hello:
18
64
 
@@ -133,7 +179,7 @@ Add the following to `Gemfile`:
133
179
  gem 'opal-rails', '~> 1.1.2'
134
180
  gem 'opal-async', '~> 1.2.0'
135
181
  gem 'opal-jquery', '~> 0.4.4'
136
- gem 'glimmer-dsl-opal', '~> 0.7.1'
182
+ gem 'glimmer-dsl-opal', '~> 0.7.2'
137
183
  gem 'glimmer-dsl-xml', '~> 1.1.0', require: false
138
184
  gem 'glimmer-dsl-css', '~> 1.1.0', require: false
139
185
 
@@ -172,7 +218,7 @@ Edit `app/views/layouts/application.html.erb` and add the following below other
172
218
 
173
219
  Clear the file `app/views/welcomes/index.html.erb` from any content.
174
220
 
175
- Open a `Document.ready?` block and add inside it Glimmer GUI DSL code or a require statement for one of the samples below.
221
+ Open `app/assets/javascripts/application.rb`, add a `Document.ready?` block, and add inside it Glimmer GUI DSL code or a require statement for one of the samples below.
176
222
 
177
223
  ```ruby
178
224
  Document.ready? do
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.1
1
+ 0.7.2
@@ -0,0 +1,31 @@
1
+ # Copyright (c) 2020 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ class Display
23
+ class << self
24
+ def setAppName(app_name)
25
+ # No Op in Opal
26
+ end
27
+ def setAppVersion(version)
28
+ # No Op in Opal
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ # Copyright (c) 2020 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ class File
23
+ class << self
24
+ def read(*args, &block)
25
+ # TODO implement via asset downloads in the future
26
+ # No Op in Opal
27
+ end
28
+ end
29
+ end
@@ -45,8 +45,10 @@ if RUBY_ENGINE == 'opal'
45
45
  # require 'glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.structure.min.css'
46
46
  # require 'glimmer-dsl-opal/vendor/jquery-ui/jquery-ui.theme.min.css'
47
47
  require 'opal-jquery'
48
- require 'glimmer'
48
+
49
49
  require 'facets/hash/symbolize_keys'
50
+ require 'glimmer-dsl-opal/ext/struct'
51
+ require 'glimmer'
50
52
  require 'glimmer-dsl-opal/ext/exception'
51
53
  require 'glimmer-dsl-opal/ext/date'
52
54
  require 'uri'
@@ -77,41 +79,6 @@ if RUBY_ENGINE == 'opal'
77
79
  result ||= method == 'handle'
78
80
  end
79
81
 
80
- class OS
81
- class << self
82
- def windows?
83
- # No Op in Opal
84
- end
85
-
86
- def mac?
87
- # No Op in Opal
88
- end
89
-
90
- def linux?
91
- # No Op in Opal
92
- end
93
- end
94
- end
95
-
96
- class File
97
- class << self
98
- def read(*args, &block)
99
- # TODO implement via asset downloads in the future
100
- # No Op in Opal
101
- end
102
- end
103
- end
104
-
105
- class Display
106
- class << self
107
- def setAppName(app_name)
108
- # No Op in Opal
109
- end
110
- def setAppVersion(version)
111
- # No Op in Opal
112
- end
113
- end
114
- end
115
82
  else
116
83
  require_relative 'glimmer/engine'
117
84
  end
@@ -0,0 +1,37 @@
1
+ # Copyright (c) 2020 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ class Struct
23
+ class << self
24
+ alias new_original new
25
+ def new(*args, &block)
26
+ new_original(*args, &block).tap do |struct_class|
27
+ if args.size >= 2 && args.last.is_a?(Hash) && args.last[:keyword_init]
28
+ struct_class.define_method(:initialize) do |struct_class_keyword_args|
29
+ struct_class_keyword_args.each do |attribute, value|
30
+ send("#{attribute}=", value)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -207,13 +207,13 @@ class HelloTable
207
207
  text 'Game Date'
208
208
  width 150
209
209
  sort_property :date # ensure sorting by real date value (not `game_date` string specified in items below)
210
- # editor :date_drop_down, property: :date_time
210
+ editor :date_drop_down, property: :date_time
211
211
  }
212
212
  table_column {
213
213
  text 'Game Time'
214
214
  width 150
215
215
  sort_property :time # ensure sorting by real time value (not `game_time` string specified in items below)
216
- # editor :time, property: :date_time
216
+ editor :time, property: :date_time
217
217
  }
218
218
  table_column {
219
219
  text 'Ballpark'
@@ -35,7 +35,7 @@ module Glimmer
35
35
  model_cells = new_model_collection.to_a.map {|m| @table.cells_for(m)}
36
36
  return if table_cells == model_cells
37
37
  if new_model_collection and new_model_collection.is_a?(Array)
38
- # @table_items_observer_registration&.unobserve # TODO re-enable
38
+ @table_items_observer_registration&.unobserve
39
39
  @table_items_observer_registration = observe(new_model_collection, @column_properties)
40
40
  add_dependent(@table_observer_registration => @table_items_observer_registration)
41
41
  @model_collection = new_model_collection
@@ -62,8 +62,7 @@ module Glimmer
62
62
  table_item.set_data(model)
63
63
  table_item.id = old_item_ids_per_model[model.hash] if old_item_ids_per_model[model.hash]
64
64
  end
65
- selected_table_items = parent.search {|item| selected_table_item_models.include?(item.get_data) }
66
- parent.selection = selected_table_items
65
+ parent.selection = parent.search {|item| selected_table_item_models.include?(item.get_data) }
67
66
  parent.redraw
68
67
  end
69
68
 
@@ -71,6 +70,7 @@ module Glimmer
71
70
  return if model_collection == @last_sorted_model_collection
72
71
  if model_collection == @last_populated_model_collection
73
72
  # Reapply the last table sort. The model collection has just been populated since it diverged from what it was before
73
+ # TODO optimize in the future by sorting elements in DOM directly
74
74
  parent.sort!
75
75
  else
76
76
  # The model collection was sorted by the model, but beyond sorting, it did not change from the last populated model collection.
@@ -45,7 +45,46 @@ module Glimmer
45
45
  event_listener.call(event)
46
46
  }
47
47
  }
48
- }
48
+ },
49
+ 'on_key_pressed' => {
50
+ event: 'keydown',
51
+ event_handler: -> (event_listener) {
52
+ -> (event) {
53
+ @last_key_pressed_event = event
54
+ @text = event.target.value
55
+ # TODO generalize this solution to all widgets that support key presses
56
+ # TODO support event.location once DOM3 is supported by opal-jquery
57
+ event.define_singleton_method(:keyCode) {event.which}
58
+ event.define_singleton_method(:key_code, &event.method(:keyCode))
59
+ event.define_singleton_method(:character) {event.which.chr}
60
+ event.define_singleton_method(:stateMask) do
61
+ state_mask = 0
62
+ state_mask |= SWTProxy[:alt] if event.alt_key
63
+ state_mask |= SWTProxy[:ctrl] if event.ctrl_key
64
+ state_mask |= SWTProxy[:shift] if event.shift_key
65
+ state_mask |= SWTProxy[:command] if event.meta_key
66
+ state_mask
67
+ end
68
+ event.define_singleton_method(:state_mask, &event.method(:stateMask))
69
+ doit = true
70
+ event.define_singleton_method(:doit=) do |value|
71
+ doit = value
72
+ end
73
+ event.define_singleton_method(:doit) { doit }
74
+ event_listener.call(event)
75
+
76
+ # TODO Fix doit false, it's not stopping input
77
+ unless doit
78
+ event.prevent
79
+ event.prevent_default
80
+ event.stop_propagation
81
+ event.stop_immediate_propagation
82
+ end
83
+
84
+ doit
85
+ }
86
+ }
87
+ },
49
88
  }
50
89
  end
51
90
 
@@ -23,8 +23,9 @@ module Glimmer
23
23
  module SWT
24
24
  # Emulates SWT's native org.eclipse.swt.custom.ControlEditor
25
25
  class ControlEditor
26
+ # TODO implement behavior for all these attributes
26
27
  ATTRIBUTES = [:grabHorizontal, :grabVertical, :horizontalAlignment, :verticalAlignment, :minimumWidth, :minimumHeight]
27
- attr_accessor *ATTRIBUTES
28
+ attr_accessor(*ATTRIBUTES)
28
29
  ATTRIBUTES.each do |attribute|
29
30
  alias_method attribute.underscore, attribute
30
31
  alias_method "#{attribute.underscore}=", "#{attribute}="
@@ -31,7 +31,13 @@ module Glimmer
31
31
  showPeriod: true,
32
32
  showLeadingZero: true,
33
33
  showOn: 'both',
34
+ showNowButton: true,
35
+ showCloseButton: true,
34
36
  button: "##{time_button_id}",
37
+ onClose: ->(v) {
38
+ @timepicker_done = true
39
+ dom_element.trigger('change')
40
+ },
35
41
  })
36
42
  else
37
43
  options = {}
@@ -105,9 +111,67 @@ module Glimmer
105
111
  {
106
112
  'on_widget_selected' => [
107
113
  {
108
- event: 'change'
114
+ event: 'change',
115
+ event_handler: -> (event_listener) {
116
+ -> (event) {
117
+ if @timepicker_done
118
+ @timepicker_done = false
119
+ event_listener.call(event)
120
+ end
121
+ }
122
+ }
109
123
  },
110
124
  ],
125
+ 'on_focus_lost' => [
126
+ {
127
+ event: 'blur',
128
+ event_handler: -> (event_listener) {
129
+ -> (event) {
130
+ if @timepicker_done
131
+ @timepicker_done = false
132
+ event_listener.call(event)
133
+ end
134
+ }
135
+ }
136
+ },
137
+ ],
138
+ 'on_key_pressed' => {
139
+ event: 'keydown',
140
+ event_handler: -> (event_listener) {
141
+ -> (event) {
142
+ # TODO generalize this solution to all widgets that support key presses
143
+ # TODO support event.location once DOM3 is supported by opal-jquery
144
+ event.define_singleton_method(:keyCode) {event.which}
145
+ event.define_singleton_method(:key_code, &event.method(:keyCode))
146
+ event.define_singleton_method(:character) {event.which.chr}
147
+ event.define_singleton_method(:stateMask) do
148
+ state_mask = 0
149
+ state_mask |= SWTProxy[:alt] if event.alt_key
150
+ state_mask |= SWTProxy[:ctrl] if event.ctrl_key
151
+ state_mask |= SWTProxy[:shift] if event.shift_key
152
+ state_mask |= SWTProxy[:command] if event.meta_key
153
+ state_mask
154
+ end
155
+ event.define_singleton_method(:state_mask, &event.method(:stateMask))
156
+ doit = true
157
+ event.define_singleton_method(:doit=) do |value|
158
+ doit = value
159
+ end
160
+ event.define_singleton_method(:doit) { doit }
161
+ event_listener.call(event)
162
+
163
+ # TODO Fix doit false, it's not stopping input
164
+ unless doit
165
+ event.prevent
166
+ event.prevent_default
167
+ event.stop_propagation
168
+ event.stop_immediate_propagation
169
+ end
170
+
171
+ doit
172
+ }
173
+ }
174
+ },
111
175
  }
112
176
  end
113
177
 
@@ -3,6 +3,7 @@ require 'glimmer/swt/property_owner'
3
3
  module Glimmer
4
4
  module SWT
5
5
  class LayoutDataProxy
6
+ # TODO make this polymorphic as GridData or RowData subclasses
6
7
  include Glimmer::SWT::PropertyOwner
7
8
  attr_reader :parent,
8
9
  :args,
@@ -48,6 +49,8 @@ module Glimmer
48
49
  @parent.dom_element.css('width', '100%') if width_hint.nil?
49
50
  else
50
51
  @parent.dom_element.css('text-align', @horizontal_alignment)
52
+ @parent.dom_element.css('margin-left', 'auto') if ['right', 'center'].include?(@horizontal_alignment.to_s)
53
+ @parent.dom_element.css('margin-right', 'auto') if ['left', 'center'].include?(@horizontal_alignment.to_s)
51
54
  end
52
55
  # TODO
53
56
  # reapply
@@ -85,13 +88,13 @@ module Glimmer
85
88
 
86
89
  def grab_excess_horizontal_space=(grab_excess_horizontal_space)
87
90
  @grab_excess_horizontal_space = grab_excess_horizontal_space
88
- @parent.dom_element.css('width', "100%") if @grab_excess_horizontal_space && width_hint.nil?
91
+ @parent.dom_element.css('width', "100%") if @grab_excess_horizontal_space && @horizontal_alignment == 'fill' && width_hint.nil?
89
92
  # reapply
90
93
  end
91
94
 
92
95
  def grab_excess_vertical_space=(grab_excess_vertical_space)
93
96
  @grab_excess_vertical_space = grab_excess_vertical_space
94
- @parent.dom_element.css('height', "100%") if @grab_excess_vertical_space && height_hint.nil?
97
+ @parent.dom_element.css('height', "100%") if @grab_excess_vertical_space && @vertical_alignment == 'fill' && height_hint.nil?
95
98
  # TODO
96
99
  # reapply
97
100
  end
@@ -75,7 +75,7 @@ module Glimmer
75
75
  end
76
76
 
77
77
  # Sets editor (e.g. combo)
78
- def editor=(args)
78
+ def editor=(*args)
79
79
  @editor = args
80
80
  end
81
81
 
@@ -37,7 +37,7 @@ module Glimmer
37
37
  editor_widget.render(table_item.cell_dom_element(table_column_index))
38
38
  # TODO tweak the width perfectly so it doesn't expand the table cell
39
39
  # editor_widget.dom_element.css('width', 'calc(100% - 20px)')
40
- editor_widget.dom_element.css('width', '90%') # just a good enough approximation
40
+ editor_widget.dom_element.css('width', "#{minimumWidth}%") # TODO implement property with pixels (and perhaps derive percentage separately from pixels)
41
41
  editor_widget.dom_element.css('height', "#{minimumHeight}px")
42
42
  editor_widget.dom_element.add_class('table-editor')
43
43
  # TODO consider relying on autofocus instead
@@ -139,6 +139,14 @@ module Glimmer
139
139
  redraw
140
140
  end
141
141
 
142
+ def redraw_selection
143
+ if parent.selection.include?(self)
144
+ dom_element.add_class('selected')
145
+ else
146
+ dom_element.remove_class('selected')
147
+ end
148
+ end
149
+
142
150
  def on_widget_selected(&block)
143
151
  event = 'click'
144
152
  delegate = $document.on(event, selector, &block)
@@ -43,6 +43,7 @@ module Glimmer
43
43
  text: {
44
44
  widget_value_property: :text,
45
45
  editor_gui: lambda do |args, model, property, table_proxy|
46
+ table_proxy.table_editor.minimumWidth = 90
46
47
  table_proxy.table_editor.minimumHeight = 10
47
48
  table_editor_widget_proxy = text(*args) {
48
49
  text model.send(property)
@@ -66,6 +67,7 @@ module Glimmer
66
67
  widget_value_property: :text,
67
68
  editor_gui: lambda do |args, model, property, table_proxy|
68
69
  first_time = true
70
+ table_proxy.table_editor.minimumWidth = 90
69
71
  table_proxy.table_editor.minimumHeight = 18
70
72
  table_editor_widget_proxy = combo(*args) {
71
73
  items model.send("#{property}_options")
@@ -118,10 +120,14 @@ module Glimmer
118
120
  widget_value_property: :date_time,
119
121
  editor_gui: lambda do |args, model, property, table_proxy|
120
122
  first_time = true
121
- table_proxy.table_editor.minimumHeight = 25
123
+ table_proxy.table_editor.minimumWidth = 90
124
+ table_proxy.table_editor.minimumHeight = 15
122
125
  date(*args) {
123
126
  date_time model.send(property)
124
127
  focus true
128
+ on_widget_selected {
129
+ table_proxy.finish_edit!
130
+ }
125
131
  on_focus_lost {
126
132
  table_proxy.finish_edit!
127
133
  }
@@ -139,10 +145,14 @@ module Glimmer
139
145
  widget_value_property: :date_time,
140
146
  editor_gui: lambda do |args, model, property, table_proxy|
141
147
  first_time = true
142
- table_proxy.table_editor.minimumHeight = 25
148
+ table_proxy.table_editor.minimumWidth = 80
149
+ table_proxy.table_editor.minimumHeight = 15
143
150
  date_drop_down(*args) {
144
151
  date_time model.send(property)
145
152
  focus true
153
+ on_widget_selected {
154
+ table_proxy.finish_edit!
155
+ }
146
156
  on_focus_lost {
147
157
  table_proxy.finish_edit!
148
158
  }
@@ -160,10 +170,14 @@ module Glimmer
160
170
  widget_value_property: :date_time,
161
171
  editor_gui: lambda do |args, model, property, table_proxy|
162
172
  first_time = true
163
- table_proxy.table_editor.minimumHeight = 25
173
+ table_proxy.table_editor.minimumWidth = 80
174
+ table_proxy.table_editor.minimumHeight = 15
164
175
  time(*args) {
165
176
  date_time model.send(property)
166
177
  focus true
178
+ on_widget_selected {
179
+ table_proxy.finish_edit!
180
+ }
167
181
  on_focus_lost {
168
182
  table_proxy.finish_edit!
169
183
  }
@@ -236,6 +250,7 @@ module Glimmer
236
250
  @table_editor = TableEditor.new(self)
237
251
  @table_editor.horizontalAlignment = SWTProxy[:left]
238
252
  @table_editor.grabHorizontal = true
253
+ @table_editor.minimumWidth = 90
239
254
  @table_editor.minimumHeight = 20
240
255
  if editable?
241
256
  on_mouse_up { |event|
@@ -300,11 +315,12 @@ module Glimmer
300
315
  new_selection = new_selection.to_a
301
316
  changed = (selection + new_selection) - (selection & new_selection)
302
317
  @selection = new_selection
303
- changed.each(&:redraw)
318
+ changed.each(&:redraw_selection)
304
319
  end
305
320
 
306
321
  def items=(new_items)
307
322
  @children = new_items
323
+ # TODO optimize in the future by sorting elements in DOM directly when no change to elements occur other than sort
308
324
  redraw
309
325
  end
310
326
 
@@ -604,7 +620,8 @@ module Glimmer
604
620
  event.singleton_class.send(:define_method, :column_index) do
605
621
  (table_data || event.target).attr('data-column-index')
606
622
  end
607
- event_listener.call(event)
623
+
624
+ event_listener.call(event) unless event.table_item.nil? && event.column_index.nil?
608
625
  }
609
626
  }
610
627
 
@@ -619,7 +636,8 @@ module Glimmer
619
636
  },
620
637
  'on_widget_selected' => {
621
638
  event: 'mouseup',
622
- }
639
+ event_handler: mouse_handler,
640
+ },
623
641
  }
624
642
  end
625
643
 
@@ -72,7 +72,7 @@ module Glimmer
72
72
  doit
73
73
  }
74
74
  }
75
- }
75
+ },
76
76
  }
77
77
  end
78
78
 
@@ -152,9 +152,9 @@ module Glimmer
152
152
  end
153
153
 
154
154
  def remove_all_listeners
155
- observation_request_to_event_mapping.keys.each do |keyword|
156
- [observation_request_to_event_mapping[keyword]].flatten.each do |mapping|
157
- @observation_requests[keyword].to_a.each do |event_listener|
155
+ effective_observation_request_to_event_mapping.keys.each do |keyword|
156
+ [effective_observation_request_to_event_mapping[keyword]].flatten.each do |mapping|
157
+ observation_requests[keyword].to_a.each do |event_listener|
158
158
  event = mapping[:event]
159
159
  event_handler = mapping[:event_handler]
160
160
  event_element_css_selector = mapping[:event_element_css_selector]
@@ -225,9 +225,9 @@ module Glimmer
225
225
  else
226
226
  old_element.replace_with(@dom)
227
227
  end
228
- @observation_requests&.clone&.each do |keyword, event_listener_set|
228
+ observation_requests&.clone&.each do |keyword, event_listener_set|
229
229
  event_listener_set.each do |event_listener|
230
- @observation_requests[keyword].delete(event_listener)
230
+ observation_requests[keyword].delete(event_listener) # TODO look into the implications of this and if it's needed.
231
231
  handle_observation_request(keyword, &event_listener)
232
232
  end
233
233
  end
@@ -268,6 +268,21 @@ module Glimmer
268
268
  {}
269
269
  end
270
270
 
271
+ def effective_observation_request_to_event_mapping
272
+ default_observation_request_to_event_mapping.merge(observation_request_to_event_mapping)
273
+ end
274
+
275
+ def default_observation_request_to_event_mapping
276
+ {
277
+ 'on_focus_gained' => {
278
+ event: 'focus',
279
+ },
280
+ 'on_focus_lost' => {
281
+ event: 'blur',
282
+ },
283
+ }
284
+ end
285
+
271
286
  def name
272
287
  self.class.name.split('::').last.underscore.sub(/_proxy$/, '').gsub('_', '-')
273
288
  end
@@ -352,14 +367,17 @@ module Glimmer
352
367
  end
353
368
  end
354
369
 
355
- def handle_observation_request(keyword, &event_listener)
356
- return unless observation_request_to_event_mapping.keys.include?(keyword)
370
+ def observation_requests
357
371
  @observation_requests ||= {}
358
- @observation_requests[keyword] ||= Set.new
372
+ end
373
+
374
+ def handle_observation_request(keyword, &event_listener)
375
+ return unless effective_observation_request_to_event_mapping.keys.include?(keyword)
359
376
  event = nil
360
377
  delegate = nil
361
- [observation_request_to_event_mapping[keyword]].flatten.each do |mapping|
362
- @observation_requests[keyword] << event_listener
378
+ [effective_observation_request_to_event_mapping[keyword]].flatten.each do |mapping|
379
+ observation_requests[keyword] ||= Set.new
380
+ observation_requests[keyword] << event_listener
363
381
  event = mapping[:event]
364
382
  event_handler = mapping[:event_handler]
365
383
  event_element_css_selector = mapping[:event_element_css_selector]
@@ -555,11 +573,7 @@ module Glimmer
555
573
  TableProxy => {
556
574
  :selection => lambda do |observer|
557
575
  on_widget_selected { |selection_event|
558
- if has_style?(:multi)
559
- observer.call(selection.map(&:get_data))
560
- else
561
- observer.call(selection.first&.get_data)
562
- end
576
+ observer.call(selection_event.table_item.get_data) # TODO ensure selection doesn't conflict with editing
563
577
  }
564
578
  end,
565
579
  },
@@ -0,0 +1,36 @@
1
+ # Copyright (c) 2020 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ class OS
23
+ class << self
24
+ def windows?
25
+ # No Op in Opal
26
+ end
27
+
28
+ def mac?
29
+ # No Op in Opal
30
+ end
31
+
32
+ def linux?
33
+ # No Op in Opal
34
+ end
35
+ end
36
+ end
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.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-06 00:00:00.000000000 Z
11
+ date: 2020-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer
@@ -222,9 +222,12 @@ files:
222
222
  - app/assets/stylesheets/glimmer/jquery-ui.structure.css
223
223
  - app/assets/stylesheets/glimmer/jquery-ui.theme.css
224
224
  - app/assets/stylesheets/glimmer/jquery.ui.timepicker.css
225
+ - lib/display.rb
226
+ - lib/file.rb
225
227
  - lib/glimmer-dsl-opal.rb
226
228
  - lib/glimmer-dsl-opal/ext/date.rb
227
229
  - lib/glimmer-dsl-opal/ext/exception.rb
230
+ - lib/glimmer-dsl-opal/ext/struct.rb
228
231
  - lib/glimmer-dsl-opal/samples/elaborate/contact_manager.rb
229
232
  - lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact.rb
230
233
  - lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_manager_presenter.rb
@@ -348,6 +351,7 @@ files:
348
351
  - lib/glimmer/ui/custom_widget.rb
349
352
  - lib/glimmer/util/proc_tracker.rb
350
353
  - lib/net/http.rb
354
+ - lib/os.rb
351
355
  - lib/uri.rb
352
356
  homepage: http://github.com/AndyObtiva/glimmer-dsl-opal
353
357
  licenses: