@cratis/scene.engine 4.2.1 → 4.4.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/editing/DescriptorCatalog.js +42 -0
- package/dist/cjs/editing/DescriptorCatalog.js.map +1 -0
- package/dist/cjs/editing/EditSession.js +44 -0
- package/dist/cjs/editing/EditSession.js.map +1 -0
- package/dist/cjs/editing/applyEdit.js +83 -0
- package/dist/cjs/editing/applyEdit.js.map +1 -0
- package/dist/cjs/editing/applyEffectiveConfiguration.js +62 -0
- package/dist/cjs/editing/applyEffectiveConfiguration.js.map +1 -0
- package/dist/cjs/editing/collectComponents.js +34 -0
- package/dist/cjs/editing/collectComponents.js.map +1 -0
- package/dist/cjs/editing/collectIconUsages.js +86 -0
- package/dist/cjs/editing/collectIconUsages.js.map +1 -0
- package/dist/cjs/editing/describeNode.js +63 -0
- package/dist/cjs/editing/describeNode.js.map +1 -0
- package/dist/cjs/editing/diagnoseIcons.js +67 -0
- package/dist/cjs/editing/diagnoseIcons.js.map +1 -0
- package/dist/cjs/editing/diagnostics.js +36 -0
- package/dist/cjs/editing/diagnostics.js.map +1 -0
- package/dist/cjs/editing/documentPaths.js +45 -0
- package/dist/cjs/editing/documentPaths.js.map +1 -0
- package/dist/cjs/editing/exposureEdits.js +106 -0
- package/dist/cjs/editing/exposureEdits.js.map +1 -0
- package/dist/cjs/editing/exposureGrants.js +115 -0
- package/dist/cjs/editing/exposureGrants.js.map +1 -0
- package/dist/cjs/editing/iconDiagnostics.js +103 -0
- package/dist/cjs/editing/iconDiagnostics.js.map +1 -0
- package/dist/cjs/editing/indexDocument.js +400 -0
- package/dist/cjs/editing/indexDocument.js.map +1 -0
- package/dist/cjs/editing/inspect.js +154 -0
- package/dist/cjs/editing/inspect.js.map +1 -0
- package/dist/cjs/editing/instanceEdits.js +267 -0
- package/dist/cjs/editing/instanceEdits.js.map +1 -0
- package/dist/cjs/editing/layoutTypeDescriptors.js +425 -0
- package/dist/cjs/editing/layoutTypeDescriptors.js.map +1 -0
- package/dist/cjs/editing/layoutTypeEdits.js +141 -0
- package/dist/cjs/editing/layoutTypeEdits.js.map +1 -0
- package/dist/cjs/editing/nodeIds.js +115 -0
- package/dist/cjs/editing/nodeIds.js.map +1 -0
- package/dist/cjs/editing/pathAccess.js +53 -0
- package/dist/cjs/editing/pathAccess.js.map +1 -0
- package/dist/cjs/editing/propertyEdits.js +125 -0
- package/dist/cjs/editing/propertyEdits.js.map +1 -0
- package/dist/cjs/editing/resolveEffectiveConfiguration.js +200 -0
- package/dist/cjs/editing/resolveEffectiveConfiguration.js.map +1 -0
- package/dist/cjs/editing/resolveTemplateChain.js +100 -0
- package/dist/cjs/editing/resolveTemplateChain.js.map +1 -0
- package/dist/cjs/editing/structureEdits.js +231 -0
- package/dist/cjs/editing/structureEdits.js.map +1 -0
- package/dist/cjs/editing/validateBinding.js +111 -0
- package/dist/cjs/editing/validateBinding.js.map +1 -0
- package/dist/cjs/editing/validateValue.js +114 -0
- package/dist/cjs/editing/validateValue.js.map +1 -0
- package/dist/cjs/icons/EffectiveIconCatalog.js +212 -0
- package/dist/cjs/icons/EffectiveIconCatalog.js.map +1 -0
- package/dist/cjs/icons/EffectiveIconEntry.js +22 -0
- package/dist/cjs/icons/EffectiveIconEntry.js.map +1 -0
- package/dist/cjs/icons/analyzeIconImpact.js +48 -0
- package/dist/cjs/icons/analyzeIconImpact.js.map +1 -0
- package/dist/cjs/icons/matchesIconQuery.js +22 -0
- package/dist/cjs/icons/matchesIconQuery.js.map +1 -0
- package/dist/cjs/icons/resolveIconLibraries.js +45 -0
- package/dist/cjs/icons/resolveIconLibraries.js.map +1 -0
- package/dist/cjs/index.js +67 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/editing/DescriptorCatalog.d.ts +9 -0
- package/dist/esm/editing/DescriptorCatalog.d.ts.map +1 -0
- package/dist/esm/editing/DescriptorCatalog.js +38 -0
- package/dist/esm/editing/DescriptorCatalog.js.map +1 -0
- package/dist/esm/editing/DocumentIndex.d.ts +31 -0
- package/dist/esm/editing/DocumentIndex.d.ts.map +1 -0
- package/dist/esm/editing/DocumentIndex.js +2 -0
- package/dist/esm/editing/DocumentIndex.js.map +1 -0
- package/dist/esm/editing/EditOutcome.d.ts +7 -0
- package/dist/esm/editing/EditOutcome.d.ts.map +1 -0
- package/dist/esm/editing/EditOutcome.js +2 -0
- package/dist/esm/editing/EditOutcome.js.map +1 -0
- package/dist/esm/editing/EditSession.d.ts +20 -0
- package/dist/esm/editing/EditSession.d.ts.map +1 -0
- package/dist/esm/editing/EditSession.js +42 -0
- package/dist/esm/editing/EditSession.js.map +1 -0
- package/dist/esm/editing/EditingContext.d.ts +10 -0
- package/dist/esm/editing/EditingContext.d.ts.map +1 -0
- package/dist/esm/editing/EditingContext.js +2 -0
- package/dist/esm/editing/EditingContext.js.map +1 -0
- package/dist/esm/editing/TemplateChain.d.ts +13 -0
- package/dist/esm/editing/TemplateChain.d.ts.map +1 -0
- package/dist/esm/editing/TemplateChain.js +2 -0
- package/dist/esm/editing/TemplateChain.js.map +1 -0
- package/dist/esm/editing/applyEdit.d.ts +5 -0
- package/dist/esm/editing/applyEdit.d.ts.map +1 -0
- package/dist/esm/editing/applyEdit.js +81 -0
- package/dist/esm/editing/applyEdit.js.map +1 -0
- package/dist/esm/editing/applyEffectiveConfiguration.d.ts +3 -0
- package/dist/esm/editing/applyEffectiveConfiguration.d.ts.map +1 -0
- package/dist/esm/editing/applyEffectiveConfiguration.js +60 -0
- package/dist/esm/editing/applyEffectiveConfiguration.js.map +1 -0
- package/dist/esm/editing/collectComponents.d.ts +3 -0
- package/dist/esm/editing/collectComponents.d.ts.map +1 -0
- package/dist/esm/editing/collectComponents.js +32 -0
- package/dist/esm/editing/collectComponents.js.map +1 -0
- package/dist/esm/editing/collectIconUsages.d.ts +5 -0
- package/dist/esm/editing/collectIconUsages.d.ts.map +1 -0
- package/dist/esm/editing/collectIconUsages.js +84 -0
- package/dist/esm/editing/collectIconUsages.js.map +1 -0
- package/dist/esm/editing/describeNode.d.ts +11 -0
- package/dist/esm/editing/describeNode.d.ts.map +1 -0
- package/dist/esm/editing/describeNode.js +60 -0
- package/dist/esm/editing/describeNode.js.map +1 -0
- package/dist/esm/editing/diagnoseIcons.d.ts +4 -0
- package/dist/esm/editing/diagnoseIcons.d.ts.map +1 -0
- package/dist/esm/editing/diagnoseIcons.js +65 -0
- package/dist/esm/editing/diagnoseIcons.js.map +1 -0
- package/dist/esm/editing/diagnostics.d.ts +6 -0
- package/dist/esm/editing/diagnostics.d.ts.map +1 -0
- package/dist/esm/editing/diagnostics.js +32 -0
- package/dist/esm/editing/diagnostics.js.map +1 -0
- package/dist/esm/editing/documentPaths.d.ts +8 -0
- package/dist/esm/editing/documentPaths.d.ts.map +1 -0
- package/dist/esm/editing/documentPaths.js +41 -0
- package/dist/esm/editing/documentPaths.js.map +1 -0
- package/dist/esm/editing/exposureEdits.d.ts +5 -0
- package/dist/esm/editing/exposureEdits.d.ts.map +1 -0
- package/dist/esm/editing/exposureEdits.js +103 -0
- package/dist/esm/editing/exposureEdits.js.map +1 -0
- package/dist/esm/editing/exposureGrants.d.ts +21 -0
- package/dist/esm/editing/exposureGrants.d.ts.map +1 -0
- package/dist/esm/editing/exposureGrants.js +112 -0
- package/dist/esm/editing/exposureGrants.js.map +1 -0
- package/dist/esm/editing/given/a_layout_document.d.ts +14 -0
- package/dist/esm/editing/given/a_layout_document.d.ts.map +1 -0
- package/dist/esm/editing/given/a_layout_document.js +67 -0
- package/dist/esm/editing/given/a_layout_document.js.map +1 -0
- package/dist/esm/editing/given/a_scene_document.d.ts +20 -0
- package/dist/esm/editing/given/a_scene_document.d.ts.map +1 -0
- package/dist/esm/editing/given/a_scene_document.js +110 -0
- package/dist/esm/editing/given/a_scene_document.js.map +1 -0
- package/dist/esm/editing/iconDiagnostics.d.ts +11 -0
- package/dist/esm/editing/iconDiagnostics.d.ts.map +1 -0
- package/dist/esm/editing/iconDiagnostics.js +99 -0
- package/dist/esm/editing/iconDiagnostics.js.map +1 -0
- package/dist/esm/editing/index.d.ts +22 -0
- package/dist/esm/editing/index.d.ts.map +1 -0
- package/dist/esm/editing/index.js +22 -0
- package/dist/esm/editing/index.js.map +1 -0
- package/dist/esm/editing/indexDocument.d.ts +6 -0
- package/dist/esm/editing/indexDocument.d.ts.map +1 -0
- package/dist/esm/editing/indexDocument.js +396 -0
- package/dist/esm/editing/indexDocument.js.map +1 -0
- package/dist/esm/editing/inspect.d.ts +8 -0
- package/dist/esm/editing/inspect.d.ts.map +1 -0
- package/dist/esm/editing/inspect.js +151 -0
- package/dist/esm/editing/inspect.js.map +1 -0
- package/dist/esm/editing/instanceEdits.d.ts +9 -0
- package/dist/esm/editing/instanceEdits.d.ts.map +1 -0
- package/dist/esm/editing/instanceEdits.js +260 -0
- package/dist/esm/editing/instanceEdits.js.map +1 -0
- package/dist/esm/editing/layoutTypeDescriptors.d.ts +5 -0
- package/dist/esm/editing/layoutTypeDescriptors.d.ts.map +1 -0
- package/dist/esm/editing/layoutTypeDescriptors.js +421 -0
- package/dist/esm/editing/layoutTypeDescriptors.js.map +1 -0
- package/dist/esm/editing/layoutTypeEdits.d.ts +4 -0
- package/dist/esm/editing/layoutTypeEdits.d.ts.map +1 -0
- package/dist/esm/editing/layoutTypeEdits.js +139 -0
- package/dist/esm/editing/layoutTypeEdits.js.map +1 -0
- package/dist/esm/editing/nodeIds.d.ts +14 -0
- package/dist/esm/editing/nodeIds.d.ts.map +1 -0
- package/dist/esm/editing/nodeIds.js +102 -0
- package/dist/esm/editing/nodeIds.js.map +1 -0
- package/dist/esm/editing/pathAccess.d.ts +7 -0
- package/dist/esm/editing/pathAccess.d.ts.map +1 -0
- package/dist/esm/editing/pathAccess.js +48 -0
- package/dist/esm/editing/pathAccess.js.map +1 -0
- package/dist/esm/editing/propertyEdits.d.ts +15 -0
- package/dist/esm/editing/propertyEdits.d.ts.map +1 -0
- package/dist/esm/editing/propertyEdits.js +120 -0
- package/dist/esm/editing/propertyEdits.js.map +1 -0
- package/dist/esm/editing/resolveEffectiveConfiguration.d.ts +5 -0
- package/dist/esm/editing/resolveEffectiveConfiguration.d.ts.map +1 -0
- package/dist/esm/editing/resolveEffectiveConfiguration.js +198 -0
- package/dist/esm/editing/resolveEffectiveConfiguration.js.map +1 -0
- package/dist/esm/editing/resolveTemplateChain.d.ts +4 -0
- package/dist/esm/editing/resolveTemplateChain.d.ts.map +1 -0
- package/dist/esm/editing/resolveTemplateChain.js +98 -0
- package/dist/esm/editing/resolveTemplateChain.js.map +1 -0
- package/dist/esm/editing/structureEdits.d.ts +6 -0
- package/dist/esm/editing/structureEdits.d.ts.map +1 -0
- package/dist/esm/editing/structureEdits.js +227 -0
- package/dist/esm/editing/structureEdits.js.map +1 -0
- package/dist/esm/editing/validateBinding.d.ts +7 -0
- package/dist/esm/editing/validateBinding.d.ts.map +1 -0
- package/dist/esm/editing/validateBinding.js +108 -0
- package/dist/esm/editing/validateBinding.js.map +1 -0
- package/dist/esm/editing/validateValue.d.ts +8 -0
- package/dist/esm/editing/validateValue.d.ts.map +1 -0
- package/dist/esm/editing/validateValue.js +111 -0
- package/dist/esm/editing/validateValue.js.map +1 -0
- package/dist/esm/icons/EffectiveIconCatalog.d.ts +25 -0
- package/dist/esm/icons/EffectiveIconCatalog.d.ts.map +1 -0
- package/dist/esm/icons/EffectiveIconCatalog.js +210 -0
- package/dist/esm/icons/EffectiveIconCatalog.js.map +1 -0
- package/dist/esm/icons/EffectiveIconEntry.d.ts +9 -0
- package/dist/esm/icons/EffectiveIconEntry.d.ts.map +1 -0
- package/dist/esm/icons/EffectiveIconEntry.js +20 -0
- package/dist/esm/icons/EffectiveIconEntry.js.map +1 -0
- package/dist/esm/icons/IconCatalogSource.d.ts +6 -0
- package/dist/esm/icons/IconCatalogSource.d.ts.map +1 -0
- package/dist/esm/icons/IconCatalogSource.js +2 -0
- package/dist/esm/icons/IconCatalogSource.js.map +1 -0
- package/dist/esm/icons/IconDiagnostic.d.ts +9 -0
- package/dist/esm/icons/IconDiagnostic.d.ts.map +1 -0
- package/dist/esm/icons/IconDiagnostic.js +2 -0
- package/dist/esm/icons/IconDiagnostic.js.map +1 -0
- package/dist/esm/icons/IconImpactReport.d.ts +18 -0
- package/dist/esm/icons/IconImpactReport.d.ts.map +1 -0
- package/dist/esm/icons/IconImpactReport.js +2 -0
- package/dist/esm/icons/IconImpactReport.js.map +1 -0
- package/dist/esm/icons/IconLibraryResolution.d.ts +7 -0
- package/dist/esm/icons/IconLibraryResolution.d.ts.map +1 -0
- package/dist/esm/icons/IconLibraryResolution.js +2 -0
- package/dist/esm/icons/IconLibraryResolution.js.map +1 -0
- package/dist/esm/icons/IconQuery.d.ts +7 -0
- package/dist/esm/icons/IconQuery.d.ts.map +1 -0
- package/dist/esm/icons/IconQuery.js +2 -0
- package/dist/esm/icons/IconQuery.js.map +1 -0
- package/dist/esm/icons/IconResolution.d.ts +14 -0
- package/dist/esm/icons/IconResolution.d.ts.map +1 -0
- package/dist/esm/icons/IconResolution.js +2 -0
- package/dist/esm/icons/IconResolution.js.map +1 -0
- package/dist/esm/icons/IconSearchResult.d.ts +7 -0
- package/dist/esm/icons/IconSearchResult.d.ts.map +1 -0
- package/dist/esm/icons/IconSearchResult.js +2 -0
- package/dist/esm/icons/IconSearchResult.js.map +1 -0
- package/dist/esm/icons/IconUsage.d.ts +6 -0
- package/dist/esm/icons/IconUsage.d.ts.map +1 -0
- package/dist/esm/icons/IconUsage.js +2 -0
- package/dist/esm/icons/IconUsage.js.map +1 -0
- package/dist/esm/icons/ResolvedIconLibrary.d.ts +8 -0
- package/dist/esm/icons/ResolvedIconLibrary.d.ts.map +1 -0
- package/dist/esm/icons/ResolvedIconLibrary.js +2 -0
- package/dist/esm/icons/ResolvedIconLibrary.js.map +1 -0
- package/dist/esm/icons/analyzeIconImpact.d.ts +5 -0
- package/dist/esm/icons/analyzeIconImpact.d.ts.map +1 -0
- package/dist/esm/icons/analyzeIconImpact.js +46 -0
- package/dist/esm/icons/analyzeIconImpact.js.map +1 -0
- package/dist/esm/icons/index.d.ts +14 -0
- package/dist/esm/icons/index.d.ts.map +1 -0
- package/dist/esm/icons/index.js +14 -0
- package/dist/esm/icons/index.js.map +1 -0
- package/dist/esm/icons/matchesIconQuery.d.ts +4 -0
- package/dist/esm/icons/matchesIconQuery.d.ts.map +1 -0
- package/dist/esm/icons/matchesIconQuery.js +20 -0
- package/dist/esm/icons/matchesIconQuery.js.map +1 -0
- package/dist/esm/icons/resolveIconLibraries.d.ts +4 -0
- package/dist/esm/icons/resolveIconLibraries.d.ts.map +1 -0
- package/dist/esm/icons/resolveIconLibraries.js +43 -0
- package/dist/esm/icons/resolveIconLibraries.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +21 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/editing/DescriptorCatalog.ts +51 -0
- package/editing/DocumentIndex.ts +73 -0
- package/editing/EditOutcome.ts +21 -0
- package/editing/EditSession.ts +50 -0
- package/editing/EditingContext.ts +34 -0
- package/editing/TemplateChain.ts +36 -0
- package/editing/applyEdit.ts +69 -0
- package/editing/applyEffectiveConfiguration.ts +53 -0
- package/editing/collectComponents.ts +36 -0
- package/editing/collectIconUsages.ts +78 -0
- package/editing/describeNode.ts +61 -0
- package/editing/diagnoseIcons.ts +60 -0
- package/editing/diagnostics.ts +30 -0
- package/editing/documentPaths.ts +40 -0
- package/editing/exposureEdits.ts +119 -0
- package/editing/exposureGrants.ts +159 -0
- package/editing/given/a_layout_document.ts +88 -0
- package/editing/given/a_scene_document.ts +135 -0
- package/editing/iconDiagnostics.ts +90 -0
- package/editing/index.ts +24 -0
- package/editing/indexDocument.ts +237 -0
- package/editing/inspect.ts +165 -0
- package/editing/instanceEdits.ts +251 -0
- package/editing/layoutTypeDescriptors.ts +191 -0
- package/editing/layoutTypeEdits.ts +135 -0
- package/editing/nodeIds.ts +111 -0
- package/editing/pathAccess.ts +81 -0
- package/editing/propertyEdits.ts +127 -0
- package/editing/resolveEffectiveConfiguration.ts +202 -0
- package/editing/resolveTemplateChain.ts +109 -0
- package/editing/structureEdits.ts +234 -0
- package/editing/validateBinding.ts +103 -0
- package/editing/validateValue.ts +130 -0
- package/icons/EffectiveIconCatalog.ts +199 -0
- package/icons/EffectiveIconEntry.ts +36 -0
- package/icons/IconCatalogSource.ts +23 -0
- package/icons/IconDiagnostic.ts +45 -0
- package/icons/IconImpactReport.ts +63 -0
- package/icons/IconLibraryResolution.ts +22 -0
- package/icons/IconQuery.ts +27 -0
- package/icons/IconResolution.ts +25 -0
- package/icons/IconSearchResult.ts +21 -0
- package/icons/IconUsage.ts +21 -0
- package/icons/ResolvedIconLibrary.ts +32 -0
- package/icons/analyzeIconImpact.ts +41 -0
- package/icons/index.ts +16 -0
- package/icons/matchesIconQuery.ts +19 -0
- package/icons/resolveIconLibraries.ts +47 -0
- package/index.ts +2 -0
- package/package.json +3 -3
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var layoutTypeDescriptors = require('./layoutTypeDescriptors.js');
|
|
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
|
+
/**
|
|
8
|
+
* Builds a catalog from the component descriptors of the active packages, plus the built-in layout types.
|
|
9
|
+
*
|
|
10
|
+
* When two descriptors name the same component the later one wins, which is the same override-priority rule
|
|
11
|
+
* the profile's package order already means for components.
|
|
12
|
+
*/ function createDescriptorCatalog(componentDescriptors = []) {
|
|
13
|
+
const byComponent = new Map();
|
|
14
|
+
for (const descriptor of componentDescriptors)byComponent.set(descriptor.component, descriptor);
|
|
15
|
+
return {
|
|
16
|
+
components: [
|
|
17
|
+
...byComponent.values()
|
|
18
|
+
],
|
|
19
|
+
layoutTypes: layoutTypeDescriptors.layoutTypeDescriptors
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Finds the descriptor of a component by the name an element carries.
|
|
24
|
+
*
|
|
25
|
+
* An exact match wins. Otherwise a bare name (`dataTable`) finds the one descriptor whose component ends in
|
|
26
|
+
* `:dataTable`; a bare name that several packages describe has no single answer, so it finds none.
|
|
27
|
+
*/ function findComponentDescriptor(catalog, componentName) {
|
|
28
|
+
const exact = catalog.components.find((descriptor)=>descriptor.component === componentName);
|
|
29
|
+
if (exact) return exact;
|
|
30
|
+
const matches = catalog.components.filter((descriptor)=>descriptor.component.endsWith(`:${componentName}`));
|
|
31
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Finds the descriptor of a layout type.
|
|
35
|
+
*/ function findLayoutTypeDescriptor(catalog, type) {
|
|
36
|
+
return catalog.layoutTypes.find((descriptor)=>descriptor.type === type);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
exports.createDescriptorCatalog = createDescriptorCatalog;
|
|
40
|
+
exports.findComponentDescriptor = findComponentDescriptor;
|
|
41
|
+
exports.findLayoutTypeDescriptor = findLayoutTypeDescriptor;
|
|
42
|
+
//# sourceMappingURL=DescriptorCatalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DescriptorCatalog.js","sources":["../../../editing/DescriptorCatalog.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 { ComponentDescriptor, LayoutTypeDescriptor } from '@cratis/scene.model';\nimport { layoutTypeDescriptors } from './layoutTypeDescriptors';\n\n/**\n * Everything an editor knows how to describe: the component descriptors packages contribute, and the layout types\n * the model itself defines.\n *\n * It is a derived view over what packages ship - not a registry anything registers into. Build one from the\n * descriptors of the packages a profile lists, and rebuild it when the list changes.\n */\nexport interface DescriptorCatalog {\n components: ComponentDescriptor[];\n layoutTypes: LayoutTypeDescriptor[];\n}\n\n/**\n * Builds a catalog from the component descriptors of the active packages, plus the built-in layout types.\n *\n * When two descriptors name the same component the later one wins, which is the same override-priority rule\n * the profile's package order already means for components.\n */\nexport function createDescriptorCatalog(componentDescriptors: ComponentDescriptor[] = []): DescriptorCatalog {\n const byComponent = new Map<string, ComponentDescriptor>();\n for (const descriptor of componentDescriptors) byComponent.set(descriptor.component, descriptor);\n\n return { components: [...byComponent.values()], layoutTypes: layoutTypeDescriptors };\n}\n\n/**\n * Finds the descriptor of a component by the name an element carries.\n *\n * An exact match wins. Otherwise a bare name (`dataTable`) finds the one descriptor whose component ends in\n * `:dataTable`; a bare name that several packages describe has no single answer, so it finds none.\n */\nexport function findComponentDescriptor(catalog: DescriptorCatalog, componentName: string): ComponentDescriptor | undefined {\n const exact = catalog.components.find(descriptor => descriptor.component === componentName);\n if (exact) return exact;\n\n const matches = catalog.components.filter(descriptor => descriptor.component.endsWith(`:${componentName}`));\n return matches.length === 1 ? matches[0] : undefined;\n}\n\n/**\n * Finds the descriptor of a layout type.\n */\nexport function findLayoutTypeDescriptor(catalog: DescriptorCatalog, type: string): LayoutTypeDescriptor | undefined {\n return catalog.layoutTypes.find(descriptor => descriptor.type === type);\n}\n"],"names":["createDescriptorCatalog","componentDescriptors","byComponent","Map","descriptor","set","component","components","values","layoutTypes","layoutTypeDescriptors","findComponentDescriptor","catalog","componentName","exact","find","matches","filter","endsWith","length","undefined","findLayoutTypeDescriptor","type"],"mappings":";;;;AAAA;AACA;AAiBA;;;;;AAKC,IACM,SAASA,uBAAAA,CAAwBC,oBAAAA,GAA8C,EAAE,EAAA;AACpF,IAAA,MAAMC,cAAc,IAAIC,GAAAA,EAAAA;IACxB,KAAK,MAAMC,cAAcH,oBAAAA,CAAsBC,WAAAA,CAAYG,GAAG,CAACD,UAAAA,CAAWE,SAAS,EAAEF,UAAAA,CAAAA;IAErF,OAAO;QAAEG,UAAAA,EAAY;AAAIL,YAAAA,GAAAA,WAAAA,CAAYM,MAAM;AAAG,SAAA;QAAEC,WAAAA,EAAaC;AAAsB,KAAA;AACvF;AAEA;;;;;AAKC,IACM,SAASC,uBAAAA,CAAwBC,OAA0B,EAAEC,aAAqB,EAAA;IACrF,MAAMC,KAAAA,GAAQF,OAAAA,CAAQL,UAAU,CAACQ,IAAI,CAACX,CAAAA,UAAAA,GAAcA,UAAAA,CAAWE,SAAS,KAAKO,aAAAA,CAAAA;AAC7E,IAAA,IAAIC,OAAO,OAAOA,KAAAA;AAElB,IAAA,MAAME,UAAUJ,OAAAA,CAAQL,UAAU,CAACU,MAAM,CAACb,CAAAA,UAAAA,GAAcA,UAAAA,CAAWE,SAAS,CAACY,QAAQ,CAAC,CAAC,CAAC,EAAEL,aAAAA,CAAAA,CAAe,CAAA,CAAA;AACzG,IAAA,OAAOG,QAAQG,MAAM,KAAK,IAAIH,OAAO,CAAC,EAAE,GAAGI,SAAAA;AAC/C;AAEA;;AAEC,IACM,SAASC,wBAAAA,CAAyBT,OAA0B,EAAEU,IAAY,EAAA;IAC7E,OAAOV,OAAAA,CAAQH,WAAW,CAACM,IAAI,CAACX,CAAAA,UAAAA,GAAcA,UAAAA,CAAWkB,IAAI,KAAKA,IAAAA,CAAAA;AACtE;;;;"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var scene_model = require('@cratis/scene.model');
|
|
4
|
+
var exposureGrants = require('./exposureGrants.js');
|
|
5
|
+
var indexDocument = require('./indexDocument.js');
|
|
6
|
+
var inspect = require('./inspect.js');
|
|
7
|
+
var resolveEffectiveConfiguration = require('./resolveEffectiveConfiguration.js');
|
|
8
|
+
var resolveTemplateChain = require('./resolveTemplateChain.js');
|
|
9
|
+
|
|
10
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
11
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
12
|
+
/**
|
|
13
|
+
* Everything an edit needs to decide whether it is allowed, worked out once against the document as it was.
|
|
14
|
+
*/ class EditSession {
|
|
15
|
+
document;
|
|
16
|
+
context;
|
|
17
|
+
index;
|
|
18
|
+
chain;
|
|
19
|
+
grants;
|
|
20
|
+
configuration;
|
|
21
|
+
constructor(document, context){
|
|
22
|
+
this.document = document;
|
|
23
|
+
this.context = context;
|
|
24
|
+
this.index = indexDocument.indexDocument(document);
|
|
25
|
+
this.chain = resolveTemplateChain.resolveTemplateChain(document, context.scope);
|
|
26
|
+
this.grants = exposureGrants.computeExposureGrants(this.chain, context.catalog);
|
|
27
|
+
this.configuration = resolveEffectiveConfiguration.resolveEffectiveConfiguration(this.chain, document.instanceContributions, context.catalog);
|
|
28
|
+
}
|
|
29
|
+
/** The instance id the scope contributes as, or `undefined` when the scope was not found. */ get scopeInstance() {
|
|
30
|
+
return this.chain.levels.at(-1)?.instance;
|
|
31
|
+
}
|
|
32
|
+
/** What the scope's instance may configure on inherited components. */ get scopeGrants() {
|
|
33
|
+
return (this.scopeInstance === undefined ? undefined : this.grants.byInstance.get(this.scopeInstance)) ?? new Map();
|
|
34
|
+
}
|
|
35
|
+
/** Whether the scope itself owns the node. */ isLocal(record) {
|
|
36
|
+
return inspect.provenanceOf(record, this.chain, this.scopeGrants).kind === scene_model.ProvenanceKind.Local;
|
|
37
|
+
}
|
|
38
|
+
/** Where an inherited node comes from, for a message. */ sourceOf(record) {
|
|
39
|
+
return record.owner;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.EditSession = EditSession;
|
|
44
|
+
//# sourceMappingURL=EditSession.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EditSession.js","sources":["../../../editing/EditSession.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 { ProvenanceKind, SceneDocument } from '@cratis/scene.model';\nimport { EditingContext } from './EditingContext';\nimport { DocumentIndex, NodeRecord } from './DocumentIndex';\nimport { ExposureGrant, ExposureGrants, computeExposureGrants } from './exposureGrants';\nimport { indexDocument } from './indexDocument';\nimport { provenanceOf } from './inspect';\nimport { resolveEffectiveConfiguration } from './resolveEffectiveConfiguration';\nimport { resolveTemplateChain } from './resolveTemplateChain';\nimport { TemplateChain } from './TemplateChain';\nimport { EffectiveConfiguration } from '@cratis/scene.model';\n\n/**\n * Everything an edit needs to decide whether it is allowed, worked out once against the document as it was.\n */\nexport class EditSession {\n readonly index: DocumentIndex;\n readonly chain: TemplateChain;\n readonly grants: ExposureGrants;\n readonly configuration: EffectiveConfiguration;\n\n constructor(readonly document: SceneDocument, readonly context: EditingContext) {\n this.index = indexDocument(document);\n this.chain = resolveTemplateChain(document, context.scope);\n this.grants = computeExposureGrants(this.chain, context.catalog);\n this.configuration = resolveEffectiveConfiguration(this.chain, document.instanceContributions, context.catalog);\n }\n\n /** The instance id the scope contributes as, or `undefined` when the scope was not found. */\n get scopeInstance(): string | undefined {\n return this.chain.levels.at(-1)?.instance;\n }\n\n /** What the scope's instance may configure on inherited components. */\n get scopeGrants(): Map<string, ExposureGrant> {\n return (this.scopeInstance === undefined ? undefined : this.grants.byInstance.get(this.scopeInstance)) ?? new Map();\n }\n\n /** Whether the scope itself owns the node. */\n isLocal(record: NodeRecord): boolean {\n return provenanceOf(record, this.chain, this.scopeGrants).kind === ProvenanceKind.Local;\n }\n\n /** Where an inherited node comes from, for a message. */\n sourceOf(record: NodeRecord): string {\n return record.owner;\n }\n}\n"],"names":["EditSession","index","chain","grants","configuration","context","document","indexDocument","resolveTemplateChain","scope","computeExposureGrants","catalog","resolveEffectiveConfiguration","instanceContributions","scopeInstance","levels","at","instance","scopeGrants","undefined","byInstance","get","Map","isLocal","record","provenanceOf","kind","ProvenanceKind","Local","sourceOf","owner"],"mappings":";;;;;;;;;AAAA;AACA;AAaA;;AAEC,IACM,MAAMA,WAAAA,CAAAA;;;IACAC,KAAAA;IACAC,KAAAA;IACAC,MAAAA;IACAC,aAAAA;AAET,IAAA,WAAA,CAAY,QAAgC,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+
var EditSession = require('./EditSession.js');
|
|
6
|
+
var exposureEdits = require('./exposureEdits.js');
|
|
7
|
+
var instanceEdits = require('./instanceEdits.js');
|
|
8
|
+
var layoutTypeEdits = require('./layoutTypeEdits.js');
|
|
9
|
+
var pathAccess = require('./pathAccess.js');
|
|
10
|
+
var propertyEdits = require('./propertyEdits.js');
|
|
11
|
+
var structureEdits = require('./structureEdits.js');
|
|
12
|
+
|
|
13
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
14
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
15
|
+
function run(session, edit, clone, diagnostics$1) {
|
|
16
|
+
const handle = (handler)=>handler(session, edit, clone, diagnostics$1);
|
|
17
|
+
switch(edit.kind){
|
|
18
|
+
case scene_model.SceneEditKind.SetProperty:
|
|
19
|
+
return handle(propertyEdits.applySetProperty);
|
|
20
|
+
case scene_model.SceneEditKind.ResetProperty:
|
|
21
|
+
return handle(propertyEdits.applyResetProperty);
|
|
22
|
+
case scene_model.SceneEditKind.ChangeLayoutType:
|
|
23
|
+
return handle(layoutTypeEdits.applyChangeLayoutType);
|
|
24
|
+
case scene_model.SceneEditKind.InsertNode:
|
|
25
|
+
return handle(structureEdits.applyInsertNode);
|
|
26
|
+
case scene_model.SceneEditKind.MoveNode:
|
|
27
|
+
return handle(structureEdits.applyMoveNode);
|
|
28
|
+
case scene_model.SceneEditKind.RemoveNode:
|
|
29
|
+
return handle(structureEdits.applyRemoveNode);
|
|
30
|
+
case scene_model.SceneEditKind.SetInstanceValue:
|
|
31
|
+
return handle(instanceEdits.applySetInstanceValue);
|
|
32
|
+
case scene_model.SceneEditKind.ResetInstanceValue:
|
|
33
|
+
return handle(instanceEdits.applyResetInstanceValue);
|
|
34
|
+
case scene_model.SceneEditKind.AddCollectionItem:
|
|
35
|
+
return handle(instanceEdits.applyAddCollectionItem);
|
|
36
|
+
case scene_model.SceneEditKind.RemoveCollectionItem:
|
|
37
|
+
return handle(instanceEdits.applyRemoveCollectionItem);
|
|
38
|
+
case scene_model.SceneEditKind.ReorderCollectionItem:
|
|
39
|
+
return handle(instanceEdits.applyReorderCollectionItem);
|
|
40
|
+
case scene_model.SceneEditKind.EditCollectionItem:
|
|
41
|
+
return handle(instanceEdits.applyEditCollectionItem);
|
|
42
|
+
case scene_model.SceneEditKind.ExposeProperty:
|
|
43
|
+
return handle(exposureEdits.applyExposeProperty);
|
|
44
|
+
case scene_model.SceneEditKind.UnexposeProperty:
|
|
45
|
+
return handle(exposureEdits.applyUnexposeProperty);
|
|
46
|
+
default:
|
|
47
|
+
diagnostics$1.push(diagnostics.errorDiagnostic(scene_model.DiagnosticCode.InvalidEdit, `'${edit.kind}' is not an edit this engine knows.`));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Applies one edit to a document.
|
|
52
|
+
*
|
|
53
|
+
* Pure and immutable: the document passed in is never changed, and the result is a new document. Edits are plain
|
|
54
|
+
* data, so a host can persist them and build undo and redo by keeping the documents either side. On any error the
|
|
55
|
+
* prior document comes back - the same object - together with the diagnostics, so a refused edit leaves nothing
|
|
56
|
+
* half done.
|
|
57
|
+
*
|
|
58
|
+
* What an edit may touch follows the editing scope. Nodes the scope owns are edited directly; inherited nodes are
|
|
59
|
+
* read-only, and their exposed properties are configured with the instance edits, which are checked against what
|
|
60
|
+
* each owner exposed.
|
|
61
|
+
*
|
|
62
|
+
* @param model The document to edit.
|
|
63
|
+
* @param edit What to do.
|
|
64
|
+
* @param context The catalog and the editing scope.
|
|
65
|
+
*/ function applyEdit(model, edit, context) {
|
|
66
|
+
const session = new EditSession.EditSession(model, context);
|
|
67
|
+
const clone = pathAccess.cloneData(model);
|
|
68
|
+
const diagnostics$1 = [];
|
|
69
|
+
run(session, edit, clone, diagnostics$1);
|
|
70
|
+
if (diagnostics.hasErrors(diagnostics$1)) return {
|
|
71
|
+
model,
|
|
72
|
+
diagnostics: diagnostics$1,
|
|
73
|
+
applied: false
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
model: clone,
|
|
77
|
+
diagnostics: diagnostics$1,
|
|
78
|
+
applied: true
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
exports.applyEdit = applyEdit;
|
|
83
|
+
//# sourceMappingURL=applyEdit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyEdit.js","sources":["../../../editing/applyEdit.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 { DiagnosticCode, SceneDiagnostic, SceneDocument, SceneEdit, SceneEditKind } from '@cratis/scene.model';\nimport { errorDiagnostic, hasErrors } from './diagnostics';\nimport { EditOutcome } from './EditOutcome';\nimport { EditingContext } from './EditingContext';\nimport { EditSession } from './EditSession';\nimport { applyExposeProperty, applyUnexposeProperty } from './exposureEdits';\nimport {\n applyAddCollectionItem, applyEditCollectionItem, applyRemoveCollectionItem, applyReorderCollectionItem,\n applyResetInstanceValue, applySetInstanceValue,\n} from './instanceEdits';\nimport { applyChangeLayoutType } from './layoutTypeEdits';\nimport { cloneData } from './pathAccess';\nimport { applyResetProperty, applySetProperty } from './propertyEdits';\nimport { applyInsertNode, applyMoveNode, applyRemoveNode } from './structureEdits';\n\ntype Handler<TEdit extends SceneEdit> = (session: EditSession, edit: TEdit, clone: SceneDocument, diagnostics: SceneDiagnostic[]) => void;\n\nfunction run(session: EditSession, edit: SceneEdit, clone: SceneDocument, diagnostics: SceneDiagnostic[]): void {\n const handle = <TEdit extends SceneEdit>(handler: Handler<TEdit>) => handler(session, edit as TEdit, clone, diagnostics);\n\n switch (edit.kind) {\n case SceneEditKind.SetProperty: return handle(applySetProperty);\n case SceneEditKind.ResetProperty: return handle(applyResetProperty);\n case SceneEditKind.ChangeLayoutType: return handle(applyChangeLayoutType);\n case SceneEditKind.InsertNode: return handle(applyInsertNode);\n case SceneEditKind.MoveNode: return handle(applyMoveNode);\n case SceneEditKind.RemoveNode: return handle(applyRemoveNode);\n case SceneEditKind.SetInstanceValue: return handle(applySetInstanceValue);\n case SceneEditKind.ResetInstanceValue: return handle(applyResetInstanceValue);\n case SceneEditKind.AddCollectionItem: return handle(applyAddCollectionItem);\n case SceneEditKind.RemoveCollectionItem: return handle(applyRemoveCollectionItem);\n case SceneEditKind.ReorderCollectionItem: return handle(applyReorderCollectionItem);\n case SceneEditKind.EditCollectionItem: return handle(applyEditCollectionItem);\n case SceneEditKind.ExposeProperty: return handle(applyExposeProperty);\n case SceneEditKind.UnexposeProperty: return handle(applyUnexposeProperty);\n default:\n diagnostics.push(errorDiagnostic(DiagnosticCode.InvalidEdit, `'${(edit as { kind?: string }).kind}' is not an edit this engine knows.`));\n }\n}\n\n/**\n * Applies one edit to a document.\n *\n * Pure and immutable: the document passed in is never changed, and the result is a new document. Edits are plain\n * data, so a host can persist them and build undo and redo by keeping the documents either side. On any error the\n * prior document comes back - the same object - together with the diagnostics, so a refused edit leaves nothing\n * half done.\n *\n * What an edit may touch follows the editing scope. Nodes the scope owns are edited directly; inherited nodes are\n * read-only, and their exposed properties are configured with the instance edits, which are checked against what\n * each owner exposed.\n *\n * @param model The document to edit.\n * @param edit What to do.\n * @param context The catalog and the editing scope.\n */\nexport function applyEdit(model: SceneDocument, edit: SceneEdit, context: EditingContext): EditOutcome {\n const session = new EditSession(model, context);\n const clone = cloneData(model);\n const diagnostics: SceneDiagnostic[] = [];\n\n run(session, edit, clone, diagnostics);\n\n if (hasErrors(diagnostics)) return { model, diagnostics, applied: false };\n return { model: clone, diagnostics, applied: true };\n}\n"],"names":["run","session","edit","clone","diagnostics","handle","handler","kind","SceneEditKind","SetProperty","applySetProperty","ResetProperty","applyResetProperty","ChangeLayoutType","applyChangeLayoutType","InsertNode","applyInsertNode","MoveNode","applyMoveNode","RemoveNode","applyRemoveNode","SetInstanceValue","applySetInstanceValue","ResetInstanceValue","applyResetInstanceValue","AddCollectionItem","applyAddCollectionItem","RemoveCollectionItem","applyRemoveCollectionItem","ReorderCollectionItem","applyReorderCollectionItem","EditCollectionItem","applyEditCollectionItem","ExposeProperty","applyExposeProperty","UnexposeProperty","applyUnexposeProperty","push","errorDiagnostic","DiagnosticCode","InvalidEdit","applyEdit","model","context","EditSession","cloneData","hasErrors","applied"],"mappings":";;;;;;;;;;;;AAAA;AACA;AAmBA,SAASA,IAAIC,OAAoB,EAAEC,IAAe,EAAEC,KAAoB,EAAEC,aAA8B,EAAA;AACpG,IAAA,MAAMC,SAAS,CAA0BC,OAAAA,GAA4BA,OAAAA,CAAQL,OAAAA,EAASC,MAAeC,KAAAA,EAAOC,aAAAA,CAAAA;AAE5G,IAAA,OAAQF,KAAKK,IAAI;AACb,QAAA,KAAKC,0BAAcC,WAAW;AAAE,YAAA,OAAOJ,MAAAA,CAAOK,8BAAAA,CAAAA;AAC9C,QAAA,KAAKF,0BAAcG,aAAa;AAAE,YAAA,OAAON,MAAAA,CAAOO,gCAAAA,CAAAA;AAChD,QAAA,KAAKJ,0BAAcK,gBAAgB;AAAE,YAAA,OAAOR,MAAAA,CAAOS,qCAAAA,CAAAA;AACnD,QAAA,KAAKN,0BAAcO,UAAU;AAAE,YAAA,OAAOV,MAAAA,CAAOW,8BAAAA,CAAAA;AAC7C,QAAA,KAAKR,0BAAcS,QAAQ;AAAE,YAAA,OAAOZ,MAAAA,CAAOa,4BAAAA,CAAAA;AAC3C,QAAA,KAAKV,0BAAcW,UAAU;AAAE,YAAA,OAAOd,MAAAA,CAAOe,8BAAAA,CAAAA;AAC7C,QAAA,KAAKZ,0BAAca,gBAAgB;AAAE,YAAA,OAAOhB,MAAAA,CAAOiB,mCAAAA,CAAAA;AACnD,QAAA,KAAKd,0BAAce,kBAAkB;AAAE,YAAA,OAAOlB,MAAAA,CAAOmB,qCAAAA,CAAAA;AACrD,QAAA,KAAKhB,0BAAciB,iBAAiB;AAAE,YAAA,OAAOpB,MAAAA,CAAOqB,oCAAAA,CAAAA;AACpD,QAAA,KAAKlB,0BAAcmB,oBA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2
|
+
|
|
3
|
+
var elementKind = require('../elementKind.js');
|
|
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
|
+
/**
|
|
8
|
+
* Returns the element tree a renderer should draw once effective configuration is applied: each configurable
|
|
9
|
+
* component carries its resolved properties.
|
|
10
|
+
*
|
|
11
|
+
* Pure, and structure-sharing - an element with nothing to change comes back as the same object, so a renderer
|
|
12
|
+
* that memoizes on identity does not redraw what did not change. There is no design-time flag here or anywhere
|
|
13
|
+
* downstream: a screen being edited and a screen being played go through this same function.
|
|
14
|
+
*
|
|
15
|
+
* @param element The element tree from the template or screen.
|
|
16
|
+
* @param configuration What {@link resolveEffectiveConfiguration} produced for the chain the tree sits in.
|
|
17
|
+
*/ function applyEffectiveConfiguration(element, configuration) {
|
|
18
|
+
if (elementKind.isExternalComponent(element)) {
|
|
19
|
+
const resolved = configuration.components.find((candidate)=>candidate.component === element.id);
|
|
20
|
+
let changed = resolved !== undefined;
|
|
21
|
+
const slots = {};
|
|
22
|
+
for (const [name, children] of Object.entries(element.slots)){
|
|
23
|
+
const mapped = children.map((child)=>applyEffectiveConfiguration(child, configuration));
|
|
24
|
+
if (mapped.some((child, index)=>child !== children[index])) changed = true;
|
|
25
|
+
slots[name] = mapped;
|
|
26
|
+
}
|
|
27
|
+
const updated = {
|
|
28
|
+
...element,
|
|
29
|
+
properties: resolved?.properties ?? element.properties,
|
|
30
|
+
slots
|
|
31
|
+
};
|
|
32
|
+
return changed ? updated : element;
|
|
33
|
+
}
|
|
34
|
+
if (elementKind.isContentControl(element)) {
|
|
35
|
+
const content = applyEffectiveConfiguration(element.content, configuration);
|
|
36
|
+
const updated = {
|
|
37
|
+
...element,
|
|
38
|
+
content
|
|
39
|
+
};
|
|
40
|
+
return content === element.content ? element : updated;
|
|
41
|
+
}
|
|
42
|
+
if (elementKind.isItemsControl(element)) {
|
|
43
|
+
const itemTemplate = applyEffectiveConfiguration(element.itemTemplate, configuration);
|
|
44
|
+
const updated = {
|
|
45
|
+
...element,
|
|
46
|
+
itemTemplate
|
|
47
|
+
};
|
|
48
|
+
return itemTemplate === element.itemTemplate ? element : updated;
|
|
49
|
+
}
|
|
50
|
+
if (elementKind.isPanel(element)) {
|
|
51
|
+
const children = element.children.map((child)=>applyEffectiveConfiguration(child, configuration));
|
|
52
|
+
const updated = {
|
|
53
|
+
...element,
|
|
54
|
+
children
|
|
55
|
+
};
|
|
56
|
+
return children.some((child, index)=>child !== element.children[index]) ? updated : element;
|
|
57
|
+
}
|
|
58
|
+
return element;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
exports.applyEffectiveConfiguration = applyEffectiveConfiguration;
|
|
62
|
+
//# sourceMappingURL=applyEffectiveConfiguration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyEffectiveConfiguration.js","sources":["../../../editing/applyEffectiveConfiguration.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 { ContentControl, EffectiveConfiguration, ExternalComponent, ItemsControl, Panel, SceneElement } from '@cratis/scene.model';\nimport { isContentControl, isExternalComponent, isItemsControl, isPanel } from '../elementKind';\n\n/**\n * Returns the element tree a renderer should draw once effective configuration is applied: each configurable\n * component carries its resolved properties.\n *\n * Pure, and structure-sharing - an element with nothing to change comes back as the same object, so a renderer\n * that memoizes on identity does not redraw what did not change. There is no design-time flag here or anywhere\n * downstream: a screen being edited and a screen being played go through this same function.\n *\n * @param element The element tree from the template or screen.\n * @param configuration What {@link resolveEffectiveConfiguration} produced for the chain the tree sits in.\n */\nexport function applyEffectiveConfiguration(element: SceneElement, configuration: EffectiveConfiguration): SceneElement {\n if (isExternalComponent(element)) {\n const resolved = configuration.components.find(candidate => candidate.component === element.id);\n let changed = resolved !== undefined;\n\n const slots: typeof element.slots = {};\n for (const [name, children] of Object.entries(element.slots)) {\n const mapped = children.map(child => applyEffectiveConfiguration(child, configuration));\n if (mapped.some((child, index) => child !== children[index])) changed = true;\n slots[name] = mapped;\n }\n\n const updated: ExternalComponent = { ...element, properties: resolved?.properties ?? element.properties, slots };\n return changed ? updated : element;\n }\n\n if (isContentControl(element)) {\n const content = applyEffectiveConfiguration(element.content, configuration);\n const updated: ContentControl = { ...element, content };\n return content === element.content ? element : updated;\n }\n\n if (isItemsControl(element)) {\n const itemTemplate = applyEffectiveConfiguration(element.itemTemplate, configuration);\n const updated: ItemsControl = { ...element, itemTemplate };\n return itemTemplate === element.itemTemplate ? element : updated;\n }\n\n if (isPanel(element)) {\n const children = element.children.map(child => applyEffectiveConfiguration(child, configuration));\n const updated: Panel = { ...element, children };\n return children.some((child, index) => child !== element.children[index]) ? updated : element;\n }\n\n return element;\n}\n"],"names":["applyEffectiveConfiguration","element","configuration","isExternalComponent","resolved","components","find","candidate","component","id","changed","undefined","slots","name","children","Object","entries","mapped","map","child","some","index","updated","properties","isContentControl","content","isItemsControl","itemTemplate","isPanel"],"mappings":";;;;AAAA;AACA;AAKA;;;;;;;;;;AAUC,IACM,SAASA,2BAAAA,CAA4BC,OAAqB,EAAEC,aAAqC,EAAA;AACpG,IAAA,IAAIC,gCAAoBF,OAAAA,CAAAA,EAAU;AAC9B,QAAA,MAAMG,QAAAA,GAAWF,aAAAA,CAAcG,UAAU,CAACC,IAAI,CAACC,CAAAA,SAAAA,GAAaA,SAAAA,CAAUC,SAAS,KAAKP,OAAAA,CAAQQ,EAAE,CAAA;AAC9F,QAAA,IAAIC,UAAUN,QAAAA,KAAaO,SAAAA;AAE3B,QAAA,MAAMC,QAA8B,EAAC;QACrC,KAAK,MAAM,CAACC,IAAAA,EAAMC,QAAAA,CAAS,IAAIC,OAAOC,OAAO,CAACf,OAAAA,CAAQW,KAAK,CAAA,CAAG;AAC1D,YAAA,MAAMK,SAASH,QAAAA,CAASI,GAAG,CAACC,CAAAA,KAAAA,GAASnB,4BAA4BmB,KAAAA,EAAOjB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CAACC,CAAAA,KAAAA,GAASnB,2BAAAA,CAA4BmB,KAAAA,EAAOjB,aAAAA,CAAAA,CAAAA;AAClF,QAAA,MAAMoB,OAAAA,GAAiB;AAAE,YAAA,GAAGrB,OAAO;AAAEa,YAAAA;AAAS,SAAA;AAC9C,QAAA,OAAOA,QAAAA,CAASM,IAAI,CAAC,CAACD,KAAAA,EAAOE,KAAAA,GAAUF,KAAAA,KAAUlB,OAAAA,CAAQa,QAAQ,CAACO,KAAAA,CAAM,CAAA,GAAIC,OAAAA,GAAUrB,OAAAA;AAC1F,IAAA;IAEA,OAAOA,OAAAA;AACX;;"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
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
|
+
function isExternalComponentValue(value) {
|
|
6
|
+
const candidate = value;
|
|
7
|
+
return typeof candidate.id === 'string' && typeof candidate.componentName === 'string' && candidate.properties !== null && typeof candidate.properties === 'object';
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Finds every external component anywhere inside a layout, template, dialog template or screen, each once by id.
|
|
11
|
+
*
|
|
12
|
+
* It scans the value's structure rather than following a fixed list of properties, so a component is found
|
|
13
|
+
* wherever the model keeps it - slot content, a flow leaf, a freeform placement, a panel's children, another
|
|
14
|
+
* component's slot. A freeform arrangement repeats an element across its size-class variants; the first copy
|
|
15
|
+
* is the one returned.
|
|
16
|
+
*/ function collectComponents(owner) {
|
|
17
|
+
const found = new Map();
|
|
18
|
+
const visit = (value)=>{
|
|
19
|
+
if (value === null || typeof value !== 'object') return;
|
|
20
|
+
if (Array.isArray(value)) {
|
|
21
|
+
for (const item of value)visit(item);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (isExternalComponentValue(value) && !found.has(value.id)) found.set(value.id, value);
|
|
25
|
+
for (const child of Object.values(value))visit(child);
|
|
26
|
+
};
|
|
27
|
+
visit(owner);
|
|
28
|
+
return [
|
|
29
|
+
...found.values()
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
exports.collectComponents = collectComponents;
|
|
34
|
+
//# sourceMappingURL=collectComponents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectComponents.js","sources":["../../../editing/collectComponents.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 { ExternalComponent } from '@cratis/scene.model';\n\nfunction isExternalComponentValue(value: object): value is ExternalComponent {\n const candidate = value as Partial<ExternalComponent>;\n return typeof candidate.id === 'string' && typeof candidate.componentName === 'string'\n && candidate.properties !== null && typeof candidate.properties === 'object';\n}\n\n/**\n * Finds every external component anywhere inside a layout, template, dialog template or screen, each once by id.\n *\n * It scans the value's structure rather than following a fixed list of properties, so a component is found\n * wherever the model keeps it - slot content, a flow leaf, a freeform placement, a panel's children, another\n * component's slot. A freeform arrangement repeats an element across its size-class variants; the first copy\n * is the one returned.\n */\nexport function collectComponents(owner: unknown): ExternalComponent[] {\n const found = new Map<string, ExternalComponent>();\n\n const visit = (value: unknown): void => {\n if (value === null || typeof value !== 'object') return;\n if (Array.isArray(value)) {\n for (const item of value) visit(item);\n return;\n }\n\n if (isExternalComponentValue(value) && !found.has(value.id)) found.set(value.id, value);\n for (const child of Object.values(value)) visit(child);\n };\n\n visit(owner);\n return [...found.values()];\n}\n"],"names":["isExternalComponentValue","value","candidate","id","componentName","properties","collectComponents","owner","found","Map","visit","Array","isArray","item","has","set","child","Object","values"],"mappings":";;AAAA;AACA;AAIA,SAASA,yBAAyBC,KAAa,EAAA;AAC3C,IAAA,MAAMC,SAAAA,GAAYD,KAAAA;AAClB,IAAA,OAAO,OAAOC,SAAAA,CAAUC,EAAE,KAAK,QAAA,IAAY,OAAOD,SAAAA,CAAUE,aAAa,KAAK,QAAA,IACvEF,UAAUG,UAAU,KAAK,QAAQ,OAAOH,SAAAA,CAAUG,UAAU,KAAK,QAAA;AAC5E;AAEA;;;;;;;IAQO,SAASC,iBAAAA,CAAkBC,KAAc,EAAA;AAC5C,IAAA,MAAMC,QAAQ,IAAIC,GAAAA,EAAAA;AAElB,IAAA,MAAMC,QAAQ,CAACT,KAAAA,GAAAA;AACX,QAAA,IAAIA,KAAAA,KAAU,IAAA,IAAQ,OAAOA,KAAAA,KAAU,QAAA,EAAU;QACjD,IAAIU,KAAAA,CAAMC,OAAO,CAACX,KAAAA,CAAAA,EAAQ;YACtB,KAAK,MAAMY,IAAAA,IAAQZ,KAAAA,CAAOS,KAAAA,CAAMG,IAAAA,CAAAA;AAChC,YAAA;AACJ,QAAA;AAEA,QAAA,IAAIb,wBAAAA,CAAyBC,KAAAA,CAAAA,IAAU,CAACO,KAAAA,CAAMM,GAAG,CAACb,KAAAA,CAAME,EAAE,CAAA,EAAGK,KAAAA,CAAMO,GAAG,CAACd,KAAAA,CAAME,EAAE,EAAEF,KAAAA,CAAAA;AACjF,QAAA,KAAK,MAAMe,KAAAA,IAASC,MAAAA,CAAOC,MAAM,CAACjB,OAAQS,KAAAA,CAAMM,KAAAA,CAAAA;AACpD,IAAA,CAAA;IAEAN,KAAAA,CAAMH,KAAAA,CAAAA;IACN,OAAO;AAAIC,QAAAA,GAAAA,KAAAA,CAAMU,MAAM;AAAG,KAAA;AAC9B;;"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var scene_model = require('@cratis/scene.model');
|
|
4
|
+
var collectComponents = require('./collectComponents.js');
|
|
5
|
+
var DescriptorCatalog = require('./DescriptorCatalog.js');
|
|
6
|
+
var pathAccess = require('./pathAccess.js');
|
|
7
|
+
|
|
8
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
9
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
10
|
+
function iconFields(property) {
|
|
11
|
+
return (property.item?.properties ?? []).filter((field)=>field.valueType === scene_model.PropertyValueType.Icon).map((field)=>field.path);
|
|
12
|
+
}
|
|
13
|
+
function usagesOf(property, value, items, location) {
|
|
14
|
+
if (property.valueType === scene_model.PropertyValueType.Icon) {
|
|
15
|
+
return value === undefined ? [] : [
|
|
16
|
+
{
|
|
17
|
+
value: value,
|
|
18
|
+
location: `${location}:${property.path}`
|
|
19
|
+
}
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
return property.valueType === scene_model.PropertyValueType.Collection ? (items ?? []).flatMap((item)=>iconFields(property).filter((field)=>item.values[field] !== undefined).map((field)=>({
|
|
23
|
+
value: item.values[field],
|
|
24
|
+
location: `${location}:${property.path}:${item.id}:${field}`
|
|
25
|
+
}))) : [];
|
|
26
|
+
}
|
|
27
|
+
function ownerItems(value) {
|
|
28
|
+
return (Array.isArray(value) ? value : []).filter((item)=>item !== null && typeof item === 'object').map(({ id, ...values })=>({
|
|
29
|
+
id: String(id),
|
|
30
|
+
values
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Finds every icon value stored anywhere in a document - the values components carry themselves, and the values
|
|
35
|
+
* and collection-item icon fields that template instances contributed - as the `IconUsage`s that
|
|
36
|
+
* `analyzeIconImpact` takes, so "what would removing this library break" can be asked of a whole document.
|
|
37
|
+
*
|
|
38
|
+
* Each usage's `location` reads `<owner or instance>:<component>:<path>[:<itemId>:<field>]`, where the first part is
|
|
39
|
+
* the contributing instance id (`screen:Orders`) for a contributed value and the name of the owning layout or
|
|
40
|
+
* template for a value the component carries. Values are read as stored; none are changed.
|
|
41
|
+
*
|
|
42
|
+
* @param document The document to read.
|
|
43
|
+
* @param catalog The descriptors saying which properties are icons.
|
|
44
|
+
*/ function collectIconUsages(document, catalog) {
|
|
45
|
+
const usages = [];
|
|
46
|
+
const componentNames = new Map();
|
|
47
|
+
const owners = [
|
|
48
|
+
...document.layouts.map((layout)=>({
|
|
49
|
+
name: layout.name,
|
|
50
|
+
value: layout
|
|
51
|
+
})),
|
|
52
|
+
...document.screenTemplates.map((template)=>({
|
|
53
|
+
name: template.name,
|
|
54
|
+
value: template
|
|
55
|
+
})),
|
|
56
|
+
...document.dialogTemplates.map((template)=>({
|
|
57
|
+
name: template.name,
|
|
58
|
+
value: template
|
|
59
|
+
})),
|
|
60
|
+
...document.screens.map((screen)=>({
|
|
61
|
+
name: screen.name,
|
|
62
|
+
value: screen
|
|
63
|
+
}))
|
|
64
|
+
];
|
|
65
|
+
for (const owner of owners){
|
|
66
|
+
for (const component of collectComponents.collectComponents(owner.value)){
|
|
67
|
+
if (!componentNames.has(component.id)) componentNames.set(component.id, component.componentName);
|
|
68
|
+
for (const property of DescriptorCatalog.findComponentDescriptor(catalog, component.componentName)?.properties ?? []){
|
|
69
|
+
const value = pathAccess.getValueAtPath(component.properties, property.path);
|
|
70
|
+
usages.push(...usagesOf(property, value, ownerItems(value), `${owner.name}:${component.id}`));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
for (const contribution of document.instanceContributions){
|
|
75
|
+
const componentName = componentNames.get(contribution.component);
|
|
76
|
+
const property = componentName === undefined ? undefined : DescriptorCatalog.findComponentDescriptor(catalog, componentName)?.properties.find((candidate)=>candidate.path === contribution.path);
|
|
77
|
+
if (property) usages.push(...contributedUsages(property, contribution));
|
|
78
|
+
}
|
|
79
|
+
return usages;
|
|
80
|
+
}
|
|
81
|
+
function contributedUsages(property, contribution) {
|
|
82
|
+
return usagesOf(property, contribution.value, contribution.items, `${contribution.instance}:${contribution.component}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
exports.collectIconUsages = collectIconUsages;
|
|
86
|
+
//# sourceMappingURL=collectIconUsages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectIconUsages.js","sources":["../../../editing/collectIconUsages.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 { InstanceContribution, PropertyDescriptor, PropertyValueType, SceneDocument } from '@cratis/scene.model';\nimport { IconUsage } from '../icons/IconUsage';\nimport { collectComponents } from './collectComponents';\nimport { DescriptorCatalog, findComponentDescriptor } from './DescriptorCatalog';\nimport { getValueAtPath } from './pathAccess';\n\nfunction iconFields(property: PropertyDescriptor): string[] {\n return (property.item?.properties ?? []).filter((field) => field.valueType === PropertyValueType.Icon).map((field) => field.path);\n}\n\nfunction usagesOf(property: PropertyDescriptor, value: unknown, items: { id: string; values: Record<string, unknown> }[] | undefined, location: string): IconUsage[] {\n if (property.valueType === PropertyValueType.Icon) {\n return value === undefined ? [] : [{ value: value as IconUsage['value'], location: `${location}:${property.path}` }];\n }\n\n return property.valueType === PropertyValueType.Collection\n ? (items ?? []).flatMap((item) =>\n iconFields(property)\n .filter((field) => item.values[field] !== undefined)\n .map((field) => ({ value: item.values[field] as IconUsage['value'], location: `${location}:${property.path}:${item.id}:${field}` })))\n : [];\n}\n\nfunction ownerItems(value: unknown): { id: string; values: Record<string, unknown> }[] {\n return (Array.isArray(value) ? value : [])\n .filter((item): item is Record<string, unknown> => item !== null && typeof item === 'object')\n .map(({ id, ...values }) => ({ id: String(id), values }));\n}\n\n/**\n * Finds every icon value stored anywhere in a document - the values components carry themselves, and the values\n * and collection-item icon fields that template instances contributed - as the `IconUsage`s that\n * `analyzeIconImpact` takes, so \"what would removing this library break\" can be asked of a whole document.\n *\n * Each usage's `location` reads `<owner or instance>:<component>:<path>[:<itemId>:<field>]`, where the first part is\n * the contributing instance id (`screen:Orders`) for a contributed value and the name of the owning layout or\n * template for a value the component carries. Values are read as stored; none are changed.\n *\n * @param document The document to read.\n * @param catalog The descriptors saying which properties are icons.\n */\nexport function collectIconUsages(document: SceneDocument, catalog: DescriptorCatalog): IconUsage[] {\n const usages: IconUsage[] = [];\n const componentNames = new Map<string, string>();\n\n const owners: { name: string; value: unknown }[] = [\n ...document.layouts.map((layout) => ({ name: layout.name, value: layout })),\n ...document.screenTemplates.map((template) => ({ name: template.name, value: template })),\n ...document.dialogTemplates.map((template) => ({ name: template.name, value: template })),\n ...document.screens.map((screen) => ({ name: screen.name, value: screen })),\n ];\n\n for (const owner of owners) {\n for (const component of collectComponents(owner.value)) {\n if (!componentNames.has(component.id)) componentNames.set(component.id, component.componentName);\n\n for (const property of findComponentDescriptor(catalog, component.componentName)?.properties ?? []) {\n const value = getValueAtPath(component.properties, property.path);\n usages.push(...usagesOf(property, value, ownerItems(value), `${owner.name}:${component.id}`));\n }\n }\n }\n\n for (const contribution of document.instanceContributions) {\n const componentName = componentNames.get(contribution.component);\n const property = componentName === undefined ? undefined : findComponentDescriptor(catalog, componentName)?.properties.find((candidate) => candidate.path === contribution.path);\n if (property) usages.push(...contributedUsages(property, contribution));\n }\n\n return usages;\n}\n\nfunction contributedUsages(property: PropertyDescriptor, contribution: InstanceContribution): IconUsage[] {\n return usagesOf(property, contribution.value, contribution.items, `${contribution.instance}:${contribution.component}`);\n}\n"],"names":["iconFields","property","item","properties","filter","field","valueType","PropertyValueType","Icon","map","path","usagesOf","value","items","location","undefined","Collection","flatMap","values","id","ownerItems","Array","isArray","String","collectIconUsages","document","catalog","usages","componentNames","Map","owners","layouts","layout","name","screenTemplates","template","dialogTemplates","screens","screen","owner","component","collectComponents","has","set","componentName","findComponentDescriptor","getValueAtPath","push","contribution","instanceContributions","get","find","candidate","contributedUsages","instance"],"mappings":";;;;;;;AAAA;AACA;AAQA,SAASA,WAAWC,QAA4B,EAAA;IAC5C,OAAQA,CAAAA,QAAAA,CAASC,IAAI,EAAEC,cAAc,EAAC,EAAGC,MAAM,CAAC,CAACC,QAAUA,KAAAA,CAAMC,SAAS,KAAKC,6BAAAA,CAAkBC,IAAI,CAAA,CAAEC,GAAG,CAAC,CAACJ,KAAAA,GAAUA,KAAAA,CAAMK,IAAI,CAAA;AACpI;AAEA,SAASC,SAASV,QAA4B,EAAEW,KAAc,EAAEC,KAAoE,EAAEC,QAAgB,EAAA;AAClJ,IAAA,IAAIb,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
|
|
4
|
+
var DescriptorCatalog = require('./DescriptorCatalog.js');
|
|
5
|
+
var diagnostics = require('./diagnostics.js');
|
|
6
|
+
var pathAccess = require('./pathAccess.js');
|
|
7
|
+
var layoutTypeDescriptors = require('./layoutTypeDescriptors.js');
|
|
8
|
+
|
|
9
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
10
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
11
|
+
const layoutTypes = new Set(Object.values(scene_model.LayoutType));
|
|
12
|
+
/**
|
|
13
|
+
* Works out which descriptors apply to a node.
|
|
14
|
+
*
|
|
15
|
+
* A component takes its descriptor from the catalog by the name it carries; a layout node takes its layout type's;
|
|
16
|
+
* a placement and a template have their own fixed sets. A component nothing describes has no editable
|
|
17
|
+
* properties, and says so rather than failing.
|
|
18
|
+
*/ function describeNode(record, catalog) {
|
|
19
|
+
const diagnostics$1 = [];
|
|
20
|
+
if (record.kind === scene_model.SceneNodeKind.Placement) return {
|
|
21
|
+
properties: layoutTypeDescriptors.placementProperties,
|
|
22
|
+
diagnostics: diagnostics$1
|
|
23
|
+
};
|
|
24
|
+
if (record.kind === scene_model.SceneNodeKind.ScreenTemplate || record.kind === scene_model.SceneNodeKind.DialogTemplate) return {
|
|
25
|
+
properties: layoutTypeDescriptors.templateProperties,
|
|
26
|
+
diagnostics: diagnostics$1
|
|
27
|
+
};
|
|
28
|
+
if (layoutTypes.has(record.typeId)) {
|
|
29
|
+
const descriptor = DescriptorCatalog.findLayoutTypeDescriptor(catalog, record.typeId);
|
|
30
|
+
return {
|
|
31
|
+
properties: descriptor?.properties ?? [],
|
|
32
|
+
capabilities: descriptor?.capabilities,
|
|
33
|
+
diagnostics: diagnostics$1
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (record.kind === scene_model.SceneNodeKind.Element && record.value.componentName !== undefined) {
|
|
37
|
+
const descriptor = DescriptorCatalog.findComponentDescriptor(catalog, record.typeId);
|
|
38
|
+
if (!descriptor) {
|
|
39
|
+
diagnostics$1.push(diagnostics.warningDiagnostic(scene_model.DiagnosticCode.MissingComponentDescriptor, `Nothing describes the component '${record.typeId}', so none of its properties can be edited.`, {
|
|
40
|
+
nodeId: record.id
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
properties: descriptor?.properties ?? [],
|
|
45
|
+
diagnostics: diagnostics$1
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
properties: [],
|
|
50
|
+
diagnostics: diagnostics$1
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Reads a descriptor's value from a node: from the property bag of a component, from the node itself otherwise.
|
|
55
|
+
*/ function readNodeValue(record, path) {
|
|
56
|
+
const value = record.value;
|
|
57
|
+
const isComponent = record.kind === scene_model.SceneNodeKind.Element && value.componentName !== undefined;
|
|
58
|
+
return pathAccess.getValueAtPath(isComponent ? value.properties : value, path);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
exports.describeNode = describeNode;
|
|
62
|
+
exports.readNodeValue = readNodeValue;
|
|
63
|
+
//# sourceMappingURL=describeNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"describeNode.js","sources":["../../../editing/describeNode.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 {\n DiagnosticCode, LayoutCapabilities, LayoutType, PropertyDescriptor, SceneDiagnostic, SceneNodeKind,\n} from '@cratis/scene.model';\nimport { DescriptorCatalog, findComponentDescriptor, findLayoutTypeDescriptor } from './DescriptorCatalog';\nimport { NodeRecord } from './DocumentIndex';\nimport { warningDiagnostic } from './diagnostics';\nimport { getValueAtPath } from './pathAccess';\nimport { placementProperties, templateProperties } from './layoutTypeDescriptors';\n\n/**\n * What describes a node: its editable properties, and for a layout node what the type can do.\n */\nexport interface NodeDescription {\n properties: PropertyDescriptor[];\n capabilities?: LayoutCapabilities;\n diagnostics: SceneDiagnostic[];\n}\n\nconst layoutTypes = new Set<string>(Object.values(LayoutType));\n\n/**\n * Works out which descriptors apply to a node.\n *\n * A component takes its descriptor from the catalog by the name it carries; a layout node takes its layout type's;\n * a placement and a template have their own fixed sets. A component nothing describes has no editable\n * properties, and says so rather than failing.\n */\nexport function describeNode(record: NodeRecord, catalog: DescriptorCatalog): NodeDescription {\n const diagnostics: SceneDiagnostic[] = [];\n\n if (record.kind === SceneNodeKind.Placement) return { properties: placementProperties, diagnostics };\n if (record.kind === SceneNodeKind.ScreenTemplate || record.kind === SceneNodeKind.DialogTemplate) return { properties: templateProperties, diagnostics };\n\n if (layoutTypes.has(record.typeId)) {\n const descriptor = findLayoutTypeDescriptor(catalog, record.typeId);\n return { properties: descriptor?.properties ?? [], capabilities: descriptor?.capabilities, diagnostics };\n }\n\n if (record.kind === SceneNodeKind.Element && (record.value as { componentName?: unknown }).componentName !== undefined) {\n const descriptor = findComponentDescriptor(catalog, record.typeId);\n if (!descriptor) {\n diagnostics.push(warningDiagnostic(DiagnosticCode.MissingComponentDescriptor, `Nothing describes the component '${record.typeId}', so none of its properties can be edited.`, { nodeId: record.id }));\n }\n\n return { properties: descriptor?.properties ?? [], diagnostics };\n }\n\n return { properties: [], diagnostics };\n}\n\n/**\n * Reads a descriptor's value from a node: from the property bag of a component, from the node itself otherwise.\n */\nexport function readNodeValue(record: NodeRecord, path: string): unknown {\n const value = record.value as Record<string, unknown>;\n const isComponent = record.kind === SceneNodeKind.Element && value.componentName !== undefined;\n return getValueAtPath(isComponent ? (value.properties as Record<string, unknown>) : value, path);\n}\n"],"names":["layoutTypes","Set","Object","values","LayoutType","describeNode","record","catalog","diagnostics","kind","SceneNodeKind","Placement","properties","placementProperties","ScreenTemplate","DialogTemplate","templateProperties","has","typeId","descriptor","findLayoutTypeDescriptor","capabilities","Element","value","componentName","undefined","findComponentDescriptor","push","warningDiagnostic","DiagnosticCode","MissingComponentDescriptor","nodeId","id","readNodeValue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eC,0BAA0B,EAAE,CAAC,iCAAiC,EAAExB,MAAAA,CAAOY,MAAM,CAAC,2CAA2C,CAAC,EAAE;AAAEa,gBAAAA,MAAAA,EAAQzB,OAAO0B;AAAG,aAAA,CAAA,CAAA;AACtM,QAAA;QAEA,OAAO;YAAEpB,UAAAA,EAAYO,UAAAA,EAAYP,cAAc,EAAE;AAAEJ,yBAAAA;AAAY,SAAA;AACnE,IAAA;IAEA,OAAO;AAAEI,QAAAA,UAAAA,EAAY,EAAE;AAAEJ,qBAAAA;AAAY,KAAA;AACzC;AAEA;;AAEC,IACM,SAASyB,aAAAA,CAAc3B,MAAkB,EAAE4B,IAAY,EAAA;IAC1D,MAAMX,KAAAA,GAAQjB,OAAOiB,KAAK;IAC1B,MAAMY,WAAAA,GAAc7B,OAAOG,IAAI,KAAKC,0BAAcY,OAAO,IAAIC,KAAAA,CAAMC,aAAa,KAAKC,SAAAA;AACrF,IAAA,OAAOW,yBAAAA,CAAeD,WAAAA,GAAeZ,KAAAA,CAAMX,UAAU,GAA+BW,KAAAA,EAAOW,IAAAA,CAAAA;AAC/F;;;"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var scene_model = require('@cratis/scene.model');
|
|
4
|
+
var DescriptorCatalog = require('./DescriptorCatalog.js');
|
|
5
|
+
var iconDiagnostics = require('./iconDiagnostics.js');
|
|
6
|
+
var pathAccess = require('./pathAccess.js');
|
|
7
|
+
var resolveEffectiveConfiguration = require('./resolveEffectiveConfiguration.js');
|
|
8
|
+
var resolveTemplateChain = require('./resolveTemplateChain.js');
|
|
9
|
+
|
|
10
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
11
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
12
|
+
function isIconBearing(property) {
|
|
13
|
+
return property.valueType === scene_model.PropertyValueType.Icon || property.valueType === scene_model.PropertyValueType.Collection && (property.item?.properties ?? []).some((field)=>field.valueType === scene_model.PropertyValueType.Icon);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Reports every icon in what the editing scope renders - the template chain's own values and what each instance
|
|
17
|
+
* contributed - that the profile's icon catalog cannot supply: a library the profile lacks, an icon or variant a
|
|
18
|
+
* library no longer has, a library at an incompatible version.
|
|
19
|
+
*
|
|
20
|
+
* It reports; it never changes anything. The offending values stay in the document, still applied (a renderer
|
|
21
|
+
* shows its fallback), and apply again as soon as the icon is available, so removing a library is reversible.
|
|
22
|
+
* Each diagnostic names the component, property, collection item and - for a contributed value - the instance.
|
|
23
|
+
*
|
|
24
|
+
* Returns nothing when the context carries no `iconCatalog`. Load the catalogs first (`iconCatalog.load()`) for
|
|
25
|
+
* definite answers; an icon from an unloaded library is reported as not verified.
|
|
26
|
+
*/ function diagnoseIcons(document, context) {
|
|
27
|
+
const iconCatalog = context.iconCatalog;
|
|
28
|
+
if (!iconCatalog) return [];
|
|
29
|
+
const chain = resolveTemplateChain.resolveTemplateChain(document, context.scope);
|
|
30
|
+
const configuration = resolveEffectiveConfiguration.resolveEffectiveConfiguration(chain, document.instanceContributions, context.catalog);
|
|
31
|
+
const diagnostics = [];
|
|
32
|
+
for (const level of chain.levels){
|
|
33
|
+
for (const element of level.elements){
|
|
34
|
+
const descriptor = DescriptorCatalog.findComponentDescriptor(context.catalog, element.componentName);
|
|
35
|
+
const configured = configuration.components.find((candidate)=>candidate.component === element.id);
|
|
36
|
+
for (const property of (descriptor?.properties ?? []).filter(isIconBearing)){
|
|
37
|
+
const effective = configured?.values.find((candidate)=>candidate.path === property.path);
|
|
38
|
+
const where = {
|
|
39
|
+
component: element.id,
|
|
40
|
+
...effective?.contributedBy === undefined ? {} : {
|
|
41
|
+
instance: effective.contributedBy
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
if (property.valueType === scene_model.PropertyValueType.Icon) {
|
|
45
|
+
const value = effective ? effective.value : pathAccess.getValueAtPath(element.properties, property.path);
|
|
46
|
+
diagnostics.push(...iconDiagnostics.iconProblemsOfProperty(iconCatalog, property, value, scene_model.DiagnosticSeverity.Warning, where));
|
|
47
|
+
} else if (effective?.items) {
|
|
48
|
+
const items = effective.items.map((item)=>({
|
|
49
|
+
id: item.id,
|
|
50
|
+
values: item.values,
|
|
51
|
+
instance: item.origin === 'owner' ? undefined : item.origin
|
|
52
|
+
}));
|
|
53
|
+
diagnostics.push(...iconDiagnostics.iconProblemsOfItems(iconCatalog, property.item, items, scene_model.DiagnosticSeverity.Warning, {
|
|
54
|
+
component: element.id,
|
|
55
|
+
path: property.path
|
|
56
|
+
}));
|
|
57
|
+
} else {
|
|
58
|
+
diagnostics.push(...iconDiagnostics.iconProblemsOfProperty(iconCatalog, property, pathAccess.getValueAtPath(element.properties, property.path), scene_model.DiagnosticSeverity.Warning, where));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return diagnostics;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
exports.diagnoseIcons = diagnoseIcons;
|
|
67
|
+
//# sourceMappingURL=diagnoseIcons.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnoseIcons.js","sources":["../../../editing/diagnoseIcons.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 { DiagnosticSeverity, PropertyDescriptor, PropertyValueType, SceneDiagnostic, SceneDocument } from '@cratis/scene.model';\nimport { findComponentDescriptor } from './DescriptorCatalog';\nimport { EditingContext } from './EditingContext';\nimport { iconProblemsOfItems, iconProblemsOfProperty } from './iconDiagnostics';\nimport { getValueAtPath } from './pathAccess';\nimport { resolveEffectiveConfiguration } from './resolveEffectiveConfiguration';\nimport { resolveTemplateChain } from './resolveTemplateChain';\n\nfunction isIconBearing(property: PropertyDescriptor): boolean {\n return property.valueType === PropertyValueType.Icon\n || (property.valueType === PropertyValueType.Collection && (property.item?.properties ?? []).some((field) => field.valueType === PropertyValueType.Icon));\n}\n\n/**\n * Reports every icon in what the editing scope renders - the template chain's own values and what each instance\n * contributed - that the profile's icon catalog cannot supply: a library the profile lacks, an icon or variant a\n * library no longer has, a library at an incompatible version.\n *\n * It reports; it never changes anything. The offending values stay in the document, still applied (a renderer\n * shows its fallback), and apply again as soon as the icon is available, so removing a library is reversible.\n * Each diagnostic names the component, property, collection item and - for a contributed value - the instance.\n *\n * Returns nothing when the context carries no `iconCatalog`. Load the catalogs first (`iconCatalog.load()`) for\n * definite answers; an icon from an unloaded library is reported as not verified.\n */\nexport function diagnoseIcons(document: SceneDocument, context: EditingContext): SceneDiagnostic[] {\n const iconCatalog = context.iconCatalog;\n if (!iconCatalog) return [];\n\n const chain = resolveTemplateChain(document, context.scope);\n const configuration = resolveEffectiveConfiguration(chain, document.instanceContributions, context.catalog);\n const diagnostics: SceneDiagnostic[] = [];\n\n for (const level of chain.levels) {\n for (const element of level.elements) {\n const descriptor = findComponentDescriptor(context.catalog, element.componentName);\n const configured = configuration.components.find((candidate) => candidate.component === element.id);\n\n for (const property of (descriptor?.properties ?? []).filter(isIconBearing)) {\n const effective = configured?.values.find((candidate) => candidate.path === property.path);\n const where = { component: element.id, ...(effective?.contributedBy === undefined ? {} : { instance: effective.contributedBy }) };\n\n if (property.valueType === PropertyValueType.Icon) {\n const value = effective ? effective.value : getValueAtPath(element.properties, property.path);\n diagnostics.push(...iconProblemsOfProperty(iconCatalog, property, value, DiagnosticSeverity.Warning, where));\n } else if (effective?.items) {\n const items = effective.items.map((item) => ({ id: item.id, values: item.values, instance: item.origin === 'owner' ? undefined : item.origin }));\n diagnostics.push(...iconProblemsOfItems(iconCatalog, property.item, items, DiagnosticSeverity.Warning, { component: element.id, path: property.path }));\n } else {\n diagnostics.push(...iconProblemsOfProperty(iconCatalog, property, getValueAtPath(element.properties, property.path), DiagnosticSeverity.Warning, where));\n }\n }\n }\n }\n\n return diagnostics;\n}\n"],"names":["isIconBearing","property","valueType","PropertyValueType","Icon","Collection","item","properties","some","field","diagnoseIcons","document","context","iconCatalog","chain","resolveTemplateChain","scope","configuration","resolveEffectiveConfiguration","instanceContributions","catalog","diagnostics","level","levels","element","elements","descriptor","findComponentDescriptor","componentName","configured","components","find","candidate","component","id","filter","effective","values","path","where","contributedBy","undefined","instance","value","getValueAtPath","push","iconProblemsOfProperty","DiagnosticSeverity","Warning","items","map","origin","iconProblemsOfItems"],"mappings":";;;;;;;;;AAAA;AACA;AAUA,SAASA,cAAcC,QAA4B,EAAA;AAC/C,IAAA,OAAOA,QAAAA,CAASC,SAAS,KAAKC,6BAAAA,CAAkBC,IAAI,IAC5CH,QAAAA,CAASC,SAAS,KAAKC,6BAAAA,CAAkBE,UAAU,IAAI,CAACJ,QAAAA,CAASK,IAAI,EAAEC,UAAAA,IAAc,EAAC,EAAGC,IAAI,CAAC,CAACC,KAAAA,GAAUA,KAAAA,CAAMP,SAAS,KAAKC,8BAAkBC,IAAI,CAAA;AAC/J;AAEA;;;;;;;;;;;AAWC,IACM,SAASM,aAAAA,CAAcC,QAAuB,EAAEC,OAAuB,EAAA;IAC1E,MAAMC,WAAAA,GAAcD,QAAQC,WAAW;IACvC,IAAI,CAACA,WAAAA,EAAa,OAAO,EAAE;AAE3B,IAAA,MAAMC,KAAAA,GAAQC,yCAAAA,CAAqBJ,QAAAA,EAAUC,OAAAA,CAAQI,KAAK,CAAA;AAC1D,IAAA,MAAMC,gBAAgBC,2DAAAA,CAA8BJ,KAAAA,EAAOH,SAASQ,qBAAqB,EAAEP,QAAQQ,OAAO,CAAA;AAC1G,IAAA,MAAMC,cAAiC,EAAE;AAEzC,IAAA,KAAK,MAAMC,KAAAA,IAASR,KAAAA,CAAMS,MAAM,CAAE;AAC9B,QAAA,KAAK,MAAMC,OAAAA,IAAWF,KAAAA,CAAMG,QAAQ,CAAE;AAClC,YAAA,MAAMC,aAAaC,yCAAAA,CAAwBf,OAAAA,CAAQQ,OAAO,EAAEI,QAAQI,aAAa,CAAA;AACjF,YAAA,MAAMC,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