@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.
- package/components/contextmenu.svelte +125 -28
- package/components/contextmenu.svelte.d.ts +2 -2
- package/components/document/editor.svelte +46 -36
- package/components/document/editor.svelte.d.ts +6 -6
- package/components/menu.d.ts +5 -1
- package/components/menu.js +7 -3
- package/components/sidebar/sidebar.item.svelte +5 -5
- package/desk.svelte +10 -9
- package/horizontal.toolbar.svelte +57 -65
- package/i18n-preprocess.d.ts +39 -0
- package/i18n-preprocess.js +100 -0
- package/i18n.d.ts +30 -0
- package/i18n.js +162 -0
- package/index.d.ts +5 -3
- package/index.js +5 -3
- package/modal.svelte +2 -1
- package/package.json +3 -1
- package/stores.d.ts +1 -0
- package/stores.js +4 -3
- package/tenant.members.svelte +46 -40
- package/utils.d.ts +14 -4
- package/utils.js +178 -18
- package/vertical.toolbar.svelte +65 -42
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import {FaUsers, FaCog, FaSignInAlt, FaSignOutAlt, FaBars, FaToggleOn, FaToggleOff} from 'svelte-icons/fa/'
|
|
2
|
+
import {FaUsers, FaCog, FaSignInAlt, FaSignOutAlt, FaBars, FaToggleOn, FaToggleOff, FaLanguage} from 'svelte-icons/fa/'
|
|
3
3
|
//import GoPrimitiveDot from 'svelte-icons/go/GoPrimitiveDot.svelte'
|
|
4
4
|
import {showMenu} from './components/menu'
|
|
5
5
|
import {push, pop, location} from 'svelte-spa-router'
|
|
@@ -8,13 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
10
|
dark_mode_store,
|
|
11
|
-
toggle_sidebar,
|
|
12
|
-
show_sidebar,
|
|
13
|
-
hide_sidebar,
|
|
14
11
|
tools_visible_store,
|
|
15
12
|
bottom_bar_visible_store,
|
|
16
|
-
previously_visible_sidebar,
|
|
17
|
-
main_sidebar_visible_store,
|
|
18
13
|
sidebar_left_pos,
|
|
19
14
|
page_title,
|
|
20
15
|
nav_titles,
|
|
@@ -24,8 +19,8 @@
|
|
|
24
19
|
import {session, signInHRef, signOutHRef} from '@humandialog/auth.svelte'
|
|
25
20
|
|
|
26
21
|
import VerticalToolbar from './vertical.toolbar.svelte'
|
|
27
|
-
import { isDeviceSmallerThan,
|
|
28
|
-
|
|
22
|
+
import { isDeviceSmallerThan, navIsVisible, navGetKey, navToggle, navShow, navHide, navPrevVisibleKey } from './utils.js';
|
|
23
|
+
import {setCurrentLanguage, getLanguages, i18n, getCurrentLanguage} from './i18n.js'
|
|
29
24
|
|
|
30
25
|
export let appConfig = undefined;
|
|
31
26
|
export let clearsContext = 'sel props'
|
|
@@ -35,7 +30,7 @@
|
|
|
35
30
|
|
|
36
31
|
let config = null;
|
|
37
32
|
let has_selection_details = false;
|
|
38
|
-
let selection_details_caption = 'Properties'
|
|
33
|
+
let selection_details_caption = i18n({en: 'Properties', es: 'Propiedades', pl: 'Właściwości'});
|
|
39
34
|
|
|
40
35
|
let show_sign_in_out_icons = false;
|
|
41
36
|
let is_logged_in = false;
|
|
@@ -53,7 +48,13 @@
|
|
|
53
48
|
config = appConfig.mainToolbar;
|
|
54
49
|
has_selection_details = appConfig.selectionDetails;
|
|
55
50
|
if(has_selection_details)
|
|
56
|
-
|
|
51
|
+
{
|
|
52
|
+
if(appConfig.selectionDetails.captionFunc)
|
|
53
|
+
selection_details_caption = appConfig.selectionDetails.captionFunc()
|
|
54
|
+
else if(appConfig.selectionDetails.caption)
|
|
55
|
+
selection_details_caption = appConfig.selectionDetails.caption
|
|
56
|
+
|
|
57
|
+
}
|
|
57
58
|
}
|
|
58
59
|
else
|
|
59
60
|
{
|
|
@@ -86,11 +87,12 @@
|
|
|
86
87
|
|
|
87
88
|
let title = ''
|
|
88
89
|
$:{
|
|
89
|
-
if(
|
|
90
|
+
if(!navIsVisible())
|
|
90
91
|
title = $page_title;
|
|
91
92
|
else
|
|
92
93
|
{
|
|
93
|
-
|
|
94
|
+
const navKey = navGetKey()
|
|
95
|
+
let nav_title = $nav_titles[navKey];
|
|
94
96
|
if(nav_title != undefined)
|
|
95
97
|
title = nav_title
|
|
96
98
|
else
|
|
@@ -100,59 +102,25 @@
|
|
|
100
102
|
|
|
101
103
|
function toggle_navigator(e)
|
|
102
104
|
{
|
|
103
|
-
if(
|
|
105
|
+
if(tabs.length == 1)
|
|
104
106
|
{
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
popNavigationPage();
|
|
108
|
-
}
|
|
109
|
-
else
|
|
110
|
-
{
|
|
111
|
-
if(tabs.length == 1)
|
|
112
|
-
{
|
|
113
|
-
$sidebar_left_pos = 0;
|
|
114
|
-
show_sidebar(tabs[0]);
|
|
115
|
-
}
|
|
116
|
-
else
|
|
117
|
-
{
|
|
118
|
-
let sidebar = $main_sidebar_visible_store;
|
|
119
|
-
if(sidebar == "*")
|
|
120
|
-
{
|
|
121
|
-
if((!previously_visible_sidebar) || previously_visible_sidebar === '*')
|
|
122
|
-
sidebar = Object.keys(appConfig.sidebar)[0];
|
|
123
|
-
else
|
|
124
|
-
sidebar = previously_visible_sidebar;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
$sidebar_left_pos = 40;
|
|
128
|
-
show_sidebar(sidebar)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
pushNavigationPage();
|
|
132
|
-
}
|
|
107
|
+
$sidebar_left_pos = 0;
|
|
108
|
+
navToggle(tabs[0])
|
|
133
109
|
}
|
|
134
110
|
else
|
|
135
111
|
{
|
|
112
|
+
$sidebar_left_pos = 40;
|
|
136
113
|
|
|
137
|
-
if(
|
|
114
|
+
if(!navIsVisible())
|
|
138
115
|
{
|
|
139
|
-
|
|
140
|
-
|
|
116
|
+
let navKey = navPrevVisibleKey()
|
|
117
|
+
if(!navKey)
|
|
118
|
+
navKey = Object.keys(appConfig.sidebar)[0]
|
|
119
|
+
|
|
120
|
+
navShow(navKey);
|
|
141
121
|
}
|
|
142
122
|
else
|
|
143
|
-
|
|
144
|
-
let sidebar = $main_sidebar_visible_store;
|
|
145
|
-
if(sidebar == "*")
|
|
146
|
-
{
|
|
147
|
-
if((!previously_visible_sidebar) || previously_visible_sidebar === '*')
|
|
148
|
-
sidebar = Object.keys(appConfig.sidebar)[0];
|
|
149
|
-
else
|
|
150
|
-
sidebar = previously_visible_sidebar;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
$sidebar_left_pos = 40;
|
|
154
|
-
toggle_sidebar(sidebar)
|
|
155
|
-
}
|
|
123
|
+
navHide()
|
|
156
124
|
}
|
|
157
125
|
}
|
|
158
126
|
|
|
@@ -177,8 +145,14 @@
|
|
|
177
145
|
|
|
178
146
|
if(add)
|
|
179
147
|
{
|
|
148
|
+
let caption = ''
|
|
149
|
+
if(o.captionFunc)
|
|
150
|
+
caption = o.captionFunc()
|
|
151
|
+
else if(o.caption)
|
|
152
|
+
caption = o.caption
|
|
153
|
+
|
|
180
154
|
options.push({
|
|
181
|
-
caption:
|
|
155
|
+
caption: caption,
|
|
182
156
|
icon: o.icon,
|
|
183
157
|
action: o.action
|
|
184
158
|
})
|
|
@@ -191,7 +165,7 @@
|
|
|
191
165
|
if(!is_logged_in)
|
|
192
166
|
{
|
|
193
167
|
options.push({
|
|
194
|
-
caption: 'Sign in',
|
|
168
|
+
caption: i18n( { en: 'Sign in', es: 'Iniciar sesión', pl: 'Zaloguj'}),
|
|
195
169
|
icon: FaSignInAlt,
|
|
196
170
|
action: (focused) => { push(sign_in_href) }
|
|
197
171
|
});
|
|
@@ -199,7 +173,7 @@
|
|
|
199
173
|
else
|
|
200
174
|
{
|
|
201
175
|
options.push({
|
|
202
|
-
caption: 'Sign out',
|
|
176
|
+
caption: i18n({en: 'Sign out', es: 'Cerrar sesión', pl: 'Wyloguj' }) ,
|
|
203
177
|
icon: FaSignOutAlt,
|
|
204
178
|
action: (focused) => { push(sign_out_href) }
|
|
205
179
|
});
|
|
@@ -211,10 +185,11 @@
|
|
|
211
185
|
|
|
212
186
|
if(!config || config.darkMode)
|
|
213
187
|
{
|
|
188
|
+
const capt = i18n({en: 'Dark mode', es: 'Modo oscuro', pl: 'Tryb ciemny'})
|
|
214
189
|
if($dark_mode_store == '')
|
|
215
190
|
{
|
|
216
191
|
options.push( {
|
|
217
|
-
caption:
|
|
192
|
+
caption: capt,
|
|
218
193
|
icon: FaToggleOff,
|
|
219
194
|
action: (focused) => { $dark_mode_store = 'dark'; }
|
|
220
195
|
});
|
|
@@ -222,24 +197,41 @@
|
|
|
222
197
|
else
|
|
223
198
|
{
|
|
224
199
|
options.push( {
|
|
225
|
-
caption:
|
|
200
|
+
caption: capt,
|
|
226
201
|
icon: FaToggleOn,
|
|
227
202
|
action: (focused) => { $dark_mode_store = ''; }
|
|
228
203
|
});
|
|
229
204
|
}
|
|
230
205
|
}
|
|
231
206
|
|
|
207
|
+
const langs = getLanguages()
|
|
208
|
+
if(langs && langs.length > 1)
|
|
209
|
+
{
|
|
210
|
+
const langMenu = langs.map( l => ({
|
|
211
|
+
caption: l.name,
|
|
212
|
+
img: l.flag,
|
|
213
|
+
action: (b) => {setCurrentLanguage(l); reloadWholeApp()},
|
|
214
|
+
disabled: getCurrentLanguage() == l
|
|
215
|
+
}))
|
|
216
|
+
|
|
217
|
+
options.push( {
|
|
218
|
+
caption: i18n({en: 'Language', es:'Idioma', pl:'Język'}),
|
|
219
|
+
menu: langMenu,
|
|
220
|
+
icon: FaLanguage
|
|
221
|
+
})
|
|
222
|
+
}
|
|
223
|
+
|
|
232
224
|
if(config && config.operations)
|
|
233
225
|
{
|
|
234
226
|
options.push( {
|
|
235
|
-
caption: 'Toolbar',
|
|
227
|
+
caption: i18n({en:'Toolbar', es:'Barra de herramientas', pl:'Pasek narzędzi'}),
|
|
236
228
|
icon: $tools_visible_store ? FaToggleOn : FaToggleOff,
|
|
237
229
|
action: (focused) => { $tools_visible_store = !$tools_visible_store; }
|
|
238
230
|
});
|
|
239
231
|
}
|
|
240
232
|
|
|
241
233
|
options.push({
|
|
242
|
-
caption: 'Left-handed
|
|
234
|
+
caption: i18n({en: 'Left-handed mode', es: 'Modo para zurdos', pl: 'Tryb dla leworęcznych'}),
|
|
243
235
|
icon: $leftHandedFAB ? FaToggleOn : FaToggleOff,
|
|
244
236
|
action: (f) => { $leftHandedFAB = !$leftHandedFAB; }
|
|
245
237
|
})
|
|
@@ -344,7 +336,7 @@
|
|
|
344
336
|
|
|
345
337
|
</div>
|
|
346
338
|
|
|
347
|
-
{#if false && tabs.length > 1 &&
|
|
339
|
+
{#if false && tabs.length > 1 && navIsVisible()}
|
|
348
340
|
<div class="no-print flex-none block fixed left-0 top-[40px] w-[40px] h-screen z-20 inset-0 overflow-hidden">
|
|
349
341
|
<div class="sticky top-0 flex h-full w-10 bg-stone-900 flex-col items-center text-stone-100 shadow">
|
|
350
342
|
<VerticalToolbar {appConfig} mobile={true}/>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zamienia:
|
|
3
|
+
* _; EN;ES ; PL
|
|
4
|
+
* "_; EN;ES ; PL"
|
|
5
|
+
* '_; Foo ; Bar;Baz'
|
|
6
|
+
* `_; A; B ; C`
|
|
7
|
+
* na:
|
|
8
|
+
* i18n(["EN", "ES", "PL"]) // znormalizowane odstępy: "; "
|
|
9
|
+
*
|
|
10
|
+
* Dwie fazy:
|
|
11
|
+
* 1) quoted: podmienia CAŁE literały stringów (", ', `)
|
|
12
|
+
* 2) unquoted: podmienia goły tekst (np. w markupie)
|
|
13
|
+
*/
|
|
14
|
+
export function i18nPreprocess({ dryRun }?: {
|
|
15
|
+
dryRun?: boolean | undefined;
|
|
16
|
+
}): {
|
|
17
|
+
name: string;
|
|
18
|
+
markup({ content, filename }: {
|
|
19
|
+
content: any;
|
|
20
|
+
filename: any;
|
|
21
|
+
}): {
|
|
22
|
+
code: any;
|
|
23
|
+
};
|
|
24
|
+
script({ content, attributes, filename }: {
|
|
25
|
+
content: any;
|
|
26
|
+
attributes: any;
|
|
27
|
+
filename: any;
|
|
28
|
+
}): {
|
|
29
|
+
code: any;
|
|
30
|
+
attributes: any;
|
|
31
|
+
};
|
|
32
|
+
style({ content, attributes }: {
|
|
33
|
+
content: any;
|
|
34
|
+
attributes: any;
|
|
35
|
+
}): {
|
|
36
|
+
code: any;
|
|
37
|
+
attributes: any;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zamienia:
|
|
3
|
+
* _; EN;ES ; PL
|
|
4
|
+
* "_; EN;ES ; PL"
|
|
5
|
+
* '_; Foo ; Bar;Baz'
|
|
6
|
+
* `_; A; B ; C`
|
|
7
|
+
* na:
|
|
8
|
+
* i18n(["EN", "ES", "PL"]) // znormalizowane odstępy: "; "
|
|
9
|
+
*
|
|
10
|
+
* Dwie fazy:
|
|
11
|
+
* 1) quoted: podmienia CAŁE literały stringów (", ', `)
|
|
12
|
+
* 2) unquoted: podmienia goły tekst (np. w markupie)
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export function i18nPreprocess({ dryRun = false } = {}) {
|
|
16
|
+
const lit = (s) => JSON.stringify(s);
|
|
17
|
+
const toArrayExpr = (list) =>
|
|
18
|
+
`[${list
|
|
19
|
+
.split(/\s*;\s*/g) // zachowuje puste między ';;'
|
|
20
|
+
.map((s) => s.trim()) // przytnij brzegi
|
|
21
|
+
.map(lit) // JSON.stringify
|
|
22
|
+
.join(', ')}]`;
|
|
23
|
+
|
|
24
|
+
// 1) W <script> zamieniamy CAŁE literały "_; ...; ..." -> i18n([ ... ])
|
|
25
|
+
// Uwaga: dla prostoty nie dopuszczamy cudzysłowów/backticków wewnątrz placeholderów
|
|
26
|
+
const QUOTED_IN_SCRIPT =
|
|
27
|
+
/(['"`])\s*_;\s*((?:[^'"`;\r\n]*)(?:\s*;\s*[^'"`;\r\n]*)*)\s*\1/g;
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
// 2) W markup – TYLKO surowy tekst między tagami (nie dotykamy atrybutów)
|
|
31
|
+
const UNQUOTED_TEXT_IN_MARKUP =
|
|
32
|
+
/(^|>)(\s*)_;\s*((?:[^;<>]*)(?:\s*;\s*[^;<>]*)*)/g;
|
|
33
|
+
|
|
34
|
+
// ATRYBUTY: name="_; A; ; C" -> name={i18n(["A", "", "C"])}
|
|
35
|
+
const ATTR_QUOTED =
|
|
36
|
+
/(\s[0-9A-Za-z_:@#.-]+)\s*=\s*(["'])\s*_;\s*((?:[^"'<>]*)(?:\s*;\s*[^"'<>]*)*)\s*\2/g;
|
|
37
|
+
|
|
38
|
+
// Wytnij i przywróć bloki, żeby w fazie markup nie ruszać <script>/<style>
|
|
39
|
+
const extractBlocks = (content, tag) => {
|
|
40
|
+
const re = new RegExp(`<${tag}\\b[\\s\\S]*?>[\\s\\S]*?<\\/${tag}>`, 'gi');
|
|
41
|
+
const blocks = [];
|
|
42
|
+
const placeholders = [];
|
|
43
|
+
let i = 0;
|
|
44
|
+
content = content.replace(re, (m) => {
|
|
45
|
+
const key = `<<<${tag.toUpperCase()}_BLOCK_${i++}>>>`;
|
|
46
|
+
blocks.push(m);
|
|
47
|
+
placeholders.push(key);
|
|
48
|
+
return key;
|
|
49
|
+
});
|
|
50
|
+
return { content, blocks, placeholders };
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// UWAGA: używamy funkcji jako replacera, by nie zepsuć `$$props` -> `$props`
|
|
54
|
+
const restoreBlocks = (content, placeholders, blocks) => {
|
|
55
|
+
placeholders.forEach((key, idx) => {
|
|
56
|
+
content = content.replace(key, () => blocks[idx]);
|
|
57
|
+
});
|
|
58
|
+
return content;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
name: 'i18n-preprocess',
|
|
63
|
+
|
|
64
|
+
markup({ content, filename }) {
|
|
65
|
+
const s = extractBlocks(content, 'script');
|
|
66
|
+
const ss = extractBlocks(s.content, 'style');
|
|
67
|
+
|
|
68
|
+
let body = ss.content;
|
|
69
|
+
let count = 0;
|
|
70
|
+
|
|
71
|
+
body = body.replace(UNQUOTED_TEXT_IN_MARKUP, (m, before, pre, list) => {
|
|
72
|
+
count++;
|
|
73
|
+
return `${before}${pre}{i18n(${toArrayExpr(list)})}`;
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
if (count) console.log(`[i18n-preprocess][markup] ${filename} -> ${count} replace(s)`);
|
|
77
|
+
|
|
78
|
+
body = restoreBlocks(body, ss.placeholders, ss.blocks);
|
|
79
|
+
body = restoreBlocks(body, s.placeholders, s.blocks);
|
|
80
|
+
|
|
81
|
+
if (dryRun) return { code: content };
|
|
82
|
+
return { code: body };
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
script({ content, attributes, filename }) {
|
|
86
|
+
let count = 0;
|
|
87
|
+
const code = content.replace(QUOTED_IN_SCRIPT, (_m, _q, list) => {
|
|
88
|
+
count++;
|
|
89
|
+
return `i18n(${toArrayExpr(list)})`;
|
|
90
|
+
});
|
|
91
|
+
// if (count) console.log(`[i18n-preprocess][script] ${filename} -> ${count} replace(s)`);
|
|
92
|
+
if (dryRun) return { code: content, attributes };
|
|
93
|
+
return { code, attributes };
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
style({ content, attributes }) {
|
|
97
|
+
return { code: content, attributes };
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
package/i18n.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function setLanguages(langs: any): void;
|
|
2
|
+
export function getLanguages(): ({
|
|
3
|
+
key: string;
|
|
4
|
+
name: string;
|
|
5
|
+
flag: string;
|
|
6
|
+
default: boolean;
|
|
7
|
+
} | {
|
|
8
|
+
key: string;
|
|
9
|
+
name: string;
|
|
10
|
+
flag: string;
|
|
11
|
+
default?: undefined;
|
|
12
|
+
})[];
|
|
13
|
+
export function setCurrentLanguage(sel: any): void;
|
|
14
|
+
export function getCurrentLanguage(): {
|
|
15
|
+
key: string;
|
|
16
|
+
name: string;
|
|
17
|
+
flag: string;
|
|
18
|
+
default: boolean;
|
|
19
|
+
} | {
|
|
20
|
+
key: string;
|
|
21
|
+
name: string;
|
|
22
|
+
flag: string;
|
|
23
|
+
default?: undefined;
|
|
24
|
+
};
|
|
25
|
+
export function getCurrentLanguageIdx(): number;
|
|
26
|
+
export function getCurrentLanguageKey(): string;
|
|
27
|
+
/**
|
|
28
|
+
* i18n("EN; ES; PL") => "EN" albo "ES" albo "PL"
|
|
29
|
+
*/
|
|
30
|
+
export function i18n(list: any): any;
|
package/i18n.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
|
|
2
|
+
// https://flagdownload.com/
|
|
3
|
+
|
|
4
|
+
let languages = [
|
|
5
|
+
{
|
|
6
|
+
key: "en",
|
|
7
|
+
name: 'English',
|
|
8
|
+
flag: '/landing/lang/GB_64.png',
|
|
9
|
+
default: true
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
key: 'es',
|
|
13
|
+
name: "Español",
|
|
14
|
+
flag: '/landing/lang/ES_64.png'
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
key: 'pl',
|
|
18
|
+
name: 'Polski',
|
|
19
|
+
flag: '/landing/lang/PL_64.png'
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
function fetchCurrentLangIndex()
|
|
24
|
+
{
|
|
25
|
+
const stored = localStorage.getItem("__hd_svelte_lang")
|
|
26
|
+
if(!stored)
|
|
27
|
+
{
|
|
28
|
+
if(languages.length == 0)
|
|
29
|
+
return 0;
|
|
30
|
+
|
|
31
|
+
if(!navigator.language)
|
|
32
|
+
return 0;
|
|
33
|
+
|
|
34
|
+
const browserLang = navigator.language.substring(0, 2)
|
|
35
|
+
const idx = languages.findIndex(l => l.key == browserLang)
|
|
36
|
+
if(idx >=0)
|
|
37
|
+
return idx;
|
|
38
|
+
else
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
else
|
|
42
|
+
{
|
|
43
|
+
try{
|
|
44
|
+
return JSON.parse(stored)
|
|
45
|
+
}
|
|
46
|
+
catch(err)
|
|
47
|
+
{
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let currentLangIndex = 0// fetchCurrentLangIndex()
|
|
54
|
+
let defaultLangIndex = 0;
|
|
55
|
+
|
|
56
|
+
export function setLanguages(langs)
|
|
57
|
+
{
|
|
58
|
+
languages = langs
|
|
59
|
+
defaultLangIndex = languages.findIndex(l => l.default == true)
|
|
60
|
+
if(defaultLangIndex < 0)
|
|
61
|
+
defaultLangIndex = 0
|
|
62
|
+
|
|
63
|
+
currentLangIndex = fetchCurrentLangIndex()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function getLanguages()
|
|
67
|
+
{
|
|
68
|
+
return languages
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function setCurrentLanguage(sel)
|
|
72
|
+
{
|
|
73
|
+
if(typeof sel === 'number')
|
|
74
|
+
currentLangIndex = sel
|
|
75
|
+
else if (typeof sel === 'string' || sel instanceof String)
|
|
76
|
+
{
|
|
77
|
+
currentLangIndex = languages.findIndex(l => l.key == sel)
|
|
78
|
+
if(currentLangIndex < 0)
|
|
79
|
+
{
|
|
80
|
+
console.error(`language ${sel} doesn't exist`)
|
|
81
|
+
currentLangIndex = defaultLangIndex
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else
|
|
85
|
+
{
|
|
86
|
+
currentLangIndex = languages.findIndex(l => l.key == sel.key)
|
|
87
|
+
if(currentLangIndex < 0)
|
|
88
|
+
{
|
|
89
|
+
console.error(`language ${sel.key} doesn't exist`)
|
|
90
|
+
currentLangIndex = defaultLangIndex
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
localStorage.setItem("__hd_svelte_lang", JSON.stringify(currentLangIndex))
|
|
95
|
+
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function getCurrentLanguage()
|
|
99
|
+
{
|
|
100
|
+
return languages[currentLangIndex]
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function getCurrentLanguageIdx()
|
|
104
|
+
{
|
|
105
|
+
return currentLangIndex
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function getCurrentLanguageKey()
|
|
109
|
+
{
|
|
110
|
+
return languages[currentLangIndex].key
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* i18n("EN; ES; PL") => "EN" albo "ES" albo "PL"
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
export function i18n(list)
|
|
119
|
+
{
|
|
120
|
+
if (typeof list === 'string' || list instanceof String)
|
|
121
|
+
{
|
|
122
|
+
const parts = list.split(/\s*;\s*/);
|
|
123
|
+
|
|
124
|
+
if(parts.length == 0)
|
|
125
|
+
return "";
|
|
126
|
+
|
|
127
|
+
if(currentLangIndex < parts.length)
|
|
128
|
+
return parts[currentLangIndex]
|
|
129
|
+
else if(defaultLangIndex < parts.length)
|
|
130
|
+
return parts[defaultLangIndex]
|
|
131
|
+
else
|
|
132
|
+
return parts[0]
|
|
133
|
+
}
|
|
134
|
+
else if (Array.isArray(list))
|
|
135
|
+
{
|
|
136
|
+
if(list.length == 0)
|
|
137
|
+
return "";
|
|
138
|
+
|
|
139
|
+
if(currentLangIndex < list.length)
|
|
140
|
+
return list[currentLangIndex]
|
|
141
|
+
else if(defaultLangIndex < list.length)
|
|
142
|
+
return list[defaultLangIndex]
|
|
143
|
+
else
|
|
144
|
+
return list[0]
|
|
145
|
+
}
|
|
146
|
+
else
|
|
147
|
+
{
|
|
148
|
+
let langKey = languages[currentLangIndex].key
|
|
149
|
+
if (Object.keys(list).includes(langKey))
|
|
150
|
+
return list[langKey]
|
|
151
|
+
else
|
|
152
|
+
{
|
|
153
|
+
langKey = languages[defaultLangIndex].key
|
|
154
|
+
const keys = Object.keys(list)
|
|
155
|
+
if (keys.includes(langKey))
|
|
156
|
+
return list[langKey]
|
|
157
|
+
else
|
|
158
|
+
return list[keys[0]]
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
package/index.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export { default as ComboItem } from './components/combo/combo.item.svelte';
|
|
|
26
26
|
export { default as RichEdit } from './components/document/rich.edit.svelte';
|
|
27
27
|
export { default as Editor } from './components/document/editor.svelte';
|
|
28
28
|
export { default as Spinner } from './components/delayed.spinner.svelte';
|
|
29
|
-
export { showMenu, showGridMenu, showFloatingToolbar } from './components/menu';
|
|
29
|
+
export { showMenu, showGridMenu, showFloatingToolbar, SHOW_MENU_BELOW, SHOW_MENU_ABOVE, SHOW_MENU_RIGHT, SHOW_MENU_LEFT } from './components/menu';
|
|
30
30
|
export { default as Fab } from './components/Fab.svelte';
|
|
31
31
|
export { default as Sidebar } from './components/sidebar/sidebar.svelte';
|
|
32
32
|
export { default as SidebarBrand } from './components/sidebar/sidebar.brand.svelte';
|
|
@@ -60,9 +60,9 @@ export { KanbanColumnTop, KanbanColumnBottom } from './components/kanban/Kanban'
|
|
|
60
60
|
export { default as Paginator } from './components/paginator.svelte';
|
|
61
61
|
export { default as Breadcrumb } from './components/breadcrumb.svelte';
|
|
62
62
|
export { breadcrumbAdd, breadcrumbParse, breadcrumbStringify, breadcrumbClipName } from './components/breadcrumb_utils';
|
|
63
|
-
export { selectItem, activateItem, clearActiveItem, isActive, isSelected, getActive, editable, startEditing, saveCurrentEditable, selectable, handleSelect, isDeviceSmallerThan, resizeImage, refreshToolbarOperations, isOnScreenKeyboardVisible, randomString, UI, } from './utils';
|
|
63
|
+
export { selectItem, activateItem, clearActiveItem, isActive, isSelected, getActive, editable, startEditing, saveCurrentEditable, selectable, handleSelect, isDeviceSmallerThan, resizeImage, refreshToolbarOperations, isOnScreenKeyboardVisible, randomString, UI, NAV_MODE_SIDEBAR, NAV_MODE_FULL_PAGE, navGetMode, navIsVisible, navGetKey, navShow, navHide, navToggle, navPrevVisibleKey, navAutoHide, } from './utils';
|
|
64
64
|
export { getNiceStringDateTime, getFormattedStringDate, getNiceStringDate, dayName, monthName } from './components/date_utils';
|
|
65
|
-
export { mainContentPageReloader, reloadMainContentPage, reloadWholeApp, alerts, addAlert, onErrorShowAlert, main_sidebar_visible_store, tagsReloader, reloadVisibleTags, dark_mode_store, showFABAlways } from './stores.js';
|
|
65
|
+
export { mainContentPageReloader, reloadMainContentPage, reloadWholeApp, wholeAppReloader, alerts, addAlert, onErrorShowAlert, main_sidebar_visible_store, navKey, tagsReloader, reloadVisibleTags, dark_mode_store, showFABAlways } from './stores.js';
|
|
66
66
|
export { data_tick_store, // tmp
|
|
67
67
|
hasSelectedItem, hasDataItem, setNavigatorTitle } from "./stores";
|
|
68
68
|
export { contextToolbarOperations, pageToolbarOperations, contextItemsStore, contextTypesStore } from './stores';
|
|
@@ -72,3 +72,5 @@ export { default as IcH2 } from './components/document/internal/h2.icon.svelte';
|
|
|
72
72
|
export { default as IcH3 } from './components/document/internal/h3.icon.svelte';
|
|
73
73
|
export { default as IcH4 } from './components/document/internal/h4.icon.svelte';
|
|
74
74
|
export { registerKicksObserver, unregisterKicksObserver, forceKicksChecking } from './kicks.js';
|
|
75
|
+
export { i18n, setLanguages, getLanguages, setCurrentLanguage, getCurrentLanguage, getCurrentLanguageIdx, getCurrentLanguageKey } from './i18n.js';
|
|
76
|
+
export { i18nPreprocess } from './i18n-preprocess.js';
|
package/index.js
CHANGED
|
@@ -32,7 +32,7 @@ export { default as RichEdit } from './components/document/rich.edit.svelte';
|
|
|
32
32
|
export { default as Editor } from './components/document/editor.svelte';
|
|
33
33
|
export { default as Spinner } from './components/delayed.spinner.svelte';
|
|
34
34
|
//export { default as Menu } from './components/contextmenu.svelte'
|
|
35
|
-
export { showMenu, showGridMenu, showFloatingToolbar } from './components/menu';
|
|
35
|
+
export { showMenu, showGridMenu, showFloatingToolbar, SHOW_MENU_BELOW, SHOW_MENU_ABOVE, SHOW_MENU_RIGHT, SHOW_MENU_LEFT } from './components/menu';
|
|
36
36
|
export { default as Fab } from './components/Fab.svelte';
|
|
37
37
|
export { default as Sidebar } from './components/sidebar/sidebar.svelte';
|
|
38
38
|
export { default as SidebarBrand } from './components/sidebar/sidebar.brand.svelte';
|
|
@@ -66,9 +66,9 @@ export { KanbanColumnTop, KanbanColumnBottom } from './components/kanban/Kanban'
|
|
|
66
66
|
export { default as Paginator } from './components/paginator.svelte';
|
|
67
67
|
export { default as Breadcrumb } from './components/breadcrumb.svelte';
|
|
68
68
|
export { breadcrumbAdd, breadcrumbParse, breadcrumbStringify, breadcrumbClipName } from './components/breadcrumb_utils';
|
|
69
|
-
export { selectItem, activateItem, clearActiveItem, isActive, isSelected, getActive, editable, startEditing, saveCurrentEditable, selectable, handleSelect, isDeviceSmallerThan, resizeImage, refreshToolbarOperations, isOnScreenKeyboardVisible, randomString, UI, } from './utils';
|
|
69
|
+
export { selectItem, activateItem, clearActiveItem, isActive, isSelected, getActive, editable, startEditing, saveCurrentEditable, selectable, handleSelect, isDeviceSmallerThan, resizeImage, refreshToolbarOperations, isOnScreenKeyboardVisible, randomString, UI, NAV_MODE_SIDEBAR, NAV_MODE_FULL_PAGE, navGetMode, navIsVisible, navGetKey, navShow, navHide, navToggle, navPrevVisibleKey, navAutoHide, } from './utils';
|
|
70
70
|
export { getNiceStringDateTime, getFormattedStringDate, getNiceStringDate, dayName, monthName } from './components/date_utils';
|
|
71
|
-
export { mainContentPageReloader, reloadMainContentPage, reloadWholeApp, alerts, addAlert, onErrorShowAlert, main_sidebar_visible_store, tagsReloader, reloadVisibleTags, dark_mode_store, showFABAlways } from './stores.js';
|
|
71
|
+
export { mainContentPageReloader, reloadMainContentPage, reloadWholeApp, wholeAppReloader, alerts, addAlert, onErrorShowAlert, main_sidebar_visible_store, navKey, tagsReloader, reloadVisibleTags, dark_mode_store, showFABAlways } from './stores.js';
|
|
72
72
|
export { data_tick_store, // tmp
|
|
73
73
|
hasSelectedItem, hasDataItem, setNavigatorTitle } from "./stores";
|
|
74
74
|
export { contextToolbarOperations, pageToolbarOperations, contextItemsStore, contextTypesStore } from './stores'; // tmp
|
|
@@ -78,3 +78,5 @@ export { default as IcH2 } from './components/document/internal/h2.icon.svelte';
|
|
|
78
78
|
export { default as IcH3 } from './components/document/internal/h3.icon.svelte';
|
|
79
79
|
export { default as IcH4 } from './components/document/internal/h4.icon.svelte';
|
|
80
80
|
export { registerKicksObserver, unregisterKicksObserver, forceKicksChecking } from './kicks.js';
|
|
81
|
+
export { i18n, setLanguages, getLanguages, setCurrentLanguage, getCurrentLanguage, getCurrentLanguageIdx, getCurrentLanguageKey } from './i18n.js';
|
|
82
|
+
export { i18nPreprocess } from './i18n-preprocess.js';
|
package/modal.svelte
CHANGED
|
@@ -3,6 +3,7 @@ import Icon from "./components/icon.svelte";
|
|
|
3
3
|
import { pushToolsActionsOperations, popToolsActionsOperations } from "./stores.js";
|
|
4
4
|
import { isDeviceSmallerThan } from "./utils";
|
|
5
5
|
import { FaTimes } from "svelte-icons/fa";
|
|
6
|
+
import { i18n } from "./i18n.js";
|
|
6
7
|
export let title = "";
|
|
7
8
|
export let open = false;
|
|
8
9
|
export let content = "";
|
|
@@ -13,7 +14,7 @@ export const Cancel = 2;
|
|
|
13
14
|
export const Custom = 3;
|
|
14
15
|
export let mode = OKCancel;
|
|
15
16
|
export let okCaption = "OK";
|
|
16
|
-
export let cancelCaption = "Cancel";
|
|
17
|
+
export let cancelCaption = i18n({ en: "Cancel", es: "Cancelar", pl: "Anuluj" });
|
|
17
18
|
export let onOkCallback = void 0;
|
|
18
19
|
export let onCancelCallback = void 0;
|
|
19
20
|
export function show(on_close_callback = void 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@humandialog/forms.svelte",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Basic Svelte UI components for Object Reef applications",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@playwright/test": "^1.28.1",
|
|
@@ -156,6 +156,8 @@
|
|
|
156
156
|
"./desk.svelte": "./desk.svelte",
|
|
157
157
|
"./form.box.svelte": "./form.box.svelte",
|
|
158
158
|
"./horizontal.toolbar.svelte": "./horizontal.toolbar.svelte",
|
|
159
|
+
"./i18n-preprocess": "./i18n-preprocess.js",
|
|
160
|
+
"./i18n": "./i18n.js",
|
|
159
161
|
".": "./index.js",
|
|
160
162
|
"./internal/configurable.content.svelte": "./internal/configurable.content.svelte",
|
|
161
163
|
"./internal/loading.svelte": "./internal/loading.svelte",
|
package/stores.d.ts
CHANGED
|
@@ -51,3 +51,4 @@ export const visible_property_tab_store: import("svelte/store").Writable<string>
|
|
|
51
51
|
export const fabCollapsed: import("svelte/store").Writable<any>;
|
|
52
52
|
export const showFABAlways: import("svelte/store").Writable<any>;
|
|
53
53
|
export const leftHandedFAB: import("svelte/store").Writable<any>;
|
|
54
|
+
export const navKey: import("svelte/store").Readable<any>;
|