@humandialog/forms.svelte 1.5.1 → 1.6.1

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.
package/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { getContext, tick } from "svelte";
2
- import {get} from 'svelte/store'
3
- import { contextItemsStore, contextToolbarOperations, pageToolbarOperations, data_tick_store } from "./stores";
2
+ import {derived, get} from 'svelte/store'
3
+ import { contextItemsStore, contextToolbarOperations, pageToolbarOperations, data_tick_store, main_sidebar_visible_store, show_sidebar, hide_sidebar, previously_visible_sidebar, auto_hide_sidebar} from "./stores";
4
4
  import {location, push, pop} from 'svelte-spa-router'
5
5
 
6
6
  export let icons = {symbols :null}
@@ -675,36 +675,196 @@ export const UI = {
675
675
  navigator: null
676
676
  }
677
677
 
678
- export const NAVIGATION_PAGE_PATH = '/'
679
- export function isOnNavigationPage()
678
+ export function dec2hex (dec)
679
+ {
680
+ return dec.toString(16).padStart(2, "0")
681
+ }
682
+
683
+
684
+ export function randomString(len)
685
+ {
686
+ var arr = new Uint8Array((len || 16) / 2)
687
+ window.crypto.getRandomValues(arr)
688
+ return Array.from(arr, dec2hex).join('')
689
+ }
690
+
691
+
692
+ export const NAVIGATION_PAGE_PATH = '/nav'
693
+ let savedAppPage = ''
694
+ let lastNavPage = ''
695
+
696
+ export function isOnNavigationPage(navKind)
680
697
  {
681
698
  const loc = get(location)
682
- if(loc == NAVIGATION_PAGE_PATH)
683
- return true;
699
+
700
+ if(!navKind)
701
+ {
702
+ if(loc.startsWith(NAVIGATION_PAGE_PATH))
703
+ return true;
704
+ else
705
+ return false;
706
+ }
684
707
  else
685
- return false;
708
+ {
709
+ if(loc.startsWith(`${NAVIGATION_PAGE_PATH}/${navKind}`))
710
+ return true;
711
+ else
712
+ return false;
713
+ }
714
+
686
715
  }
687
716
 
688
- export function pushNavigationPage()
717
+
718
+ export function pushNavigationPage(navKind)
689
719
  {
690
- push(NAVIGATION_PAGE_PATH)
720
+ if(!isOnNavigationPage())
721
+ savedAppPage = get(location)
722
+
723
+ if(!navKind)
724
+ {
725
+ navKind = navPrevVisibleKey()
726
+ if(!navKind)
727
+ lastNavPage = `${NAVIGATION_PAGE_PATH}/`
728
+ else
729
+ lastNavPage = `${NAVIGATION_PAGE_PATH}/${navKind}`
730
+ }
731
+ else
732
+ lastNavPage = `${NAVIGATION_PAGE_PATH}/${navKind}`
733
+
734
+ push(lastNavPage)
691
735
  }
692
736
 
693
737
  export function popNavigationPage()
694
738
  {
695
739
  if(isOnNavigationPage())
696
- pop();
740
+ {
741
+ if(savedAppPage)
742
+ push(savedAppPage)
743
+ else
744
+ pop()
745
+
746
+ savedAppPage = ''
747
+ }
697
748
  }
698
749
 
699
- export function dec2hex (dec)
750
+ export const NAV_MODE_SIDEBAR = 0
751
+ export const NAV_MODE_FULL_PAGE = 1
752
+
753
+ let navMode = isDeviceSmallerThan("sm") ? NAV_MODE_FULL_PAGE : NAV_MODE_SIDEBAR
754
+
755
+ export function navGetMode()
700
756
  {
701
- return dec.toString(16).padStart(2, "0")
757
+ return navMode;
702
758
  }
703
-
704
759
 
705
- export function randomString(len)
760
+ export function navIsVisible()
706
761
  {
707
- var arr = new Uint8Array((len || 16) / 2)
708
- window.crypto.getRandomValues(arr)
709
- return Array.from(arr, dec2hex).join('')
710
- }
762
+ switch(navMode)
763
+ {
764
+ case NAV_MODE_SIDEBAR:
765
+ return get(main_sidebar_visible_store) != '*'
766
+
767
+ case NAV_MODE_FULL_PAGE:
768
+ return isOnNavigationPage();
769
+ }
770
+ }
771
+
772
+ export function navGetKey()
773
+ {
774
+ switch(navMode)
775
+ {
776
+ case NAV_MODE_SIDEBAR:
777
+ return get(main_sidebar_visible_store)
778
+
779
+ case NAV_MODE_FULL_PAGE:
780
+ {
781
+ const segments = get(location).split('/')
782
+ if(segments.length > 1)
783
+ return segments[2]
784
+ else
785
+ return ""
786
+ }
787
+ return ""
788
+ }
789
+ }
790
+
791
+ export function navShow(key)
792
+ {
793
+ switch(navMode)
794
+ {
795
+ case NAV_MODE_SIDEBAR:
796
+ show_sidebar(key)
797
+ break;
798
+
799
+ case NAV_MODE_FULL_PAGE:
800
+ pushNavigationPage(key)
801
+ break;
802
+ }
803
+ }
804
+
805
+ export function navHide()
806
+ {
807
+ switch(navMode)
808
+ {
809
+ case NAV_MODE_SIDEBAR:
810
+ hide_sidebar()
811
+ break;
812
+
813
+ case NAV_MODE_FULL_PAGE:
814
+ popNavigationPage()
815
+ break;
816
+ }
817
+ }
818
+
819
+
820
+ export function navToggle(key)
821
+ {
822
+ if(navIsVisible())
823
+ {
824
+ if(navGetKey() == key)
825
+ navHide()
826
+ else
827
+ navShow(key)
828
+ }
829
+ else
830
+ navShow(key)
831
+
832
+ }
833
+
834
+ export function navPrevVisibleKey()
835
+ {
836
+ switch(navMode)
837
+ {
838
+ case NAV_MODE_SIDEBAR:
839
+ if(!previously_visible_sidebar)
840
+ return ''
841
+ else if(previously_visible_sidebar == '*')
842
+ return ''
843
+ else
844
+ return previously_visible_sidebar
845
+
846
+ case NAV_MODE_FULL_PAGE:
847
+ {
848
+ const segs = lastNavPage.split('/')
849
+ if(segs.length > 1)
850
+ return segs[2]
851
+ else
852
+ return ''
853
+ }
854
+ }
855
+ }
856
+
857
+ export function navAutoHide()
858
+ {
859
+ switch(navMode)
860
+ {
861
+ case NAV_MODE_SIDEBAR:
862
+ auto_hide_sidebar()
863
+ break;
864
+
865
+ case NAV_MODE_FULL_PAGE:
866
+ break;
867
+ }
868
+ }
869
+
870
+
@@ -1,33 +1,31 @@
1
1
  <script>
2
- import {FaUsers, FaCog, FaToggleOn, FaToggleOff, FaSignInAlt, FaSignOutAlt, FaPlus} from 'svelte-icons/fa/'
2
+ import {FaUsers, FaCog, FaToggleOn, FaToggleOff, FaSignInAlt, FaSignOutAlt, FaPlus, FaLanguage} from 'svelte-icons/fa/'
3
3
  //import GoPrimitiveDot from 'svelte-icons/go/GoPrimitiveDot.svelte'
4
- import {showMenu} from './components/menu'
4
+ import {showMenu, SHOW_MENU_RIGHT} from './components/menu'
5
5
  import {reef} from '@humandialog/auth.svelte'
6
6
  import Modal from './modal.svelte'
7
7
  import Input from './components/inputbox.ltop.svelte'
8
8
  //import Menu from './components/contextmenu.svelte'
9
9
 
10
10
  import {dark_mode_store,
11
- toggle_sidebar,
12
- show_sidebar,
13
- hide_sidebar,
14
11
  tools_visible_store,
15
12
  bottom_bar_visible_store,
16
13
  right_sidebar_visible_store,
17
- main_sidebar_visible_store,
18
14
  contextItemsStore,
19
15
  context_info_store,
20
16
  contextToolbarOperations,
21
17
  data_tick_store,
22
18
  reloadWholeApp,
23
19
  showFABAlways,
24
- leftHandedFAB
20
+ leftHandedFAB,
21
+ navKey
25
22
  } from "./stores.js";
26
23
  import Icon from './components/icon.svelte';
27
24
  import {session, signInHRef, signOutHRef} from '@humandialog/auth.svelte'
28
25
  import { pop, push } from 'svelte-spa-router';
29
26
  import { tick } from 'svelte';
30
- import { isDeviceSmallerThan, popNavigationPage } from './utils';
27
+ import { isDeviceSmallerThan, navGetKey, navHide, navIsVisible, navShow, navToggle } from './utils';
28
+ import {setCurrentLanguage, getLanguages, i18n, getCurrentLanguage} from './i18n.js'
31
29
 
32
30
 
33
31
  export let appConfig = undefined;
@@ -40,7 +38,7 @@
40
38
  let tabs = new Array();
41
39
  let config = null;
42
40
  let has_selection_details = false;
43
- let selection_detils_caption = 'Properties';
41
+ let selection_detils_caption = i18n({en: 'Properties', es: 'Propiedades', pl: 'Właściwości'});
44
42
 
45
43
  let show_sign_in_out_icons = false;
46
44
  let is_logged_in = false;
@@ -54,8 +52,15 @@
54
52
  {
55
53
  config = appConfig.mainToolbar;
56
54
  has_selection_details = appConfig.selectionDetails;
55
+
57
56
  if(has_selection_details)
58
- selection_detils_caption = appConfig.selectionDetails.caption ?? 'Properties'
57
+ {
58
+ if(appConfig.selectionDetails.captionFunc)
59
+ selection_detils_caption = appConfig.selectionDetails.captionFunc()
60
+ else if(appConfig.selectionDetails.caption)
61
+ selection_detils_caption = appConfig.selectionDetails.caption
62
+
63
+ }
59
64
  }
60
65
  else
61
66
  {
@@ -93,17 +98,20 @@
93
98
  });
94
99
 
95
100
  // there is no current visible sidebar
96
- if($main_sidebar_visible_store != '*')
101
+ if(navIsVisible())
97
102
  {
98
- if(tabs.every( (e) => e.key != $main_sidebar_visible_store))
103
+ const selectedNav = navGetKey()
104
+ if(tabs.every( (e) => e.key != selectedNav))
99
105
  {
100
106
  if(tabs.length)
101
- show_sidebar(tabs[0].key);
107
+ navShow(tabs[0].key);
102
108
  else
103
- hide_sidebar();
109
+ navHide();
104
110
  }
105
111
  }
106
112
  }
113
+
114
+
107
115
 
108
116
  /*show_groups_switch_menu = $session.tenants.length > 1
109
117
 
@@ -124,17 +132,8 @@
124
132
 
125
133
  function on_navigator_tab_clicked(e, key)
126
134
  {
127
- e.stopPropagation();
128
-
129
- if(!mobile)
130
- toggle_sidebar(key);
131
- else
132
- {
133
- if($main_sidebar_visible_store == key)
134
- popNavigationPage();
135
- else
136
- show_sidebar(key);
137
- }
135
+ e.stopPropagation();
136
+ navToggle(key);
138
137
  }
139
138
 
140
139
  function show_options(e)
@@ -159,8 +158,14 @@
159
158
 
160
159
  if(add)
161
160
  {
161
+ let caption = ''
162
+ if(o.captionFunc)
163
+ caption = o.captionFunc()
164
+ else if(o.caption)
165
+ caption = o.caption
166
+
162
167
  options.push({
163
- caption: o.caption,
168
+ caption: caption,
164
169
  icon: o.icon,
165
170
  action: o.action
166
171
  })
@@ -173,7 +178,7 @@
173
178
  if(!is_logged_in)
174
179
  {
175
180
  options.push({
176
- caption: 'Sign in',
181
+ caption: i18n( { en: 'Sign in', es: 'Iniciar sesión', pl: 'Zaloguj'}),
177
182
  icon: FaSignInAlt,
178
183
  action: (focused) => { push(sign_in_href) }
179
184
  });
@@ -181,7 +186,7 @@
181
186
  else
182
187
  {
183
188
  options.push({
184
- caption: 'Sign out',
189
+ caption: i18n({en: 'Sign out', es: 'Cerrar sesión', pl: 'Wyloguj' }) ,
185
190
  icon: FaSignOutAlt,
186
191
  action: (focused) => { push(sign_out_href) }
187
192
  });
@@ -193,10 +198,11 @@
193
198
 
194
199
  if(!config || config.darkMode)
195
200
  {
201
+ const capt = i18n({en: 'Dark mode', es: 'Modo oscuro', pl: 'Tryb ciemny'})
196
202
  if($dark_mode_store == '')
197
203
  {
198
204
  options.push( {
199
- caption: 'Dark mode',
205
+ caption: capt,
200
206
  icon: FaToggleOff,
201
207
  action: (focused) => { $dark_mode_store = 'dark'; }
202
208
  });
@@ -204,17 +210,34 @@
204
210
  else
205
211
  {
206
212
  options.push( {
207
- caption: 'Dark mode',
213
+ caption: capt,
208
214
  icon: FaToggleOn,
209
215
  action: (focused) => { $dark_mode_store = ''; }
210
216
  });
211
217
  }
212
218
  }
213
219
 
220
+ const langs = getLanguages()
221
+ if(langs && langs.length > 1)
222
+ {
223
+ const langMenu = langs.map( l => ({
224
+ caption: l.name,
225
+ img: l.flag,
226
+ action: (b) => {setCurrentLanguage(l); reloadWholeApp()},
227
+ disabled: getCurrentLanguage() == l
228
+ }))
229
+
230
+ options.push( {
231
+ caption: i18n({en: 'Language', es:'Idioma', pl:'Język'}),
232
+ menu: langMenu,
233
+ icon: FaLanguage
234
+ })
235
+ }
236
+
214
237
  if(config && config.operations)
215
238
  {
216
239
  options.push( {
217
- caption: 'Toolbar',
240
+ caption: i18n({en:'Toolbar', es:'Barra de herramientas', pl:'Pasek narzędzi'}),
218
241
  icon: $tools_visible_store ? FaToggleOn : FaToggleOff,
219
242
  action: (focused) => { $tools_visible_store = !$tools_visible_store; }
220
243
  });
@@ -223,13 +246,13 @@
223
246
  if(!isDeviceSmallerThan("sm"))
224
247
  {
225
248
  options.push({
226
- caption: 'Floating actions',
249
+ caption: i18n({en: 'Floating buttons', es: 'Botones flotantes', pl: 'Pływające przyciski'}),
227
250
  icon: $showFABAlways ? FaToggleOn : FaToggleOff,
228
251
  action: (f) => { $showFABAlways = !$showFABAlways; }
229
252
  })
230
253
 
231
254
  options.push({
232
- caption: 'Left-handed floating actions',
255
+ caption: i18n({en: 'Left-handed mode', es: 'Modo para zurdos', pl: 'Tryb dla leworęcznych'}),
233
256
  icon: $leftHandedFAB ? FaToggleOn : FaToggleOff,
234
257
  disabled: !$showFABAlways,
235
258
  action: (f) => { $leftHandedFAB = !$leftHandedFAB; }
@@ -245,8 +268,8 @@
245
268
  });
246
269
  }
247
270
 
248
- let pt = new DOMPoint(rect.right, rect.top)
249
- showMenu(pt, options);
271
+ //let anchor = new DOMPoint(rect.right, rect.top)
272
+ showMenu(rect, options, SHOW_MENU_RIGHT);
250
273
  }
251
274
 
252
275
  function show_groups(e)
@@ -281,15 +304,15 @@
281
304
  separator: true
282
305
  })
283
306
  options.push({
284
- caption: 'Add group',
307
+ caption: i18n({en:'Add group', es: 'Añadir grupo', pl: 'Dodaj grupę' }),
285
308
  icon: FaPlus,
286
309
  action: (f) => launchNewGroupWizzard()
287
310
  })
288
311
  }
289
312
 
290
313
 
291
- let pt = new DOMPoint(rect.right, rect.top)
292
- showMenu(pt, options);
314
+ //const anchor = new DOMPoint(rect.right, rect.top)
315
+ showMenu(rect, options, SHOW_MENU_RIGHT);
293
316
  }
294
317
 
295
318
  function clearSelection()
@@ -373,7 +396,7 @@
373
396
  <section class="no-print flex flex-col w-full h-full" on:click={clearSelection}>
374
397
  <div class="px-0 w-12 sm:w-10">
375
398
  {#each tabs as tab}
376
- {@const isSelected = $main_sidebar_visible_store == tab.key}
399
+ {@const isSelected = $navKey == tab.key}
377
400
  <button
378
401
  class="h-16 px-0 flex justify-center items-center w-full text-stone-300 hover:text-stone-100"
379
402
  class:bg-orange-500={isSelected}
@@ -409,13 +432,13 @@
409
432
  <!--Menu bind:this={menu}/-->
410
433
 
411
434
  <Modal bind:open={newGroupModalVisible}
412
- title='Create group'
413
- okCaption='Create'
435
+ title={ i18n({en:'Create group', es:'Crear grupo', pl:'Utwórz grupę'})}
436
+ okCaption={ i18n({en:'Create', es:'Crear', pl:'Utwórz'})}
414
437
  onOkCallback={onNewGroupOK}
415
438
  onCancelCallback={onNewGroupCancel}
416
439
  icon={FaUsers}
417
440
  >
418
- <Input label='Group name'
441
+ <Input label={i18n({en:'Group name', es:'Nombre del grupo', pl:'Nazwa grupy'})}
419
442
  placeholder=''
420
443
  self={newGroupParams}
421
444
  a="name"