@cratis/scene.engine 4.7.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/dist/cjs/index.js
CHANGED
|
@@ -20,6 +20,7 @@ var packageVersionRange = require('./packageVersionRange.js');
|
|
|
20
20
|
var resolvePackageDependencies = require('./resolvePackageDependencies.js');
|
|
21
21
|
var packageCatalog = require('./packageCatalog.js');
|
|
22
22
|
var resolveScreenTemplates = require('./resolveScreenTemplates.js');
|
|
23
|
+
var templateApplicability = require('./templateApplicability.js');
|
|
23
24
|
var buildStarterProfile = require('./buildStarterProfile.js');
|
|
24
25
|
var incompatibleStarterThemes = require('./incompatibleStarterThemes.js');
|
|
25
26
|
var runActions = require('./runActions.js');
|
|
@@ -88,6 +89,10 @@ exports.packagesOfKind = packageCatalog.packagesOfKind;
|
|
|
88
89
|
exports.toComponentCatalog = packageCatalog.toComponentCatalog;
|
|
89
90
|
exports.isScreenTemplateResolutionValid = resolveScreenTemplates.isScreenTemplateResolutionValid;
|
|
90
91
|
exports.resolveScreenTemplates = resolveScreenTemplates.resolveScreenTemplates;
|
|
92
|
+
exports.filterApplicableScreenTemplates = templateApplicability.filterApplicableScreenTemplates;
|
|
93
|
+
exports.validateDialogTemplateApplicability = templateApplicability.validateDialogTemplateApplicability;
|
|
94
|
+
exports.validateLayoutApplicability = templateApplicability.validateLayoutApplicability;
|
|
95
|
+
exports.validateScreenTemplateApplicability = templateApplicability.validateScreenTemplateApplicability;
|
|
91
96
|
exports.buildStarterProfile = buildStarterProfile.buildStarterProfile;
|
|
92
97
|
exports.incompatibleStarterThemes = incompatibleStarterThemes.incompatibleStarterThemes;
|
|
93
98
|
exports.InteractionStop = runActions.InteractionStop;
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var scene_model = require('@cratis/scene.model');
|
|
4
|
+
|
|
5
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
6
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
7
|
+
/** Validates application-shell selection without introducing a competing shell model. */ function validateLayoutApplicability(layout, scope) {
|
|
8
|
+
return layout ? validateRole(layout.name, 'Layout', layout.metadata, scope) : [];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Validates selection at any depth of the application hierarchy, including qualified fitsSlot names.
|
|
12
|
+
* Undefined represents outlet-only composition and is valid. Invalid author input is never rewritten.
|
|
13
|
+
*/ function validateScreenTemplateApplicability(template, scope, container) {
|
|
14
|
+
if (!template) return [];
|
|
15
|
+
const problems = validateRole(template.name, 'ScreenTemplate', template.metadata, scope);
|
|
16
|
+
if (template.fitsSlot !== undefined) {
|
|
17
|
+
const separator = template.fitsSlot.lastIndexOf('.');
|
|
18
|
+
const qualifier = separator < 0 ? undefined : template.fitsSlot.slice(0, separator);
|
|
19
|
+
const slot = separator < 0 ? template.fitsSlot : template.fitsSlot.slice(separator + 1);
|
|
20
|
+
if (!container || qualifier !== undefined && qualifier !== container.name || !container.slots.some((candidate)=>candidate.name === slot)) {
|
|
21
|
+
problems.push(`Template '${template.name}' does not fit slot '${template.fitsSlot}' on '${container?.name ?? '(no container)'}'`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return problems;
|
|
25
|
+
}
|
|
26
|
+
/** Validates an overlay template separately from slot-based screen composition. */ function validateDialogTemplateApplicability(template, scope) {
|
|
27
|
+
return template ? validateRole(template.name, 'DialogTemplate', template.metadata, scope) : [];
|
|
28
|
+
}
|
|
29
|
+
/** The shared picker predicate uses exactly the same rules as validation on apply. */ function filterApplicableScreenTemplates(templates, scope, container) {
|
|
30
|
+
return templates.filter((template)=>validateScreenTemplateApplicability(template, scope, container).length === 0);
|
|
31
|
+
}
|
|
32
|
+
function validateRole(name, kind, metadata, scope) {
|
|
33
|
+
const problems = [];
|
|
34
|
+
if (!Object.values(scene_model.TemplateScope).includes(scope)) {
|
|
35
|
+
problems.push(`Template '${name}' has unknown target scope '${scope}'`);
|
|
36
|
+
} else if (kind === 'Layout' !== (scope === scene_model.TemplateScope.Application)) {
|
|
37
|
+
problems.push(`Template '${name}' of kind '${kind}' cannot be applied at scope '${scope}'`);
|
|
38
|
+
}
|
|
39
|
+
if (metadata?.type === 'ApplicationShell' && kind !== 'Layout') {
|
|
40
|
+
problems.push(`Template '${name}' of type 'ApplicationShell' must be a Layout`);
|
|
41
|
+
}
|
|
42
|
+
if (metadata?.type === 'Dialog' && kind !== 'DialogTemplate') {
|
|
43
|
+
problems.push(`Template '${name}' of type 'Dialog' must be a DialogTemplate`);
|
|
44
|
+
}
|
|
45
|
+
if (kind === 'Layout' && [
|
|
46
|
+
'Workspace',
|
|
47
|
+
'List',
|
|
48
|
+
'Detail',
|
|
49
|
+
'Form'
|
|
50
|
+
].includes(metadata?.type ?? '')) {
|
|
51
|
+
problems.push(`Template '${name}' of type '${metadata?.type}' must not be a Layout`);
|
|
52
|
+
}
|
|
53
|
+
for (const declaredScope of metadata?.scopes ?? []){
|
|
54
|
+
if (!Object.values(scene_model.TemplateScope).includes(declaredScope)) {
|
|
55
|
+
problems.push(`Template '${name}' declares unknown scope '${declaredScope}'`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (metadata?.scopes !== undefined && !metadata.scopes.includes(scope)) {
|
|
59
|
+
problems.push(`Template '${name}' does not declare scope '${scope}'`);
|
|
60
|
+
}
|
|
61
|
+
return problems;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
exports.filterApplicableScreenTemplates = filterApplicableScreenTemplates;
|
|
65
|
+
exports.validateDialogTemplateApplicability = validateDialogTemplateApplicability;
|
|
66
|
+
exports.validateLayoutApplicability = validateLayoutApplicability;
|
|
67
|
+
exports.validateScreenTemplateApplicability = validateScreenTemplateApplicability;
|
|
68
|
+
//# sourceMappingURL=templateApplicability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templateApplicability.js","sources":["../../templateApplicability.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DialogTemplate, Layout, ScreenTemplate, TemplateMetadata, TemplateScope } from '@cratis/scene.model';\n\ntype TemplateKind = 'Layout' | 'ScreenTemplate' | 'DialogTemplate';\ntype TemplateContainer = Pick<Layout, 'name' | 'slots'>;\n\n/** Validates application-shell selection without introducing a competing shell model. */\nexport function validateLayoutApplicability(layout: Layout | undefined, scope: TemplateScope): string[] {\n return layout ? validateRole(layout.name, 'Layout', layout.metadata, scope) : [];\n}\n\n/**\n * Validates selection at any depth of the application hierarchy, including qualified fitsSlot names.\n * Undefined represents outlet-only composition and is valid. Invalid author input is never rewritten.\n */\nexport function validateScreenTemplateApplicability(\n template: ScreenTemplate | undefined,\n scope: TemplateScope,\n container?: TemplateContainer,\n): string[] {\n if (!template) return [];\n const problems = validateRole(template.name, 'ScreenTemplate', template.metadata, scope);\n if (template.fitsSlot !== undefined) {\n const separator = template.fitsSlot.lastIndexOf('.');\n const qualifier = separator < 0 ? undefined : template.fitsSlot.slice(0, separator);\n const slot = separator < 0 ? template.fitsSlot : template.fitsSlot.slice(separator + 1);\n if (!container || (qualifier !== undefined && qualifier !== container.name) || !container.slots.some(candidate => candidate.name === slot)) {\n problems.push(`Template '${template.name}' does not fit slot '${template.fitsSlot}' on '${container?.name ?? '(no container)'}'`);\n }\n }\n return problems;\n}\n\n/** Validates an overlay template separately from slot-based screen composition. */\nexport function validateDialogTemplateApplicability(template: DialogTemplate | undefined, scope: TemplateScope): string[] {\n return template ? validateRole(template.name, 'DialogTemplate', template.metadata, scope) : [];\n}\n\n/** The shared picker predicate uses exactly the same rules as validation on apply. */\nexport function filterApplicableScreenTemplates(\n templates: readonly ScreenTemplate[],\n scope: TemplateScope,\n container?: TemplateContainer,\n): ScreenTemplate[] {\n return templates.filter(template => validateScreenTemplateApplicability(template, scope, container).length === 0);\n}\n\nfunction validateRole(name: string, kind: TemplateKind, metadata: TemplateMetadata | undefined, scope: TemplateScope): string[] {\n const problems: string[] = [];\n if (!Object.values(TemplateScope).includes(scope)) {\n problems.push(`Template '${name}' has unknown target scope '${scope}'`);\n } else if ((kind === 'Layout') !== (scope === TemplateScope.Application)) {\n problems.push(`Template '${name}' of kind '${kind}' cannot be applied at scope '${scope}'`);\n }\n if (metadata?.type === 'ApplicationShell' && kind !== 'Layout') {\n problems.push(`Template '${name}' of type 'ApplicationShell' must be a Layout`);\n }\n if (metadata?.type === 'Dialog' && kind !== 'DialogTemplate') {\n problems.push(`Template '${name}' of type 'Dialog' must be a DialogTemplate`);\n }\n if (kind === 'Layout' && ['Workspace', 'List', 'Detail', 'Form'].includes(metadata?.type ?? '')) {\n problems.push(`Template '${name}' of type '${metadata?.type}' must not be a Layout`);\n }\n for (const declaredScope of metadata?.scopes ?? []) {\n if (!Object.values(TemplateScope).includes(declaredScope)) {\n problems.push(`Template '${name}' declares unknown scope '${declaredScope}'`);\n }\n }\n if (metadata?.scopes !== undefined && !metadata.scopes.includes(scope)) {\n problems.push(`Template '${name}' does not declare scope '${scope}'`);\n }\n return problems;\n}\n"],"names":["validateLayoutApplicability","layout","scope","validateRole","name","metadata","validateScreenTemplateApplicability","template","container","problems","fitsSlot","undefined","separator","lastIndexOf","qualifier","slice","slot","slots","some","candidate","push","validateDialogTemplateApplicability","filterApplicableScreenTemplates","templates","filter","length","kind","Object","values","TemplateScope","includes","Application","type","declaredScope","scopes"],"mappings":";;;;AAAA;AACA;AAOA,0FACO,SAASA,2BAAAA,CAA4BC,MAA0B,EAAEC,KAAoB,EAAA;IACxF,OAAOD,MAAAA,GAASE,YAAAA,CAAaF,MAAAA,CAAOG,IAAI,EAAE,UAAUH,MAAAA,CAAOI,QAAQ,EAAEH,KAAAA,CAAAA,GAAS,EAAE;AACpF;AAEA;;;AAGC,IACM,SAASI,mCAAAA,CACZC,QAAoC,EACpCL,KAAoB,EACpBM,SAA6B,EAAA;IAE7B,IAAI,CAACD,QAAAA,EAAU,OAAO,EAAE;IACxB,MAAME,QAAAA,GAAWN,aAAaI,QAAAA,CAASH,IAAI,EAAE,gBAAA,EAAkBG,QAAAA,CAASF,QAAQ,EAAEH,KAAAA,CAAAA;IAClF,IAAIK,QAAAA,CAASG,QAAQ,KAAKC,SAAAA,EAAW;AACjC,QAAA,MAAMC,SAAAA,GAAYL,QAAAA,CAASG,QAAQ,CAACG,WAAW,CAAC,GAAA,CAAA;QAChD,MAAMC,SAAAA,GAAYF,YAAY,CAAA,GAAID,SAAAA,GAAYJ,SAASG,QAAQ,CAACK,KAAK,CAAC,CAAA,EAAGH,SAAAA,CAAAA;QACzE,MAAMI,IAAAA,GAAOJ,SAAAA,GAAY,CAAA,GAAIL,QAAAA,CAASG,QAAQ,GAAGH,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CAASW,IAAI,CAAC,CAAC,UAAU,EAAEhB,KAAK,0BAA0B,EAAE6B,aAAAA,CAAc,CAAC,CAAC,CAAA;AAChF,QAAA;AACJ,IAAA;IACA,IAAI5B,QAAAA,EAAU6B,WAAWvB,SAAAA,IAAa,CAACN,SAAS6B,MAAM,CAACJ,QAAQ,CAAC5B,KAAAA,CAAAA,EAAQ;QACpEO,QAAAA,CAASW,IAAI,CAAC,CAAC,UAAU,EAAEhB,KAAK,0BAA0B,EAAEF,KAAAA,CAAM,CAAC,CAAC,CAAA;AACxE,IAAA;IACA,OAAOO,QAAAA;AACX;;;;;"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export * from './packageVersionRange';
|
|
|
18
18
|
export * from './resolvePackageDependencies';
|
|
19
19
|
export * from './packageCatalog';
|
|
20
20
|
export * from './resolveScreenTemplates';
|
|
21
|
+
export * from './templateApplicability';
|
|
21
22
|
export * from './buildStarterProfile';
|
|
22
23
|
export * from './incompatibleStarterThemes';
|
|
23
24
|
export * from './ActionDispatcher';
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAGA,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC;AACxB,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAGA,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC;AACxB,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -18,6 +18,7 @@ export { isVersionSatisfiedBy } from './packageVersionRange.js';
|
|
|
18
18
|
export { resolvePackageDependencies } from './resolvePackageDependencies.js';
|
|
19
19
|
export { availablePackagesFor, baseComponentLibraries, componentsForPackages, packagesOfKind, toComponentCatalog } from './packageCatalog.js';
|
|
20
20
|
export { isScreenTemplateResolutionValid, resolveScreenTemplates } from './resolveScreenTemplates.js';
|
|
21
|
+
export { filterApplicableScreenTemplates, validateDialogTemplateApplicability, validateLayoutApplicability, validateScreenTemplateApplicability } from './templateApplicability.js';
|
|
21
22
|
export { buildStarterProfile } from './buildStarterProfile.js';
|
|
22
23
|
export { incompatibleStarterThemes } from './incompatibleStarterThemes.js';
|
|
23
24
|
export { InteractionStop, runActions, runBindings } from './runActions.js';
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DialogTemplate, Layout, ScreenTemplate, TemplateScope } from '@cratis/scene.model';
|
|
2
|
+
type TemplateContainer = Pick<Layout, 'name' | 'slots'>;
|
|
3
|
+
export declare function validateLayoutApplicability(layout: Layout | undefined, scope: TemplateScope): string[];
|
|
4
|
+
export declare function validateScreenTemplateApplicability(template: ScreenTemplate | undefined, scope: TemplateScope, container?: TemplateContainer): string[];
|
|
5
|
+
export declare function validateDialogTemplateApplicability(template: DialogTemplate | undefined, scope: TemplateScope): string[];
|
|
6
|
+
export declare function filterApplicableScreenTemplates(templates: readonly ScreenTemplate[], scope: TemplateScope, container?: TemplateContainer): ScreenTemplate[];
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=templateApplicability.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templateApplicability.d.ts","sourceRoot":"","sources":["../../templateApplicability.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,EAAoB,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAG9G,KAAK,iBAAiB,GAAG,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC;AAGxD,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,aAAa,GAAG,MAAM,EAAE,CAEtG;AAMD,wBAAgB,mCAAmC,CAC/C,QAAQ,EAAE,cAAc,GAAG,SAAS,EACpC,KAAK,EAAE,aAAa,EACpB,SAAS,CAAC,EAAE,iBAAiB,GAC9B,MAAM,EAAE,CAYV;AAGD,wBAAgB,mCAAmC,CAAC,QAAQ,EAAE,cAAc,GAAG,SAAS,EAAE,KAAK,EAAE,aAAa,GAAG,MAAM,EAAE,CAExH;AAGD,wBAAgB,+BAA+B,CAC3C,SAAS,EAAE,SAAS,cAAc,EAAE,EACpC,KAAK,EAAE,aAAa,EACpB,SAAS,CAAC,EAAE,iBAAiB,GAC9B,cAAc,EAAE,CAElB"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { TemplateScope } from '@cratis/scene.model';
|
|
2
|
+
|
|
3
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
4
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
5
|
+
/** Validates application-shell selection without introducing a competing shell model. */ function validateLayoutApplicability(layout, scope) {
|
|
6
|
+
return layout ? validateRole(layout.name, 'Layout', layout.metadata, scope) : [];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Validates selection at any depth of the application hierarchy, including qualified fitsSlot names.
|
|
10
|
+
* Undefined represents outlet-only composition and is valid. Invalid author input is never rewritten.
|
|
11
|
+
*/ function validateScreenTemplateApplicability(template, scope, container) {
|
|
12
|
+
if (!template) return [];
|
|
13
|
+
const problems = validateRole(template.name, 'ScreenTemplate', template.metadata, scope);
|
|
14
|
+
if (template.fitsSlot !== undefined) {
|
|
15
|
+
const separator = template.fitsSlot.lastIndexOf('.');
|
|
16
|
+
const qualifier = separator < 0 ? undefined : template.fitsSlot.slice(0, separator);
|
|
17
|
+
const slot = separator < 0 ? template.fitsSlot : template.fitsSlot.slice(separator + 1);
|
|
18
|
+
if (!container || qualifier !== undefined && qualifier !== container.name || !container.slots.some((candidate)=>candidate.name === slot)) {
|
|
19
|
+
problems.push(`Template '${template.name}' does not fit slot '${template.fitsSlot}' on '${container?.name ?? '(no container)'}'`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return problems;
|
|
23
|
+
}
|
|
24
|
+
/** Validates an overlay template separately from slot-based screen composition. */ function validateDialogTemplateApplicability(template, scope) {
|
|
25
|
+
return template ? validateRole(template.name, 'DialogTemplate', template.metadata, scope) : [];
|
|
26
|
+
}
|
|
27
|
+
/** The shared picker predicate uses exactly the same rules as validation on apply. */ function filterApplicableScreenTemplates(templates, scope, container) {
|
|
28
|
+
return templates.filter((template)=>validateScreenTemplateApplicability(template, scope, container).length === 0);
|
|
29
|
+
}
|
|
30
|
+
function validateRole(name, kind, metadata, scope) {
|
|
31
|
+
const problems = [];
|
|
32
|
+
if (!Object.values(TemplateScope).includes(scope)) {
|
|
33
|
+
problems.push(`Template '${name}' has unknown target scope '${scope}'`);
|
|
34
|
+
} else if (kind === 'Layout' !== (scope === TemplateScope.Application)) {
|
|
35
|
+
problems.push(`Template '${name}' of kind '${kind}' cannot be applied at scope '${scope}'`);
|
|
36
|
+
}
|
|
37
|
+
if (metadata?.type === 'ApplicationShell' && kind !== 'Layout') {
|
|
38
|
+
problems.push(`Template '${name}' of type 'ApplicationShell' must be a Layout`);
|
|
39
|
+
}
|
|
40
|
+
if (metadata?.type === 'Dialog' && kind !== 'DialogTemplate') {
|
|
41
|
+
problems.push(`Template '${name}' of type 'Dialog' must be a DialogTemplate`);
|
|
42
|
+
}
|
|
43
|
+
if (kind === 'Layout' && [
|
|
44
|
+
'Workspace',
|
|
45
|
+
'List',
|
|
46
|
+
'Detail',
|
|
47
|
+
'Form'
|
|
48
|
+
].includes(metadata?.type ?? '')) {
|
|
49
|
+
problems.push(`Template '${name}' of type '${metadata?.type}' must not be a Layout`);
|
|
50
|
+
}
|
|
51
|
+
for (const declaredScope of metadata?.scopes ?? []){
|
|
52
|
+
if (!Object.values(TemplateScope).includes(declaredScope)) {
|
|
53
|
+
problems.push(`Template '${name}' declares unknown scope '${declaredScope}'`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (metadata?.scopes !== undefined && !metadata.scopes.includes(scope)) {
|
|
57
|
+
problems.push(`Template '${name}' does not declare scope '${scope}'`);
|
|
58
|
+
}
|
|
59
|
+
return problems;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { filterApplicableScreenTemplates, validateDialogTemplateApplicability, validateLayoutApplicability, validateScreenTemplateApplicability };
|
|
63
|
+
//# sourceMappingURL=templateApplicability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templateApplicability.js","sources":["../../templateApplicability.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DialogTemplate, Layout, ScreenTemplate, TemplateMetadata, TemplateScope } from '@cratis/scene.model';\n\ntype TemplateKind = 'Layout' | 'ScreenTemplate' | 'DialogTemplate';\ntype TemplateContainer = Pick<Layout, 'name' | 'slots'>;\n\n/** Validates application-shell selection without introducing a competing shell model. */\nexport function validateLayoutApplicability(layout: Layout | undefined, scope: TemplateScope): string[] {\n return layout ? validateRole(layout.name, 'Layout', layout.metadata, scope) : [];\n}\n\n/**\n * Validates selection at any depth of the application hierarchy, including qualified fitsSlot names.\n * Undefined represents outlet-only composition and is valid. Invalid author input is never rewritten.\n */\nexport function validateScreenTemplateApplicability(\n template: ScreenTemplate | undefined,\n scope: TemplateScope,\n container?: TemplateContainer,\n): string[] {\n if (!template) return [];\n const problems = validateRole(template.name, 'ScreenTemplate', template.metadata, scope);\n if (template.fitsSlot !== undefined) {\n const separator = template.fitsSlot.lastIndexOf('.');\n const qualifier = separator < 0 ? undefined : template.fitsSlot.slice(0, separator);\n const slot = separator < 0 ? template.fitsSlot : template.fitsSlot.slice(separator + 1);\n if (!container || (qualifier !== undefined && qualifier !== container.name) || !container.slots.some(candidate => candidate.name === slot)) {\n problems.push(`Template '${template.name}' does not fit slot '${template.fitsSlot}' on '${container?.name ?? '(no container)'}'`);\n }\n }\n return problems;\n}\n\n/** Validates an overlay template separately from slot-based screen composition. */\nexport function validateDialogTemplateApplicability(template: DialogTemplate | undefined, scope: TemplateScope): string[] {\n return template ? validateRole(template.name, 'DialogTemplate', template.metadata, scope) : [];\n}\n\n/** The shared picker predicate uses exactly the same rules as validation on apply. */\nexport function filterApplicableScreenTemplates(\n templates: readonly ScreenTemplate[],\n scope: TemplateScope,\n container?: TemplateContainer,\n): ScreenTemplate[] {\n return templates.filter(template => validateScreenTemplateApplicability(template, scope, container).length === 0);\n}\n\nfunction validateRole(name: string, kind: TemplateKind, metadata: TemplateMetadata | undefined, scope: TemplateScope): string[] {\n const problems: string[] = [];\n if (!Object.values(TemplateScope).includes(scope)) {\n problems.push(`Template '${name}' has unknown target scope '${scope}'`);\n } else if ((kind === 'Layout') !== (scope === TemplateScope.Application)) {\n problems.push(`Template '${name}' of kind '${kind}' cannot be applied at scope '${scope}'`);\n }\n if (metadata?.type === 'ApplicationShell' && kind !== 'Layout') {\n problems.push(`Template '${name}' of type 'ApplicationShell' must be a Layout`);\n }\n if (metadata?.type === 'Dialog' && kind !== 'DialogTemplate') {\n problems.push(`Template '${name}' of type 'Dialog' must be a DialogTemplate`);\n }\n if (kind === 'Layout' && ['Workspace', 'List', 'Detail', 'Form'].includes(metadata?.type ?? '')) {\n problems.push(`Template '${name}' of type '${metadata?.type}' must not be a Layout`);\n }\n for (const declaredScope of metadata?.scopes ?? []) {\n if (!Object.values(TemplateScope).includes(declaredScope)) {\n problems.push(`Template '${name}' declares unknown scope '${declaredScope}'`);\n }\n }\n if (metadata?.scopes !== undefined && !metadata.scopes.includes(scope)) {\n problems.push(`Template '${name}' does not declare scope '${scope}'`);\n }\n return problems;\n}\n"],"names":["validateLayoutApplicability","layout","scope","validateRole","name","metadata","validateScreenTemplateApplicability","template","container","problems","fitsSlot","undefined","separator","lastIndexOf","qualifier","slice","slot","slots","some","candidate","push","validateDialogTemplateApplicability","filterApplicableScreenTemplates","templates","filter","length","kind","Object","values","TemplateScope","includes","Application","type","declaredScope","scopes"],"mappings":";;AAAA;AACA;AAOA,0FACO,SAASA,2BAAAA,CAA4BC,MAA0B,EAAEC,KAAoB,EAAA;IACxF,OAAOD,MAAAA,GAASE,YAAAA,CAAaF,MAAAA,CAAOG,IAAI,EAAE,UAAUH,MAAAA,CAAOI,QAAQ,EAAEH,KAAAA,CAAAA,GAAS,EAAE;AACpF;AAEA;;;AAGC,IACM,SAASI,mCAAAA,CACZC,QAAoC,EACpCL,KAAoB,EACpBM,SAA6B,EAAA;IAE7B,IAAI,CAACD,QAAAA,EAAU,OAAO,EAAE;IACxB,MAAME,QAAAA,GAAWN,aAAaI,QAAAA,CAASH,IAAI,EAAE,gBAAA,EAAkBG,QAAAA,CAASF,QAAQ,EAAEH,KAAAA,CAAAA;IAClF,IAAIK,QAAAA,CAASG,QAAQ,KAAKC,SAAAA,EAAW;AACjC,QAAA,MAAMC,SAAAA,GAAYL,QAAAA,CAASG,QAAQ,CAACG,WAAW,CAAC,GAAA,CAAA;QAChD,MAAMC,SAAAA,GAAYF,YAAY,CAAA,GAAID,SAAAA,GAAYJ,SAASG,QAAQ,CAACK,KAAK,CAAC,CAAA,EAAGH,SAAAA,CAAAA;QACzE,MAAMI,IAAAA,GAAOJ,SAAAA,GAAY,CAAA,GAAIL,QAAAA,CAASG,QAAQ,GAAGH,QAAAA,CAASG,QAAQ,CAACK,KAAK,CAACH,SAAAA,GAAY,CAAA,CAAA;AACrF,QAAA,IAAI,CAACJ,SAAAA,IAAcM,SAAAA,KAAcH,aAAaG,SAAAA,KAAcN,SAAAA,CAAUJ,IAAI,IAAK,CAAC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