@humandialog/forms.svelte 1.5.1 → 1.6.0

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.
@@ -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"