@cratis/scene.blueprint.default 4.34.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/scene.blueprint.default",
3
- "version": "4.34.0",
3
+ "version": "4.35.0",
4
4
  "description": "The default blueprint: application shell layouts, the screen and dialog templates that go inside them, the components that fill their slots, and two themes.",
5
5
  "keywords": [
6
6
  "cratis",
@@ -55,15 +55,15 @@
55
55
  "build-storybook": "storybook build"
56
56
  },
57
57
  "dependencies": {
58
- "@cratis/scene.engine": "4.34.0",
59
- "@cratis/scene.model": "4.34.0",
60
- "@cratis/scene.react": "4.34.0"
58
+ "@cratis/scene.engine": "4.35.0",
59
+ "@cratis/scene.model": "4.35.0",
60
+ "@cratis/scene.react": "4.35.0"
61
61
  },
62
62
  "devDependencies": {
63
- "@cratis/scene.engine": "4.34.0",
64
- "@cratis/scene.model": "4.34.0",
65
- "@cratis/scene.primereact": "4.34.0",
66
- "@cratis/scene.react": "4.34.0",
63
+ "@cratis/scene.engine": "4.35.0",
64
+ "@cratis/scene.model": "4.35.0",
65
+ "@cratis/scene.primereact": "4.35.0",
66
+ "@cratis/scene.react": "4.35.0",
67
67
  "@primereact/core": "11.2.0",
68
68
  "@primereact/headless": "11.2.0",
69
69
  "@primeuix/themes": "^3.0.1",
@@ -2,7 +2,7 @@
2
2
  // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
 
4
4
  import { ReactNode, useMemo, useState } from 'react';
5
- import { SceneElement, type EffectiveConfiguration } from '@cratis/scene.model';
5
+ import { DialogTemplate, SceneElement, type EffectiveConfiguration } from '@cratis/scene.model';
6
6
  import { BindingResolver, BindingScope } from '@cratis/scene.engine';
7
7
  import {
8
8
  ComponentRegistry, SceneElementView, SceneHistory, SceneNavigationContextValue, SceneNavigationModel, SceneNavigationModelProvider,
@@ -50,6 +50,30 @@ export interface ApplicationHostProps {
50
50
  */
51
51
  renderDialog?(navigation: SceneNavigationContextValue): ReactNode;
52
52
 
53
+ /**
54
+ * Draws a dialog the document declares, in place of the host's plain one - a host that wants its own backdrop, a close button
55
+ * and keyboard handling around the template's content. Called inside {@link scope}.
56
+ * @param template The dialog template that is open.
57
+ * @param content The template's composed content.
58
+ * @param navigation Where the user is.
59
+ */
60
+ renderDialogTemplate?(template: DialogTemplate, content: SceneElement, navigation: SceneNavigationContextValue): ReactNode;
61
+
62
+ /**
63
+ * What a host provides around everything that renders - the screen on the page and the dialog over it: its data, its command
64
+ * dispatcher, its chrome state. Inside the navigation providers, so it can read where the user is. Stage puts its data and
65
+ * interaction scope here, so the screen, a dialog template and a slice dialog all share them.
66
+ * @param navigation Where the user is.
67
+ * @param children The screen and the dialog.
68
+ */
69
+ scope?(navigation: SceneNavigationContextValue, children: ReactNode): ReactNode;
70
+
71
+ /**
72
+ * Where the shell keeps its layout configuration - the sidebar's state, the chosen theme. A preview keeps none (null, the default);
73
+ * a running application passes its storage so what a user chose is still chosen on the next visit.
74
+ */
75
+ layoutConfigStorage?: Storage | null;
76
+
53
77
  /** Rendered inside the host's providers, after the application. */
54
78
  children?: ReactNode;
55
79
  }
@@ -61,7 +85,7 @@ export interface ApplicationHostProps {
61
85
  * button or a dialog destination opened shown over it - one place for all of it (spec PRV9), so a behaviour that differs between
62
86
  * the two hosts is a bug in the host, not a second implementation.
63
87
  */
64
- export function ApplicationHost({ application, composition = {}, navigationModel, registry: hostRegistry, initialScreen, history, resolveBinding, queryResults, renderScreen, renderDialog, children }: ApplicationHostProps) {
88
+ export function ApplicationHost({ application, composition = {}, navigationModel, registry: hostRegistry, initialScreen, history, resolveBinding, queryResults, renderScreen, renderDialog, renderDialogTemplate, scope, layoutConfigStorage = null, children }: ApplicationHostProps) {
65
89
  const [memoryHistory] = useState(() => createMemorySceneHistory());
66
90
  const registry = useMemo(() => ({ ...previewComponents, ...hostRegistry }), [hostRegistry]);
67
91
  const hostHistory = history ?? memoryHistory;
@@ -86,25 +110,37 @@ export function ApplicationHost({ application, composition = {}, navigationModel
86
110
  const sliceDialog = !dialogTemplate && navigation.currentDialog && sliceDialogParameters(navigation.currentDialogParameters) !== undefined;
87
111
  const dialogName = sliceDialogParameters(navigation.currentDialogParameters)?.title ?? navigation.currentDialog;
88
112
 
89
- const drawn = composed
90
- ? renderScreen?.(composed.element, composed.configuration, navigation)
91
- ?? <SceneElementView element={composed.element} registry={registry} resolveBinding={resolveBinding} queryResults={queryResults} configuration={composed.configuration} />
92
- : null;
113
+ const dialogContent = dialogTemplate ? composeDialog(application, dialogTemplate, composition) : undefined;
114
+
115
+ const body = (
116
+ <>
117
+ <div data-scene-outlet='primary' data-scene-url={navigation.currentUrl} data-scene-screen={navigation.primaryScreen}>
118
+ {composed && <Drawn>{renderScreen
119
+ ? () => renderScreen(composed.element, composed.configuration, navigation)
120
+ : () => <SceneElementView element={composed.element} registry={registry} resolveBinding={resolveBinding} queryResults={queryResults} configuration={composed.configuration} />}</Drawn>}
121
+ </div>
122
+ {dialogTemplate && dialogContent && (renderDialogTemplate
123
+ ? <Drawn>{() => renderDialogTemplate(dialogTemplate, dialogContent, navigation)}</Drawn>
124
+ : (
125
+ <div role='dialog' aria-modal='true' aria-label={dialogName} data-scene-dialog={navigation.currentDialog}>
126
+ <SceneElementView element={dialogContent} registry={registry} resolveBinding={resolveBinding} queryResults={queryResults} />
127
+ </div>
128
+ ))}
129
+ {sliceDialog && (
130
+ <div role='dialog' aria-modal='true' aria-label={dialogName} data-scene-dialog={navigation.currentDialog}>
131
+ {renderDialog?.(navigation) ?? <SliceDialogView />}
132
+ </div>
133
+ )}
134
+ </>
135
+ );
93
136
 
94
137
  return (
95
138
  <SceneNavigationProvider value={navigation}>
96
139
  <SceneOutletContext.Provider value={outletContext}>
97
140
  <SceneNavigationModelProvider model={navigationModel}>
98
- {/* The shell reads its layout configuration from a provider; nothing is saved from a hosted application's own. */}
99
- <LayoutConfigProvider storage={null}>
100
- <div data-scene-outlet='primary' data-scene-url={navigation.currentUrl} data-scene-screen={navigation.primaryScreen}>{drawn}</div>
101
- {(dialogTemplate || sliceDialog) && (
102
- <div role='dialog' aria-modal='true' aria-label={dialogName} data-scene-dialog={navigation.currentDialog}>
103
- {dialogTemplate
104
- ? <SceneElementView element={composeDialog(application, dialogTemplate, composition)} registry={registry} resolveBinding={resolveBinding} queryResults={queryResults} />
105
- : renderDialog?.(navigation) ?? <SliceDialogView />}
106
- </div>
107
- )}
141
+ {/* The shell reads its layout configuration from a provider; nothing is saved unless the host gives it somewhere to. */}
142
+ <LayoutConfigProvider storage={layoutConfigStorage}>
143
+ {scope ? scope(navigation, body) : body}
108
144
  {children}
109
145
  </LayoutConfigProvider>
110
146
  </SceneNavigationModelProvider>
@@ -112,3 +148,8 @@ export function ApplicationHost({ application, composition = {}, navigationModel
112
148
  </SceneNavigationProvider>
113
149
  );
114
150
  }
151
+
152
+ /** Calls what a host draws as part of this component, so a hook it uses runs under the providers the host put in scope. */
153
+ function Drawn({ children }: { children(): ReactNode }) {
154
+ return <>{children()}</>;
155
+ }