imba-localization 0.3.6 → 0.3.8

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.
Files changed (2) hide show
  1. package/localization.imba +23 -3
  2. package/package.json +1 -1
package/localization.imba CHANGED
@@ -5,6 +5,8 @@ export class Localization
5
5
  languages = {}
6
6
  preferred = (window..navigator..language || 'en-US').slice(0, 2)
7
7
  default
8
+ ready = false
9
+ errors = {}
8
10
 
9
11
  def constructor url, dft = 'en'
10
12
  default = dft
@@ -15,10 +17,16 @@ export class Localization
15
17
 
16
18
  return new Proxy self, {
17
19
  get: do(target, p, receiver)
20
+ if !ready
21
+ console.log("Request before localization is ready", p)
22
+ return
23
+ return if errors[p]
18
24
  return Reflect.get(target, p, receiver) if self[p]
19
25
  return target.languages[p] if target.languages[p]
20
26
  return target.languages[active][p] if target.languages[active] and target.languages[active][p]
21
- onerror('no_localization_key', p) if onerror isa Function
27
+ if !errors[p]
28
+ onerror('no_localization_key', p) if onerror isa Function
29
+ errors[p] = true
22
30
  return ''
23
31
  }
24
32
 
@@ -36,6 +44,7 @@ export class Localization
36
44
  else
37
45
  console.log('There is no Localization for the default language', default)
38
46
  return
47
+ ready = true
39
48
  onready! if onready isa Function
40
49
  onchange(active) if onchange isa Function
41
50
 
@@ -50,6 +59,7 @@ export class Localization
50
59
  if window.localStorage.getItem('imba-localization') != name
51
60
  window.localStorage.setItem('imba-localization', name)
52
61
  onchange(name) if onchange isa Function
62
+ errors = {}
53
63
 
54
64
  export const path-arrow-down = <path d="M213.66,165.66a8,8,0,0,1-11.32,0L128,91.31,53.66,165.66a8,8,0,0,1-11.32-11.32l80-80a8,8,0,0,1,11.32,0l80,80A8,8,0,0,1,213.66,165.66Z">
55
65
 
@@ -58,6 +68,7 @@ tag language-selector
58
68
  icons = "https://kapowaz.github.io/square-flags/flags/##.svg"
59
69
  #dropdown = false
60
70
  arrow = path-arrow-down
71
+ passive = false
61
72
 
62
73
  def setup
63
74
  if data
@@ -74,11 +85,20 @@ tag language-selector
74
85
  return icons.replace('##',country)
75
86
 
76
87
  def mouseleave e
88
+ return if passive
77
89
  const rect = self.getBoundingClientRect!
78
90
  const menu = $menu.getBoundingClientRect!
79
91
  const inside = e.clientY >= menu.bottom || e.clientY <= rect.top || (e.clientX <= rect.left and e.clientY <= rect.bottom) || (e.clientX <= menu.left and e.clientY >= menu.top) || (e.clientX >= rect.right and e.clientY <= rect.bottom) || (e.clientX >= menu.right and e.clientY >= menu.top)
80
92
  #dropdown = !inside
81
93
 
94
+ def mouseenter
95
+ return if passive
96
+ #dropdown = true
97
+
98
+ def click
99
+ return if !passive
100
+ #dropdown = !#dropdown
101
+
82
102
  css
83
103
  $ease: 0.5s
84
104
  .container rd:8px px:15px py:8px cursor:pointer bgc:light-dark(#000000/10, #FFFFFF/20) fw:500 fs:13px ead:$ease bd:1px solid transparent
@@ -92,7 +112,7 @@ tag language-selector
92
112
  .icon h:20px w:20px mr:10px rd:50% bd:1px solid transparent
93
113
  .text fs:13px bd:1px solid transparent
94
114
 
95
- <self [pos:rel] @mouseenter=(#dropdown = true) @mouseleave=mouseleave>
115
+ <self [pos:rel] @mouseenter=mouseenter @mouseleave=mouseleave @click=click>
96
116
  <div.container [pos:rel d:hcc] .active=#dropdown>
97
117
  <img.flag src=icon(state[state.active].$.flag)>
98
118
  <div.name> state.$.name
@@ -102,6 +122,6 @@ tag language-selector
102
122
  if #dropdown
103
123
  <div$menu.menu [pos:abs w:100% > max-content o@off:0] ease>
104
124
  for own key, value of state.languages
105
- <div.item @click=onselect(key) [d:none]=(key == state.active)>
125
+ <div.item @click.trap=onselect(key) [d:none]=(key == state.active)>
106
126
  <img.icon src=icon(value.$.flag)>
107
127
  <span.text> value.$.name
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imba-localization",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/HeapVoid/imba-localization.git"