atome 0.5.7.3.3 → 0.5.7.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f111d86401c9293ac46fa899d202bf0ab2a1c905d5d17186f0b87ba0560f65d
4
- data.tar.gz: ae3208f9349448b93a93864308445ce9108c450366ce8ee2ac1b7026724b40c2
3
+ metadata.gz: 7d7593f1e5f01474e9e5445f3af74ca576521aa07623acc289a2df9946d38447
4
+ data.tar.gz: 157a8892017ec1c64a7193d261ae21c2c0361c8fef232ceeda18181a02e470b8
5
5
  SHA512:
6
- metadata.gz: 3139df2c2320097e707d095e2aa577104669823e61c77fa9b7a4e43553537068926cea7701bd0cd9c8e21bd41087f9d1e04f101883adcd0ea3b5cc84ba1d665e
7
- data.tar.gz: c151bca3643df87d2388087cf534eb44e22e3ca8bf4281de8a9311bc7a20717164dd8be7c4a65dced3365e23e110af18648d732374706aaa9aab1fabcfc98bee
6
+ metadata.gz: 49dff402a4d28eaf636d76574701b7739b4e33d961b1402936469facd548234c17c4d4e4733aecbea7c1a5e31d8089bbbdd5a8b4c2cf008d8c6b220af8be6f6a
7
+ data.tar.gz: 0ab6747de306ebcd4d0e06974bc0f6ecdbad1eb59477c2b96aca7be4bfaaf5851bb507d5cdb04f8ea8e6fdf5196842b5c1d8bd083aafa07bcc53c8e882d68e88
data/lib/atome/atome.rb CHANGED
@@ -19,7 +19,6 @@ class Atome
19
19
  #
20
20
  # end
21
21
 
22
-
23
22
  def initialize(new_atome = {}, &atomes_proc)
24
23
  # TODO: atome format should always be as followed : {value: 0.44, unit: :px, opt1: 554}
25
24
  # when using optimised version of atome you must type eg : a.set({left: {value: 33, unit: '%', reference: :center}})
@@ -38,8 +37,8 @@ class Atome
38
37
  # @language = :english
39
38
  # @callback = {}
40
39
  @tag = {}
41
- @tick={}
42
- @storage={}
40
+ @tick = {}
41
+ @storage = {}
43
42
  @behavior = {}
44
43
  @selected = false
45
44
  #@metrics = {}
@@ -48,49 +47,44 @@ class Atome
48
47
  @collect = {}
49
48
  @int8 = {}
50
49
  @css = {}
51
- @code={}
52
- @aid= new_atome[:aid] || identity_generator
53
- @controller_proc=[]
50
+ @code = {}
51
+ @aid = new_atome[:aid] || identity_generator
52
+ @controller_proc = []
54
53
  @id = new_atome[:id] || @aid
55
- Universe.atomes.each_value do |atome_f|
56
- # we affect the already existing atome to target
57
- next unless atome_f.id == @id
54
+ # if grab(@id)
55
+ # collapse({})
56
+ # puts "#{@id} already exists"
57
+ # else
58
+ Universe.atomes.each_value do |atome_f|
59
+ # we affect the already existing atome to target
60
+ next unless atome_f.id == @id
58
61
 
59
- new_atome[:affect].each do |affected|
60
- grab(affected).apply(@id)
62
+ new_atome[:affect].each do |affected|
63
+ grab(affected).apply(@id)
64
+ end if new_atome[:affect]
65
+ return false
61
66
  end
62
- return false
63
- end
64
- Universe.add_to_atomes(@aid, self)
65
- Universe.id_to_aid(@id, @aid)
66
- @type = new_atome[:type] || :element
67
- @attached = []
68
- @affect = []
69
- @category = []
70
- # @display = { mode: :default }
71
- # @backup={} # mainly used to restore particle when using grid /table /list display mode
72
- @html = HTML.new(@id, self)
73
- @headless = Headless.new(@id, self)
74
- @initialized={}
75
- @creator= Universe.current_user
76
- # now we store the proc in a an atome's property called :bloc
77
- new_atome[:code] = atomes_proc if atomes_proc
78
- # we reorder the hash
79
- reordered_atome = reorder_particles(new_atome)
80
- # FIXME : try to remove the condition below (it crash in the method : def generator ... in genesis.rb)
81
- collapse(reordered_atome)
82
- # end
83
- # puts "@initialized : #{Atome.instance_variable_get('@initialized')}"
84
- # puts "****> #{Atome.instance_variable_get('@initialized')}"
67
+ Universe.add_to_atomes(@aid, self)
68
+ Universe.id_to_aid(@id, @aid)
69
+ @type = new_atome[:type] || :element
70
+ @attached = []
71
+ @affect = []
72
+ @category = []
73
+ # @display = { mode: :default }
74
+ # @backup={} # mainly used to restore particle when using grid /table /list display mode
75
+ @html = HTML.new(@id, self)
76
+ @headless = Headless.new(@id, self)
77
+ @initialized = {}
78
+ @creator = Universe.current_user
79
+ # now we store the proc in a an atome's property called :bloc
80
+ new_atome[:code] = atomes_proc if atomes_proc
81
+ # we reorder the hash
82
+ reordered_atome = reorder_particles(new_atome)
83
+ # FIXME : try to remove the condition below (it crash in the method : def generator ... in genesis.rb)
85
84
 
86
- # if Atome.instance_variable_get('@initialized')
87
- # puts "-----> #{Atome.instance_variable_get('@initialized')}"
88
- # Atome.instance_variable_get('@initialized').each do |p_found, bloc|
89
- # # puts "==> #{p_found}"
90
- # # instance_exec.call
91
- # # instance_exec(p_found, &bloc) if bloc.is_a?(Proc)
92
- # end
85
+ collapse(reordered_atome)
93
86
  # end
87
+
94
88
  end
95
89
 
96
90
  def js
@@ -1,16 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ObjectExtension
3
+ require 'time'
4
4
 
5
+ module ObjectExtension
5
6
 
6
7
  def new(params, &bloc)
7
8
  # Genesis = Genesis.Genesis
8
9
  if params.key?(:atome)
9
- # if Universe.atome_list.include?(params[:atome])
10
- # puts "atome #{params[:atome]} already exist you can't create it"
11
- # else
12
- Universe.add_atomes_specificities params[:atome]
13
- Genesis.build_atome(params[:atome], &bloc)
10
+ Universe.add_atomes_specificities params[:atome]
11
+ Genesis.build_atome(params[:atome], &bloc)
14
12
  # end
15
13
  elsif params.key?(:particle)
16
14
  if Universe.particle_list[params[:particle]]
@@ -51,12 +49,12 @@ module ObjectExtension
51
49
  # bloc.call(option)
52
50
  # end
53
51
  elsif params.key?(:molecule)
54
- molecule=params[:molecule]
52
+ molecule = params[:molecule]
55
53
  Genesis.build_molecule(molecule, &bloc)
56
54
  Universe.add_to_molecule_list(molecule)
57
55
 
58
- # elsif params.key?(:applicaton)
59
- # alert params
56
+ # elsif params.key?(:applicaton)
57
+ # alert params
60
58
 
61
59
  # molecule=params[:molecule]
62
60
  # Genesis.build_molecule(molecule, &bloc)
@@ -66,7 +64,7 @@ module ObjectExtension
66
64
 
67
65
  tool_content = Atome.instance_exec(&bloc) if bloc.is_a?(Proc)
68
66
 
69
- Universe.tools[params[:tool]]=tool_content
67
+ Universe.tools[params[:tool]] = tool_content
70
68
  # Universe.tools[params[:tool]]=bloc
71
69
 
72
70
  elsif params.key?(:template)
@@ -86,54 +84,6 @@ end
86
84
  # atome extensions
87
85
  class Object
88
86
  include ObjectExtension
89
- # def new(params, &bloc)
90
- # # Genesis = Genesis.Genesis
91
- # if params.key?(:atome)
92
- # if Universe.atome_list.include?(params[:atome])
93
- # puts "atome #{params[:atome]} already exist you can't create it"
94
- # else
95
- # Universe.add_atomes_specificities params[:atome]
96
- # Genesis.build_atome(params[:atome], &bloc)
97
- # end
98
- # elsif params.key?(:particle)
99
- # if Universe.particle_list[params[:particle]]
100
- # puts "particle #{params[:particle]} already exist you can't create it"
101
- # else
102
- # Atome.instance_variable_set("@main_#{params[:particle]}", bloc)
103
- # # render indicate if the particle needs to be rendered
104
- # # store tell the system if it need to store the particle value
105
- # # type help the system what type of type the particle will receive and store
106
- # Genesis.build_particle(params[:particle], { render: params[:render], return: params[:return],
107
- # store: params[:store], type: params[:type],
108
- # category: params[:category] }, &bloc)
109
- # end
110
- #
111
- # elsif params.key?(:sanitizer)
112
- # Genesis.build_sanitizer(params[:sanitizer], &bloc)
113
- # elsif params.key?(:pre)
114
- # Atome.instance_variable_set("@pre_#{params[:pre]}", bloc)
115
- # elsif params.key?(:post)
116
- # Atome.instance_variable_set("@post_#{params[:post]}", bloc)
117
- # elsif params.key?(:after)
118
- # Atome.instance_variable_set("@after_#{params[:after]}", bloc)
119
- # elsif params.key?(:read)
120
- # Atome.instance_variable_set("@read_#{params[:read]}", bloc)
121
- # elsif params[:renderer]
122
- # renderer_found = params[:renderer]
123
- # if params[:specific]
124
- # Universe.set_atomes_specificities(params)
125
- # params[:specific] = "#{params[:specific]}_"
126
- # end
127
- # render_method = "#{renderer_found}_#{params[:specific]}#{params[:method]}"
128
- # Genesis.build_render(render_method, &bloc)
129
- # # elsif params.key?(:callback)
130
- # # particle_targetted = params[:callback]
131
- # # Atome.define_method("#{particle_targetted}_callback", option) do
132
- # # alert option
133
- # # bloc.call(option)
134
- # # end
135
- # end
136
- # end
137
87
 
138
88
  def reorder_particles(hash_to_reorder)
139
89
  # we reorder the hash
@@ -142,7 +92,7 @@ class Object
142
92
  ordered_part = ordered_keys.map { |k| [k, hash_to_reorder[k]] }.to_h
143
93
  other_part = hash_to_reorder.reject { |k, _| ordered_keys.include?(k) }
144
94
  # merge the parts to obtain an re-ordered hash
145
- ordered_part.merge(other_part)
95
+ ordered_part.merge(other_part)
146
96
  # reordered_hash
147
97
  end
148
98
 
@@ -155,16 +105,14 @@ class Object
155
105
  end
156
106
 
157
107
  def hook(a_id)
158
- a_id=a_id.to_sym
108
+ a_id = a_id.to_sym
159
109
  Universe.atomes[a_id]
160
110
  end
161
111
 
162
112
  def grab(id_to_get)
163
- id_to_get=id_to_get.to_sym
113
+ id_to_get = id_to_get.to_sym
164
114
  return if id_to_get == false
165
- aid_to_get= Universe.atomes_ids[id_to_get]
166
- # puts id_to_get.class
167
- # alert Universe.atomes
115
+ aid_to_get = Universe.atomes_ids[id_to_get]
168
116
  aid_to_get = '' if aid_to_get.instance_of? Array
169
117
  # id_to_get = id_to_get.to_sym
170
118
 
@@ -255,7 +203,7 @@ class Object
255
203
 
256
204
  return intervalId;
257
205
  JS
258
- repeat_id+1
206
+ repeat_id + 1
259
207
  end
260
208
 
261
209
  def stop(params)
@@ -266,16 +214,16 @@ class Object
266
214
  JS.eval(<<~JS)
267
215
  clearInterval(#{repeater_to_stop});
268
216
  JS
269
- elsif params.key?(:wait)
217
+ elsif params.key?(:wait)
270
218
  waiter_to_stop = params[:wait]
271
219
  JS.eval(<<~JS)
272
- clearTimeout(window.timeoutIds['#{waiter_to_stop}'])
220
+ clearTimeout(window.timeoutIds['#{waiter_to_stop}'])
273
221
  JS
274
222
  else
275
- puts "La clé :repeat n'existe pas dans params"
223
+ puts "msg from stop method: the :repeat key doesn't exist"
276
224
  end
277
225
  else
278
- puts "params n'est pas un hash"
226
+ puts "msg from stop method, this params is not a Hash"
279
227
  end
280
228
  end
281
229
 
@@ -462,7 +410,6 @@ class Object
462
410
  event = Native(native_event)
463
411
  event.preventDefault
464
412
  event.stopPropagation
465
- # puts 'File drop out of the special zonne'
466
413
  end
467
414
  end
468
415
  end
@@ -480,12 +427,12 @@ class Object
480
427
  particle_list.delete(:password)
481
428
  particle_list.delete(:selection)
482
429
  infos = {}
483
- particle_list[:css]=:poil
430
+ particle_list[:css] = :poil
484
431
  particle_list.each do |particle_found|
485
432
  infos[particle_found[0]] = send(particle_found[0]) unless send(particle_found[0]).nil?
486
433
  end
487
434
  # we convert CssProxy object to hash below
488
- infos[:css]=eval(infos[:css].to_s)
435
+ infos[:css] = eval(infos[:css].to_s)
489
436
  infos
490
437
  end
491
438
 
@@ -618,8 +565,6 @@ class Object
618
565
  # convert any foreign object (think HTML) to a pseudo atome objet , that embed foreign objet
619
566
  end
620
567
 
621
-
622
-
623
568
  def touch_allow(allow)
624
569
  if allow
625
570
  # Retire l'écouteur d'événements en utilisant la fonction globale
@@ -630,7 +575,6 @@ class Object
630
575
  end
631
576
  end
632
577
 
633
-
634
578
  def allow_copy(allow)
635
579
  if allow
636
580
  # allow selection and text copy
@@ -647,7 +591,7 @@ class Object
647
591
  end
648
592
  end
649
593
 
650
- def above(item, margin=6)
594
+ def above(item, margin = 6)
651
595
  pos = item.to_px(:bottom) + item.height + margin
652
596
  if item.display == :none
653
597
  33
@@ -656,7 +600,7 @@ class Object
656
600
  end
657
601
  end
658
602
 
659
- def below(item, margin=6)
603
+ def below(item, margin = 6)
660
604
  pos = item.to_px(:top) + item.to_px(:height) + margin
661
605
  if item.display == :none
662
606
  0
@@ -666,7 +610,7 @@ class Object
666
610
 
667
611
  end
668
612
 
669
- def after(item, margin=6)
613
+ def after(item, margin = 6)
670
614
  left_f = if item.left.instance_of?(Integer)
671
615
  item.left
672
616
  else
@@ -686,7 +630,7 @@ class Object
686
630
  end
687
631
  end
688
632
 
689
- def before(item, margin=6)
633
+ def before(item, margin = 6)
690
634
  pos = item.to_px(:right) + item.width + margin
691
635
  if item.display == :none
692
636
  0
@@ -695,6 +639,130 @@ class Object
695
639
  end
696
640
  end
697
641
 
642
+ # Helper method to store task configuration in localStorage
643
+ def store_task(name, config)
644
+ JS.global[:localStorage].setItem(name, config.to_json)
645
+ end
646
+
647
+ # Helper method to retrieve task configuration from localStorage
648
+ def retrieve_task(name)
649
+ config = JS.global[:localStorage].getItem(name)
650
+ config.nil? ? nil : JSON.parse(config)
651
+ end
652
+
653
+ # Helper method to retrieve all tasks from localStorage
654
+ def retrieve_all_tasks
655
+ tasks = []
656
+ local_storage = JS.global[:localStorage]
657
+ if Atome::host == "web-opal"
658
+ local_storage.each do |key|
659
+ value = local_storage.getItem(key)
660
+ if value
661
+ value = JSON.parse(value)
662
+ tasks << { name: key, config: value }
663
+ end
664
+ end
665
+ else
666
+ length = local_storage[:length].to_i
667
+ length.times do |i|
668
+ key = local_storage.call(:key, i)
669
+ value = local_storage.call(:getItem, key)
670
+ tasks << { name: key, config: JSON.parse(value.to_s) } if value
671
+ end
672
+ end
673
+ tasks
674
+ end
675
+
676
+ # Helper method to schedule a task
677
+ def schedule_task(name, years, month, day, hours, minutes, seconds, recurrence: nil, &block)
678
+ target_time = Time.new(years, month, day, hours, minutes, seconds)
679
+ now = Time.now
680
+
681
+ if target_time < now
682
+ schedule_recurrence(name, target_time, recurrence, &block)
683
+ else
684
+ seconds_until_target = target_time - now
685
+ wait_task = wait(seconds_until_target) do
686
+ block.call
687
+ schedule_recurrence(name, target_time, recurrence, &block) if recurrence
688
+ end
689
+ store_task(name, { wait: wait_task, target_time: target_time, recurrence: recurrence })
690
+ end
691
+ end
692
+
693
+ def schedule_recurrence(name, target_time, recurrence, &block)
694
+ now = Time.now
695
+ next_time = target_time
696
+
697
+ case recurrence
698
+ when :yearly
699
+ next_time += 365 * 24 * 60 * 60 while next_time <= now
700
+ when :monthly
701
+ next_time = next_time >> 1 while next_time <= now
702
+ when :weekly
703
+ next_time += 7 * 24 * 60 * 60 while next_time <= now
704
+ when :daily
705
+ next_time += 24 * 60 * 60 while next_time <= now
706
+ when :hourly
707
+ next_time += 60 * 60 while next_time <= now
708
+ when :minutely
709
+ next_time += 60 while next_time <= now
710
+ when :secondly
711
+ next_time += 1 while next_time <= now
712
+ when Hash
713
+ if recurrence[:weekly]
714
+ wday = recurrence[:weekly]
715
+ next_time += 7 * 24 * 60 * 60 while next_time <= now
716
+ next_time += 24 * 60 * 60 until next_time.wday == wday
717
+ elsif recurrence[:monthly]
718
+ week_of_month = recurrence[:monthly][:week]
719
+ wday = recurrence[:monthly][:wday]
720
+ while next_time <= now
721
+ next_month = next_time >> 1
722
+ next_time = Time.new(next_month.year, next_month.month, 1, target_time.hour, target_time.min, target_time.sec)
723
+ next_time += 24 * 60 * 60 while next_time.wday != wday
724
+ next_time += (week_of_month - 1) * 7 * 24 * 60 * 60
725
+ end
726
+ end
727
+ else
728
+ puts "Invalid recurrence option"
729
+ return
730
+ end
731
+
732
+ seconds_until_next = next_time - Time.now
733
+ wait_task = wait(seconds_until_next) do
734
+ block.call
735
+ schedule_recurrence(name, next_time, recurrence, &block)
736
+ end
737
+ store_task(name, { wait: wait_task, target_time: next_time, recurrence: recurrence })
738
+ end
739
+
740
+ # Helper method to stop a scheduled task
741
+ def stop_task(name)
742
+ task_config = retrieve_task(name)
743
+ return unless task_config
744
+
745
+ stop({ wait: task_config['wait'] })
746
+ JS.global[:localStorage].removeItem(name)
747
+ end
748
+
749
+ # Method to relaunch all tasks from localStorage
750
+ def relaunch_all_tasks
751
+ tasks = retrieve_all_tasks
752
+
753
+ tasks.each do |task|
754
+ name = task[:name]
755
+ config = task[:config]
756
+ target_time_found = config['target_time']
757
+ target_time = Time.parse(target_time_found)
758
+ recurrence_found = config['recurrence']
759
+ next unless recurrence_found
760
+ recurrence = config['recurrence'].is_a?(Hash) ? config['recurrence'].transform_keys(&:to_sym) : config['recurrence'].to_sym
761
+ schedule_task(name, target_time.year, target_time.month, target_time.day, target_time.hour, target_time.min, target_time.sec, recurrence: recurrence) do
762
+ puts "Relaunched task #{name}(add proc here)"
763
+ end
764
+ end
765
+ end
698
766
 
699
767
  end
700
768
 
@@ -720,7 +788,7 @@ class CssProxy
720
788
  @js[@parent_key][key] = value
721
789
  @current_atome.instance_variable_set('@css', { @parent_key => { key => value } })
722
790
  @css[@parent_key] = { key => value }
723
- puts "==> Clé parente: #{@parent_key}, Clé: #{key}, Valeur: #{value}"
791
+ puts "==> parent key: #{@parent_key}, Clé: #{key}, value: #{value}"
724
792
  else
725
793
  @style[key] = value
726
794
  @js[key] = value
@@ -738,8 +806,6 @@ class CssProxy
738
806
  bloc.call(parsed)
739
807
  end
740
808
 
741
-
742
-
743
809
  end
744
810
 
745
811
 
@@ -81,12 +81,8 @@ class Genesis
81
81
  # end
82
82
 
83
83
  Atome.define_method element do |params = nil, &user_proc|
84
- # if @id
85
- # alert "======> #{self.class}"
86
84
  @history[element] ||= []
87
- # else
88
- # alert "======> #{self.inspect}"
89
- # end
85
+
90
86
  if (params || params == false) && write_auth(element)
91
87
  params = particle_sanitizer(element, params, &user_proc)
92
88
  # the line below execute the main code when creating a new particle
@@ -1,7 +1,16 @@
1
1
  # frozen_string_literal: true
2
+ class Atome
3
+ def animation_callback(proc_sub_category, value=nil)
4
+ # puts "#{p◊roc_sub_category}"
5
+ proc_found = @animate_code[proc_sub_category]
6
+ # puts proc_found
7
+ instance_exec(value,&proc_found) if proc_found.is_a?(Proc)
8
+ end
9
+ end
2
10
 
3
11
  new({ particle: :touch, category: :event, type: :hash, store: false })
4
12
  new({ sanitizer: :touch }) do |params, user_bloc|
13
+ # user_params=params.dup
5
14
  if params
6
15
  # TODO: factorise code below
7
16
  @touch ||= {}
@@ -11,6 +20,7 @@ new({ sanitizer: :touch }) do |params, user_bloc|
11
20
  user_bloc =params.delete(:code) if params[:code]
12
21
  @touch_code[params.keys[0]] = user_bloc
13
22
  option = params[params.keys[0]]
23
+ @touch={ code: user_bloc}
14
24
  params.keys[0]
15
25
  else
16
26
  case params
@@ -47,7 +57,6 @@ new({ sanitizer: :touch }) do |params, user_bloc|
47
57
  @touch = false
48
58
  params
49
59
  end
50
-
51
60
  end
52
61
  new({ particle: :play, category: :event, type: :boolean, store: false })
53
62
  new({ sanitizer: :play }) do |params, user_bloc|
@@ -94,6 +103,7 @@ new({ sanitizer: :on }) do |params, user_bloc|
94
103
  params = if params.instance_of? Hash
95
104
  @on_code[:view_resize] = user_bloc
96
105
  option = params[params.keys[0]]
106
+ @resize={ code: user_bloc}
97
107
  :resize
98
108
  else
99
109
  case params
@@ -123,6 +133,7 @@ new({ sanitizer: :drag }) do |params, user_bloc|
123
133
  user_bloc =params.delete(:code) if params[:code]
124
134
  @drag_code[params.keys[0]] = user_bloc
125
135
  option = params[params.keys[0]]
136
+ @drag={ code: user_bloc}
126
137
  params.keys[0]
127
138
  else
128
139
  case params
@@ -177,6 +188,7 @@ new({ sanitizer: :drop }) do |params, user_bloc|
177
188
  user_bloc =params.delete(:code) if params[:code]
178
189
  @drop_code[params.keys[0]] = user_bloc
179
190
  option = params[params.keys[0]]
191
+ @drop={ code: user_bloc}
180
192
  params.keys[0]
181
193
  else
182
194
  case params
@@ -215,6 +227,8 @@ new({ sanitizer: :over }) do |params, user_bloc|
215
227
  user_bloc =params.delete(:code) if params[:code]
216
228
  @over_code[params.keys[0]] = user_bloc
217
229
  option = params[params.keys[0]]
230
+ @over={ code: user_bloc}
231
+
218
232
  params.keys[0]
219
233
  else
220
234
  case params
@@ -242,9 +256,6 @@ new({ sanitizer: :over }) do |params, user_bloc|
242
256
  params
243
257
 
244
258
  end
245
- # new({ particle: :sort }) do |_value, sort_proc|
246
- # @sort_proc = sort_proc
247
- # end
248
259
  new({ particle: :targets, category: :event, type: :string })
249
260
  new({ particle: :start, category: :event, type: :boolean })
250
261
  new({ pre: :start }) do |_value, user_proc|
@@ -261,9 +272,8 @@ new({ particle: :mass, category: :event, type: :int })
261
272
  new({ particle: :damping, category: :event, type: :int })
262
273
  new({ particle: :stiffness, category: :event, type: :int })
263
274
  new({ particle: :velocity, category: :event, type: :int })
264
- # new({ particle: :repeat, category: :event, type: :boolean })
265
275
  new({ particle: :ease, category: :event, type: :boolean })
266
- new(particle: :keyboard, category: :event, type: :hash, store: false)
276
+ new({ particle: :keyboard, category: :event, type: :hash, store: false })
267
277
  new({ sanitizer: :keyboard }) do |params, user_bloc|
268
278
  @keyboard ||= {}
269
279
  @keyboard_code ||= {}
@@ -277,6 +287,8 @@ new({ sanitizer: :keyboard }) do |params, user_bloc|
277
287
  @keyboard_code[params.keys[0]] = user_bloc
278
288
  option = params[params.keys[0]]
279
289
  params.keys[0]
290
+ @keyboard={ code: user_bloc}
291
+
280
292
  else
281
293
  case params
282
294
  when true
@@ -314,6 +326,8 @@ new({ sanitizer: :resize }) do |params, user_bloc|
314
326
  params = if params.instance_of? Hash
315
327
  @resize_code[:resize] = user_bloc
316
328
  option = params[params.keys[0]]
329
+ @resize={ code: user_bloc}
330
+
317
331
  :resize
318
332
  else
319
333
  case params
@@ -338,16 +352,6 @@ new({ particle: :overflow, category: :event, type: :boolean }) do |params, bloc|
338
352
  params
339
353
 
340
354
  end
341
-
342
- class Atome
343
- def animation_callback(proc_sub_category, value=nil)
344
- # puts "#{p◊roc_sub_category}"
345
- proc_found = @animate_code[proc_sub_category]
346
- # puts proc_found
347
- instance_exec(value,&proc_found) if proc_found.is_a?(Proc)
348
- end
349
- end
350
-
351
355
  new({ particle: :animate, category: :event, type: :hash }) do |params, proc|
352
356
  if params.instance_of? Hash
353
357
  params = { from: 0, to: 300, duration: 1000 }.merge(params)
@@ -364,7 +368,12 @@ new({ particle: :animate, category: :event, type: :hash }) do |params, proc|
364
368
 
365
369
  params
366
370
  end
367
-
368
- new ({ after: :animate }) do |params|
371
+ new({ after: :animate }) do |params|
369
372
  html.animate(params) unless params[:end] || params[:start]
370
373
  end
374
+
375
+
376
+ # new({ particle: :repeat, category: :event, type: :boolean })
377
+ # # new({ particle: :sort }) do |_value, sort_proc|
378
+ # # @sort_proc = sort_proc
379
+ # # end
@@ -2,7 +2,7 @@
2
2
 
3
3
  new({ particle: :renderers, category: :utility, type: :string })
4
4
  new({ particle: :code, category: :utility, type: :string, store: false }) do |params, code|
5
- @code[params]=code
5
+ @code[params] = code
6
6
  end
7
7
  # new({ particle: :run, category: :utility, type: :boolean }) do |params|
8
8
  # code_found = @code
@@ -10,9 +10,9 @@ end
10
10
  # end
11
11
 
12
12
  new({ particle: :run }) do |params, code|
13
- instance_exec(&params) if params.is_a?(Proc)
14
- code_found = @code[params]
15
- instance_exec(params, &code_found) if code_found.is_a?(Proc)
13
+ instance_exec(&params) if params.is_a?(Proc)
14
+ code_found = @code[params]
15
+ instance_exec(params, &code_found) if code_found.is_a?(Proc)
16
16
  end
17
17
 
18
18
  new({ particle: :target }) do |params|
@@ -27,10 +27,9 @@ new({ particle: :target }) do |params|
27
27
  end
28
28
  end
29
29
 
30
-
31
30
  # new({ particle: :broadcast })
32
31
 
33
- def delete_recursive(atome_id, force=false)
32
+ def delete_recursive(atome_id, force = false)
34
33
  return if grab(atome_id).tag && (grab(atome_id).tag[:persistent] || grab(atome_id).tag[:system]) unless force
35
34
 
36
35
  parent_id_found = grab(atome_id).attach
@@ -47,86 +46,95 @@ def delete_recursive(atome_id, force=false)
47
46
  end
48
47
 
49
48
  new({ particle: :delete, category: :utility, type: :boolean, render: false }) do |params|
50
- if params == true
51
49
 
52
- # We use the tag persistent to exclude color of system object and other default colors
53
- unless @tag && (@tag[:persistent] || @tag[:system])
50
+ basic_system_object = %i[view eDen black_matter intuition copy atome
51
+ user_view view_color shape_color
52
+ box_color invisible_color text_color circle_color back_selection
53
+ text_selection nil
54
+ ]
55
+
56
+ unless basic_system_object.include?(id) || id.nil?
57
+
58
+ if params == true
59
+ # We use the tag persistent to exclude color of system object and other default colors
60
+ unless @tag && (@tag[:persistent] || @tag[:system])
61
+ # if we are on a matrix we delete cells found & group found
62
+ cells.delete(true)
63
+ group.delete(true)
64
+ # now we detach the atome from it's parent
65
+ # now we init rendering
66
+ render(:delete, params)
67
+ # the machine delete the current atome from the universe
68
+ id_found = @id.to_sym
69
+ if @attach
70
+ parent_found = grab(@attach)
71
+ parent_found.attached.delete(id_found)
72
+ end
73
+ @affect&.each do |affected_atome|
74
+ affected_found = grab(affected_atome)
75
+ affected_found.apply.delete(id_found)
76
+ affected_found.refresh
77
+ end
78
+
79
+ # Universe.delete(@aid)
80
+ end
81
+ elsif params.instance_of? Hash
54
82
  # if we are on a matrix we delete cells found & group found
55
83
  cells.delete(true)
56
84
  group.delete(true)
57
- # now we detach the atome from it's parent
58
- # now we init rendering
59
- render(:delete, params)
60
- # the machine delete the current atome from the universe
61
- id_found = @id.to_sym
62
- if @attach
63
- parent_found = grab(@attach)
64
- parent_found.attached.delete(id_found)
65
- end
66
- @affect&.each do |affected_atome|
67
- affected_found = grab(affected_atome)
68
- affected_found.apply.delete(id_found)
69
- affected_found.refresh
70
- end
71
- Universe.delete(@aid)
72
- end
73
- # elsif params == :force
74
- # cells.delete(true)
75
- # group.delete(true)
76
- # # now we detach the atome from it's parent
77
- # # now we init rendering
78
- # render(:delete, params)
79
- # # the machine delete the current atome from the universe
80
- # id_found = @id.to_sym
81
- # if @attach
82
- # parent_found = grab(@attach)
83
- # parent_found.attached.delete(id_found)
84
- # end
85
- # @affect&.each do |affected_atome|
86
- # affected_found = grab(affected_atome)
87
- # affected_found.apply.delete(id_found)
88
- # affected_found.refresh
89
- # end
90
- # Universe.delete(@aid)
91
- elsif params.instance_of? Hash
92
- # if we are on a matrix we delete cells found & group found
93
- cells.delete(true)
94
- group.delete(true)
95
- if params[:recursive]
96
- unless grab(@id).tag && (grab(@id).tag[:persistent] || grab(@id).tag[:system])
85
+ if params[:recursive]
86
+ unless grab(@id).tag && (grab(@id).tag[:persistent] || grab(@id).tag[:system])
87
+ attached.each do |atttached_atomes|
88
+ delete_recursive(atttached_atomes)
89
+ end
90
+ # touch(:remove)
91
+ # render(:delete, params)
92
+ # Universe.delete(@aid)
93
+ end
94
+ elsif params[:force]
97
95
  attached.each do |atttached_atomes|
98
- delete_recursive(atttached_atomes)
96
+ # alert "attached : #{attached}"
97
+ delete_recursive(atttached_atomes, true)
98
+ end
99
+ # touch(:remove)
100
+ # render(:delete, params)
101
+ # Universe.delete(@aid)
102
+ else
103
+ # the machine try to find the sub particle id and remove it eg a.delete(monitor: :my_monitor) remove the monitor
104
+ # with id my_monitor
105
+ params.each do |param, value|
106
+ atome[param][value] = nil
99
107
  end
100
- touch(:remove)
101
- render(:delete, params)
102
- Universe.delete(@aid)
103
- end
104
- elsif params[:force]
105
- attached.each do |atttached_atomes|
106
- # alert "attached : #{attached}"
107
- delete_recursive(atttached_atomes, true)
108
108
  end
109
- touch(:remove)
110
- render(:delete, params)
111
- # alert "Universe : #{Universe.atomes[@aid]}"
112
- # alert "length = #{Universe.atomes.length}"
113
- Universe.delete(@aid)
114
- # alert "Universe : #{Universe.atomes.length}"
115
109
 
110
+ elsif Universe.atome_list.include?(params)
111
+ # we check if the params passed is an atome to treat it in a different way
112
+ puts "write code here : #{apply} , #{attached}"
116
113
  else
117
- # the machine try to find the sub particle id and remove it eg a.delete(monitor: :my_monitor) remove the monitor
118
- # with id my_monitor
119
- params.each do |param, value|
120
- atome[param][value] = nil
114
+ send(params, 0) unless params == :id
115
+ end
116
+ touch(:remove)
117
+ drag(false)
118
+ drop(false)
119
+ on(false)
120
+ keyboard(false)
121
+ resize(:remove)
122
+ overflow(:remove)
123
+
124
+ render(:delete, params)
125
+ Universe.delete(@aid)
126
+
127
+ exclusions = %i[@history @renderers @type @tag @html]
128
+
129
+ instance_variables.each do |i_var|
130
+ unless exclusions.include?(i_var)
131
+ instance_variable_set(i_var, nil)
121
132
  end
122
133
  end
123
134
 
124
- elsif Universe.atome_list.include?(params)
125
- # we check if the params passed is an atome to treat it in a different way
126
- puts "write code here : #{apply} , #{attached}"
127
- else
128
- send(params, 0) unless params == :id
135
+ instance_variable_set('@renderers', [])
129
136
  end
137
+
130
138
  end
131
139
 
132
140
  new({ particle: :clear, category: :utility, type: :boolean })
@@ -226,7 +234,7 @@ new({ particle: :duplicate, category: :utility, type: :string, store: false }) d
226
234
  end
227
235
  params[:attached] = attached_atomes
228
236
  infos_found = infos.dup
229
- keys_to_delete = [:history, :callback, :duplicate, :copy, :paste, :touch_code, :html, :attached, :aid]
237
+ keys_to_delete = %i[history callback duplicate copy paste touch_code html attached aid]
230
238
  keys_to_delete.each { |key| infos_found.delete(key) }
231
239
  new_atome_id = "#{@id}_copy_#{copy_number}".to_sym
232
240
  infos_found[:id] = new_atome_id
@@ -117,6 +117,11 @@ class Atome
117
117
 
118
118
  @initialized = {}
119
119
 
120
+
121
+ def recursive(_val)
122
+ #dummy method
123
+ end
124
+
120
125
  def help(particle, &doc)
121
126
  if doc
122
127
  Universe.set_help(particle, &doc)
@@ -149,7 +154,6 @@ class Atome
149
154
  def collapse(new_atome)
150
155
  initialized_procs = []
151
156
  initialized = Atome.initialized
152
-
153
157
  new_atome.each do |element, value|
154
158
  send(element, value)
155
159
  initialized_proc = initialized[element]
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.7.3.3'
5
+ VERSION = '0.5.7.3.5'
6
6
  end
@@ -1303,6 +1303,7 @@ class HTML
1303
1303
  proc_content = @touch_tap.call(event) if event_validation(@touch_tap)
1304
1304
  if proc_content.instance_of? Hash
1305
1305
  proc_content.each do |k, v|
1306
+ # alert "(#{@original_atome.id}, #{k}, #{v}, #{_option})"
1306
1307
  @original_atome.send(k, v)
1307
1308
  end
1308
1309
  end
@@ -1329,8 +1330,6 @@ class HTML
1329
1330
  end
1330
1331
  end
1331
1332
  end
1332
-
1333
- # end
1334
1333
  end
1335
1334
 
1336
1335
  def touch_double(_option)
@@ -6,7 +6,7 @@ class Atome
6
6
 
7
7
  def render(element, params, &user_proc)
8
8
 
9
- render_engines = @renderers
9
+ render_engines = @renderers || []
10
10
  render_engines.each do |render_engine|
11
11
  # in case we found an exception the method call will have the form, example for color top : html_color_top
12
12
  exception_found = "#{Universe.get_atomes_specificities[type][element]}"
@@ -1,131 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'time'
4
- # Helper method to store task configuration in localStorage
5
- def store_task(name, config)
6
- JS.global[:localStorage].setItem(name, config.to_json)
7
- end
8
-
9
- # Helper method to retrieve task configuration from localStorage
10
- def retrieve_task(name)
11
- config = JS.global[:localStorage].getItem(name)
12
- config.nil? ? nil : JSON.parse(config)
13
- end
14
-
15
- # Helper method to retrieve all tasks from localStorage
16
- def retrieve_all_tasks
17
- tasks = []
18
- local_storage = JS.global[:localStorage]
19
- if Atome::host == "web-opal"
20
- local_storage.each do |key|
21
- value = local_storage.getItem(key)
22
- if value
23
- value= JSON.parse(value)
24
- tasks << { name: key, config:value }
25
- end
26
- end
27
- else
28
- length = local_storage[:length].to_i
29
- length.times do |i|
30
- key = local_storage.call(:key, i)
31
- value = local_storage.call(:getItem, key)
32
- tasks << { name: key, config: JSON.parse(value.to_s) } if value
33
- end
34
- end
35
- tasks
36
- end
37
-
38
- # Helper method to schedule a task
39
- def schedule_task(name, years, month, day, hours, minutes, seconds, recurrence: nil, &block)
40
- target_time = Time.new(years, month, day, hours, minutes, seconds)
41
- now = Time.now
42
-
43
- if target_time < now
44
- schedule_recurrence(name, target_time, recurrence, &block)
45
- else
46
- seconds_until_target = target_time - now
47
- wait_task = wait(seconds_until_target) do
48
- block.call
49
- schedule_recurrence(name, target_time, recurrence, &block) if recurrence
50
- end
51
- store_task(name, { wait: wait_task, target_time: target_time, recurrence: recurrence })
52
- end
53
- end
54
-
55
- def schedule_recurrence(name, target_time, recurrence, &block)
56
- now = Time.now
57
- next_time = target_time
58
-
59
- case recurrence
60
- when :yearly
61
- next_time += 365 * 24 * 60 * 60 while next_time <= now
62
- when :monthly
63
- next_time = next_time >> 1 while next_time <= now
64
- when :weekly
65
- next_time += 7 * 24 * 60 * 60 while next_time <= now
66
- when :daily
67
- next_time += 24 * 60 * 60 while next_time <= now
68
- when :hourly
69
- next_time += 60 * 60 while next_time <= now
70
- when :minutely
71
- next_time += 60 while next_time <= now
72
- when :secondly
73
- next_time += 1 while next_time <= now
74
- when Hash
75
- if recurrence[:weekly]
76
- wday = recurrence[:weekly]
77
- next_time += 7 * 24 * 60 * 60 while next_time <= now
78
- next_time += 24 * 60 * 60 until next_time.wday == wday
79
- elsif recurrence[:monthly]
80
- week_of_month = recurrence[:monthly][:week]
81
- wday = recurrence[:monthly][:wday]
82
- while next_time <= now
83
- next_month = next_time >> 1
84
- next_time = Time.new(next_month.year, next_month.month, 1, target_time.hour, target_time.min, target_time.sec)
85
- next_time += 24 * 60 * 60 while next_time.wday != wday
86
- next_time += (week_of_month - 1) * 7 * 24 * 60 * 60
87
- end
88
- end
89
- else
90
- puts "Invalid recurrence option"
91
- return
92
- end
93
-
94
- seconds_until_next = next_time - Time.now
95
- wait_task = wait(seconds_until_next) do
96
- block.call
97
- schedule_recurrence(name, next_time, recurrence, &block)
98
- end
99
- store_task(name, { wait: wait_task, target_time: next_time, recurrence: recurrence })
100
- end
101
-
102
- # Helper method to stop a scheduled task
103
- def stop_task(name)
104
- task_config = retrieve_task(name)
105
- return unless task_config
106
-
107
- stop({ wait: task_config['wait'] })
108
- JS.global[:localStorage].removeItem(name)
109
- end
110
-
111
- # Method to relaunch all tasks from localStorage
112
- def relaunch_all_tasks
113
- tasks = retrieve_all_tasks
114
-
115
- tasks.each do |task|
116
- name = task[:name]
117
- config = task[:config]
118
- target_time_found = config['target_time']
119
- target_time = Time.parse(target_time_found)
120
- recurrence_found = config['recurrence']
121
- next unless recurrence_found
122
- recurrence = config['recurrence'].is_a?(Hash) ? config['recurrence'].transform_keys(&:to_sym) : config['recurrence'].to_sym
123
- puts "found : #{name}, #{target_time.year}, #{target_time.month}, #{target_time.day}, #{target_time.hour}, #{target_time.min}, #{target_time.sec}, recurrence: #{recurrence}"
124
- schedule_task(name, target_time.year, target_time.month, target_time.day, target_time.hour, target_time.min, target_time.sec, recurrence: recurrence) do
125
- puts "Relaunched task #{name}"
126
- end
127
- end
128
- end
129
3
 
130
4
  ######## check
131
5
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atome
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7.3.3
4
+ version: 0.5.7.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Eric Godard
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-09 00:00:00.000000000 Z
11
+ date: 2024-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine