@cratis/scene.engine 4.6.0 → 4.8.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/dist/cjs/index.js +5 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/templateApplicability.js +68 -0
- package/dist/cjs/templateApplicability.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/templateApplicability.d.ts +8 -0
- package/dist/esm/templateApplicability.d.ts.map +1 -0
- package/dist/esm/templateApplicability.js +63 -0
- package/dist/esm/templateApplicability.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/index.ts +1 -0
- package/package.json +3 -3
- package/templateApplicability.ts +75 -0
package/index.ts
CHANGED
|
@@ -21,6 +21,7 @@ export * from './packageVersionRange';
|
|
|
21
21
|
export * from './resolvePackageDependencies';
|
|
22
22
|
export * from './packageCatalog';
|
|
23
23
|
export * from './resolveScreenTemplates';
|
|
24
|
+
export * from './templateApplicability';
|
|
24
25
|
export * from './buildStarterProfile';
|
|
25
26
|
export * from './incompatibleStarterThemes';
|
|
26
27
|
export * from './ActionDispatcher';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cratis/scene.engine",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.8.0",
|
|
4
4
|
"description": "The Scene runtime: walks a Scene element tree and drives whichever renderer is plugged in. Does not know React, or any other rendering platform, exists.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cratis",
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"up": "yarn g:up"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@cratis/scene.model": "4.
|
|
51
|
+
"@cratis/scene.model": "4.8.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@cratis/scene.model": "4.
|
|
54
|
+
"@cratis/scene.model": "4.8.0"
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { DialogTemplate, Layout, ScreenTemplate, TemplateMetadata, TemplateScope } from '@cratis/scene.model';
|
|
5
|
+
|
|
6
|
+
type TemplateKind = 'Layout' | 'ScreenTemplate' | 'DialogTemplate';
|
|
7
|
+
type TemplateContainer = Pick<Layout, 'name' | 'slots'>;
|
|
8
|
+
|
|
9
|
+
/** Validates application-shell selection without introducing a competing shell model. */
|
|
10
|
+
export function validateLayoutApplicability(layout: Layout | undefined, scope: TemplateScope): string[] {
|
|
11
|
+
return layout ? validateRole(layout.name, 'Layout', layout.metadata, scope) : [];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Validates selection at any depth of the application hierarchy, including qualified fitsSlot names.
|
|
16
|
+
* Undefined represents outlet-only composition and is valid. Invalid author input is never rewritten.
|
|
17
|
+
*/
|
|
18
|
+
export function validateScreenTemplateApplicability(
|
|
19
|
+
template: ScreenTemplate | undefined,
|
|
20
|
+
scope: TemplateScope,
|
|
21
|
+
container?: TemplateContainer,
|
|
22
|
+
): string[] {
|
|
23
|
+
if (!template) return [];
|
|
24
|
+
const problems = validateRole(template.name, 'ScreenTemplate', template.metadata, scope);
|
|
25
|
+
if (template.fitsSlot !== undefined) {
|
|
26
|
+
const separator = template.fitsSlot.lastIndexOf('.');
|
|
27
|
+
const qualifier = separator < 0 ? undefined : template.fitsSlot.slice(0, separator);
|
|
28
|
+
const slot = separator < 0 ? template.fitsSlot : template.fitsSlot.slice(separator + 1);
|
|
29
|
+
if (!container || (qualifier !== undefined && qualifier !== container.name) || !container.slots.some(candidate => candidate.name === slot)) {
|
|
30
|
+
problems.push(`Template '${template.name}' does not fit slot '${template.fitsSlot}' on '${container?.name ?? '(no container)'}'`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return problems;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Validates an overlay template separately from slot-based screen composition. */
|
|
37
|
+
export function validateDialogTemplateApplicability(template: DialogTemplate | undefined, scope: TemplateScope): string[] {
|
|
38
|
+
return template ? validateRole(template.name, 'DialogTemplate', template.metadata, scope) : [];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The shared picker predicate uses exactly the same rules as validation on apply. */
|
|
42
|
+
export function filterApplicableScreenTemplates(
|
|
43
|
+
templates: readonly ScreenTemplate[],
|
|
44
|
+
scope: TemplateScope,
|
|
45
|
+
container?: TemplateContainer,
|
|
46
|
+
): ScreenTemplate[] {
|
|
47
|
+
return templates.filter(template => validateScreenTemplateApplicability(template, scope, container).length === 0);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function validateRole(name: string, kind: TemplateKind, metadata: TemplateMetadata | undefined, scope: TemplateScope): string[] {
|
|
51
|
+
const problems: string[] = [];
|
|
52
|
+
if (!Object.values(TemplateScope).includes(scope)) {
|
|
53
|
+
problems.push(`Template '${name}' has unknown target scope '${scope}'`);
|
|
54
|
+
} else if ((kind === 'Layout') !== (scope === TemplateScope.Application)) {
|
|
55
|
+
problems.push(`Template '${name}' of kind '${kind}' cannot be applied at scope '${scope}'`);
|
|
56
|
+
}
|
|
57
|
+
if (metadata?.type === 'ApplicationShell' && kind !== 'Layout') {
|
|
58
|
+
problems.push(`Template '${name}' of type 'ApplicationShell' must be a Layout`);
|
|
59
|
+
}
|
|
60
|
+
if (metadata?.type === 'Dialog' && kind !== 'DialogTemplate') {
|
|
61
|
+
problems.push(`Template '${name}' of type 'Dialog' must be a DialogTemplate`);
|
|
62
|
+
}
|
|
63
|
+
if (kind === 'Layout' && ['Workspace', 'List', 'Detail', 'Form'].includes(metadata?.type ?? '')) {
|
|
64
|
+
problems.push(`Template '${name}' of type '${metadata?.type}' must not be a Layout`);
|
|
65
|
+
}
|
|
66
|
+
for (const declaredScope of metadata?.scopes ?? []) {
|
|
67
|
+
if (!Object.values(TemplateScope).includes(declaredScope)) {
|
|
68
|
+
problems.push(`Template '${name}' declares unknown scope '${declaredScope}'`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (metadata?.scopes !== undefined && !metadata.scopes.includes(scope)) {
|
|
72
|
+
problems.push(`Template '${name}' does not declare scope '${scope}'`);
|
|
73
|
+
}
|
|
74
|
+
return problems;
|
|
75
|
+
}
|