@appsemble/lang-sdk 0.40.3-test.4 → 0.40.3
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/package.json +1 -1
- package/pageUtils.d.ts +36 -2
- package/pageUtils.js +55 -14
- package/validation.d.ts +2 -1
package/package.json
CHANGED
package/pageUtils.d.ts
CHANGED
|
@@ -1,10 +1,44 @@
|
|
|
1
1
|
import { type MessageGetter } from './remap.js';
|
|
2
2
|
import { type PageDefinition } from './types/index.js';
|
|
3
3
|
type NamedPage = Pick<PageDefinition, 'name'>;
|
|
4
|
+
/**
|
|
5
|
+
* The built-in routes whose URL segment an app may translate through a `routes.<Name>` message.
|
|
6
|
+
*/
|
|
7
|
+
export declare const translatableRoutes: readonly ["Login", "Register", "Settings", "Reset-Password", "Edit-Password", "Verify", "Group-Invite", "App-Invite", "Feedback"];
|
|
8
|
+
export type TranslatableRoute = (typeof translatableRoutes)[number];
|
|
4
9
|
export declare function getPageMessageId(pageName: string): string;
|
|
5
|
-
export declare function
|
|
10
|
+
export declare function getRouteMessageId(name: TranslatableRoute): string;
|
|
6
11
|
export declare function getPageDisplayName(page: NamedPage, getAppMessage: MessageGetter): string;
|
|
7
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Get the URL segment of a page in the current language.
|
|
14
|
+
*
|
|
15
|
+
* @param page The page to get the segment of.
|
|
16
|
+
* @param getAppMessage The app message getter of the current language.
|
|
17
|
+
* @returns The normalized translated page name. It equals the canonical segment
|
|
18
|
+
* `normalize(page.name)` when the page name is untranslated, or when the translated name has no
|
|
19
|
+
* Latin letters or digits to build a segment from.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getPagePathSegment(page: NamedPage, getAppMessage: MessageGetter): string;
|
|
22
|
+
/**
|
|
23
|
+
* Get the URL segment of a built-in route in the current language.
|
|
24
|
+
*
|
|
25
|
+
* @param name The English name of the built-in route.
|
|
26
|
+
* @param getAppMessage The app message getter of the current language.
|
|
27
|
+
* @returns The `routes.<name>` message as written, falling back to the English name.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getRouteSegment(name: TranslatableRoute, getAppMessage: MessageGetter): string;
|
|
30
|
+
/**
|
|
31
|
+
* Find a page by the `:pageId` URL segment.
|
|
32
|
+
*
|
|
33
|
+
* Translated segments are matched before canonical ones, so a link generated in the current
|
|
34
|
+
* language always resolves to the page it was generated for. The canonical segment is an alias.
|
|
35
|
+
*
|
|
36
|
+
* @param pages The pages of the app, containers included.
|
|
37
|
+
* @param normalizedPageId The normalized `:pageId` URL segment.
|
|
38
|
+
* @param getAppMessage The app message getter of the current language.
|
|
39
|
+
* @returns The matching page, or null if no page has the segment.
|
|
40
|
+
*/
|
|
41
|
+
export declare function findPageById(pages: PageDefinition[], normalizedPageId: string, getAppMessage: MessageGetter): PageDefinition | null;
|
|
8
42
|
/**
|
|
9
43
|
* Collect the pages a page sits under, by following `parent` upwards.
|
|
10
44
|
*
|
package/pageUtils.js
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
import { findPageByName } from './findPageByName.js';
|
|
2
2
|
import { normalize } from './normalize.js';
|
|
3
|
+
/**
|
|
4
|
+
* The built-in routes whose URL segment an app may translate through a `routes.<Name>` message.
|
|
5
|
+
*/
|
|
6
|
+
export const translatableRoutes = [
|
|
7
|
+
'Login',
|
|
8
|
+
'Register',
|
|
9
|
+
'Settings',
|
|
10
|
+
'Reset-Password',
|
|
11
|
+
'Edit-Password',
|
|
12
|
+
'Verify',
|
|
13
|
+
'Group-Invite',
|
|
14
|
+
'App-Invite',
|
|
15
|
+
'Feedback',
|
|
16
|
+
];
|
|
3
17
|
export function getPageMessageId(pageName) {
|
|
4
18
|
return `pages.${normalize(pageName)}`;
|
|
5
19
|
}
|
|
6
|
-
export function
|
|
7
|
-
return
|
|
20
|
+
export function getRouteMessageId(name) {
|
|
21
|
+
return `routes.${name}`;
|
|
8
22
|
}
|
|
9
23
|
export function getPageDisplayName(page, getAppMessage) {
|
|
10
24
|
return getAppMessage({
|
|
@@ -12,23 +26,35 @@ export function getPageDisplayName(page, getAppMessage) {
|
|
|
12
26
|
defaultMessage: page.name,
|
|
13
27
|
}).format();
|
|
14
28
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Get the URL segment of a page in the current language.
|
|
31
|
+
*
|
|
32
|
+
* @param page The page to get the segment of.
|
|
33
|
+
* @param getAppMessage The app message getter of the current language.
|
|
34
|
+
* @returns The normalized translated page name. It equals the canonical segment
|
|
35
|
+
* `normalize(page.name)` when the page name is untranslated, or when the translated name has no
|
|
36
|
+
* Latin letters or digits to build a segment from.
|
|
37
|
+
*/
|
|
38
|
+
export function getPagePathSegment(page, getAppMessage) {
|
|
39
|
+
return normalize(getPageDisplayName(page, getAppMessage)) || normalize(page.name);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get the URL segment of a built-in route in the current language.
|
|
43
|
+
*
|
|
44
|
+
* @param name The English name of the built-in route.
|
|
45
|
+
* @param getAppMessage The app message getter of the current language.
|
|
46
|
+
* @returns The `routes.<name>` message as written, falling back to the English name.
|
|
47
|
+
*/
|
|
48
|
+
export function getRouteSegment(name, getAppMessage) {
|
|
49
|
+
return getAppMessage({ id: getRouteMessageId(name), defaultMessage: name }).format();
|
|
24
50
|
}
|
|
25
|
-
|
|
51
|
+
function findPage(pages, matches) {
|
|
26
52
|
for (const page of pages) {
|
|
27
|
-
if (
|
|
53
|
+
if (matches(page)) {
|
|
28
54
|
return page;
|
|
29
55
|
}
|
|
30
56
|
if (page.type === 'container') {
|
|
31
|
-
const foundPage =
|
|
57
|
+
const foundPage = findPage(page.pages, matches);
|
|
32
58
|
if (foundPage) {
|
|
33
59
|
return foundPage;
|
|
34
60
|
}
|
|
@@ -36,6 +62,21 @@ export function findPageById(pages, normalizedPageId, appMessageIds, getAppMessa
|
|
|
36
62
|
}
|
|
37
63
|
return null;
|
|
38
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Find a page by the `:pageId` URL segment.
|
|
67
|
+
*
|
|
68
|
+
* Translated segments are matched before canonical ones, so a link generated in the current
|
|
69
|
+
* language always resolves to the page it was generated for. The canonical segment is an alias.
|
|
70
|
+
*
|
|
71
|
+
* @param pages The pages of the app, containers included.
|
|
72
|
+
* @param normalizedPageId The normalized `:pageId` URL segment.
|
|
73
|
+
* @param getAppMessage The app message getter of the current language.
|
|
74
|
+
* @returns The matching page, or null if no page has the segment.
|
|
75
|
+
*/
|
|
76
|
+
export function findPageById(pages, normalizedPageId, getAppMessage) {
|
|
77
|
+
return (findPage(pages, (page) => getPagePathSegment(page, getAppMessage) === normalizedPageId) ??
|
|
78
|
+
findPage(pages, (page) => normalize(page.name) === normalizedPageId));
|
|
79
|
+
}
|
|
39
80
|
/**
|
|
40
81
|
* Resolve which parent page applies to a member.
|
|
41
82
|
*
|
package/validation.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ValidatorResult } from 'jsonschema';
|
|
2
2
|
import { type Promisable } from 'type-fest';
|
|
3
3
|
import { type IdentifiableBlock } from './blockUtils.js';
|
|
4
|
+
import { type TranslatableRoute } from './pageUtils.js';
|
|
4
5
|
import { type AppDefinition, type BlockManifest, type ProjectImplementations, type Remapper } from './types/index.js';
|
|
5
6
|
/**
|
|
6
7
|
* Check whether or not the given link represents a link related to the Appsemble core.
|
|
@@ -8,7 +9,7 @@ import { type AppDefinition, type BlockManifest, type ProjectImplementations, ty
|
|
|
8
9
|
* @param link The link to check
|
|
9
10
|
* @returns Whether or not the given link represents a link related to the Appsemble core.
|
|
10
11
|
*/
|
|
11
|
-
export declare function isAppLink(link: Remapper | string[] | string):
|
|
12
|
+
export declare function isAppLink(link: Remapper | string[] | string): link is `/${TranslatableRoute}`;
|
|
12
13
|
export type BlockVersionsGetter = (blockMap: IdentifiableBlock[]) => Promisable<BlockManifest[]>;
|
|
13
14
|
/**
|
|
14
15
|
* Validate an app definition.
|