@appsemble/lang-sdk 0.36.6-test.0 → 0.36.7-test.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/README.md +7 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
- package/pageUtils.d.ts +8 -0
- package/pageUtils.js +38 -0
package/README.md
CHANGED
|
@@ -22,6 +22,9 @@ npm install @appsemble/lang-sdk
|
|
|
22
22
|
|
|
23
23
|
This package provides utilities and tools for working with the language DSL used in Appsemble.
|
|
24
24
|
|
|
25
|
+
It also includes helpers for working with app page definitions, translated page labels, and
|
|
26
|
+
canonical page path segments.
|
|
27
|
+
|
|
25
28
|
## Exports
|
|
26
29
|
|
|
27
30
|
### 1. **Validators**
|
|
@@ -90,6 +93,10 @@ This package provides utilities and tools for working with the language DSL used
|
|
|
90
93
|
### 6. **Miscellaneous**
|
|
91
94
|
|
|
92
95
|
- `findPageByName`
|
|
96
|
+
- `findPageById`
|
|
97
|
+
- `getPageDisplayName`
|
|
98
|
+
- `getPageMessageId`
|
|
99
|
+
- `getPagePathSegment`
|
|
93
100
|
- `examples`
|
|
94
101
|
- `noop`
|
|
95
102
|
- `schemaExample`
|
package/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from './authorization.js';
|
|
|
6
6
|
export * from './blockUtils.js';
|
|
7
7
|
export * from './validation.js';
|
|
8
8
|
export * from './findPageByName.js';
|
|
9
|
+
export * from './pageUtils.js';
|
|
9
10
|
export * from './iterApp.js';
|
|
10
11
|
export * from './serverActions.js';
|
|
11
12
|
export * from './allActions.js';
|
package/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export * from './authorization.js';
|
|
|
6
6
|
export * from './blockUtils.js';
|
|
7
7
|
export * from './validation.js';
|
|
8
8
|
export * from './findPageByName.js';
|
|
9
|
+
export * from './pageUtils.js';
|
|
9
10
|
export * from './iterApp.js';
|
|
10
11
|
export * from './serverActions.js';
|
|
11
12
|
export * from './allActions.js';
|
package/package.json
CHANGED
package/pageUtils.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type MessageGetter } from './remap.js';
|
|
2
|
+
import { type PageDefinition } from './types/index.js';
|
|
3
|
+
type NamedPage = Pick<PageDefinition, 'name'>;
|
|
4
|
+
export declare function getPageMessageId(pageName: string): string;
|
|
5
|
+
export declare function getPagePathSegment(page: string | NamedPage): string;
|
|
6
|
+
export declare function getPageDisplayName(page: NamedPage, getAppMessage: MessageGetter): string;
|
|
7
|
+
export declare function findPageById(pages: PageDefinition[], normalizedPageId: string, appMessageIds: string[], getAppMessage: MessageGetter): PageDefinition | null;
|
|
8
|
+
export {};
|
package/pageUtils.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { normalize } from './normalize.js';
|
|
2
|
+
export function getPageMessageId(pageName) {
|
|
3
|
+
return `pages.${normalize(pageName)}`;
|
|
4
|
+
}
|
|
5
|
+
export function getPagePathSegment(page) {
|
|
6
|
+
return normalize(typeof page === 'string' ? page : page.name);
|
|
7
|
+
}
|
|
8
|
+
export function getPageDisplayName(page, getAppMessage) {
|
|
9
|
+
return getAppMessage({
|
|
10
|
+
id: getPageMessageId(page.name),
|
|
11
|
+
defaultMessage: page.name,
|
|
12
|
+
}).format();
|
|
13
|
+
}
|
|
14
|
+
function matchesPageId(page, normalizedPageId, appMessageIds, getAppMessage) {
|
|
15
|
+
if (getPagePathSegment(page) === normalizedPageId) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
const pageMessageId = getPageMessageId(page.name);
|
|
19
|
+
if (!appMessageIds.includes(pageMessageId)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return normalize(getPageDisplayName(page, getAppMessage)) === normalizedPageId;
|
|
23
|
+
}
|
|
24
|
+
export function findPageById(pages, normalizedPageId, appMessageIds, getAppMessage) {
|
|
25
|
+
for (const page of pages) {
|
|
26
|
+
if (matchesPageId(page, normalizedPageId, appMessageIds, getAppMessage)) {
|
|
27
|
+
return page;
|
|
28
|
+
}
|
|
29
|
+
if (page.type === 'container') {
|
|
30
|
+
const foundPage = findPageById(page.pages, normalizedPageId, appMessageIds, getAppMessage);
|
|
31
|
+
if (foundPage) {
|
|
32
|
+
return foundPage;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=pageUtils.js.map
|