@panomc/theme-core 1.1.0-dev.2 → 1.2.0-dev.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/assets/css/pano-fallback.css +10 -0
- package/lang/en-US.json +16 -0
- package/lang/ru.json +16 -0
- package/lang/tr.json +16 -0
- package/package.json +3 -3
- package/skin-contract.json +36 -2
- package/src/kit/__tests__/vite-config-dev-ssr.test.js +26 -0
- package/src/kit/vite-config.js +23 -0
- package/src/lib/__tests__/contentI18n.test.js +216 -0
- package/src/lib/__tests__/engineParts.helper.js +1 -0
- package/src/lib/__tests__/engineStyles.test.js +2 -2
- package/src/lib/__tests__/ticketFields.test.js +258 -0
- package/src/lib/components/Post.svelte +6 -1
- package/src/lib/components/Posts.svelte +6 -1
- package/src/lib/components/TicketFields.svelte +40 -0
- package/src/lib/components/TicketFieldsForm.svelte +63 -0
- package/src/lib/components/TicketRow.svelte +9 -1
- package/src/lib/contentI18n.js +227 -0
- package/src/lib/pages/HomePage.svelte +12 -1
- package/src/lib/pages/PostDetailPage.svelte +31 -2
- package/src/lib/pages/PreviewPostPage.svelte +14 -2
- package/src/lib/pages/RulesPage.svelte +14 -1
- package/src/lib/pages/profile/TicketsPage.svelte +22 -1
- package/src/lib/pages/ticket/CreateTicketPage.svelte +25 -3
- package/src/lib/pages/ticket/TicketDetailPage.svelte +21 -0
- package/src/lib/services/tickets.js +3 -0
- package/src/lib/siteRealtime.js +53 -1
- package/src/lib/ticketFields.js +354 -0
- package/src/lib/ui-logics/page-logics/CreateTicketPageLogics.js +40 -3
- package/src/lib/ui-logics/page-logics/PostDetailPageLogics.js +13 -1
- package/src/lib/ui-logics/page-logics/TicketDetailPageLogics.js +43 -3
- package/src/lib/ui-logics/page-logics/TicketsPageLogics.js +54 -5
- package/src/lib/views/CreateTicketView.svelte +6 -1
- package/src/lib/views/TicketDetailView.svelte +5 -1
- package/src/lib/views/parts/TicketFields.svelte +31 -0
- package/src/lib/views/parts/TicketFieldsForm.svelte +170 -0
- package/src/lib/views/parts/engine-views.generated.js +4 -2
|
@@ -484,6 +484,10 @@
|
|
|
484
484
|
--bs-gutter-y: 1rem;
|
|
485
485
|
}
|
|
486
486
|
@media (min-width: 576px) {
|
|
487
|
+
.col-sm-4 {
|
|
488
|
+
flex: 0 0 auto;
|
|
489
|
+
width: 33.33333333%;
|
|
490
|
+
}
|
|
487
491
|
.col-sm-8 {
|
|
488
492
|
flex: 0 0 auto;
|
|
489
493
|
width: 66.66666667%;
|
|
@@ -573,6 +577,9 @@
|
|
|
573
577
|
overflow-x: auto;
|
|
574
578
|
-webkit-overflow-scrolling: touch;
|
|
575
579
|
}
|
|
580
|
+
.form-label {
|
|
581
|
+
margin-bottom: 0.5rem;
|
|
582
|
+
}
|
|
576
583
|
.col-form-label {
|
|
577
584
|
padding-top: calc(0.375rem + var(--bs-border-width));
|
|
578
585
|
padding-bottom: calc(0.375rem + var(--bs-border-width));
|
|
@@ -2952,6 +2959,9 @@
|
|
|
2952
2959
|
.mb-0 {
|
|
2953
2960
|
margin-bottom: 0;
|
|
2954
2961
|
}
|
|
2962
|
+
.mb-1 {
|
|
2963
|
+
margin-bottom: 0.25rem;
|
|
2964
|
+
}
|
|
2955
2965
|
.mb-2 {
|
|
2956
2966
|
margin-bottom: 0.5rem;
|
|
2957
2967
|
}
|
package/lang/en-US.json
CHANGED
|
@@ -195,6 +195,17 @@
|
|
|
195
195
|
"inputs": {
|
|
196
196
|
"title": "Title",
|
|
197
197
|
"no-category": "No Category"
|
|
198
|
+
},
|
|
199
|
+
"fields": {
|
|
200
|
+
"choose": "Choose...",
|
|
201
|
+
"errors": {
|
|
202
|
+
"REQUIRED": "This field is required.",
|
|
203
|
+
"INVALID": "This value is not valid.",
|
|
204
|
+
"TOO_SHORT": "Enter at least {min} characters.",
|
|
205
|
+
"TOO_LONG": "Enter at most {max} characters.",
|
|
206
|
+
"OUT_OF_RANGE": "This number is out of the allowed range.",
|
|
207
|
+
"UNKNOWN_OPTION": "Choose one of the listed options."
|
|
208
|
+
}
|
|
198
209
|
}
|
|
199
210
|
},
|
|
200
211
|
"player-profile": {
|
|
@@ -257,6 +268,10 @@
|
|
|
257
268
|
"message": {
|
|
258
269
|
"placeholder": "Your message..."
|
|
259
270
|
}
|
|
271
|
+
},
|
|
272
|
+
"fields": {
|
|
273
|
+
"yes": "Yes",
|
|
274
|
+
"no": "No"
|
|
260
275
|
}
|
|
261
276
|
},
|
|
262
277
|
"settings": {
|
|
@@ -469,6 +484,7 @@
|
|
|
469
484
|
"CANT_RESET_PASSWORD_WAIT5MINUTES": "Can't reset password, wait 5 minutes.",
|
|
470
485
|
"CATEGORY_NOT_EXISTS": "This category is not found!",
|
|
471
486
|
"TICKET_CATEGORY_REQUIRED": "Pick a category to open a ticket.",
|
|
487
|
+
"INVALID_FIELDS": "Check the marked fields.",
|
|
472
488
|
"CURRENT_PASSWORD_NOT_CORRECT": "Current password is not correct!",
|
|
473
489
|
"INVALID_DATA": "Invalid data!",
|
|
474
490
|
"INVALID_EMAIL": "Invalid e-mail!",
|
package/lang/ru.json
CHANGED
|
@@ -195,6 +195,17 @@
|
|
|
195
195
|
"inputs": {
|
|
196
196
|
"title": "Заголовок",
|
|
197
197
|
"no-category": "Без категории"
|
|
198
|
+
},
|
|
199
|
+
"fields": {
|
|
200
|
+
"choose": "Выберите...",
|
|
201
|
+
"errors": {
|
|
202
|
+
"REQUIRED": "Это поле обязательно.",
|
|
203
|
+
"INVALID": "Недопустимое значение.",
|
|
204
|
+
"TOO_SHORT": "Введите не менее {min} символов.",
|
|
205
|
+
"TOO_LONG": "Введите не более {max} символов.",
|
|
206
|
+
"OUT_OF_RANGE": "Число вне допустимого диапазона.",
|
|
207
|
+
"UNKNOWN_OPTION": "Выберите один из вариантов списка."
|
|
208
|
+
}
|
|
198
209
|
}
|
|
199
210
|
},
|
|
200
211
|
"player-profile": {
|
|
@@ -257,6 +268,10 @@
|
|
|
257
268
|
"message": {
|
|
258
269
|
"placeholder": "Ваше сообщение..."
|
|
259
270
|
}
|
|
271
|
+
},
|
|
272
|
+
"fields": {
|
|
273
|
+
"yes": "Да",
|
|
274
|
+
"no": "Нет"
|
|
260
275
|
}
|
|
261
276
|
},
|
|
262
277
|
"settings": {
|
|
@@ -469,6 +484,7 @@
|
|
|
469
484
|
"CANT_RESET_PASSWORD_WAIT5MINUTES": "Нельзя сбросить пароль, подождите 5 минут.",
|
|
470
485
|
"CATEGORY_NOT_EXISTS": "Эта категория не найдена!",
|
|
471
486
|
"TICKET_CATEGORY_REQUIRED": "Выберите категорию, чтобы создать тикет.",
|
|
487
|
+
"INVALID_FIELDS": "Проверьте отмеченные поля.",
|
|
472
488
|
"CURRENT_PASSWORD_NOT_CORRECT": "Текущий пароль неверен!",
|
|
473
489
|
"INVALID_DATA": "Неверные данные!",
|
|
474
490
|
"INVALID_EMAIL": "Неверный e-mail!",
|
package/lang/tr.json
CHANGED
|
@@ -195,6 +195,17 @@
|
|
|
195
195
|
"inputs": {
|
|
196
196
|
"title": "Başlık",
|
|
197
197
|
"no-category": "Kategorisiz"
|
|
198
|
+
},
|
|
199
|
+
"fields": {
|
|
200
|
+
"choose": "Seçin...",
|
|
201
|
+
"errors": {
|
|
202
|
+
"REQUIRED": "Bu alan zorunludur.",
|
|
203
|
+
"INVALID": "Bu değer geçerli değil.",
|
|
204
|
+
"TOO_SHORT": "En az {min} karakter girin.",
|
|
205
|
+
"TOO_LONG": "En fazla {max} karakter girin.",
|
|
206
|
+
"OUT_OF_RANGE": "Bu sayı izin verilen aralığın dışında.",
|
|
207
|
+
"UNKNOWN_OPTION": "Listedeki seçeneklerden birini seçin."
|
|
208
|
+
}
|
|
198
209
|
}
|
|
199
210
|
},
|
|
200
211
|
"player-profile": {
|
|
@@ -257,6 +268,10 @@
|
|
|
257
268
|
"message": {
|
|
258
269
|
"placeholder": "Mesajınız..."
|
|
259
270
|
}
|
|
271
|
+
},
|
|
272
|
+
"fields": {
|
|
273
|
+
"yes": "Evet",
|
|
274
|
+
"no": "Hayır"
|
|
260
275
|
}
|
|
261
276
|
},
|
|
262
277
|
"settings": {
|
|
@@ -469,6 +484,7 @@
|
|
|
469
484
|
"CANT_RESET_PASSWORD_WAIT5MINUTES": "Şifre sıfırlanamaz, 5 dakika bekleyin.",
|
|
470
485
|
"CATEGORY_NOT_EXISTS": "Bu kategori bulunamadı!",
|
|
471
486
|
"TICKET_CATEGORY_REQUIRED": "Destek talebi açmak için bir kategori seçin.",
|
|
487
|
+
"INVALID_FIELDS": "İşaretli alanları kontrol edin.",
|
|
472
488
|
"CURRENT_PASSWORD_NOT_CORRECT": "Mevcut şifre doğru değil!",
|
|
473
489
|
"INVALID_DATA": "Geçersiz veri!",
|
|
474
490
|
"INVALID_EMAIL": "Geçersiz e-posta!",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panomc/theme-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0-dev.1",
|
|
4
4
|
"description": "The Pano theme engine: hooks factories, plugin engine, headless page controllers, default views and the theme CLI. Themes depend on this package instead of forking vanilla-theme.",
|
|
5
5
|
"author": "PanoMC",
|
|
6
6
|
"pano": {
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@fortawesome/fontawesome-free": "^6.7.2"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
|
-
"@panomc/sdk": "^2.0.0-dev.
|
|
64
|
+
"@panomc/sdk": "^2.0.0-dev.1",
|
|
65
65
|
"@sveltejs/adapter-node": "^6.0.0",
|
|
66
66
|
"@sveltejs/kit": "^3.1.0",
|
|
67
67
|
"@sveltejs/vite-plugin-svelte": "^7.3.1",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"vite": "^8.3.4"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@panomc/sdk": "2.0.0-dev.
|
|
74
|
+
"@panomc/sdk": "2.0.0-dev.1",
|
|
75
75
|
"@sveltejs/adapter-node": "^6.0.0",
|
|
76
76
|
"@sveltejs/kit": "^3.1.0",
|
|
77
77
|
"@sveltejs/vite-plugin-svelte": "^7.3.1",
|
package/skin-contract.json
CHANGED
|
@@ -398,7 +398,7 @@
|
|
|
398
398
|
"TicketDetailView": {
|
|
399
399
|
"contract": 1,
|
|
400
400
|
"source": "src/lib/views/TicketDetailView.svelte",
|
|
401
|
-
"uses": ["Date", "TicketStatus"],
|
|
401
|
+
"uses": ["Date", "TicketFields", "TicketStatus"],
|
|
402
402
|
"hooks": [],
|
|
403
403
|
"slotProps": {},
|
|
404
404
|
"props": {
|
|
@@ -423,7 +423,7 @@
|
|
|
423
423
|
"CreateTicketView": {
|
|
424
424
|
"contract": 1,
|
|
425
425
|
"source": "src/lib/views/CreateTicketView.svelte",
|
|
426
|
-
"uses": [],
|
|
426
|
+
"uses": ["TicketFieldsForm"],
|
|
427
427
|
"hooks": [],
|
|
428
428
|
"slotProps": {},
|
|
429
429
|
"props": {
|
|
@@ -693,6 +693,38 @@
|
|
|
693
693
|
"props": ["status"]
|
|
694
694
|
}
|
|
695
695
|
},
|
|
696
|
+
"TicketFieldsForm": {
|
|
697
|
+
"kind": "component",
|
|
698
|
+
"contract": 1,
|
|
699
|
+
"source": "src/lib/views/parts/TicketFieldsForm.svelte",
|
|
700
|
+
"uses": [],
|
|
701
|
+
"hooks": [],
|
|
702
|
+
"slotProps": {},
|
|
703
|
+
"props": {
|
|
704
|
+
"fields": "array — the visible custom field definitions of the chosen category, in order ({ key, label, type, required, placeholder, help, options: [{ value, label }], min, max }); the controller applies the conditions",
|
|
705
|
+
"values": "writable store — field key -> value; bind inputs to $values[field.key] (string; NUMBER number; MULTISELECT string array; CHECKBOX boolean)",
|
|
706
|
+
"errors": "object — field key -> error code (REQUIRED, INVALID, TOO_SHORT, TOO_LONG, OUT_OF_RANGE, UNKNOWN_OPTION)"
|
|
707
|
+
},
|
|
708
|
+
"locked": {
|
|
709
|
+
"contract": 1,
|
|
710
|
+
"props": ["errors", "fields", "values"]
|
|
711
|
+
}
|
|
712
|
+
},
|
|
713
|
+
"TicketFields": {
|
|
714
|
+
"kind": "component",
|
|
715
|
+
"contract": 1,
|
|
716
|
+
"source": "src/lib/views/parts/TicketFields.svelte",
|
|
717
|
+
"uses": [],
|
|
718
|
+
"hooks": [],
|
|
719
|
+
"slotProps": {},
|
|
720
|
+
"props": {
|
|
721
|
+
"entries": "array — the ticket's custom fields that have a value, in order: { key, label, type, value, text, href } (text = readable value; href only for an http(s) URL or an e-mail)"
|
|
722
|
+
},
|
|
723
|
+
"locked": {
|
|
724
|
+
"contract": 1,
|
|
725
|
+
"props": ["entries"]
|
|
726
|
+
}
|
|
727
|
+
},
|
|
696
728
|
"Toast": {
|
|
697
729
|
"kind": "component",
|
|
698
730
|
"contract": 1,
|
|
@@ -1187,6 +1219,8 @@
|
|
|
1187
1219
|
"Tickets",
|
|
1188
1220
|
"TicketRow",
|
|
1189
1221
|
"TicketStatus",
|
|
1222
|
+
"TicketFieldsForm",
|
|
1223
|
+
"TicketFields",
|
|
1190
1224
|
"Toast",
|
|
1191
1225
|
"DefaultToast",
|
|
1192
1226
|
"ToastContainer",
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { serverDevModeOff } from "../vite-config.js";
|
|
3
|
+
|
|
4
|
+
describe("serverDevModeOff", () => {
|
|
5
|
+
test("turns Svelte dev mode off for the server compile only", async () => {
|
|
6
|
+
const fn = serverDevModeOff();
|
|
7
|
+
|
|
8
|
+
expect(await fn({ compileOptions: { generate: "server", dev: true } })).toEqual({ dev: false });
|
|
9
|
+
expect(await fn({ compileOptions: { generate: "client", dev: true } })).toBeUndefined();
|
|
10
|
+
expect(await fn({ compileOptions: { generate: "server", dev: false } })).toBeUndefined();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("the theme's own dynamicCompileOptions still runs and wins", async () => {
|
|
14
|
+
const fn = serverDevModeOff(({ filename }) => (filename.endsWith("X.svelte") ? { dev: true, runes: true } : undefined));
|
|
15
|
+
|
|
16
|
+
expect(await fn({ filename: "a/X.svelte", compileOptions: { generate: "server", dev: true } })).toEqual({
|
|
17
|
+
dev: true,
|
|
18
|
+
runes: true,
|
|
19
|
+
});
|
|
20
|
+
expect(await fn({ filename: "a/Y.svelte", compileOptions: { generate: "server", dev: true } })).toEqual({ dev: false });
|
|
21
|
+
expect(await fn({ filename: "a/X.svelte", compileOptions: { generate: "client", dev: true } })).toEqual({
|
|
22
|
+
dev: true,
|
|
23
|
+
runes: true,
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
});
|
package/src/kit/vite-config.js
CHANGED
|
@@ -22,6 +22,27 @@ import { loadThemeConfig, pullContracts, writeCoreMeta } from "../../bin/contrac
|
|
|
22
22
|
|
|
23
23
|
const require = createRequire(import.meta.url);
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* vite-plugin-svelte `dynamicCompileOptions` for the dev server: the server (SSR) compile of the theme runs without
|
|
27
|
+
* Svelte dev mode, like every production build and like the plugins' server bundles.
|
|
28
|
+
*
|
|
29
|
+
* A plugin's server bundle carries its own copy of `svelte/internal/server` (production has no node_modules to share
|
|
30
|
+
* the theme's). Host components the engine hands to plugins (`NoContent`, `Pagination`, theme overrides of plugin
|
|
31
|
+
* views, ...) are rendered inside the plugin's renderer, so Svelte's server-side dev checks (`push_element`) read the
|
|
32
|
+
* theme copy's `ssr_context`, which is null there: `/store` with no products failed with
|
|
33
|
+
* `Cannot read properties of null (reading 'function')` under `vite dev` only. The browser compile keeps dev mode.
|
|
34
|
+
*
|
|
35
|
+
* @param {Function} [themeFn] the theme's own `dynamicCompileOptions`; its result wins over this one
|
|
36
|
+
*/
|
|
37
|
+
export function serverDevModeOff(themeFn) {
|
|
38
|
+
return async (args) => {
|
|
39
|
+
const own = args?.compileOptions?.generate === "server" && args.compileOptions.dev ? { dev: false } : undefined;
|
|
40
|
+
const theme = themeFn ? await themeFn(args) : undefined;
|
|
41
|
+
|
|
42
|
+
return own || theme ? { ...own, ...theme } : undefined;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
25
46
|
function copyFolderPlugin(folder) {
|
|
26
47
|
let outDir = "";
|
|
27
48
|
|
|
@@ -272,6 +293,8 @@ export function createViteConfig(opts = {}) {
|
|
|
272
293
|
const kitOptions = await createKitOptions(process.cwd(), {
|
|
273
294
|
...kitOverrides,
|
|
274
295
|
...(base ? { paths: { ...(kitOverrides.paths ?? {}), base } } : {}),
|
|
296
|
+
// vite dev only: the SSR compile without Svelte dev mode (see serverDevModeOff)
|
|
297
|
+
...(command === "serve" ? { dynamicCompileOptions: serverDevModeOff(kitOverrides.dynamicCompileOptions) } : {}),
|
|
275
298
|
});
|
|
276
299
|
|
|
277
300
|
// Every dev start refreshes plugin-contracts/ from the installed plugins and prints the views whose
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
localizeCategories,
|
|
5
|
+
localizeCategory,
|
|
6
|
+
localizeField,
|
|
7
|
+
localized,
|
|
8
|
+
localizedDisplay,
|
|
9
|
+
localizedOption,
|
|
10
|
+
localizedString,
|
|
11
|
+
localizePost,
|
|
12
|
+
localizePostCategory,
|
|
13
|
+
localizePosts,
|
|
14
|
+
} from "../contentI18n.js";
|
|
15
|
+
|
|
16
|
+
const field = {
|
|
17
|
+
key: "topic",
|
|
18
|
+
label: "Konu",
|
|
19
|
+
type: "SELECT",
|
|
20
|
+
placeholder: "Seç",
|
|
21
|
+
help: "",
|
|
22
|
+
options: [
|
|
23
|
+
{ value: "appeal", label: "Ban itirazı" },
|
|
24
|
+
{ value: "bug", label: "Hata" },
|
|
25
|
+
],
|
|
26
|
+
i18n: {
|
|
27
|
+
"en-US": { label: "Topic", help: "Pick one", options: { appeal: "Ban appeal" } },
|
|
28
|
+
ru: { label: "Тема", placeholder: " " },
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
describe("localized", () => {
|
|
33
|
+
test("exact locale code", () => {
|
|
34
|
+
expect(localized("Konu", field.i18n, "en-US", "label")).toBe("Topic");
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("language part fallback (ru-RU -> ru)", () => {
|
|
38
|
+
expect(localized("Konu", field.i18n, "ru-RU", "label")).toBe("Тема");
|
|
39
|
+
expect(localized("Konu", { tr: { label: "Konu TR" } }, "tr-TR", "label")).toBe("Konu TR");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("blank or missing translation -> default", () => {
|
|
43
|
+
expect(localized("Seç", field.i18n, "ru", "placeholder")).toBe("Seç");
|
|
44
|
+
expect(localized("Konu", field.i18n, "de", "label")).toBe("Konu");
|
|
45
|
+
expect(localized("Konu", field.i18n, "en-US", "missing")).toBe("Konu");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("no i18n or locale (older backend) -> default", () => {
|
|
49
|
+
expect(localized("Konu", undefined, "en-US", "label")).toBe("Konu");
|
|
50
|
+
expect(localized("Konu", null, null, "label")).toBe("Konu");
|
|
51
|
+
expect(localized(undefined, undefined, "en-US", "label")).toBe("");
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe("localizedOption", () => {
|
|
56
|
+
test("translated option, fallback to own label", () => {
|
|
57
|
+
expect(localizedOption(field.options[0], field.i18n, "en-US")).toBe("Ban appeal");
|
|
58
|
+
expect(localizedOption(field.options[0], field.i18n, "en")).toBe("Ban itirazı");
|
|
59
|
+
expect(localizedOption(field.options[1], field.i18n, "en-US")).toBe("Hata");
|
|
60
|
+
expect(localizedOption(field.options[0], undefined, "en-US")).toBe("Ban itirazı");
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe("localizedString", () => {
|
|
65
|
+
test("flat map with fallback", () => {
|
|
66
|
+
const texts = { "en-US": "<p>Rules</p>", ru: "" };
|
|
67
|
+
expect(localizedString("<p>Kurallar</p>", texts, "en-US")).toBe("<p>Rules</p>");
|
|
68
|
+
expect(localizedString("<p>Kurallar</p>", texts, "ru")).toBe("<p>Kurallar</p>");
|
|
69
|
+
expect(localizedString("<p>Kurallar</p>", undefined, "en-US")).toBe("<p>Kurallar</p>");
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("localizedDisplay", () => {
|
|
74
|
+
const entry = (type, value, display) => ({ ...field, type, value, display });
|
|
75
|
+
|
|
76
|
+
test("SELECT is rebuilt from the value", () => {
|
|
77
|
+
expect(localizedDisplay(entry("SELECT", "appeal", "Ban itirazı"), "en-US")).toBe("Ban appeal");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("MULTISELECT is joined with ', '", () => {
|
|
81
|
+
expect(localizedDisplay(entry("MULTISELECT", ["appeal", "bug"], "Ban itirazı, Hata"), "en-US")).toBe(
|
|
82
|
+
"Ban appeal, Hata",
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("no translation keeps display", () => {
|
|
87
|
+
expect(localizedDisplay(entry("MULTISELECT", ["appeal", "bug"], "Ban itirazı, Hata"), "de")).toBe(
|
|
88
|
+
"Ban itirazı, Hata",
|
|
89
|
+
);
|
|
90
|
+
expect(localizedDisplay({ type: "SELECT", value: "x", display: "X" }, "en-US")).toBe("X");
|
|
91
|
+
expect(localizedDisplay({ type: "SELECT", value: "x" }, "en-US")).toBe("x");
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("other types use display as is", () => {
|
|
95
|
+
expect(localizedDisplay({ type: "TEXT", value: "abc", display: "abc", i18n: field.i18n }, "en-US")).toBe("abc");
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe("localizeField / localizeCategory", () => {
|
|
100
|
+
test("field texts and options are localized, i18n kept", () => {
|
|
101
|
+
const result = localizeField(field, "en-US");
|
|
102
|
+
expect(result.label).toBe("Topic");
|
|
103
|
+
expect(result.placeholder).toBe("Seç");
|
|
104
|
+
expect(result.help).toBe("Pick one");
|
|
105
|
+
expect(result.options.map((option) => option.label)).toEqual(["Ban appeal", "Hata"]);
|
|
106
|
+
expect(result.options.map((option) => option.value)).toEqual(["appeal", "bug"]);
|
|
107
|
+
expect(result.i18n).toBe(field.i18n);
|
|
108
|
+
expect(field.label).toBe("Konu");
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("localizing a localized copy starts from the source", () => {
|
|
112
|
+
const english = localizeField(field, "en-US");
|
|
113
|
+
expect(localizeField(english, "de").label).toBe("Konu");
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("category title, description and fields", () => {
|
|
117
|
+
const category = {
|
|
118
|
+
id: 1,
|
|
119
|
+
title: "Destek",
|
|
120
|
+
description: "Açıklama",
|
|
121
|
+
fields: [field],
|
|
122
|
+
i18n: { en: { title: "Support" } },
|
|
123
|
+
};
|
|
124
|
+
const result = localizeCategory(category, "en-US");
|
|
125
|
+
expect(result.title).toBe("Support");
|
|
126
|
+
expect(result.description).toBe("Açıklama");
|
|
127
|
+
expect(result.fields[0].label).toBe("Topic");
|
|
128
|
+
expect(localizeCategory(result, "tr").title).toBe("Destek");
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("absent data is safe", () => {
|
|
132
|
+
expect(localizeCategory(null, "en")).toBe(null);
|
|
133
|
+
expect(localizeCategory("-", "en")).toBe("-");
|
|
134
|
+
expect(localizeCategory({ title: "-", url: "-" }, "en").title).toBe("-");
|
|
135
|
+
expect(localizeCategories(undefined, "en")).toEqual([]);
|
|
136
|
+
expect(localizeCategories([{ id: 2, title: "A" }], "en")[0].title).toBe("A");
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const post = {
|
|
141
|
+
id: 7,
|
|
142
|
+
url: "yeni-sezon",
|
|
143
|
+
title: "Yeni sezon",
|
|
144
|
+
text: "<p>Merhaba</p>",
|
|
145
|
+
category: {
|
|
146
|
+
id: 2,
|
|
147
|
+
title: "Duyurular",
|
|
148
|
+
description: "Haberler",
|
|
149
|
+
url: "duyurular",
|
|
150
|
+
i18n: { "en-US": { title: "Announcements" }, en: { description: "News" } },
|
|
151
|
+
},
|
|
152
|
+
i18n: { "en-US": { title: "New season", text: "<p>Hello</p>" }, ru: { title: " " } },
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
describe("localizePost", () => {
|
|
156
|
+
test("title, HTML text and category in the locale", () => {
|
|
157
|
+
const copy = localizePost(post, "en-US");
|
|
158
|
+
|
|
159
|
+
expect(copy.title).toBe("New season");
|
|
160
|
+
expect(copy.text).toBe("<p>Hello</p>");
|
|
161
|
+
expect(copy.category.title).toBe("Announcements");
|
|
162
|
+
expect(copy.category.description).toBe("News");
|
|
163
|
+
expect(copy.url).toBe("yeni-sezon");
|
|
164
|
+
expect(copy.i18n).toBe(post.i18n);
|
|
165
|
+
expect(post.title).toBe("Yeni sezon");
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test("blank translation and unknown locale fall back to the default", () => {
|
|
169
|
+
const ru = localizePost(post, "ru");
|
|
170
|
+
|
|
171
|
+
expect(ru.title).toBe("Yeni sezon");
|
|
172
|
+
expect(ru.text).toBe("<p>Merhaba</p>");
|
|
173
|
+
expect(ru.category.title).toBe("Duyurular");
|
|
174
|
+
expect(localizePost(post, null).title).toBe("Yeni sezon");
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("re-localizing starts from the original", () => {
|
|
178
|
+
const english = localizePost(post, "en-US");
|
|
179
|
+
const back = localizePost(english, "tr");
|
|
180
|
+
|
|
181
|
+
expect(back.title).toBe("Yeni sezon");
|
|
182
|
+
expect(back.text).toBe("<p>Merhaba</p>");
|
|
183
|
+
expect(back.category.title).toBe("Duyurular");
|
|
184
|
+
expect(localizePost(back, "en-US").title).toBe("New season");
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test("without i18n: defaults, no errors", () => {
|
|
188
|
+
const plain = { title: "A", text: "B", category: { title: "C", url: "c" } };
|
|
189
|
+
const copy = localizePost(plain, "en-US");
|
|
190
|
+
|
|
191
|
+
expect(copy).toEqual(plain);
|
|
192
|
+
expect("i18n" in copy).toBe(false);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test("placeholders are returned as is", () => {
|
|
196
|
+
expect(localizePost("-", "en-US")).toBe("-");
|
|
197
|
+
expect(localizePost(null, "en-US")).toBe(null);
|
|
198
|
+
expect(localizePost({ title: "A", category: "-" }, "en-US").category).toBe("-");
|
|
199
|
+
expect(localizePostCategory({ title: "-", i18n: { en: { title: "X" } } }, "en").title).toBe("-");
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test("a previous / next link without text keeps its shape", () => {
|
|
203
|
+
expect(localizePost({ url: "a", title: "A", i18n: { en: { title: "B" } } }, "en-GB")).toEqual({
|
|
204
|
+
url: "a",
|
|
205
|
+
title: "B",
|
|
206
|
+
i18n: { en: { title: "B" } },
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
describe("localizePosts", () => {
|
|
212
|
+
test("maps every post; a non-array answers []", () => {
|
|
213
|
+
expect(localizePosts([post], "en-US").map((item) => item.title)).toEqual(["New season"]);
|
|
214
|
+
expect(localizePosts(undefined, "en-US")).toEqual([]);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
@@ -25,6 +25,7 @@ export function findSvelte() {
|
|
|
25
25
|
|
|
26
26
|
const STUB_JS = {
|
|
27
27
|
"svelte-i18n": `import { readable } from "svelte/store";
|
|
28
|
+
export const locale = readable("en-US");
|
|
28
29
|
export const _ = readable((key, options) => (options && options.values && Object.keys(options.values).length ? key + JSON.stringify(options.values) : key));`,
|
|
29
30
|
"$app/env": `export const dev = false; export const browser = false;`,
|
|
30
31
|
"@panomc/sdk/core/js/basePath.js": `export const base = "";`,
|
|
@@ -38,8 +38,8 @@ const views = files.map((file) => ({ name: basename(file, ".svelte"), file: rel(
|
|
|
38
38
|
const inScope = new Set(views.map((v) => v.file));
|
|
39
39
|
|
|
40
40
|
describe("engine semantic classes (doc 03 section 1, ns = pano)", () => {
|
|
41
|
-
test("covers
|
|
42
|
-
expect(files.length).toBe(
|
|
41
|
+
test("covers 59 engine files: the views, their parts and the registry components", () => {
|
|
42
|
+
expect(files.length).toBe(59);
|
|
43
43
|
for (const name of ["HomeView", "LoginView", "Post", "Navbar", "Footer", "RegisterForm", "Pagination", "Toast"]) {
|
|
44
44
|
expect(views.some((v) => v.name === name)).toBe(true);
|
|
45
45
|
}
|