atome 0.5.6.6.9 → 0.5.6.7.3

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: 2b169503f78f879fea8335938cae3163960a85a2eb561956d3e39d48fc252866
4
- data.tar.gz: 26136e4215e1f80dbb644552c49b917b5c76f41375d8f30169c8c8a59a54abba
3
+ metadata.gz: 363b43b98c73c072bcd284e79e3903ce50f7aaa28b2ce8ae448862533c3ea355
4
+ data.tar.gz: b14b4c7f34e5fd98a83afaf1bfec698df673e8183ec056551dcbbf15c0287be1
5
5
  SHA512:
6
- metadata.gz: b8d08c0f3f2fe78f10989f52dd4521c8330754f5911fb5ce0c18689b77d59d14e3f0c50dd68d7b01917741d9be3bb557f58e11ae21587e47eca12a73a98c9805
7
- data.tar.gz: ee5092720184ad6f81ab86f3c3fd32161647377325f9455581a029bb4ac7e91e6596b42b96a527492aa8a6a3b7fde006f8f821b11861e07a59ec2b4a66663de3
6
+ metadata.gz: 7d3dbb34d73af5b09479b1dbef64365aaf509acd3cb7859d185e4ec79f5479b58cdbb2f15fb170b8ab8765fc7265915fe4aff04b0e419709d1835b4157bcb053
7
+ data.tar.gz: c1dd6f6ad63ee105768e565f345301c028c2cb8294ea872c8c6403f56402d4d48d8ecd705e0d0588234e36e6158a2c97079f2b25573ee7646619a3e28967b542
data/exe/atome CHANGED
@@ -574,7 +574,26 @@ if ARGV.include?('create')
574
574
  end
575
575
 
576
576
  if ARGV.include?('update')
577
- `gem install atome`
577
+
578
+ gem_name = 'atome'
579
+ local_gem_spec = Gem::Specification.find_by_name(gem_name) rescue nil
580
+ if local_gem_spec.nil?
581
+ puts " #{gem_name} gem is not install will install from distant server"
582
+ system("gem update #{gem_name}")
583
+ else
584
+ available_versions = Gem::Specification.find_all_by_name(gem_name).map(&:version)
585
+
586
+ latest_version = available_versions.max
587
+
588
+ if latest_version > local_gem_spec.version
589
+ puts "update availlable: #{local_gem_spec.version} -> #{latest_version}"
590
+ system("gem update #{gem_name}")
591
+ else
592
+ puts "No update necessary '#{gem_name}'. current version : #{local_gem_spec.version}"
593
+ end
594
+ end
595
+
596
+
578
597
  # TODO: also update index.html and all other files except the application folder
579
598
  # we check we are in atome app
580
599
  if Dir.exist?("#{destination}/application") && !Dir.exist?("#{destination}/vendor")
@@ -619,12 +638,8 @@ src/favicon.ico src/index_wasm.html src/index_opal.html src/index_server.html sr
619
638
 
620
639
  # now we get the version of the atome gem
621
640
  gem_name = 'atome'
622
-
623
- # Obtenez les informations du gem depuis RubyGems.org
624
- gem_info = Gems.info(gem_name)
625
-
626
- # Extrait la version la plus récente du gem
627
- latest_version = gem_info['version']
641
+ local_gem_spec = Gem::Specification.find_by_name(gem_name) rescue nil
642
+ latest_version=local_gem_spec.version
628
643
  puts "#{gem_name} #{latest_version} is now installed "
629
644
 
630
645
  end
data/lib/atome/atome.rb CHANGED
@@ -109,9 +109,9 @@ class Atome
109
109
  # post rendering processor
110
110
  params = particle_post(element, params, &user_proc)
111
111
  instance_variable_set("@#{element}", params) if store
112
+ Universe.historicize(@aid, :write, element, params)
112
113
  # after storage processor
113
114
  particle_after(element, params, &user_proc)
114
-
115
115
  # self
116
116
  end
117
117
 
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module ObjectExtension
3
4
 
5
+
4
6
  def new(params, &bloc)
5
7
  # Genesis = Genesis.Genesis
6
8
  if params.key?(:atome)
@@ -580,6 +582,48 @@ class Object
580
582
  # convert any foreign object (think HTML) to a pseudo atome objet , that embed foreign objet
581
583
  end
582
584
 
585
+
586
+ JS.eval(<<~JS)
587
+ window.preventDefaultAction = function(e) {
588
+ e.preventDefault();
589
+ }
590
+ JS
591
+
592
+ def touch_allow(allow)
593
+ if allow
594
+ # Retire l'écouteur d'événements en utilisant la fonction globale
595
+ JS.eval('document.removeEventListener("contextmenu", window.preventDefaultAction);')
596
+ else
597
+ # Ajoute l'écouteur d'événements en utilisant la fonction globale
598
+ JS.eval('document.addEventListener("contextmenu", window.preventDefaultAction);')
599
+ end
600
+ end
601
+
602
+
603
+ def allow_copy(allow)
604
+ if allow
605
+ # Rétablir la sélection et la copie de texte
606
+ JS.eval(<<~JS)
607
+ document.body.style.userSelect = 'auto'; // Permet la sélection de texte
608
+ document.removeEventListener('copy', preventDefaultAction); // Permet la copie
609
+ JS
610
+ else
611
+ # Bloquer la sélection et la copie de texte
612
+ JS.eval(<<~JS)
613
+ document.body.style.userSelect = 'none'; // Bloque la sélection de texte
614
+ document.addEventListener('copy', preventDefaultAction); // Bloque la copie
615
+ JS
616
+ end
617
+ end
618
+
619
+ # Définit la fonction preventDefaultAction dans un contexte global pour être utilisée par allow_copy
620
+ JS.eval(<<~JS)
621
+ window.preventDefaultAction = function(e) {
622
+ e.preventDefault();
623
+ }
624
+ JS
625
+
626
+
583
627
  end
584
628
 
585
629
  class CssProxy
@@ -617,7 +661,6 @@ class CssProxy
617
661
  @current_atome.instance_variable_get('@css').to_s
618
662
  end
619
663
 
664
+ end
620
665
 
621
666
 
622
-
623
- end
@@ -100,7 +100,7 @@ class Genesis
100
100
 
101
101
  # we historicize all write action below
102
102
  # we add the changes to the stack that must be synchronised
103
- Universe.historicize(@aid, :write, element, params)
103
+ # Universe.historicize(@aid, :write, element, params)
104
104
  computed_params
105
105
  elsif params || params == false
106
106
  "send a valid password to write #{element} value"
@@ -110,10 +110,6 @@ def atome_infos
110
110
  puts "users: #{Universe.users}"
111
111
  puts "current user: #{Universe.current_user}"
112
112
  puts "machine: #{Universe.current_machine}"
113
- server = Universe.current_server
114
- server ||= 'disconnected'
115
- puts "server: #{server}"
116
-
117
113
  end
118
114
 
119
115
  # help and example below :
@@ -141,21 +137,23 @@ end
141
137
  # the method below init the user
142
138
  def atome_genesis
143
139
  atome_infos
144
- A.server({ address: 'localhost:9292', type: 'ws' })
145
- A.init_websocket do |msg|
146
- puts "websocket initialised #{msg}"
140
+ server = Universe.current_server
141
+ server ||= 'disconnected'
142
+ puts "server: #{server}"
143
+
144
+ if server.start_with?('http')
145
+ A.server({ address: 'localhost:9292', type: 'ws' })
146
+ A.init_websocket do |msg|
147
+ puts "websocket initialised #{msg}"
148
+ end
147
149
  end
150
+
148
151
  end
149
152
 
150
153
  def init_database # this method is call from JS (atome/communication) at WS connection
151
154
  # we init the db file eDen
152
155
  A.sync({ action: :init_db, data: { database: :eDen } }) do |data|
153
-
154
- if data[:data][:message] == 'database_ready'
155
- Universe.database_ready = true
156
- else
157
- Universe.database_ready = false
158
- end
156
+ Universe.database_ready = data[:data][:message] == 'database_ready'
159
157
  end
160
158
  # authentication : email, pass
161
159
  # atome : date, particles
@@ -163,7 +161,7 @@ def init_database # this method is call from JS (atome/communication) at WS conn
163
161
 
164
162
  particles = Universe.particle_list
165
163
  # now we populate the DB
166
- A.sync({ action: :crate_db_table, data: { table: :user, type: :string } }) do |_db_state|
164
+ A.sync({ action: :crate_db_table, data: { table: :user, type: :string } }) do |_db_state|
167
165
  # puts "===> #{_db_state}"
168
166
  end
169
167
 
@@ -193,10 +191,9 @@ def init_database # this method is call from JS (atome/communication) at WS conn
193
191
  end
194
192
 
195
193
  # now we send localstorage content to the server
196
- puts "now we send localstorage send_localstorage_content to the server"
197
- send_localstorage_content
198
- # A.message({ action: :localstorage, data: get_localstorage_content }) do |_db_state|
199
- # end
194
+ puts "sending localstorage"
195
+ Atome.send_localstorage_content
196
+
200
197
  end
201
198
 
202
199
  def user_login
@@ -211,4 +208,5 @@ def user_login
211
208
 
212
209
  end
213
210
 
214
- Universe.allow_history=true
211
+ Universe.allow_history = true
212
+ touch_allow(false) # this lock the system right click in web view
@@ -105,6 +105,7 @@ class Universe
105
105
  def id_to_aid(id, aid)
106
106
  @atomes_ids[id] = aid
107
107
  end
108
+
108
109
  # def update_atome_id(aid, atome, prev_id)
109
110
  # @atomes[id] = atome
110
111
  # @atomes.delete(prev_id)
@@ -197,10 +198,8 @@ class Universe
197
198
  end
198
199
 
199
200
  def current_server
200
- # Remplacez 'atome' par la valeur correcte pour votre environnement Atome
201
- return unless RUBY_ENGINE.downcase == 'opal'
201
+ # return unless RUBY_ENGINE.downcase == 'opal'
202
202
  JS.global[:location][:href].to_s
203
-
204
203
  end
205
204
 
206
205
  def current_user
@@ -248,14 +247,16 @@ class Universe
248
247
  def historicize(id, operation, element, params)
249
248
 
250
249
  # if @allow_history && @database_ready
251
- if @allow_history
252
- # A.sync({ action: :historicize, data: { table: :user } }) do |_db_state|
253
- # end
250
+ if @allow_history
251
+ # A.sync({ action: :historicize, data: { table: :user } }) do |_db_state|
252
+ # end
254
253
  operation_timing = Time.now.strftime("%Y%m%d%H%M%S%3N") + @increment.to_s
255
254
  @increment += 1
256
255
  @increment = @increment % 100
256
+
257
257
  JS.global[:localStorage].setItem(operation_timing, "{ #{id} => { #{operation} => { #{element} => #{params} } }, sync: false }")
258
258
  @history[@history.length] = { operation_timing => { id => { operation => { element => params } }, sync: false, time: Time.now } }
259
+
259
260
  end
260
261
  end
261
262
 
@@ -6,8 +6,36 @@ require 'json'
6
6
  class Atome
7
7
  class << self
8
8
  attr_accessor :initialized
9
+ def sanitize_data_for_json(data)
10
+ data = data.gsub('"', '\\"')
11
+ # case data
12
+ # when String
13
+ # data.gsub('"', '\\"')
14
+ # when Hash
15
+ # data.transform_values { |value| sanitize_data(value) }
16
+ # when Array
17
+ # data.map { |value| sanitize_data(value) }
18
+ # else
19
+ # data
20
+ # end
21
+ data
22
+ end
23
+
24
+
25
+ def send_localstorage_content
26
+ storage = JS.global[:localStorage]
27
+ storage_array = storage.to_a
28
+ storage_array.each_with_index do |_i, index|
29
+ key = JS.global[:localStorage].key(index)
30
+ sanitize_data_for_json(storage.getItem(key))
31
+ end
32
+ end
33
+
34
+ def server_receiver(params)
35
+ callback_found = Universe.messages[params[:message_id]]
36
+ callback_found.call(params) if callback_found.is_a? Proc
37
+ end
9
38
 
10
- # end
11
39
  def file_handler(parent, content, bloc)
12
40
  grab(parent).instance_exec(content, &bloc)
13
41
  end
@@ -403,10 +431,6 @@ class Atome
403
431
  end
404
432
  end
405
433
 
406
- def server_receiver(params)
407
- callback_found = Universe.messages[params[:message_id]]
408
- callback_found.call(params) if callback_found.is_a? Proc
409
- end
410
434
 
411
435
  def init_websocket
412
436
  connection(@current_server)
@@ -434,39 +458,7 @@ class Atome
434
458
  storage_items
435
459
  end
436
460
 
437
- def sanitize_data_for_json(data)
438
- data = data.gsub('"', '\\"')
439
- # case data
440
- # when String
441
- # data.gsub('"', '\\"')
442
- # when Hash
443
- # data.transform_values { |value| sanitize_data(value) }
444
- # when Array
445
- # data.map { |value| sanitize_data(value) }
446
- # else
447
- # data
448
- # end
449
- data
450
- end
451
461
 
452
- def send_localstorage_content
453
- storage = JS.global[:localStorage]
454
- storage_array = storage.to_a
455
- # storage_items={}
456
- storage_array.each_with_index do |_i, index|
457
- key = JS.global[:localStorage].key(index)
458
- value = sanitize_data_for_json(JS.global[:localStorage].getItem(key))
459
- # storage_items[key] = value
460
- # puts key
461
- # puts value
462
- # A.message({ action: :localstorage, data: {key => value} }) do |_db_state|
463
- # # puts _db_state
464
- # end
465
- end
466
- # A.message({ action: :end_localstorage, data: '' }) do |_db_state|
467
- # puts _db_state
468
- # end
469
- end
470
462
 
471
463
  # def to_sym
472
464
  # puts "sanitizer temp patch when an atome is passed instead of an id"
@@ -480,6 +472,24 @@ class Atome
480
472
  Universe.store_messages({ msg_nb: message_id, proc: bloc })
481
473
  html.send_message(params)
482
474
  end
475
+
476
+ def alternate(*states)
477
+ @alternate ||= { state: 0 }
478
+ @alternate[:data] = states
479
+ if @alternate[:state] < states.length - 1
480
+ @alternate[:state] += 1
481
+ else
482
+ @alternate[:state] = 0
483
+ end
484
+
485
+ current_state = @alternate[:data][@alternate[:state] - 1]
486
+ if current_state.instance_of?(Hash)
487
+ current_state.each do |state, value|
488
+ send(state, value)
489
+ end
490
+ end
491
+ current_state
492
+ end
483
493
  end
484
494
 
485
495
 
data/lib/atome/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  # return atome version
4
4
  class Atome
5
- VERSION = '0.5.6.6.9'
5
+ VERSION = '0.5.6.7.3'
6
6
  end
@@ -223,6 +223,9 @@ class HTML
223
223
  # particles=params[:particles]
224
224
  # 'atomeJS.connect' is in the communication.js file ( connect: function (type, server, )
225
225
  JS.eval("atomeJS.connect('#{type}','#{server}')")
226
+
227
+ # @websocket = JS.new(JS.global.WebSocket.new("#{type}://#{server}"))
228
+
226
229
  # JS.eval("atomeJS.connect('ws://#{server}')")
227
230
  end
228
231
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  box({ left: 12, id: :the_first_box })
4
- c=color({ id: :the_bananas, blue: 0.21, green: 1 })
4
+ c=color({ id: :the_col, blue: 0.21, green: 1 })
5
5
 
6
6
  wait 1 do
7
7
  c.affect(:the_first_box)
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+
4
+ t=text(:hello)
5
+ t.edit(true)
6
+ b=box({left: 99})
7
+
8
+ b.touch(true) do
9
+ allow_copy(true)
10
+ touch_allow(true)
11
+ end
12
+
13
+
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+ # class Atome
3
+
4
+ b=box({ left: 12, id: :the_first_box })
5
+ b.touch(true) do
6
+
7
+ alt=b.alternate(true, false)
8
+ if alt
9
+ b.color(:green)
10
+ else
11
+ b.color(:red)
12
+ end
13
+ touch_allow(alt)
14
+
15
+ end
16
+
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ b = box({ left: 12, id: :the_first_box, top: 30 })
4
+
5
+ b.touch(true) do
6
+ b.alternate({ width: 33, color: :red, height: 33 , smooth: 0 }, { width: 66, color: :orange, blur: 8}, { height: 66, color: :green, smooth: 9, blur: 0})
7
+ end
8
+
9
+ c = circle({ left: 333 , top: 30})
10
+
11
+ c.touch(true) do
12
+ alt = b.alternate(true, false)
13
+ if alt
14
+ c.color(:yellowgreen)
15
+ else
16
+ c.color(:orange)
17
+ end
18
+ end
@@ -1,31 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
-
4
3
  # JS to ruby example & ruby to js example
5
4
 
6
5
  def my_ruby_meth(val)
7
- alert "kool from rb_meth: #{val}"
6
+ puts "=> rb_meth call from js: #{val}"
8
7
  end
9
8
 
10
- opal_js_code=<<STR
11
- function my_js_fct(val){
12
- Opal.eval("my_ruby_meth('"+val+"')");
13
- Opal.Object.$my_ruby_meth(val);
14
- }
15
- STR
16
-
17
-
18
- ruby_wasm_js_code=<<STR
19
- function my_js_fct(val){
20
- rubyVM.eval("my_ruby_meth('"+val+"')");
21
- }
22
- STR
23
-
24
-
25
-
26
- JS.eval("my_js_fct('hello')")
27
- JS.global.my_js_fct('super')
28
-
29
9
 
10
+ if Atome::host.to_s == 'web-opal'
11
+ JS.eval("my_opal_js_fct('js fct call with an eval')")
12
+ JS.global.my_opal_js_fct('js fct call directly')
13
+ elsif Atome::host.to_sym == :pure_wasm
14
+ JS.eval("my_ruby_wasm_js_fct('js fct call with an eval')")
15
+ end
30
16
 
31
17
 
18
+ "js code is in js/atome/atome.js"
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ t=text("touch the box to erase localstorage, long touch on the box to stop historicize")
3
+ b=box({top: 66})
4
+ c=circle({top: 99})
5
+ c.touch(true) do
6
+ c.left(c.left+99)
7
+ # c.left=c.left+33
8
+ # box
9
+ end
10
+ b.touch(true) do
11
+ JS.eval('localStorage.clear()')
12
+ end
13
+
14
+ b.touch(:long) do
15
+ b.color(:red)
16
+ Universe.allow_history = false
17
+
18
+ end
19
+
@@ -113,18 +113,18 @@ module Molecule
113
113
  end
114
114
 
115
115
 
116
- def alternate(states = nil)
117
- if states
118
-
119
- else
120
- @alternate
121
- end
122
-
116
+ def alternate(*states)
117
+ # if states
118
+ #
119
+ # else
120
+ # @alternate
121
+ # end
122
+ alert states
123
123
  end
124
124
  end
125
125
  c= circle({left: 399})
126
126
  test_cell.touch(true) do
127
- test_cell.alternate([{ width: 33, color: :red }, { width: 66, color: :orange }])
127
+ test_cell.alternate({ width: 33, color: :red }, { width: 66, color: :orange })
128
128
  # puts "=> #{Universe.atomes.length}"
129
129
  # puts test_cell.color
130
130
  # if test_cell.data==true
@@ -1,31 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
 
4
- # JS to ruby example & ruby to js example
5
4
 
6
- def my_ruby_meth(val)
7
- alert "kool from rb_meth: #{val}"
8
- end
9
5
 
10
- opal_js_code=<<STR
11
- function my_js_fct(val){
12
- Opal.eval("my_ruby_meth('"+val+"')");
13
- Opal.Object.$my_ruby_meth(val);
14
- }
15
- STR
16
6
 
17
7
 
18
- ruby_wasm_js_code=<<STR
19
- function my_js_fct(val){
20
- rubyVM.eval("my_ruby_meth('"+val+"')");
21
- }
22
- STR
23
8
 
24
9
 
25
10
 
26
- JS.eval("my_js_fct('hello')")
27
- JS.global.my_js_fct('super')
28
-
29
-
30
11
 
31
12