@cratis/scene.blueprint.default 4.33.0 → 4.35.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 +53 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/preview-host/ApplicationDocument.js +17 -0
- package/dist/cjs/preview-host/ApplicationDocument.js.map +1 -0
- package/dist/cjs/preview-host/ApplicationHost.js +134 -0
- package/dist/cjs/preview-host/ApplicationHost.js.map +1 -0
- package/dist/cjs/preview-host/FlowArrangementView.js +75 -0
- package/dist/cjs/preview-host/FlowArrangementView.js.map +1 -0
- package/dist/cjs/preview-host/PreviewProblem.js +32 -0
- package/dist/cjs/preview-host/PreviewProblem.js.map +1 -0
- package/dist/cjs/preview-host/PreviewProblemsView.js +51 -0
- package/dist/cjs/preview-host/PreviewProblemsView.js.map +1 -0
- package/dist/cjs/preview-host/PreviewSliceFragment.js +55 -0
- package/dist/cjs/preview-host/PreviewSliceFragment.js.map +1 -0
- package/dist/cjs/preview-host/PreviewTarget.js +17 -0
- package/dist/cjs/preview-host/PreviewTarget.js.map +1 -0
- package/dist/cjs/preview-host/PreviewTemplate.js +49 -0
- package/dist/cjs/preview-host/PreviewTemplate.js.map +1 -0
- package/dist/cjs/preview-host/PreviewToast.js +45 -0
- package/dist/cjs/preview-host/PreviewToast.js.map +1 -0
- package/dist/cjs/preview-host/ScenePreviewHost.js +290 -0
- package/dist/cjs/preview-host/ScenePreviewHost.js.map +1 -0
- package/dist/cjs/preview-host/composeApplication.js +249 -0
- package/dist/cjs/preview-host/composeApplication.js.map +1 -0
- package/dist/cjs/preview-host/defaultApplicationChrome.js +43 -0
- package/dist/cjs/preview-host/defaultApplicationChrome.js.map +1 -0
- package/dist/cjs/preview-host/diagnosePreview.js +100 -0
- package/dist/cjs/preview-host/diagnosePreview.js.map +1 -0
- package/dist/cjs/preview-host/previewProfile.js +53 -0
- package/dist/cjs/preview-host/previewProfile.js.map +1 -0
- package/dist/cjs/preview-host/previewSampleData.js +116 -0
- package/dist/cjs/preview-host/previewSampleData.js.map +1 -0
- package/dist/cjs/preview-host/resolvePreviewPlan.js +126 -0
- package/dist/cjs/preview-host/resolvePreviewPlan.js.map +1 -0
- package/dist/cjs/preview-host/useSizeClass.js +23 -0
- package/dist/cjs/preview-host/useSizeClass.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 +17 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/preview-host/ApplicationDocument.d.ts +7 -0
- package/dist/esm/preview-host/ApplicationDocument.d.ts.map +1 -0
- package/dist/esm/preview-host/ApplicationDocument.js +15 -0
- package/dist/esm/preview-host/ApplicationDocument.js.map +1 -0
- package/dist/esm/preview-host/ApplicationHost.d.ts +24 -0
- package/dist/esm/preview-host/ApplicationHost.d.ts.map +1 -0
- package/dist/esm/preview-host/ApplicationHost.js +132 -0
- package/dist/esm/preview-host/ApplicationHost.js.map +1 -0
- package/dist/esm/preview-host/FlowArrangementView.d.ts +7 -0
- package/dist/esm/preview-host/FlowArrangementView.d.ts.map +1 -0
- package/dist/esm/preview-host/FlowArrangementView.js +73 -0
- package/dist/esm/preview-host/FlowArrangementView.js.map +1 -0
- package/dist/esm/preview-host/PreviewProblem.d.ts +26 -0
- package/dist/esm/preview-host/PreviewProblem.d.ts.map +1 -0
- package/dist/esm/preview-host/PreviewProblem.js +28 -0
- package/dist/esm/preview-host/PreviewProblem.js.map +1 -0
- package/dist/esm/preview-host/PreviewProblemsView.d.ts +7 -0
- package/dist/esm/preview-host/PreviewProblemsView.d.ts.map +1 -0
- package/dist/esm/preview-host/PreviewProblemsView.js +49 -0
- package/dist/esm/preview-host/PreviewProblemsView.js.map +1 -0
- package/dist/esm/preview-host/PreviewSliceFragment.d.ts +3 -0
- package/dist/esm/preview-host/PreviewSliceFragment.d.ts.map +1 -0
- package/dist/esm/preview-host/PreviewSliceFragment.js +53 -0
- package/dist/esm/preview-host/PreviewSliceFragment.js.map +1 -0
- package/dist/esm/preview-host/PreviewTarget.d.ts +10 -0
- package/dist/esm/preview-host/PreviewTarget.d.ts.map +1 -0
- package/dist/esm/preview-host/PreviewTarget.js +15 -0
- package/dist/esm/preview-host/PreviewTarget.js.map +1 -0
- package/dist/esm/preview-host/PreviewTemplate.d.ts +5 -0
- package/dist/esm/preview-host/PreviewTemplate.d.ts.map +1 -0
- package/dist/esm/preview-host/PreviewTemplate.js +45 -0
- package/dist/esm/preview-host/PreviewTemplate.js.map +1 -0
- package/dist/esm/preview-host/PreviewToast.d.ts +10 -0
- package/dist/esm/preview-host/PreviewToast.d.ts.map +1 -0
- package/dist/esm/preview-host/PreviewToast.js +43 -0
- package/dist/esm/preview-host/PreviewToast.js.map +1 -0
- package/dist/esm/preview-host/ScenePreviewHost.d.ts +32 -0
- package/dist/esm/preview-host/ScenePreviewHost.d.ts.map +1 -0
- package/dist/esm/preview-host/ScenePreviewHost.js +288 -0
- package/dist/esm/preview-host/ScenePreviewHost.js.map +1 -0
- package/dist/esm/preview-host/composeApplication.d.ts +34 -0
- package/dist/esm/preview-host/composeApplication.d.ts.map +1 -0
- package/dist/esm/preview-host/composeApplication.js +239 -0
- package/dist/esm/preview-host/composeApplication.js.map +1 -0
- package/dist/esm/preview-host/defaultApplicationChrome.d.ts +4 -0
- package/dist/esm/preview-host/defaultApplicationChrome.d.ts.map +1 -0
- package/dist/esm/preview-host/defaultApplicationChrome.js +41 -0
- package/dist/esm/preview-host/defaultApplicationChrome.js.map +1 -0
- package/dist/esm/preview-host/diagnosePreview.d.ts +22 -0
- package/dist/esm/preview-host/diagnosePreview.d.ts.map +1 -0
- package/dist/esm/preview-host/diagnosePreview.js +98 -0
- package/dist/esm/preview-host/diagnosePreview.js.map +1 -0
- package/dist/esm/preview-host/index.d.ts +18 -0
- package/dist/esm/preview-host/index.d.ts.map +1 -0
- package/dist/esm/preview-host/index.js +18 -0
- package/dist/esm/preview-host/index.js.map +1 -0
- package/dist/esm/preview-host/previewProfile.d.ts +6 -0
- package/dist/esm/preview-host/previewProfile.d.ts.map +1 -0
- package/dist/esm/preview-host/previewProfile.js +49 -0
- package/dist/esm/preview-host/previewProfile.js.map +1 -0
- package/dist/esm/preview-host/previewSampleData.d.ts +22 -0
- package/dist/esm/preview-host/previewSampleData.d.ts.map +1 -0
- package/dist/esm/preview-host/previewSampleData.js +113 -0
- package/dist/esm/preview-host/previewSampleData.js.map +1 -0
- package/dist/esm/preview-host/resolvePreviewPlan.d.ts +18 -0
- package/dist/esm/preview-host/resolvePreviewPlan.d.ts.map +1 -0
- package/dist/esm/preview-host/resolvePreviewPlan.js +124 -0
- package/dist/esm/preview-host/resolvePreviewPlan.js.map +1 -0
- package/dist/esm/preview-host/useSizeClass.d.ts +3 -0
- package/dist/esm/preview-host/useSizeClass.d.ts.map +1 -0
- package/dist/esm/preview-host/useSizeClass.js +21 -0
- package/dist/esm/preview-host/useSizeClass.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/index.ts +1 -0
- package/package.json +8 -8
- package/preview-host/ApplicationDocument.ts +31 -0
- package/preview-host/ApplicationHost.tsx +155 -0
- package/preview-host/FlowArrangementView.tsx +59 -0
- package/preview-host/PreviewProblem.ts +68 -0
- package/preview-host/PreviewProblemsView.tsx +31 -0
- package/preview-host/PreviewSliceFragment.ts +43 -0
- package/preview-host/PreviewTarget.ts +19 -0
- package/preview-host/PreviewTemplate.tsx +45 -0
- package/preview-host/PreviewToast.tsx +32 -0
- package/preview-host/ScenePreviewHost.tsx +250 -0
- package/preview-host/composeApplication.ts +273 -0
- package/preview-host/defaultApplicationChrome.ts +33 -0
- package/preview-host/diagnosePreview.ts +132 -0
- package/preview-host/index.ts +20 -0
- package/preview-host/previewProfile.ts +47 -0
- package/preview-host/previewSampleData.ts +144 -0
- package/preview-host/resolvePreviewPlan.ts +100 -0
- package/preview-host/useSizeClass.ts +23 -0
- package/shell/layout.css +22 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PreviewTemplate.js","sources":["../../../preview-host/PreviewTemplate.tsx"],"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 type { ReactNode } from 'react';\nimport type { FlowArrangement } from '@cratis/scene.model';\nimport { evaluateFlowArrangement } from '@cratis/scene.engine';\nimport type { ComponentRegistry, RegisteredComponentProps } from '@cratis/scene.react';\nimport { FlowArrangementView } from './FlowArrangementView';\nimport { useSizeClass } from './useSizeClass';\n\n/** The name the template wrapper is registered under. */\nexport const previewTemplateComponent = 'Scene:template';\n\nfunction isFlowArrangement(arrangement: unknown): arrangement is FlowArrangement {\n return !!arrangement && typeof arrangement === 'object' && 'root' in arrangement;\n}\n\n/**\n * A screen's content inside the screen template it names.\n *\n * The template's own `arrangement flow` positions its slots - header, body, aside - exactly as the document wrote it, evaluated\n * for the window's current size class. A template with no flow arrangement stacks them. It sits inside the shell's content\n * slot, so the shell, not this, owns the chrome around it. Stage and the preview host render templates with this one component.\n */\nexport function PreviewTemplate({ element, slots }: RegisteredComponentProps) {\n const sizeClass = useSizeClass();\n const arrangement = (element.properties as Record<string, unknown> | undefined)?.arrangement;\n const nodes: Record<string, ReactNode> = {};\n for (const [name, content] of Object.entries(slots)) {\n nodes[name] = <section className='scene-template-slot' data-slot={name}>{content}</section>;\n }\n\n return (\n <div className='scene-template' data-scene-id={element.id}>\n {isFlowArrangement(arrangement)\n ? <FlowArrangementView node={evaluateFlowArrangement(arrangement, sizeClass)} slots={nodes} />\n : Object.entries(nodes).map(([name, node]) => <div key={name}>{node}</div>)}\n </div>\n );\n}\n\n/** The components the preview host and the Stage add to the registry for composed screens. */\nexport const previewComponents: ComponentRegistry = {\n [previewTemplateComponent]: PreviewTemplate,\n};\n"],"names":["previewTemplateComponent","isFlowArrangement","arrangement","PreviewTemplate","element","slots","sizeClass","useSizeClass","properties","nodes","name","content","Object","entries","_jsx","section","className","data-slot","div","data-scene-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AA,CAAAA;;AAGxE;AAEA,+FACO,MAAMe,iBAAAA,GAAuC;AAChD,IAAA,CAACzB,2BAA2BG;AAChC;;;;"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
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
|
+
* The toast that confirms a dry run: "Command would be sent", with the payload in an expandable detail. Nothing was sent to
|
|
9
|
+
* Chronicle or Arc.
|
|
10
|
+
*/ function PreviewToast({ invocation, onDismiss }) {
|
|
11
|
+
return /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
12
|
+
className: "scene-preview-toast",
|
|
13
|
+
role: "status",
|
|
14
|
+
"data-scene-preview-toast": true,
|
|
15
|
+
children: [
|
|
16
|
+
/*#__PURE__*/ jsxRuntime.jsx("strong", {
|
|
17
|
+
children: "Command would be sent"
|
|
18
|
+
}),
|
|
19
|
+
/*#__PURE__*/ jsxRuntime.jsxs("span", {
|
|
20
|
+
children: [
|
|
21
|
+
" · ",
|
|
22
|
+
invocation.command ?? invocation.sliceId
|
|
23
|
+
]
|
|
24
|
+
}),
|
|
25
|
+
/*#__PURE__*/ jsxRuntime.jsxs("details", {
|
|
26
|
+
children: [
|
|
27
|
+
/*#__PURE__*/ jsxRuntime.jsx("summary", {
|
|
28
|
+
children: "Payload"
|
|
29
|
+
}),
|
|
30
|
+
/*#__PURE__*/ jsxRuntime.jsx("pre", {
|
|
31
|
+
children: JSON.stringify(invocation.payload, null, 2)
|
|
32
|
+
})
|
|
33
|
+
]
|
|
34
|
+
}),
|
|
35
|
+
/*#__PURE__*/ jsxRuntime.jsx("button", {
|
|
36
|
+
type: "button",
|
|
37
|
+
onClick: onDismiss,
|
|
38
|
+
children: "Dismiss"
|
|
39
|
+
})
|
|
40
|
+
]
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
exports.PreviewToast = PreviewToast;
|
|
45
|
+
//# sourceMappingURL=PreviewToast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PreviewToast.js","sources":["../../../preview-host/PreviewToast.tsx"],"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\n/** What a dry run reports (PRV5). */\nexport interface PreviewInvocation {\n /** The qualified id of the slice. */\n sliceId: string;\n\n /** The command the slice accepts, when known. */\n command?: string;\n\n /** The payload that would have been sent. */\n payload: Record<string, unknown>;\n}\n\n/**\n * The toast that confirms a dry run: \"Command would be sent\", with the payload in an expandable detail. Nothing was sent to\n * Chronicle or Arc.\n */\nexport function PreviewToast({ invocation, onDismiss }: { invocation: PreviewInvocation; onDismiss(): void }) {\n return (\n <div className='scene-preview-toast' role='status' data-scene-preview-toast>\n <strong>Command would be sent</strong>\n <span> · {invocation.command ?? invocation.sliceId}</span>\n <details>\n <summary>Payload</summary>\n <pre>{JSON.stringify(invocation.payload, null, 2)}</pre>\n </details>\n <button type='button' onClick={onDismiss}>Dismiss</button>\n </div>\n );\n}\n"],"names":["PreviewToast","invocation","onDismiss","_jsxs","div","className","role","data-scene-preview-toast","_jsx","strong","span","command","sliceId","details","summary","pre","JSON","stringify","payload","button","type","onClick"],"mappings":";;;;AAAA;AACA;AAcA;;;AAGC,IACM,SAASA,YAAAA,CAAa,EAAEC,UAAU,EAAEC,SAAS,EAAwD,EAAA;AACxG,IAAA,qBACIC,eAAA,CAACC,KAAAA,EAAAA;QAAIC,SAAAA,EAAU,qBAAA;QAAsBC,IAAAA,EAAK,QAAA;QAASC,0BAAwB,EAAA,IAAA;;0BACvEC,cAAA,CAACC,QAAAA,EAAAA;AAAO,gBAAA,QAAA,EAAA;;0BACRN,eAAA,CAACO,MAAAA,EAAAA;;AAAK,oBAAA,KAAA;oBAAIT,UAAAA,CAAWU,OAAO,IAAIV,UAAAA,CAAWW;;;0BAC3CT,eAAA,CAACU,SAAAA,EAAAA;;kCACGL,cAAA,CAACM,SAAAA,EAAAA;AAAQ,wBAAA,QAAA,EAAA;;kCACTN,cAAA,CAACO,KAAAA,EAAAA;AAAKC,wBAAAA,QAAAA,EAAAA,IAAAA,CAAKC,SAAS,CAAChB,UAAAA,CAAWiB,OAAO,EAAE,IAAA,EAAM,CAAA;;;;0BAEnDV,cAAA,CAACW,QAAAA,EAAAA;gBAAOC,IAAAA,EAAK,QAAA;gBAASC,OAAAA,EAASnB,SAAAA;AAAW,gBAAA,QAAA,EAAA;;;;AAGtD;;"}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var scene_model = require('@cratis/scene.model');
|
|
6
|
+
var scene_engine = require('@cratis/scene.engine');
|
|
7
|
+
var scene_react = require('@cratis/scene.react');
|
|
8
|
+
var ComponentName = require('../ComponentName.js');
|
|
9
|
+
var elements = require('../gallery/elements.js');
|
|
10
|
+
var SlotName = require('../layouts/SlotName.js');
|
|
11
|
+
var LayoutName = require('../layouts/LayoutName.js');
|
|
12
|
+
require('../layouts/shellComponents.js');
|
|
13
|
+
require('../layouts/appShell.js');
|
|
14
|
+
require('../layouts/fullPage.js');
|
|
15
|
+
var previewProfile = require('./previewProfile.js');
|
|
16
|
+
var ApplicationHost = require('./ApplicationHost.js');
|
|
17
|
+
var diagnosePreview = require('./diagnosePreview.js');
|
|
18
|
+
var PreviewProblem = require('./PreviewProblem.js');
|
|
19
|
+
var PreviewProblemsView = require('./PreviewProblemsView.js');
|
|
20
|
+
var previewSampleData = require('./previewSampleData.js');
|
|
21
|
+
var PreviewSliceFragment = require('./PreviewSliceFragment.js');
|
|
22
|
+
var PreviewToast = require('./PreviewToast.js');
|
|
23
|
+
|
|
24
|
+
const previewPageScreen = '#preview-page';
|
|
25
|
+
const noNavigation = {
|
|
26
|
+
application: {
|
|
27
|
+
regions: []
|
|
28
|
+
},
|
|
29
|
+
modules: []
|
|
30
|
+
};
|
|
31
|
+
/** The page a slice preview happens over when its feature has no screen of its own, or a State View's fragment is shown. */ function minimalPage(layout, content) {
|
|
32
|
+
return {
|
|
33
|
+
name: previewPageScreen,
|
|
34
|
+
layout,
|
|
35
|
+
slotContent: {
|
|
36
|
+
[SlotName.SlotName.Content]: content
|
|
37
|
+
},
|
|
38
|
+
forms: [],
|
|
39
|
+
contributions: []
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Renders the effective application (spec 10, PRV1-PRV9) from an in-memory document: the real shell, its navigation regions, the
|
|
44
|
+
* first feature of a module, a feature, or a slice - a State Change slice as its task dialog over a minimal host page, a State View
|
|
45
|
+
* slice as its data fragment.
|
|
46
|
+
*
|
|
47
|
+
* - **One code path**: the composition and the host are the Stage's own (`composeApplicationScreen`, `ApplicationHost`); nothing
|
|
48
|
+
* here draws a shell, a menu or a dialog (PRV9).
|
|
49
|
+
* - **Read-only**: no design affordances, no edits (PRV8) - a toolbar button without a slice shows no warning badge here; it is
|
|
50
|
+
* reported as a problem instead. A model that cannot render - an unknown target, a feature without a screen,
|
|
51
|
+
* a layout or template nobody provides - gives a {@link PreviewProblemsView} and `onProblems`, not a blank screen.
|
|
52
|
+
* - **Navigation** keeps to an in-memory history; a different module swaps the shell's effective navigation (PRV4).
|
|
53
|
+
* - **Dialogs** submit through the dry-run invoker unless one is given: validation runs, nothing is sent, a toast says so (PRV5).
|
|
54
|
+
* - **Data** is the active sample data pack's (PRV6); the same seed shows the same rows.
|
|
55
|
+
* - The strip (`Previewing`, sample data, `Exit preview · Esc`) is the host application's: this reports the breadcrumb and calls
|
|
56
|
+
* `onExit` on Escape.
|
|
57
|
+
*/ function ScenePreviewHost({ document: application, structure, navigation = noNavigation, target, sampleData, registry, invoker, onInvoked, fieldsFor, composition = {}, theme, isVisible, history, onProblems, onSelectProblem, onBreadcrumbChange, onExit, children }) {
|
|
58
|
+
const index = react.useMemo(()=>structure instanceof scene_engine.ApplicationStructureIndex ? structure : new scene_engine.ApplicationStructureIndex(structure), [
|
|
59
|
+
structure
|
|
60
|
+
]);
|
|
61
|
+
const compose = react.useMemo(()=>({
|
|
62
|
+
logo: navigation.application.logo,
|
|
63
|
+
...composition
|
|
64
|
+
}), [
|
|
65
|
+
composition,
|
|
66
|
+
navigation.application.logo
|
|
67
|
+
]);
|
|
68
|
+
const diagnosis = react.useMemo(()=>diagnosePreview.diagnosePreview({
|
|
69
|
+
document: application,
|
|
70
|
+
structure: index,
|
|
71
|
+
navigation,
|
|
72
|
+
target,
|
|
73
|
+
packs: sampleData?.packs,
|
|
74
|
+
composition: compose
|
|
75
|
+
}), [
|
|
76
|
+
application,
|
|
77
|
+
compose,
|
|
78
|
+
index,
|
|
79
|
+
navigation,
|
|
80
|
+
sampleData?.packs,
|
|
81
|
+
target
|
|
82
|
+
]);
|
|
83
|
+
const problems = react.useMemo(()=>{
|
|
84
|
+
const found = [
|
|
85
|
+
...diagnosis.problems
|
|
86
|
+
];
|
|
87
|
+
const { plan, screen } = diagnosis;
|
|
88
|
+
if (plan?.kind === 'stateView' && screen && plan.slice) {
|
|
89
|
+
const slice = index.findSlice(plan.slice);
|
|
90
|
+
if (slice && PreviewSliceFragment.findSliceFragment(screen, plan.slice, slice).length === 0) {
|
|
91
|
+
found.push({
|
|
92
|
+
code: PreviewProblem.PreviewProblemCode.SliceFragmentMissing,
|
|
93
|
+
severity: PreviewProblem.PreviewProblemSeverity.Warning,
|
|
94
|
+
message: `Nothing on the screen '${screen.name}' is bound to the State View '${plan.slice}', so its page is shown.`,
|
|
95
|
+
nodeId: plan.slice
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return found;
|
|
100
|
+
}, [
|
|
101
|
+
diagnosis,
|
|
102
|
+
index
|
|
103
|
+
]);
|
|
104
|
+
const key = JSON.stringify(problems);
|
|
105
|
+
const reported = react.useRef(undefined);
|
|
106
|
+
react.useEffect(()=>{
|
|
107
|
+
if (reported.current === key) return;
|
|
108
|
+
reported.current = key;
|
|
109
|
+
onProblems?.(problems);
|
|
110
|
+
}, [
|
|
111
|
+
key,
|
|
112
|
+
onProblems,
|
|
113
|
+
problems
|
|
114
|
+
]);
|
|
115
|
+
const breadcrumb = diagnosis.plan?.breadcrumb;
|
|
116
|
+
const breadcrumbKey = breadcrumb?.join('\u0000');
|
|
117
|
+
react.useEffect(()=>{
|
|
118
|
+
if (breadcrumb) onBreadcrumbChange?.(breadcrumb);
|
|
119
|
+
// `breadcrumbKey` is the value of `breadcrumb`.
|
|
120
|
+
}, [
|
|
121
|
+
breadcrumbKey,
|
|
122
|
+
onBreadcrumbChange
|
|
123
|
+
]);
|
|
124
|
+
const [memoryHistory] = react.useState(()=>scene_react.createMemorySceneHistory());
|
|
125
|
+
const [toast, setToast] = react.useState();
|
|
126
|
+
const dryRun = react.useMemo(()=>scene_react.createDryRunInvoker({
|
|
127
|
+
onInvoked: (invocation)=>{
|
|
128
|
+
setToast(invocation);
|
|
129
|
+
onInvoked?.(invocation);
|
|
130
|
+
}
|
|
131
|
+
}), [
|
|
132
|
+
onInvoked
|
|
133
|
+
]);
|
|
134
|
+
const samples = react.useMemo(()=>previewSampleData.createPreviewSampleData(application, sampleData), [
|
|
135
|
+
application,
|
|
136
|
+
sampleData
|
|
137
|
+
]);
|
|
138
|
+
const fields = react.useMemo(()=>(command, slice)=>samples.commandFields(command, fieldsFor?.(command, slice) ?? []), [
|
|
139
|
+
fieldsFor,
|
|
140
|
+
samples
|
|
141
|
+
]);
|
|
142
|
+
const page = react.useMemo(()=>{
|
|
143
|
+
const { plan, screen } = diagnosis;
|
|
144
|
+
if (!plan) return undefined;
|
|
145
|
+
if (!screen) {
|
|
146
|
+
// A slice whose feature has no screen of its own: a minimal host page, headed with where it is.
|
|
147
|
+
if (plan.slice === undefined) return undefined;
|
|
148
|
+
const layout = previewProfile.previewProfile(application.uiProfiles).layout ?? LayoutName.LayoutName.AppShell;
|
|
149
|
+
const header = elements.externalComponent('preview-page-header', ComponentName.ComponentName.PageHeader, {
|
|
150
|
+
title: plan.breadcrumb.slice(0, -1).join(' › ') || plan.breadcrumb[0]
|
|
151
|
+
});
|
|
152
|
+
return {
|
|
153
|
+
screens: [
|
|
154
|
+
...application.screens,
|
|
155
|
+
minimalPage(layout, [
|
|
156
|
+
header
|
|
157
|
+
])
|
|
158
|
+
],
|
|
159
|
+
initial: previewPageScreen
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
if (plan.kind === 'stateView' && plan.slice) {
|
|
163
|
+
const slice = index.findSlice(plan.slice);
|
|
164
|
+
const fragment = slice ? PreviewSliceFragment.findSliceFragment(screen, plan.slice, slice) : [];
|
|
165
|
+
if (fragment.length > 0) return {
|
|
166
|
+
screens: [
|
|
167
|
+
...application.screens,
|
|
168
|
+
minimalPage(screen.layout, fragment)
|
|
169
|
+
],
|
|
170
|
+
initial: previewPageScreen
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
screens: application.screens,
|
|
175
|
+
initial: screen.name
|
|
176
|
+
};
|
|
177
|
+
}, [
|
|
178
|
+
application.screens,
|
|
179
|
+
application.uiProfiles,
|
|
180
|
+
diagnosis,
|
|
181
|
+
index
|
|
182
|
+
]);
|
|
183
|
+
const hostApplication = react.useMemo(()=>page ? {
|
|
184
|
+
...application,
|
|
185
|
+
screens: page.screens
|
|
186
|
+
} : application, [
|
|
187
|
+
application,
|
|
188
|
+
page
|
|
189
|
+
]);
|
|
190
|
+
const navigationModel = react.useMemo(()=>({
|
|
191
|
+
structure: index,
|
|
192
|
+
navigation,
|
|
193
|
+
isVisible
|
|
194
|
+
}), [
|
|
195
|
+
index,
|
|
196
|
+
isVisible,
|
|
197
|
+
navigation
|
|
198
|
+
]);
|
|
199
|
+
const onKeyDown = react.useCallback((event)=>{
|
|
200
|
+
if (event.key === 'Escape' && !event.defaultPrevented) onExit?.();
|
|
201
|
+
}, [
|
|
202
|
+
onExit
|
|
203
|
+
]);
|
|
204
|
+
if (PreviewProblem.hasBlockingProblem(problems) || !page) {
|
|
205
|
+
return /*#__PURE__*/ jsxRuntime.jsx(PreviewProblemsView.PreviewProblemsView, {
|
|
206
|
+
problems: problems.filter((problem)=>problem.severity === PreviewProblem.PreviewProblemSeverity.Error),
|
|
207
|
+
onSelectProblem: onSelectProblem
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
const body = /*#__PURE__*/ jsxRuntime.jsx(scene_react.SliceInvokerProvider, {
|
|
211
|
+
invoker: invoker ?? dryRun,
|
|
212
|
+
warnEmptySlices: false,
|
|
213
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(scene_react.SliceCommandFieldsProvider, {
|
|
214
|
+
fieldsFor: fields,
|
|
215
|
+
children: /*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
216
|
+
className: "scene-preview-host",
|
|
217
|
+
"data-scene-preview": diagnosis.plan?.kind,
|
|
218
|
+
"data-preview-breadcrumb": breadcrumb?.join(' › '),
|
|
219
|
+
children: /*#__PURE__*/ jsxRuntime.jsxs(ApplicationHost.ApplicationHost, {
|
|
220
|
+
application: hostApplication,
|
|
221
|
+
composition: compose,
|
|
222
|
+
navigationModel: navigationModel,
|
|
223
|
+
registry: registry,
|
|
224
|
+
initialScreen: page.initial,
|
|
225
|
+
history: history ?? memoryHistory,
|
|
226
|
+
resolveBinding: samples.resolveBinding,
|
|
227
|
+
queryResults: samples.queryResults,
|
|
228
|
+
children: [
|
|
229
|
+
diagnosis.plan?.kind === 'stateChange' && /*#__PURE__*/ jsxRuntime.jsx(OpenSliceDialog, {
|
|
230
|
+
index: index,
|
|
231
|
+
plan: diagnosis.plan
|
|
232
|
+
}),
|
|
233
|
+
/*#__PURE__*/ jsxRuntime.jsx(EscapeToExit, {
|
|
234
|
+
onKeyDown: onKeyDown,
|
|
235
|
+
enabled: onExit !== undefined
|
|
236
|
+
}),
|
|
237
|
+
toast && invoker === undefined && /*#__PURE__*/ jsxRuntime.jsx(PreviewToast.PreviewToast, {
|
|
238
|
+
invocation: toast,
|
|
239
|
+
onDismiss: ()=>setToast(undefined)
|
|
240
|
+
}),
|
|
241
|
+
children
|
|
242
|
+
]
|
|
243
|
+
})
|
|
244
|
+
})
|
|
245
|
+
})
|
|
246
|
+
});
|
|
247
|
+
return theme ? /*#__PURE__*/ jsxRuntime.jsx(scene_react.SceneThemeProvider, {
|
|
248
|
+
theme: theme,
|
|
249
|
+
children: body
|
|
250
|
+
}) : body;
|
|
251
|
+
}
|
|
252
|
+
/** Opens the task dialog of a State Change slice once the page is up - the slice preview (PRV3). */ function OpenSliceDialog({ index, plan }) {
|
|
253
|
+
const navigation = scene_react.useSceneNavigation();
|
|
254
|
+
const opened = react.useRef(false);
|
|
255
|
+
react.useEffect(()=>{
|
|
256
|
+
if (opened.current || plan.slice === undefined) return;
|
|
257
|
+
const slice = index.findSlice(plan.slice);
|
|
258
|
+
if (!slice || slice.kind !== scene_model.SliceKind.StateChange) return;
|
|
259
|
+
const destination = scene_react.sliceDialogDestination(scene_engine.resolveToolbarButton(index, {
|
|
260
|
+
id: plan.slice,
|
|
261
|
+
title: slice.name,
|
|
262
|
+
slice: plan.slice
|
|
263
|
+
}));
|
|
264
|
+
if (destination === undefined) return;
|
|
265
|
+
opened.current = true;
|
|
266
|
+
navigation.navigate(destination);
|
|
267
|
+
}, [
|
|
268
|
+
index,
|
|
269
|
+
navigation,
|
|
270
|
+
plan.slice
|
|
271
|
+
]);
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
/** Exits the preview on Escape, unless something - an open dialog - already used the key. */ function EscapeToExit({ onKeyDown, enabled }) {
|
|
275
|
+
const navigation = scene_react.useSceneNavigation();
|
|
276
|
+
const dialogOpen = navigation.currentDialog !== undefined;
|
|
277
|
+
react.useEffect(()=>{
|
|
278
|
+
if (!enabled || dialogOpen) return undefined;
|
|
279
|
+
globalThis.addEventListener('keydown', onKeyDown);
|
|
280
|
+
return ()=>globalThis.removeEventListener('keydown', onKeyDown);
|
|
281
|
+
}, [
|
|
282
|
+
dialogOpen,
|
|
283
|
+
enabled,
|
|
284
|
+
onKeyDown
|
|
285
|
+
]);
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
exports.ScenePreviewHost = ScenePreviewHost;
|
|
290
|
+
//# sourceMappingURL=ScenePreviewHost.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScenePreviewHost.js","sources":["../../../preview-host/ScenePreviewHost.tsx"],"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 { ReactNode, useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { ApplicationStructure, NavigationModel, Screen, SliceKind, Theme } from '@cratis/scene.model';\nimport { ApplicationStructureIndex, EffectiveNavItem, resolveToolbarButton } from '@cratis/scene.engine';\nimport {\n ComponentRegistry, SceneHistory, SceneThemeProvider, SliceCommandFieldsProvider, SliceCommandFieldsSource, SliceInvoker,\n SliceInvokerProvider, createDryRunInvoker, createMemorySceneHistory, sliceDialogDestination, useSceneNavigation,\n} from '@cratis/scene.react';\nimport { ComponentName } from '../ComponentName';\nimport { externalComponent } from '../gallery/elements';\nimport { LayoutName, SlotName } from '../layouts';\nimport { previewProfile } from './previewProfile';\nimport { ApplicationDocument } from './ApplicationDocument';\nimport { ApplicationHost } from './ApplicationHost';\nimport { CompositionOptions } from './composeApplication';\nimport { diagnosePreview } from './diagnosePreview';\nimport { PreviewProblem, PreviewProblemCode, PreviewProblemSeverity, hasBlockingProblem } from './PreviewProblem';\nimport { PreviewProblemsView } from './PreviewProblemsView';\nimport { PreviewSampleData, createPreviewSampleData } from './previewSampleData';\nimport { findSliceFragment } from './PreviewSliceFragment';\nimport { PreviewTarget } from './PreviewTarget';\nimport { PreviewInvocation, PreviewToast } from './PreviewToast';\nimport { PreviewPlan } from './resolvePreviewPlan';\n\nexport interface ScenePreviewHostProps {\n /** The document to preview - the in-memory one, unsaved edits included. */\n document: ApplicationDocument;\n\n /** The modules, features and slices of the application. */\n structure: ApplicationStructure | ApplicationStructureIndex;\n\n /** The application and module navigation regions; none when absent. */\n navigation?: NavigationModel;\n\n /** What to preview: a module, a feature or a slice. */\n target: PreviewTarget;\n\n /** The sample data to preview with; none when absent. */\n sampleData?: PreviewSampleData;\n\n /** The components to draw with. */\n registry: ComponentRegistry;\n\n /** What a submitted slice dialog goes through; a dry run, which only validates and reports, when absent (PRV5). */\n invoker?: SliceInvoker;\n\n /** Called for every dry run that passes validation, with what would have been sent. */\n onInvoked?(invocation: PreviewInvocation): void;\n\n /** The fields of a command, for the slice dialogs; the preview's sample rows fill their starting values. */\n fieldsFor?: SliceCommandFieldsSource;\n\n /** What the host decides about composition, such as the packages names resolve against. */\n composition?: CompositionOptions;\n\n /** The theme to apply; Studio passes the application's selected one (PRV9). */\n theme?: Theme;\n\n /** Hides a navigation item the preview user is not allowed to see. */\n isVisible?(item: EffectiveNavItem): boolean;\n\n /** Keeps the preview's navigation; an in-memory history by default, so a preview never touches the host's address (PRV4). */\n history?: SceneHistory;\n\n /** Called with the problems found - blocking or not - whenever they change (PRV8). */\n onProblems?(problems: PreviewProblem[]): void;\n\n /** Called when the author follows a problem to its node. */\n onSelectProblem?(problem: PreviewProblem): void;\n\n /** Called with what is being previewed, `Sales`, `Orders`, ... - the strip's breadcrumb (PRV7). */\n onBreadcrumbChange?(breadcrumb: string[]): void;\n\n /** Called when Escape is pressed with no dialog open: the host exits the preview (PRV7). */\n onExit?(): void;\n\n /** Extra content inside the host, such as a design layer's strip. */\n children?: ReactNode;\n}\n\nconst previewPageScreen = '#preview-page';\nconst noNavigation: NavigationModel = { application: { regions: [] }, modules: [] };\n\n/** The page a slice preview happens over when its feature has no screen of its own, or a State View's fragment is shown. */\nfunction minimalPage(layout: string, content: Screen['slotContent'][string]): Screen {\n return {\n name: previewPageScreen,\n layout,\n slotContent: { [SlotName.Content]: content },\n forms: [],\n contributions: [],\n };\n}\n\n/**\n * Renders the effective application (spec 10, PRV1-PRV9) from an in-memory document: the real shell, its navigation regions, the\n * first feature of a module, a feature, or a slice - a State Change slice as its task dialog over a minimal host page, a State View\n * slice as its data fragment.\n *\n * - **One code path**: the composition and the host are the Stage's own (`composeApplicationScreen`, `ApplicationHost`); nothing\n * here draws a shell, a menu or a dialog (PRV9).\n * - **Read-only**: no design affordances, no edits (PRV8) - a toolbar button without a slice shows no warning badge here; it is\n * reported as a problem instead. A model that cannot render - an unknown target, a feature without a screen,\n * a layout or template nobody provides - gives a {@link PreviewProblemsView} and `onProblems`, not a blank screen.\n * - **Navigation** keeps to an in-memory history; a different module swaps the shell's effective navigation (PRV4).\n * - **Dialogs** submit through the dry-run invoker unless one is given: validation runs, nothing is sent, a toast says so (PRV5).\n * - **Data** is the active sample data pack's (PRV6); the same seed shows the same rows.\n * - The strip (`Previewing`, sample data, `Exit preview · Esc`) is the host application's: this reports the breadcrumb and calls\n * `onExit` on Escape.\n */\nexport function ScenePreviewHost({\n document: application, structure, navigation = noNavigation, target, sampleData, registry, invoker, onInvoked, fieldsFor, composition = {},\n theme, isVisible, history, onProblems, onSelectProblem, onBreadcrumbChange, onExit, children,\n}: ScenePreviewHostProps) {\n const index = useMemo(() => structure instanceof ApplicationStructureIndex ? structure : new ApplicationStructureIndex(structure), [structure]);\n const compose = useMemo<CompositionOptions>(() => ({ logo: navigation.application.logo, ...composition }), [composition, navigation.application.logo]);\n const diagnosis = useMemo(\n () => diagnosePreview({ document: application, structure: index, navigation, target, packs: sampleData?.packs, composition: compose }),\n [application, compose, index, navigation, sampleData?.packs, target]);\n\n const problems = useMemo(() => {\n const found = [...diagnosis.problems];\n const { plan, screen } = diagnosis;\n if (plan?.kind === 'stateView' && screen && plan.slice) {\n const slice = index.findSlice(plan.slice);\n if (slice && findSliceFragment(screen, plan.slice, slice).length === 0) {\n found.push({ code: PreviewProblemCode.SliceFragmentMissing, severity: PreviewProblemSeverity.Warning, message: `Nothing on the screen '${screen.name}' is bound to the State View '${plan.slice}', so its page is shown.`, nodeId: plan.slice });\n }\n }\n\n return found;\n }, [diagnosis, index]);\n\n const key = JSON.stringify(problems);\n const reported = useRef<string | undefined>(undefined);\n useEffect(() => {\n if (reported.current === key) return;\n reported.current = key;\n onProblems?.(problems);\n }, [key, onProblems, problems]);\n\n const breadcrumb = diagnosis.plan?.breadcrumb;\n const breadcrumbKey = breadcrumb?.join('\\u0000');\n useEffect(() => {\n if (breadcrumb) onBreadcrumbChange?.(breadcrumb);\n // `breadcrumbKey` is the value of `breadcrumb`.\n }, [breadcrumbKey, onBreadcrumbChange]);\n\n const [memoryHistory] = useState(() => createMemorySceneHistory());\n const [toast, setToast] = useState<PreviewInvocation>();\n const dryRun = useMemo(() => createDryRunInvoker({\n onInvoked: invocation => {\n setToast(invocation);\n onInvoked?.(invocation);\n },\n }), [onInvoked]);\n\n const samples = useMemo(() => createPreviewSampleData(application, sampleData), [application, sampleData]);\n const fields = useMemo<SliceCommandFieldsSource>(() => (command, slice) => samples.commandFields(command, fieldsFor?.(command, slice) ?? []), [fieldsFor, samples]);\n\n const page = useMemo(() => {\n const { plan, screen } = diagnosis;\n if (!plan) return undefined;\n\n if (!screen) {\n // A slice whose feature has no screen of its own: a minimal host page, headed with where it is.\n if (plan.slice === undefined) return undefined;\n const layout = previewProfile(application.uiProfiles).layout ?? LayoutName.AppShell;\n const header = externalComponent('preview-page-header', ComponentName.PageHeader, { title: plan.breadcrumb.slice(0, -1).join(' › ') || plan.breadcrumb[0] });\n return { screens: [...application.screens, minimalPage(layout, [header])], initial: previewPageScreen };\n }\n\n if (plan.kind === 'stateView' && plan.slice) {\n const slice = index.findSlice(plan.slice);\n const fragment = slice ? findSliceFragment(screen, plan.slice, slice) : [];\n if (fragment.length > 0) return { screens: [...application.screens, minimalPage(screen.layout, fragment)], initial: previewPageScreen };\n }\n\n return { screens: application.screens, initial: screen.name };\n }, [application.screens, application.uiProfiles, diagnosis, index]);\n\n const hostApplication = useMemo(() => page ? { ...application, screens: page.screens } : application, [application, page]);\n const navigationModel = useMemo(() => ({ structure: index, navigation, isVisible }), [index, isVisible, navigation]);\n\n const onKeyDown = useCallback((event: KeyboardEvent) => {\n if (event.key === 'Escape' && !event.defaultPrevented) onExit?.();\n }, [onExit]);\n\n if (hasBlockingProblem(problems) || !page) {\n return <PreviewProblemsView problems={problems.filter(problem => problem.severity === PreviewProblemSeverity.Error)} onSelectProblem={onSelectProblem} />;\n }\n\n const body = (\n <SliceInvokerProvider invoker={invoker ?? dryRun} warnEmptySlices={false}>\n <SliceCommandFieldsProvider fieldsFor={fields}>\n <div className='scene-preview-host' data-scene-preview={diagnosis.plan?.kind} data-preview-breadcrumb={breadcrumb?.join(' › ')}>\n <ApplicationHost\n application={hostApplication}\n composition={compose}\n navigationModel={navigationModel}\n registry={registry}\n initialScreen={page.initial}\n history={history ?? memoryHistory}\n resolveBinding={samples.resolveBinding}\n queryResults={samples.queryResults}>\n {diagnosis.plan?.kind === 'stateChange' && <OpenSliceDialog index={index} plan={diagnosis.plan} />}\n <EscapeToExit onKeyDown={onKeyDown} enabled={onExit !== undefined} />\n {toast && invoker === undefined && <PreviewToast invocation={toast} onDismiss={() => setToast(undefined)} />}\n {children}\n </ApplicationHost>\n </div>\n </SliceCommandFieldsProvider>\n </SliceInvokerProvider>\n );\n\n return theme ? <SceneThemeProvider theme={theme}>{body}</SceneThemeProvider> : body;\n}\n\n/** Opens the task dialog of a State Change slice once the page is up - the slice preview (PRV3). */\nfunction OpenSliceDialog({ index, plan }: { index: ApplicationStructureIndex; plan: PreviewPlan }) {\n const navigation = useSceneNavigation();\n const opened = useRef(false);\n useEffect(() => {\n if (opened.current || plan.slice === undefined) return;\n const slice = index.findSlice(plan.slice);\n if (!slice || slice.kind !== SliceKind.StateChange) return;\n\n const destination = sliceDialogDestination(resolveToolbarButton(index, { id: plan.slice, title: slice.name, slice: plan.slice }));\n if (destination === undefined) return;\n opened.current = true;\n navigation.navigate(destination);\n }, [index, navigation, plan.slice]);\n\n return null;\n}\n\n/** Exits the preview on Escape, unless something - an open dialog - already used the key. */\nfunction EscapeToExit({ onKeyDown, enabled }: { onKeyDown(event: KeyboardEvent): void; enabled: boolean }) {\n const navigation = useSceneNavigation();\n const dialogOpen = navigation.currentDialog !== undefined;\n useEffect(() => {\n if (!enabled || dialogOpen) return undefined;\n globalThis.addEventListener('keydown', onKeyDown);\n return () => globalThis.removeEventListener('keydown', onKeyDown);\n }, [dialogOpen, enabled, onKeyDown]);\n\n return null;\n}\n"],"names":["previewPageScreen","noNavigation","application","regions","modules","minimalPage","layout","content","name","slotContent","SlotName","Content","forms","contributions","ScenePreviewHost","document","structure","navigation","target","sampleData","registry","invoker","onInvoked","fieldsFor","composition","theme","isVisible","history","onProblems","onSelectProblem","onBreadcrumbChange","onExit","children","index","useMemo","ApplicationStructureIndex","compose","logo","diagnosis","diagnosePreview","packs","problems","found","plan","screen","kind","slice","findSlice","findSliceFragment","length","push","code","PreviewProblemCode","SliceFragmentMissing","severity","PreviewProblemSeverity","Warning","message","nodeId","key","JSON","stringify","reported","useRef","undefined","useEffect","current","breadcrumb","breadcrumbKey","join","memoryHistory","useState","createMemorySceneHistory","toast","setToast","dryRun","createDryRunInvoker","invocation","samples","createPreviewSampleData","fields","command","commandFields","page","previewProfile","uiProfiles","LayoutName","AppShell","header","externalComponent","ComponentName","PageHeader","title","screens","initial","fragment","hostApplication","navigationModel","onKeyDown","useCallback","event","defaultPrevented","hasBlockingProblem","_jsx","PreviewProblemsView","filter","problem","Error","body","SliceInvokerProvider","warnEmptySlices","SliceCommandFieldsProvider","div","className","data-scene-preview","data-preview-breadcrumb","_jsxs","ApplicationHost","initialScreen","resolveBinding","queryResults","OpenSliceDialog","EscapeToExit","enabled","PreviewToast","onDismiss","SceneThemeProvider","useSceneNavigation","opened","SliceKind","StateChange","destination","sliceDialogDestination","resolveToolbarButton","id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C,kCAAAA,CAAuBC,iCAAAA,CAAqBpG,KAAAA,EAAO;AAAEqG,YAAAA,EAAAA,EAAI3F,KAAKG,KAAK;AAAE8C,YAAAA,KAAAA,EAAO9C,MAAMtC,IAAI;AAAEsC,YAAAA,KAAAA,EAAOH,KAAKG;AAAM,SAAA,CAAA,CAAA;AAC9H,QAAA,IAAIqF,gBAAgBnE,SAAAA,EAAW;AAC/BgE,QAAAA,MAAAA,CAAO9D,OAAO,GAAG,IAAA;AACjBjD,QAAAA,UAAAA,CAAWsH,QAAQ,CAACJ,WAAAA,CAAAA;IACxB,CAAA,EAAG;AAAClG,QAAAA,KAAAA;AAAOhB,QAAAA,UAAAA;AAAY0B,QAAAA,IAAAA,CAAKG;AAAM,KAAA,CAAA;IAElC,OAAO,IAAA;AACX;AAEA,8FACA,SAAS4E,YAAAA,CAAa,EAAExB,SAAS,EAAEyB,OAAO,EAA+D,EAAA;AACrG,IAAA,MAAM1G,UAAAA,GAAa8G,8BAAAA,EAAAA;IACnB,MAAMS,UAAAA,GAAavH,UAAAA,CAAWwH,aAAa,KAAKzE,SAAAA;IAChDC,eAAAA,CAAU,IAAA;QACN,IAAI,CAAC0D,OAAAA,IAAWa,UAAAA,EAAY,OAAOxE,SAAAA;QACnC0E,UAAAA,CAAWC,gBAAgB,CAAC,SAAA,EAAWzC,SAAAA,CAAAA;AACvC,QAAA,OAAO,IAAMwC,UAAAA,CAAWE,mBAAmB,CAAC,SAAA,EAAW1C,SAAAA,CAAAA;IAC3D,CAAA,EAAG;AAACsC,QAAAA,UAAAA;AAAYb,QAAAA,OAAAA;AAASzB,QAAAA;AAAU,KAAA,CAAA;IAEnC,OAAO,IAAA;AACX;;"}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var scene_model = require('@cratis/scene.model');
|
|
4
|
+
var scene_engine = require('@cratis/scene.engine');
|
|
5
|
+
var ComponentName = require('../ComponentName.js');
|
|
6
|
+
var elements = require('../gallery/elements.js');
|
|
7
|
+
var resolveElementNames = require('../gallery/resolveElementNames.js');
|
|
8
|
+
var screens = require('../gallery/screens.js');
|
|
9
|
+
var SlotName = require('../layouts/SlotName.js');
|
|
10
|
+
var shellComponents = require('../layouts/shellComponents.js');
|
|
11
|
+
require('../layouts/appShell.js');
|
|
12
|
+
require('../layouts/fullPage.js');
|
|
13
|
+
var defaultLayouts = require('../layouts/defaultLayouts.js');
|
|
14
|
+
var ApplicationDocument = require('./ApplicationDocument.js');
|
|
15
|
+
var defaultApplicationChrome = require('./defaultApplicationChrome.js');
|
|
16
|
+
var PreviewTemplate = require('./PreviewTemplate.js');
|
|
17
|
+
var previewProfile = require('./previewProfile.js');
|
|
18
|
+
|
|
19
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
20
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
21
|
+
function previewCatalog(options) {
|
|
22
|
+
return options.catalog ?? previewProfile.blueprintPackageCatalog;
|
|
23
|
+
}
|
|
24
|
+
function profileOf(application, options) {
|
|
25
|
+
return options.profile ?? previewProfile.previewProfile(application.uiProfiles);
|
|
26
|
+
}
|
|
27
|
+
function defaultForm(screenName, form) {
|
|
28
|
+
return elements.externalComponent(`form-${screenName}-${form.name}`, 'commandForm', {
|
|
29
|
+
command: form.forCommand,
|
|
30
|
+
label: form.name,
|
|
31
|
+
generationMode: form.generationMode,
|
|
32
|
+
layout: form.layout,
|
|
33
|
+
fields: form.fields
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function mergeSlots(...sources) {
|
|
37
|
+
const merged = {};
|
|
38
|
+
for (const source of sources){
|
|
39
|
+
for (const [slot, elements] of Object.entries(source ?? {}))merged[slot] = [
|
|
40
|
+
...merged[slot] ?? [],
|
|
41
|
+
...elements
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
return merged;
|
|
45
|
+
}
|
|
46
|
+
/** The layout a screen names: the document's own, or one the blueprint provides. */ function findLayout(application, name, options = {}) {
|
|
47
|
+
return application.layouts.find((candidate)=>candidate.name === name) ?? (options.blueprintLayouts ?? defaultLayouts.defaultLayouts).find((candidate)=>candidate.name === name);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The templates a screen is composed with: the document's own, then the blueprint's for any name the document does not declare.
|
|
51
|
+
* A model that writes `template CrudList` without declaring it is naming one of the blueprint's templates; the document's
|
|
52
|
+
* own declaration always wins the name.
|
|
53
|
+
*/ function templatesOf(application, options = {}) {
|
|
54
|
+
const own = application.screenTemplates;
|
|
55
|
+
return [
|
|
56
|
+
...own,
|
|
57
|
+
...(options.blueprintTemplates ?? screens.galleryScreenTemplates).filter((template)=>!own.some((candidate)=>candidate.name === template.name))
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The templates a screen's template chain is worked out among: the document's own when the screen's template is one of them,
|
|
62
|
+
* otherwise the blueprint's as well. The blueprint's templates are never mixed into a document's own chain - several of them fit
|
|
63
|
+
* the same slot name, which would make every slot ambiguous.
|
|
64
|
+
*/ function templatePoolFor(application, screen, options = {}) {
|
|
65
|
+
return application.screenTemplates.some((candidate)=>candidate.name === screen.screenTemplate) ? application.screenTemplates : templatesOf(application, options);
|
|
66
|
+
}
|
|
67
|
+
/** The slot of the layout a template chain's outermost template fits: its declared slot, or `content`. */ function layoutSlotOf(layout, outermost) {
|
|
68
|
+
const fits = outermost.fitsSlot;
|
|
69
|
+
if (fits === undefined) return SlotName.SlotName.Content;
|
|
70
|
+
const slot = fits.includes('.') ? fits.slice(fits.lastIndexOf('.') + 1) : fits;
|
|
71
|
+
return layout === undefined || layout.slots.some((candidate)=>candidate.name === slot) ? slot : SlotName.SlotName.Content;
|
|
72
|
+
}
|
|
73
|
+
/** The templates a screen's own template sits inside, outermost first, ending with the screen's own template. */ function templateChainOf(application, screen, options = {}) {
|
|
74
|
+
if (!screen.screenTemplate) return [];
|
|
75
|
+
const templates = templatePoolFor(application, screen, options);
|
|
76
|
+
const own = templates.find((candidate)=>candidate.name === screen.screenTemplate);
|
|
77
|
+
if (!own) return [];
|
|
78
|
+
const layout = findLayout(application, screen.layout, options);
|
|
79
|
+
const placements = layout ? scene_engine.resolveScreenTemplates(layout, templates).placements : [];
|
|
80
|
+
const chain = [
|
|
81
|
+
own
|
|
82
|
+
];
|
|
83
|
+
for(let guard = 0; guard <= templates.length; guard++){
|
|
84
|
+
const placement = placements.find((candidate)=>candidate.template === chain[0].name);
|
|
85
|
+
if (!placement || placement.container === layout?.name) break;
|
|
86
|
+
const parent = templates.find((candidate)=>candidate.name === placement.container);
|
|
87
|
+
if (!parent || chain.includes(parent)) break;
|
|
88
|
+
chain.unshift(parent);
|
|
89
|
+
}
|
|
90
|
+
return chain;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* What a screen puts in the shell's content slot: the screen - inside the template chain it names, when it names one - and the
|
|
94
|
+
* forms it hosts. The same content fills the shell on the primary region and a nested outlet.
|
|
95
|
+
*
|
|
96
|
+
* The innermost template takes the screen's own slot content; each template outside it holds the one inside in the slot it
|
|
97
|
+
* declared (`fitsSlot`), so the chain's arrangements all apply.
|
|
98
|
+
*/ function screenContent(application, screen, options = {}) {
|
|
99
|
+
const form = options.form ?? defaultForm;
|
|
100
|
+
const forms = screen.forms.map((candidate)=>form(screen.name, candidate));
|
|
101
|
+
const chain = templateChainOf(application, screen, options);
|
|
102
|
+
if (chain.length === 0) {
|
|
103
|
+
return {
|
|
104
|
+
content: [
|
|
105
|
+
...Object.values(screen.slotContent).flat(),
|
|
106
|
+
...forms
|
|
107
|
+
],
|
|
108
|
+
templates: [],
|
|
109
|
+
slot: SlotName.SlotName.Content
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
let inner;
|
|
113
|
+
for(let index = chain.length - 1; index >= 0; index--){
|
|
114
|
+
const template = chain[index];
|
|
115
|
+
const slots = index === chain.length - 1 ? mergeSlots(template.content, screen.slotContent, {
|
|
116
|
+
forms
|
|
117
|
+
}) : mergeSlots(template.content, {
|
|
118
|
+
[slotName(chain[index + 1])]: [
|
|
119
|
+
inner
|
|
120
|
+
]
|
|
121
|
+
});
|
|
122
|
+
inner = elements.externalComponent(`template-${screen.name}-${template.name}`, PreviewTemplate.previewTemplateComponent, {
|
|
123
|
+
arrangement: template.arrangement
|
|
124
|
+
}, slots);
|
|
125
|
+
}
|
|
126
|
+
const layout = findLayout(application, screen.layout, options);
|
|
127
|
+
return {
|
|
128
|
+
content: [
|
|
129
|
+
inner
|
|
130
|
+
],
|
|
131
|
+
templates: chain.map((template)=>template.name),
|
|
132
|
+
slot: layoutSlotOf(layout, chain[0])
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function slotName(template) {
|
|
136
|
+
const fits = template.fitsSlot ?? SlotName.SlotName.Content;
|
|
137
|
+
return fits.includes('.') ? fits.slice(fits.lastIndexOf('.') + 1) : fits;
|
|
138
|
+
}
|
|
139
|
+
function finish(element, profile, catalog, options) {
|
|
140
|
+
const decorated = options.decorate ? options.decorate(element) : element;
|
|
141
|
+
return resolveElementNames.resolveElementComponentNames(decorated, profile, catalog);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Composes one screen the way the application shows it: the shell for the screen's layout, the chrome every screen shares in the
|
|
145
|
+
* shell's slots, and the screen - inside the template chain it names - in the slot the chain fits. Stage and the preview host
|
|
146
|
+
* both compose through this, so a screen is the same screen in both (spec PRV9, REN2).
|
|
147
|
+
*
|
|
148
|
+
* A layout the selected package set does not provide stays unresolved in the rendered tree: showing that missing component is
|
|
149
|
+
* deliberate, because silently substituting a default shell would hide a package/profile problem.
|
|
150
|
+
*
|
|
151
|
+
* @param application The document and profiles.
|
|
152
|
+
* @param screen The screen to compose.
|
|
153
|
+
* @param options What the host decides.
|
|
154
|
+
* @returns The element to render, the configuration its templates resolved, and the templates around the screen.
|
|
155
|
+
*/ function composeApplicationScreen(application, screen, options = {}) {
|
|
156
|
+
const profile = profileOf(application, options);
|
|
157
|
+
const { content, templates, slot } = screenContent(application, screen, options);
|
|
158
|
+
const shell = shellComponents.shellComponentForLayout(screen.layout) ?? screen.layout;
|
|
159
|
+
const chrome = options.chrome ? options.chrome(screen, shell) : shell === ComponentName.ComponentName.FullPageShell ? {} : defaultApplicationChrome.defaultApplicationChrome(options.logo);
|
|
160
|
+
const composed = elements.externalComponent(`screen-${screen.name}`, shell, {
|
|
161
|
+
screenName: screen.name
|
|
162
|
+
}, {
|
|
163
|
+
...chrome,
|
|
164
|
+
[slot]: [
|
|
165
|
+
...chrome[slot] ?? [],
|
|
166
|
+
...content,
|
|
167
|
+
...slot === SlotName.SlotName.Content ? options.trailing ?? [] : []
|
|
168
|
+
]
|
|
169
|
+
});
|
|
170
|
+
return {
|
|
171
|
+
element: finish(composed, profile, previewCatalog(options), options),
|
|
172
|
+
configuration: configurationOf(application, screen, options),
|
|
173
|
+
templates
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* A screen as it appears inside an outlet of another screen: its content alone, without the shell the primary region wraps
|
|
178
|
+
* every screen in, with the same name resolution.
|
|
179
|
+
*/ function composeOutletScreen(application, screen, options = {}) {
|
|
180
|
+
const { content } = screenContent(application, screen, options);
|
|
181
|
+
const element = content.length === 1 ? content[0] : {
|
|
182
|
+
id: `outlet-${screen.name}`,
|
|
183
|
+
children: content
|
|
184
|
+
};
|
|
185
|
+
return finish(element, profileOf(application, options), previewCatalog(options), options);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* A dialog template as it is shown over the application: its slot content inside the template wrapper, with the arrangement the
|
|
189
|
+
* template wrote, names resolved - the same wrapper a screen's template gets.
|
|
190
|
+
*/ function composeDialog(application, template, options = {}) {
|
|
191
|
+
const element = elements.externalComponent(`dialog-${template.name}`, PreviewTemplate.previewTemplateComponent, {
|
|
192
|
+
arrangement: template.arrangement
|
|
193
|
+
}, template.content ?? {});
|
|
194
|
+
return finish(element, profileOf(application, options), previewCatalog(options), options);
|
|
195
|
+
}
|
|
196
|
+
function configurationOf(application, screen, options) {
|
|
197
|
+
if (!options.descriptors || (application.instanceContributions ?? []).length === 0) return undefined;
|
|
198
|
+
const templates = templatesOf(application, options);
|
|
199
|
+
const document = {
|
|
200
|
+
...ApplicationDocument.completeDocument(application),
|
|
201
|
+
screenTemplates: templates,
|
|
202
|
+
layouts: [
|
|
203
|
+
...application.layouts,
|
|
204
|
+
...(options.blueprintLayouts ?? defaultLayouts.defaultLayouts).filter((layout)=>!application.layouts.some((own)=>own.name === layout.name))
|
|
205
|
+
]
|
|
206
|
+
};
|
|
207
|
+
const chain = scene_engine.resolveTemplateChain(document, {
|
|
208
|
+
kind: scene_model.EditingScopeKind.Screen,
|
|
209
|
+
name: screen.name
|
|
210
|
+
});
|
|
211
|
+
return scene_engine.resolveEffectiveConfiguration(chain, document.instanceContributions, options.descriptors);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Every destination the document authors - on actions, navigations, contributions and toolbar items - wherever it sits, so a
|
|
215
|
+
* route override on one of them can be deep linked.
|
|
216
|
+
*/ function collectDestinations(application) {
|
|
217
|
+
const found = [];
|
|
218
|
+
const visit = (value)=>{
|
|
219
|
+
if (value === null || typeof value !== 'object') return;
|
|
220
|
+
if (Array.isArray(value)) {
|
|
221
|
+
value.forEach(visit);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
for (const [key, entry] of Object.entries(value)){
|
|
225
|
+
if (key === 'destination' && entry !== null && typeof entry === 'object' && !Array.isArray(entry)) found.push(entry);
|
|
226
|
+
visit(entry);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
for (const screen of application.screens){
|
|
230
|
+
visit(screen.slotContent);
|
|
231
|
+
visit(screen.contributions);
|
|
232
|
+
}
|
|
233
|
+
for (const template of [
|
|
234
|
+
...application.screenTemplates,
|
|
235
|
+
...application.dialogTemplates ?? []
|
|
236
|
+
])visit(template.content);
|
|
237
|
+
return found;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
exports.collectDestinations = collectDestinations;
|
|
241
|
+
exports.composeApplicationScreen = composeApplicationScreen;
|
|
242
|
+
exports.composeDialog = composeDialog;
|
|
243
|
+
exports.composeOutletScreen = composeOutletScreen;
|
|
244
|
+
exports.findLayout = findLayout;
|
|
245
|
+
exports.screenContent = screenContent;
|
|
246
|
+
exports.templateChainOf = templateChainOf;
|
|
247
|
+
exports.templatePoolFor = templatePoolFor;
|
|
248
|
+
exports.templatesOf = templatesOf;
|
|
249
|
+
//# sourceMappingURL=composeApplication.js.map
|