@cratis/scene.react 4.14.0 → 4.16.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/core/ScreenplayCoreComponents.tsx +24 -3
- package/dist/cjs/SceneElementView.js +1 -0
- package/dist/cjs/SceneElementView.js.map +1 -1
- package/dist/cjs/core/ScreenplayCoreComponents.js +25 -5
- package/dist/cjs/core/ScreenplayCoreComponents.js.map +1 -1
- package/dist/cjs/index.js +11 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/navigation/createHashSceneHistory.js +43 -0
- package/dist/cjs/navigation/createHashSceneHistory.js.map +1 -0
- package/dist/cjs/packages/PackageHostConfiguration.js +18 -2
- package/dist/cjs/packages/PackageHostConfiguration.js.map +1 -1
- package/dist/cjs/packages/isNetworkAsset.js +18 -0
- package/dist/cjs/packages/isNetworkAsset.js.map +1 -0
- package/dist/cjs/renderer/RenderBindingScopeContext.js +15 -5
- package/dist/cjs/renderer/RenderBindingScopeContext.js.map +1 -1
- package/dist/cjs/renderer/useBoundQuery.js +50 -0
- package/dist/cjs/renderer/useBoundQuery.js.map +1 -0
- package/dist/cjs/renderer/useValueOutput.js +31 -0
- package/dist/cjs/renderer/useValueOutput.js.map +1 -0
- package/dist/cjs/renderer/valueOutputProperty.js +28 -0
- package/dist/cjs/renderer/valueOutputProperty.js.map +1 -0
- package/dist/esm/SceneElementView.js +1 -0
- package/dist/esm/SceneElementView.js.map +1 -1
- package/dist/esm/core/ScreenplayCoreComponents.d.ts.map +1 -1
- package/dist/esm/core/ScreenplayCoreComponents.js +25 -5
- package/dist/esm/core/ScreenplayCoreComponents.js.map +1 -1
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/navigation/createHashSceneHistory.d.ts +4 -0
- package/dist/esm/navigation/createHashSceneHistory.d.ts.map +1 -0
- package/dist/esm/navigation/createHashSceneHistory.js +41 -0
- package/dist/esm/navigation/createHashSceneHistory.js.map +1 -0
- package/dist/esm/navigation/index.d.ts +1 -0
- package/dist/esm/navigation/index.d.ts.map +1 -1
- package/dist/esm/navigation/index.js +1 -0
- package/dist/esm/navigation/index.js.map +1 -1
- package/dist/esm/packages/PackageHostConfiguration.d.ts +2 -0
- package/dist/esm/packages/PackageHostConfiguration.d.ts.map +1 -1
- package/dist/esm/packages/PackageHostConfiguration.js +19 -3
- package/dist/esm/packages/PackageHostConfiguration.js.map +1 -1
- package/dist/esm/packages/index.d.ts +1 -0
- package/dist/esm/packages/index.d.ts.map +1 -1
- package/dist/esm/packages/index.js +1 -0
- package/dist/esm/packages/index.js.map +1 -1
- package/dist/esm/packages/isNetworkAsset.d.ts +2 -0
- package/dist/esm/packages/isNetworkAsset.d.ts.map +1 -0
- package/dist/esm/packages/isNetworkAsset.js +16 -0
- package/dist/esm/packages/isNetworkAsset.js.map +1 -0
- package/dist/esm/renderer/RenderBindingScopeContext.d.ts.map +1 -1
- package/dist/esm/renderer/RenderBindingScopeContext.js +17 -7
- package/dist/esm/renderer/RenderBindingScopeContext.js.map +1 -1
- package/dist/esm/renderer/index.d.ts +3 -0
- package/dist/esm/renderer/index.d.ts.map +1 -1
- package/dist/esm/renderer/index.js +3 -0
- package/dist/esm/renderer/index.js.map +1 -1
- package/dist/esm/renderer/useBoundQuery.d.ts +3 -0
- package/dist/esm/renderer/useBoundQuery.d.ts.map +1 -0
- package/dist/esm/renderer/useBoundQuery.js +48 -0
- package/dist/esm/renderer/useBoundQuery.js.map +1 -0
- package/dist/esm/renderer/useValueOutput.d.ts +4 -0
- package/dist/esm/renderer/useValueOutput.d.ts.map +1 -0
- package/dist/esm/renderer/useValueOutput.js +28 -0
- package/dist/esm/renderer/useValueOutput.js.map +1 -0
- package/dist/esm/renderer/valueOutputProperty.d.ts +3 -0
- package/dist/esm/renderer/valueOutputProperty.d.ts.map +1 -0
- package/dist/esm/renderer/valueOutputProperty.js +26 -0
- package/dist/esm/renderer/valueOutputProperty.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/navigation/createHashSceneHistory.ts +42 -0
- package/navigation/index.ts +1 -0
- package/package.json +5 -5
- package/packages/PackageHostConfiguration.ts +26 -3
- package/packages/index.ts +1 -0
- package/packages/isNetworkAsset.ts +15 -0
- package/renderer/RenderBindingScopeContext.tsx +12 -8
- package/renderer/index.ts +3 -0
- package/renderer/useBoundQuery.ts +50 -0
- package/renderer/useValueOutput.ts +28 -0
- package/renderer/valueOutputProperty.ts +25 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Copyright (c) Cratis. All rights reserved.
|
|
2
2
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { resolveArgumentSource } from '@cratis/scene.engine';
|
|
5
|
+
import { RegisteredComponentProps, useRenderBindingScope } from '../renderer';
|
|
5
6
|
|
|
6
7
|
function textProperty(properties: Record<string, unknown>, name: string, fallback = ''): string {
|
|
7
8
|
return typeof properties[name] === 'string' ? properties[name] : fallback;
|
|
@@ -12,11 +13,31 @@ export function CoreData({ element }: RegisteredComponentProps) {
|
|
|
12
13
|
return <span hidden data-scene-id={element.id} data-scene-data={textProperty(element.properties, 'typeName')} />;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
/**
|
|
16
|
+
/** One entry of a command action's argument mapping. */
|
|
17
|
+
interface ArgumentMapping {
|
|
18
|
+
name?: unknown;
|
|
19
|
+
source?: unknown;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Renders a modeled command action and emits a host-neutral command event when invoked.
|
|
24
|
+
*
|
|
25
|
+
* The event carries the resolved `arguments`, by name, read when the action is invoked: a
|
|
26
|
+
* `component.<id>.<output>` source reads what another element publishes - such as what the user typed into
|
|
27
|
+
* an input - and any other source is a data-context path. Hosts that read the mapping from `element`
|
|
28
|
+
* themselves keep working.
|
|
29
|
+
*/
|
|
16
30
|
export function CoreAction({ element }: RegisteredComponentProps) {
|
|
17
31
|
const command = textProperty(element.properties, 'command');
|
|
18
32
|
const label = textProperty(element.properties, 'label', command);
|
|
19
|
-
const
|
|
33
|
+
const scope = useRenderBindingScope();
|
|
34
|
+
const invoke = () => {
|
|
35
|
+
const mapping = Array.isArray(element.properties.arguments) ? element.properties.arguments as ArgumentMapping[] : [];
|
|
36
|
+
const args = Object.fromEntries(mapping
|
|
37
|
+
.filter((argument): argument is { name: string; source: string } => typeof argument.name === 'string' && typeof argument.source === 'string')
|
|
38
|
+
.map(argument => [argument.name, resolveArgumentSource(argument.source, scope)]));
|
|
39
|
+
globalThis.dispatchEvent(new CustomEvent('cratis.scene.command', { detail: { command, element, arguments: args } }));
|
|
40
|
+
};
|
|
20
41
|
return <button type='button' data-scene-id={element.id} onClick={invoke}>{label}</button>;
|
|
21
42
|
}
|
|
22
43
|
|
|
@@ -4,6 +4,7 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
4
4
|
var react = require('react');
|
|
5
5
|
var scene_engine = require('@cratis/scene.engine');
|
|
6
6
|
var RenderBindingScopeContext = require('./renderer/RenderBindingScopeContext.js');
|
|
7
|
+
require('@cratis/scene.model');
|
|
7
8
|
var createReactRenderer = require('./renderer/createReactRenderer.js');
|
|
8
9
|
require('./interactions/useInteractions.js');
|
|
9
10
|
require('./interactions/NotificationHost.js');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SceneElementView.js","sources":["../../SceneElementView.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 { useMemo } from 'react';\nimport { applyEffectiveConfiguration, renderElement, BindingResolver } from '@cratis/scene.engine';\nimport { EffectiveConfiguration, SceneElement } from '@cratis/scene.model';\nimport { ComponentRegistry, RenderBindingScopeProvider, createReactRenderer, useRenderBindingResolver } from './renderer';\n\nexport interface SceneElementViewProps {\n element: SceneElement;\n registry: ComponentRegistry;\n resolveBinding?: BindingResolver;\n dataContext?: unknown;\n queryResults?: Record<string, unknown>;\n componentOutputs?: Record<string, Record<string, unknown>>;\n\n /**\n * The resolved configuration of the template chain the element sits in, from `resolveEffectiveConfiguration`.\n * When given, each configurable component renders with its resolved properties - what a screen's own values add\n * to an inherited template. It is the same data the editor shows, and the same code path whether the screen is\n * being edited or played: there is no design-time mode.\n */\n configuration?: EffectiveConfiguration;\n\n /** Called when rendered components publish or clear output properties for typed bindings. */\n onComponentOutputsChanged?: (outputs: Record<string, Record<string, unknown>>) => void;\n}\n\n/**\n * Renders a Scene element tree with the real `Scene.React` renderer - the WYSIWYG building block Studio's\n * preview surface and Stage's shipped web bundle both consume unmodified.\n */\nexport function SceneElementView({\n element,\n registry,\n resolveBinding,\n configuration,\n onComponentOutputsChanged,\n dataContext,\n queryResults,\n componentOutputs,\n}: SceneElementViewProps) {\n const configured = useMemo(() => configuration ? applyEffectiveConfiguration(element, configuration) : element, [element, configuration]);\n return (\n <RenderBindingScopeProvider\n dataContext={dataContext}\n queryResults={queryResults}\n componentOutputs={componentOutputs}\n resolveBinding={resolveBinding}\n onComponentOutputsChanged={onComponentOutputsChanged}>\n <RenderedElement element={configured} registry={registry} />\n </RenderBindingScopeProvider>\n );\n}\n\nfunction RenderedElement({ element, registry }: { element: SceneElement; registry: ComponentRegistry }) {\n const renderer = useMemo(() => createReactRenderer(registry), [registry]);\n const resolveBinding = useRenderBindingResolver();\n return <>{renderElement(element, renderer, resolveBinding)}</>;\n}\n"],"names":["SceneElementView","element","registry","resolveBinding","configuration","onComponentOutputsChanged","dataContext","queryResults","componentOutputs","configured","useMemo","applyEffectiveConfiguration","_jsx","RenderBindingScopeProvider","RenderedElement","renderer","createReactRenderer","useRenderBindingResolver","_Fragment","renderElement"],"mappings":"
|
|
1
|
+
{"version":3,"file":"SceneElementView.js","sources":["../../SceneElementView.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 { useMemo } from 'react';\nimport { applyEffectiveConfiguration, renderElement, BindingResolver } from '@cratis/scene.engine';\nimport { EffectiveConfiguration, SceneElement } from '@cratis/scene.model';\nimport { ComponentRegistry, RenderBindingScopeProvider, createReactRenderer, useRenderBindingResolver } from './renderer';\n\nexport interface SceneElementViewProps {\n element: SceneElement;\n registry: ComponentRegistry;\n resolveBinding?: BindingResolver;\n dataContext?: unknown;\n queryResults?: Record<string, unknown>;\n componentOutputs?: Record<string, Record<string, unknown>>;\n\n /**\n * The resolved configuration of the template chain the element sits in, from `resolveEffectiveConfiguration`.\n * When given, each configurable component renders with its resolved properties - what a screen's own values add\n * to an inherited template. It is the same data the editor shows, and the same code path whether the screen is\n * being edited or played: there is no design-time mode.\n */\n configuration?: EffectiveConfiguration;\n\n /** Called when rendered components publish or clear output properties for typed bindings. */\n onComponentOutputsChanged?: (outputs: Record<string, Record<string, unknown>>) => void;\n}\n\n/**\n * Renders a Scene element tree with the real `Scene.React` renderer - the WYSIWYG building block Studio's\n * preview surface and Stage's shipped web bundle both consume unmodified.\n */\nexport function SceneElementView({\n element,\n registry,\n resolveBinding,\n configuration,\n onComponentOutputsChanged,\n dataContext,\n queryResults,\n componentOutputs,\n}: SceneElementViewProps) {\n const configured = useMemo(() => configuration ? applyEffectiveConfiguration(element, configuration) : element, [element, configuration]);\n return (\n <RenderBindingScopeProvider\n dataContext={dataContext}\n queryResults={queryResults}\n componentOutputs={componentOutputs}\n resolveBinding={resolveBinding}\n onComponentOutputsChanged={onComponentOutputsChanged}>\n <RenderedElement element={configured} registry={registry} />\n </RenderBindingScopeProvider>\n );\n}\n\nfunction RenderedElement({ element, registry }: { element: SceneElement; registry: ComponentRegistry }) {\n const renderer = useMemo(() => createReactRenderer(registry), [registry]);\n const resolveBinding = useRenderBindingResolver();\n return <>{renderElement(element, renderer, resolveBinding)}</>;\n}\n"],"names":["SceneElementView","element","registry","resolveBinding","configuration","onComponentOutputsChanged","dataContext","queryResults","componentOutputs","configured","useMemo","applyEffectiveConfiguration","_jsx","RenderBindingScopeProvider","RenderedElement","renderer","createReactRenderer","useRenderBindingResolver","_Fragment","renderElement"],"mappings":";;;;;;;;;;;AA4BA;;;AAGC,IACM,SAASA,gBAAAA,CAAiB,EAC7BC,OAAO,EACPC,QAAQ,EACRC,cAAc,EACdC,aAAa,EACbC,yBAAyB,EACzBC,WAAW,EACXC,YAAY,EACZC,gBAAgB,EACI,EAAA;AACpB,IAAA,MAAMC,aAAaC,aAAAA,CAAQ,IAAMN,gBAAgBO,wCAAAA,CAA4BV,OAAAA,EAASG,iBAAiBH,OAAAA,EAAS;AAACA,QAAAA,OAAAA;AAASG,QAAAA;AAAc,KAAA,CAAA;AACxI,IAAA,qBACIQ,cAAA,CAACC,oDAAAA,EAAAA;QACGP,WAAAA,EAAaA,WAAAA;QACbC,YAAAA,EAAcA,YAAAA;QACdC,gBAAAA,EAAkBA,gBAAAA;QAClBL,cAAAA,EAAgBA,cAAAA;QAChBE,yBAAAA,EAA2BA,yBAAAA;AAC3B,QAAA,QAAA,gBAAAO,cAAA,CAACE,eAAAA,EAAAA;YAAgBb,OAAAA,EAASQ,UAAAA;YAAYP,QAAAA,EAAUA;;;AAG5D;AAEA,SAASY,eAAAA,CAAgB,EAAEb,OAAO,EAAEC,QAAQ,EAA0D,EAAA;AAClG,IAAA,MAAMa,QAAAA,GAAWL,aAAAA,CAAQ,IAAMM,uCAAAA,CAAoBd,QAAAA,CAAAA,EAAW;AAACA,QAAAA;AAAS,KAAA,CAAA;AACxE,IAAA,MAAMC,cAAAA,GAAiBc,kDAAAA,EAAAA;IACvB,qBAAOL,cAAA,CAAAM,mBAAA,EAAA;AAAGC,QAAAA,QAAAA,EAAAA,0BAAAA,CAAclB,SAASc,QAAAA,EAAUZ,cAAAA;;AAC/C;;"}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var scene_engine = require('@cratis/scene.engine');
|
|
5
|
+
require('react');
|
|
6
|
+
var RenderBindingScopeContext = require('../renderer/RenderBindingScopeContext.js');
|
|
7
|
+
require('@cratis/scene.model');
|
|
8
|
+
require('../interactions/useInteractions.js');
|
|
9
|
+
require('../interactions/NotificationHost.js');
|
|
4
10
|
|
|
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
11
|
function textProperty(properties, name, fallback = '') {
|
|
8
12
|
return typeof properties[name] === 'string' ? properties[name] : fallback;
|
|
9
13
|
}
|
|
@@ -14,15 +18,31 @@ function textProperty(properties, name, fallback = '') {
|
|
|
14
18
|
"data-scene-data": textProperty(element.properties, 'typeName')
|
|
15
19
|
});
|
|
16
20
|
}
|
|
17
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Renders a modeled command action and emits a host-neutral command event when invoked.
|
|
23
|
+
*
|
|
24
|
+
* The event carries the resolved `arguments`, by name, read when the action is invoked: a
|
|
25
|
+
* `component.<id>.<output>` source reads what another element publishes - such as what the user typed into
|
|
26
|
+
* an input - and any other source is a data-context path. Hosts that read the mapping from `element`
|
|
27
|
+
* themselves keep working.
|
|
28
|
+
*/ function CoreAction({ element }) {
|
|
18
29
|
const command = textProperty(element.properties, 'command');
|
|
19
30
|
const label = textProperty(element.properties, 'label', command);
|
|
20
|
-
const
|
|
31
|
+
const scope = RenderBindingScopeContext.useRenderBindingScope();
|
|
32
|
+
const invoke = ()=>{
|
|
33
|
+
const mapping = Array.isArray(element.properties.arguments) ? element.properties.arguments : [];
|
|
34
|
+
const args = Object.fromEntries(mapping.filter((argument)=>typeof argument.name === 'string' && typeof argument.source === 'string').map((argument)=>[
|
|
35
|
+
argument.name,
|
|
36
|
+
scene_engine.resolveArgumentSource(argument.source, scope)
|
|
37
|
+
]));
|
|
38
|
+
globalThis.dispatchEvent(new CustomEvent('cratis.scene.command', {
|
|
21
39
|
detail: {
|
|
22
40
|
command,
|
|
23
|
-
element
|
|
41
|
+
element,
|
|
42
|
+
arguments: args
|
|
24
43
|
}
|
|
25
44
|
}));
|
|
45
|
+
};
|
|
26
46
|
return /*#__PURE__*/ jsxRuntime.jsx("button", {
|
|
27
47
|
type: "button",
|
|
28
48
|
"data-scene-id": element.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScreenplayCoreComponents.js","sources":["../../../core/ScreenplayCoreComponents.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 { RegisteredComponentProps } from '../renderer';\n\nfunction textProperty(properties: Record<string, unknown>, name: string, fallback = ''): string {\n return typeof properties[name] === 'string' ? properties[name] : fallback;\n}\n\n/** Carries a Screenplay data declaration without adding visual chrome. */\nexport function CoreData({ element }: RegisteredComponentProps) {\n return <span hidden data-scene-id={element.id} data-scene-data={textProperty(element.properties, 'typeName')} />;\n}\n\n/** Renders a modeled command action and emits a host-neutral command event when invoked. */\nexport function CoreAction({ element }: RegisteredComponentProps) {\n const command = textProperty(element.properties, 'command');\n const label = textProperty(element.properties, 'label', command);\n const invoke = () => globalThis.dispatchEvent(new CustomEvent('cratis.scene.command', { detail: { command, element } }));\n return <button type='button' data-scene-id={element.id} onClick={invoke}>{label}</button>;\n}\n\n/** Groups the nested content of a Screenplay section. */\nexport function CoreSection({ element, slots }: RegisteredComponentProps) {\n const name = textProperty(element.properties, 'name');\n return <section data-scene-id={element.id}>{name && <h2>{name}</h2>}{slots.content}</section>;\n}\n\n/** Renders navigation intent and emits a host-neutral navigation event. */\nexport function CoreNavigate({ element }: RegisteredComponentProps) {\n const targetScreen = textProperty(element.properties, 'targetScreen');\n const navigate = () => globalThis.dispatchEvent(new CustomEvent('cratis.scene.navigate', { detail: { targetScreen, element } }));\n return <button type='button' data-scene-id={element.id} onClick={navigate}>{targetScreen}</button>;\n}\n\n/** Renders a Screenplay title directive. */\nexport function CoreTitle({ element }: RegisteredComponentProps) {\n return <h1 data-scene-id={element.id}>{textProperty(element.properties, 'text')}</h1>;\n}\n\n/** Renders the structural shell of a Screenplay table. Query data is supplied by the host. */\nexport function CoreTable({ element, slots }: RegisteredComponentProps) {\n return <section data-scene-id={element.id} role='table'><header role='row'>{slots.columns}</header></section>;\n}\n\n/** Renders a Screenplay table-column heading. */\nexport function CoreColumn({ element }: RegisteredComponentProps) {\n const property = textProperty(element.properties, 'property');\n return <span data-scene-id={element.id} role='columnheader'>{textProperty(element.properties, 'label', property)}</span>;\n}\n\n/** Renders the structural shell of a Screenplay summary. Query data is supplied by the host. */\nexport function CoreSummary({ element, slots }: RegisteredComponentProps) {\n return <dl data-scene-id={element.id}>{slots.fields}</dl>;\n}\n\n/** Renders a Screenplay summary field label. */\nexport function CoreField({ element }: RegisteredComponentProps) {\n const property = textProperty(element.properties, 'property');\n return <dt data-scene-id={element.id}>{textProperty(element.properties, 'label', property)}</dt>;\n}\n\n/** Renders a Screenplay code block. */\nexport function CoreCode({ element }: RegisteredComponentProps) {\n const language = textProperty(element.properties, 'language');\n return <pre data-scene-id={element.id}><code data-language={language}>{textProperty(element.properties, 'code')}</code></pre>;\n}\n\n/** Makes an external screen-file reference visible until a host supplies that file. */\nexport function CoreFile({ element }: RegisteredComponentProps) {\n return <p data-scene-id={element.id}>Screen source: {textProperty(element.properties, 'path')}</p>;\n}\n"],"names":["textProperty","properties","name","fallback","CoreData","element","_jsx","span","hidden","data-scene-id","id","data-scene-data","CoreAction","command","label","invoke","globalThis","dispatchEvent","CustomEvent","detail","button","type","onClick","CoreSection","slots","_jsxs","section","h2","content","CoreNavigate","targetScreen","navigate","CoreTitle","h1","CoreTable","role","header","columns","CoreColumn","property","CoreSummary","dl","fields","CoreField","dt","CoreCode","language","pre","code","data-language","CoreFile","p"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ScreenplayCoreComponents.js","sources":["../../../core/ScreenplayCoreComponents.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 { resolveArgumentSource } from '@cratis/scene.engine';\nimport { RegisteredComponentProps, useRenderBindingScope } from '../renderer';\n\nfunction textProperty(properties: Record<string, unknown>, name: string, fallback = ''): string {\n return typeof properties[name] === 'string' ? properties[name] : fallback;\n}\n\n/** Carries a Screenplay data declaration without adding visual chrome. */\nexport function CoreData({ element }: RegisteredComponentProps) {\n return <span hidden data-scene-id={element.id} data-scene-data={textProperty(element.properties, 'typeName')} />;\n}\n\n/** One entry of a command action's argument mapping. */\ninterface ArgumentMapping {\n name?: unknown;\n source?: unknown;\n}\n\n/**\n * Renders a modeled command action and emits a host-neutral command event when invoked.\n *\n * The event carries the resolved `arguments`, by name, read when the action is invoked: a\n * `component.<id>.<output>` source reads what another element publishes - such as what the user typed into\n * an input - and any other source is a data-context path. Hosts that read the mapping from `element`\n * themselves keep working.\n */\nexport function CoreAction({ element }: RegisteredComponentProps) {\n const command = textProperty(element.properties, 'command');\n const label = textProperty(element.properties, 'label', command);\n const scope = useRenderBindingScope();\n const invoke = () => {\n const mapping = Array.isArray(element.properties.arguments) ? element.properties.arguments as ArgumentMapping[] : [];\n const args = Object.fromEntries(mapping\n .filter((argument): argument is { name: string; source: string } => typeof argument.name === 'string' && typeof argument.source === 'string')\n .map(argument => [argument.name, resolveArgumentSource(argument.source, scope)]));\n globalThis.dispatchEvent(new CustomEvent('cratis.scene.command', { detail: { command, element, arguments: args } }));\n };\n return <button type='button' data-scene-id={element.id} onClick={invoke}>{label}</button>;\n}\n\n/** Groups the nested content of a Screenplay section. */\nexport function CoreSection({ element, slots }: RegisteredComponentProps) {\n const name = textProperty(element.properties, 'name');\n return <section data-scene-id={element.id}>{name && <h2>{name}</h2>}{slots.content}</section>;\n}\n\n/** Renders navigation intent and emits a host-neutral navigation event. */\nexport function CoreNavigate({ element }: RegisteredComponentProps) {\n const targetScreen = textProperty(element.properties, 'targetScreen');\n const navigate = () => globalThis.dispatchEvent(new CustomEvent('cratis.scene.navigate', { detail: { targetScreen, element } }));\n return <button type='button' data-scene-id={element.id} onClick={navigate}>{targetScreen}</button>;\n}\n\n/** Renders a Screenplay title directive. */\nexport function CoreTitle({ element }: RegisteredComponentProps) {\n return <h1 data-scene-id={element.id}>{textProperty(element.properties, 'text')}</h1>;\n}\n\n/** Renders the structural shell of a Screenplay table. Query data is supplied by the host. */\nexport function CoreTable({ element, slots }: RegisteredComponentProps) {\n return <section data-scene-id={element.id} role='table'><header role='row'>{slots.columns}</header></section>;\n}\n\n/** Renders a Screenplay table-column heading. */\nexport function CoreColumn({ element }: RegisteredComponentProps) {\n const property = textProperty(element.properties, 'property');\n return <span data-scene-id={element.id} role='columnheader'>{textProperty(element.properties, 'label', property)}</span>;\n}\n\n/** Renders the structural shell of a Screenplay summary. Query data is supplied by the host. */\nexport function CoreSummary({ element, slots }: RegisteredComponentProps) {\n return <dl data-scene-id={element.id}>{slots.fields}</dl>;\n}\n\n/** Renders a Screenplay summary field label. */\nexport function CoreField({ element }: RegisteredComponentProps) {\n const property = textProperty(element.properties, 'property');\n return <dt data-scene-id={element.id}>{textProperty(element.properties, 'label', property)}</dt>;\n}\n\n/** Renders a Screenplay code block. */\nexport function CoreCode({ element }: RegisteredComponentProps) {\n const language = textProperty(element.properties, 'language');\n return <pre data-scene-id={element.id}><code data-language={language}>{textProperty(element.properties, 'code')}</code></pre>;\n}\n\n/** Makes an external screen-file reference visible until a host supplies that file. */\nexport function CoreFile({ element }: RegisteredComponentProps) {\n return <p data-scene-id={element.id}>Screen source: {textProperty(element.properties, 'path')}</p>;\n}\n"],"names":["textProperty","properties","name","fallback","CoreData","element","_jsx","span","hidden","data-scene-id","id","data-scene-data","CoreAction","command","label","scope","useRenderBindingScope","invoke","mapping","Array","isArray","arguments","args","Object","fromEntries","filter","argument","source","map","resolveArgumentSource","globalThis","dispatchEvent","CustomEvent","detail","button","type","onClick","CoreSection","slots","_jsxs","section","h2","content","CoreNavigate","targetScreen","navigate","CoreTitle","h1","CoreTable","role","header","columns","CoreColumn","property","CoreSummary","dl","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,EAAE;AAAG4B,QAAAA,QAAAA,EAAAA,KAAAA,CAAMkB;;AACjD;AAEA,iDACO,SAASC,SAAAA,CAAU,EAAEpD,OAAO,EAA4B,EAAA;AAC3D,IAAA,MAAMgD,QAAAA,GAAWrD,YAAAA,CAAaK,OAAAA,CAAQJ,UAAU,EAAE,UAAA,CAAA;AAClD,IAAA,qBAAOK,cAAA,CAACoD,IAAAA,EAAAA;AAAGjD,QAAAA,eAAAA,EAAeJ,QAAQK,EAAE;kBAAGV,YAAAA,CAAaK,OAAAA,CAAQJ,UAAU,EAAE,OAAA,EAASoD,QAAAA;;AACrF;AAEA,wCACO,SAASM,QAAAA,CAAS,EAAEtD,OAAO,EAA4B,EAAA;AAC1D,IAAA,MAAMuD,QAAAA,GAAW5D,YAAAA,CAAaK,OAAAA,CAAQJ,UAAU,EAAE,UAAA,CAAA;AAClD,IAAA,qBAAOK,cAAA,CAACuD,KAAAA,EAAAA;AAAIpD,QAAAA,eAAAA,EAAeJ,QAAQK,EAAE;AAAE,QAAA,QAAA,gBAAAJ,cAAA,CAACwD,MAAAA,EAAAA;YAAKC,eAAAA,EAAeH,QAAAA;sBAAW5D,YAAAA,CAAaK,OAAAA,CAAQJ,UAAU,EAAE,MAAA;;;AAC5G;AAEA,wFACO,SAAS+D,QAAAA,CAAS,EAAE3D,OAAO,EAA4B,EAAA;AAC1D,IAAA,qBAAOkC,eAAA,CAAC0B,GAAAA,EAAAA;AAAExD,QAAAA,eAAAA,EAAeJ,QAAQK,EAAE;;AAAE,YAAA,iBAAA;YAAgBV,YAAAA,CAAaK,OAAAA,CAAQJ,UAAU,EAAE,MAAA;;;AAC1F;;;;;;;;;;;;"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -5,6 +5,9 @@ var AbortableQueryRunner = require('./renderer/AbortableQueryRunner.js');
|
|
|
5
5
|
var BindingOutputContext = require('./renderer/BindingOutputContext.js');
|
|
6
6
|
var RenderBindingScopeContext = require('./renderer/RenderBindingScopeContext.js');
|
|
7
7
|
var UnresolvedComponent = require('./renderer/UnresolvedComponent.js');
|
|
8
|
+
var useBoundQuery = require('./renderer/useBoundQuery.js');
|
|
9
|
+
var useValueOutput = require('./renderer/useValueOutput.js');
|
|
10
|
+
var valueOutputProperty = require('./renderer/valueOutputProperty.js');
|
|
8
11
|
var createReactRenderer = require('./renderer/createReactRenderer.js');
|
|
9
12
|
var InteractiveComponent = require('./renderer/InteractiveComponent.js');
|
|
10
13
|
var CoreText = require('./core/CoreText.js');
|
|
@@ -20,6 +23,7 @@ var extractNavigationItem = require('./NavBar/extractNavigationItem.js');
|
|
|
20
23
|
var SceneNavigationContext = require('./navigation/SceneNavigationContext.js');
|
|
21
24
|
var SceneNavigationHost = require('./navigation/SceneNavigationHost.js');
|
|
22
25
|
var createBrowserSceneHistory = require('./navigation/createBrowserSceneHistory.js');
|
|
26
|
+
var createHashSceneHistory = require('./navigation/createHashSceneHistory.js');
|
|
23
27
|
var createMemorySceneHistory = require('./navigation/createMemorySceneHistory.js');
|
|
24
28
|
var diagnoseRenderedNavigation = require('./navigation/diagnoseRenderedNavigation.js');
|
|
25
29
|
var identityRoute = require('./navigation/identityRoute.js');
|
|
@@ -38,6 +42,7 @@ var DesignTimeExtensionPoint = require('./packages/DesignTimeExtensionPoint.js')
|
|
|
38
42
|
var DesignTimeProvider = require('./packages/DesignTimeProvider.js');
|
|
39
43
|
var EmbeddedPackageHost = require('./packages/EmbeddedPackageHost.js');
|
|
40
44
|
var loadDesignTimeContributions = require('./packages/loadDesignTimeContributions.js');
|
|
45
|
+
var isNetworkAsset = require('./packages/isNetworkAsset.js');
|
|
41
46
|
var PackageHostAssets = require('./packages/PackageHostAssets.js');
|
|
42
47
|
var PackageHostConfiguration = require('./packages/PackageHostConfiguration.js');
|
|
43
48
|
var PackageHostRenderMode = require('./packages/PackageHostRenderMode.js');
|
|
@@ -69,6 +74,10 @@ exports.RenderBindingScopeProvider = RenderBindingScopeContext.RenderBindingScop
|
|
|
69
74
|
exports.useRenderBindingResolver = RenderBindingScopeContext.useRenderBindingResolver;
|
|
70
75
|
exports.useRenderBindingScope = RenderBindingScopeContext.useRenderBindingScope;
|
|
71
76
|
exports.UnresolvedComponent = UnresolvedComponent.UnresolvedComponent;
|
|
77
|
+
exports.useBoundQuery = useBoundQuery.useBoundQuery;
|
|
78
|
+
exports.useValueOutput = useValueOutput.useValueOutput;
|
|
79
|
+
exports.valueOutputName = useValueOutput.valueOutputName;
|
|
80
|
+
exports.valueOutputProperty = valueOutputProperty.valueOutputProperty;
|
|
72
81
|
exports.createReactRenderer = createReactRenderer.createReactRenderer;
|
|
73
82
|
exports.InteractiveComponent = InteractiveComponent.InteractiveComponent;
|
|
74
83
|
exports.CoreText = CoreText.CoreText;
|
|
@@ -96,6 +105,7 @@ exports.SceneNavigationProvider = SceneNavigationContext.SceneNavigationProvider
|
|
|
96
105
|
exports.useSceneNavigation = SceneNavigationContext.useSceneNavigation;
|
|
97
106
|
exports.SceneNavigationHost = SceneNavigationHost.SceneNavigationHost;
|
|
98
107
|
exports.createBrowserSceneHistory = createBrowserSceneHistory.createBrowserSceneHistory;
|
|
108
|
+
exports.createHashSceneHistory = createHashSceneHistory.createHashSceneHistory;
|
|
99
109
|
exports.createMemorySceneHistory = createMemorySceneHistory.createMemorySceneHistory;
|
|
100
110
|
exports.diagnoseRenderedNavigation = diagnoseRenderedNavigation.diagnoseRenderedNavigation;
|
|
101
111
|
exports.identityRoute = identityRoute.identityRoute;
|
|
@@ -118,6 +128,7 @@ exports.DesignTimeProvider = DesignTimeProvider.DesignTimeProvider;
|
|
|
118
128
|
exports.useDesignTimeContext = DesignTimeProvider.useDesignTimeContext;
|
|
119
129
|
exports.EmbeddedPackageHost = EmbeddedPackageHost.EmbeddedPackageHost;
|
|
120
130
|
exports.loadDesignTimeContributions = loadDesignTimeContributions.loadDesignTimeContributions;
|
|
131
|
+
exports.isNetworkAsset = isNetworkAsset.isNetworkAsset;
|
|
121
132
|
exports.PackageHostAssets = PackageHostAssets.PackageHostAssets;
|
|
122
133
|
exports.resolvePackageHost = PackageHostConfiguration.resolvePackageHost;
|
|
123
134
|
exports.PackageHostRenderMode = PackageHostRenderMode.PackageHostRenderMode;
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
const stateKey = 'sceneNavigation';
|
|
6
|
+
/**
|
|
7
|
+
* A history kept in the URL fragment - `index.html#/WorkItemDetails?workItemId=B` - for hosts that are served
|
|
8
|
+
* as a single file or from a path they do not control, such as a generated runtime or a webview. It behaves
|
|
9
|
+
* like `createBrowserSceneHistory`: entries are pushed with their navigation state, back and forward restore
|
|
10
|
+
* them, and a typed or bookmarked fragment is matched by URL alone. A fragment changed by hand, which fires
|
|
11
|
+
* `hashchange` rather than `popstate`, is reported the same way.
|
|
12
|
+
*/ function createHashSceneHistory(browser = window) {
|
|
13
|
+
const location = ()=>{
|
|
14
|
+
const fragment = browser.location.hash.replace(/^#\/?/, '');
|
|
15
|
+
return fragment.length ? fragment : undefined;
|
|
16
|
+
};
|
|
17
|
+
const href = (url)=>`${browser.location.pathname}${browser.location.search}#/${url ?? ''}`;
|
|
18
|
+
const stored = (value)=>value?.[stateKey];
|
|
19
|
+
return {
|
|
20
|
+
location,
|
|
21
|
+
state: ()=>stored(browser.history.state),
|
|
22
|
+
push: (state)=>browser.history.pushState({
|
|
23
|
+
[stateKey]: state
|
|
24
|
+
}, '', href(state.url)),
|
|
25
|
+
replace: (state)=>browser.history.replaceState({
|
|
26
|
+
[stateKey]: state
|
|
27
|
+
}, '', href(state.url)),
|
|
28
|
+
back: ()=>browser.history.back(),
|
|
29
|
+
listen: (listener)=>{
|
|
30
|
+
const onPopState = (event)=>listener(location(), stored(event.state));
|
|
31
|
+
const onHashChange = ()=>listener(location(), stored(browser.history.state));
|
|
32
|
+
browser.addEventListener('popstate', onPopState);
|
|
33
|
+
browser.addEventListener('hashchange', onHashChange);
|
|
34
|
+
return ()=>{
|
|
35
|
+
browser.removeEventListener('popstate', onPopState);
|
|
36
|
+
browser.removeEventListener('hashchange', onHashChange);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.createHashSceneHistory = createHashSceneHistory;
|
|
43
|
+
//# sourceMappingURL=createHashSceneHistory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHashSceneHistory.js","sources":["../../../navigation/createHashSceneHistory.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 { SceneBrowserWindow } from './createBrowserSceneHistory';\nimport { SceneHistory } from './SceneHistory';\nimport { SceneNavigationState } from './SceneNavigationState';\n\nconst stateKey = 'sceneNavigation';\n\n/**\n * A history kept in the URL fragment - `index.html#/WorkItemDetails?workItemId=B` - for hosts that are served\n * as a single file or from a path they do not control, such as a generated runtime or a webview. It behaves\n * like `createBrowserSceneHistory`: entries are pushed with their navigation state, back and forward restore\n * them, and a typed or bookmarked fragment is matched by URL alone. A fragment changed by hand, which fires\n * `hashchange` rather than `popstate`, is reported the same way.\n */\nexport function createHashSceneHistory(browser: SceneBrowserWindow = window): SceneHistory {\n const location = () => {\n const fragment = browser.location.hash.replace(/^#\\/?/, '');\n return fragment.length ? fragment : undefined;\n };\n const href = (url: string | undefined) => `${browser.location.pathname}${browser.location.search}#/${url ?? ''}`;\n const stored = (value: unknown) => (value as Record<string, SceneNavigationState> | null)?.[stateKey];\n\n return {\n location,\n state: () => stored(browser.history.state),\n push: state => browser.history.pushState({ [stateKey]: state }, '', href(state.url)),\n replace: state => browser.history.replaceState({ [stateKey]: state }, '', href(state.url)),\n back: () => browser.history.back(),\n listen: listener => {\n const onPopState = (event: PopStateEvent) => listener(location(), stored(event.state));\n const onHashChange = () => listener(location(), stored(browser.history.state));\n browser.addEventListener('popstate', onPopState);\n browser.addEventListener('hashchange', onHashChange);\n return () => {\n browser.removeEventListener('popstate', onPopState);\n browser.removeEventListener('hashchange', onHashChange);\n };\n },\n };\n}\n"],"names":["stateKey","createHashSceneHistory","browser","window","location","fragment","hash","replace","length","undefined","href","url","pathname","search","stored","value","state","history","push","pushState","replaceState","back","listen","listener","onPopState","event","onHashChange","addEventListener","removeEventListener"],"mappings":";;AAAA;AACA;AAMA,MAAMA,QAAAA,GAAW,iBAAA;AAEjB;;;;;;AAMC,IACM,SAASC,sBAAAA,CAAuBC,OAAAA,GAA8BC,MAAM,EAAA;AACvE,IAAA,MAAMC,QAAAA,GAAW,IAAA;QACb,MAAMC,QAAAA,GAAWH,QAAQE,QAAQ,CAACE,IAAI,CAACC,OAAO,CAAC,OAAA,EAAS,EAAA,CAAA;QACxD,OAAOF,QAAAA,CAASG,MAAM,GAAGH,QAAAA,GAAWI,SAAAA;AACxC,IAAA,CAAA;AACA,IAAA,MAAMC,OAAO,CAACC,GAAAA,GAA4B,CAAA,EAAGT,OAAAA,CAAQE,QAAQ,CAACQ,QAAQ,CAAA,EAAGV,OAAAA,CAAQE,QAAQ,CAACS,MAAM,CAAC,EAAE,EAAEF,OAAO,EAAA,CAAA,CAAI;AAChH,IAAA,MAAMG,MAAAA,GAAS,CAACC,KAAAA,GAAoBA,KAAAA,GAAwDf,QAAAA,CAAS;IAErG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
|
var scene_engine = require('@cratis/scene.engine');
|
|
4
4
|
var IconAdapterRegistry = require('../icons/IconAdapterRegistry.js');
|
|
5
5
|
var ScenePackageBundle = require('./ScenePackageBundle.js');
|
|
6
|
+
var isNetworkAsset = require('./isNetworkAsset.js');
|
|
6
7
|
|
|
7
8
|
// Copyright (c) Cratis. All rights reserved.
|
|
8
9
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
@@ -41,8 +42,9 @@ var ScenePackageBundle = require('./ScenePackageBundle.js');
|
|
|
41
42
|
diagnostics.push(`Package '${packageName}' provides executable design-time contributions, but host policy forbids them`);
|
|
42
43
|
}
|
|
43
44
|
const packageAssets = bundle.manifest.assets ?? [];
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
const networkAssets = packageAssets.filter(isNetworkAsset.isNetworkAsset);
|
|
46
|
+
if (!configuration.policy.allowNetworkAssets && networkAssets.length > 0) {
|
|
47
|
+
diagnostics.push(`Package '${packageName}' declares network assets (${networkAssets.join(', ')}), but host policy forbids them`);
|
|
46
48
|
}
|
|
47
49
|
assets.push(...packageAssets);
|
|
48
50
|
for (const dependency of bundle.manifest.runtimeSingletons ?? []){
|
|
@@ -54,6 +56,18 @@ var ScenePackageBundle = require('./ScenePackageBundle.js');
|
|
|
54
56
|
}
|
|
55
57
|
bundles.push(bundle);
|
|
56
58
|
}
|
|
59
|
+
const layouts = bundles.flatMap((bundle)=>bundle.layouts ?? []);
|
|
60
|
+
const themes = bundles.flatMap((bundle)=>bundle.themes ?? []);
|
|
61
|
+
const layout = configuration.profile.layout ? layouts.find((candidate)=>candidate.name === configuration.profile.layout) : undefined;
|
|
62
|
+
const theme = configuration.profile.theme ? themes.find((candidate)=>candidate.name === configuration.profile.theme) : undefined;
|
|
63
|
+
if (configuration.profile.layout && !layout) {
|
|
64
|
+
diagnostics.push(`UI profile '${configuration.profile.name}' uses layout '${configuration.profile.layout}', which no approved package provides`);
|
|
65
|
+
}
|
|
66
|
+
if (configuration.profile.theme && !theme) {
|
|
67
|
+
diagnostics.push(`UI profile '${configuration.profile.name}' uses theme '${configuration.profile.theme}', which no approved package provides`);
|
|
68
|
+
} else if (theme && scene_engine.incompatiblePackages(theme, configuration.profile).length > 0) {
|
|
69
|
+
diagnostics.push(`Theme '${theme.name}' is not compatible with ${scene_engine.incompatiblePackages(theme, configuration.profile).join(', ')} in UI profile '${configuration.profile.name}'`);
|
|
70
|
+
}
|
|
57
71
|
const blocked = diagnostics.length > 0;
|
|
58
72
|
const approved = blocked ? [] : bundles;
|
|
59
73
|
const approvedAssets = blocked ? [] : assets;
|
|
@@ -64,6 +78,8 @@ var ScenePackageBundle = require('./ScenePackageBundle.js');
|
|
|
64
78
|
screenTemplates: approved.flatMap((bundle)=>bundle.screenTemplates ?? []),
|
|
65
79
|
dialogTemplates: approved.flatMap((bundle)=>bundle.dialogTemplates ?? []),
|
|
66
80
|
themes: approved.flatMap((bundle)=>bundle.themes ?? []),
|
|
81
|
+
layout: blocked ? undefined : layout,
|
|
82
|
+
theme: blocked ? undefined : theme,
|
|
67
83
|
templates: scene_engine.describeTemplateCatalog(approved, configuration.sceneVersion),
|
|
68
84
|
icons: IconAdapterRegistry.createIconAdapterRegistry(approved.map((bundle)=>bundle.iconLibrary?.adapter).filter((adapter)=>adapter !== undefined)),
|
|
69
85
|
assets: approvedAssets,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageHostConfiguration.js","sources":["../../../packages/PackageHostConfiguration.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DialogTemplate, Layout, ScreenTemplate, Theme, UiProfile } from '@cratis/scene.model';\nimport { TemplateCatalogEntry, describeTemplateCatalog, resolvePackageDependencies } from '@cratis/scene.engine';\nimport { IconAdapterRegistry, createIconAdapterRegistry } from '../icons/IconAdapterRegistry';\nimport { ScenePackageBundle, mergePackageRegistries, validatePackageBundle } from './ScenePackageBundle';\n\nexport interface PackageHostPolicy {\n allowExecutableImports: boolean;\n allowNetworkAssets: boolean;\n\n /** Whether this host is resolving optional design-time bundles in addition to runtime contributions. */\n loadDesignTime?: boolean;\n}\n\nexport interface PackageHostConfiguration {\n bundles: ScenePackageBundle[];\n profile: UiProfile;\n policy: PackageHostPolicy;\n\n /** The Scene version the host runs, checked against each template's compatibility range when given. */\n sceneVersion?: string;\n}\n\nexport interface ResolvedPackageHost {\n bundles: ScenePackageBundle[];\n components: ReturnType<typeof mergePackageRegistries>;\n layouts: Layout[];\n screenTemplates: ScreenTemplate[];\n dialogTemplates: DialogTemplate[];\n themes: Theme[];\n\n /**\n * Every template the approved packages provide, with compatibility, attribution and license metadata and\n * whether it can be used with this package set. Template browsers read this rather than the raw lists.\n */\n templates: TemplateCatalogEntry[];\n icons: IconAdapterRegistry;\n assets: string[];\n fonts: string[];\n blocked: boolean;\n diagnostics: string[];\n}\n\n/**\n * Resolves the approved package set a standalone or embedded React host uses.\n */\nexport function resolvePackageHost(configuration: PackageHostConfiguration): ResolvedPackageHost {\n const diagnostics: string[] = [];\n const names = new Map<string, number>();\n for (const bundle of configuration.bundles) {\n names.set(bundle.manifest.name, (names.get(bundle.manifest.name) ?? 0) + 1);\n }\n\n for (const [name, count] of names) {\n if (count > 1) diagnostics.push(`Package '${name}' is approved more than once; duplicate bundles are ambiguous`);\n }\n\n const byName = new Map(configuration.bundles.map(bundle => [bundle.manifest.name, bundle]));\n const selection = resolvePackageDependencies(configuration.profile.packages, configuration.bundles.map(bundle => bundle.manifest));\n for (const missing of selection.missing) diagnostics.push(`Package '${missing.package}' depends on missing package '${missing.dependsOn}'`);\n for (const conflict of selection.versionConflicts) {\n diagnostics.push(`Package '${conflict.package}' requires '${conflict.dependsOn}' ${conflict.requiredRange} but approved version is ${conflict.actualVersion}`);\n }\n for (const cycle of selection.cycles) diagnostics.push(`Package dependency cycle: ${cycle.join(' -> ')}`);\n\n const bundles: ScenePackageBundle[] = [];\n const runtimeSingletons = new Map<string, string>();\n const assets: string[] = [];\n\n for (const packageName of selection.packages) {\n const bundle = byName.get(packageName);\n if (!bundle) {\n diagnostics.push(`UI profile asks for '${packageName}' but the host did not approve a bundle for it`);\n continue;\n }\n\n diagnostics.push(...validatePackageBundle(bundle).map(problem => `${packageName}: ${problem}`));\n if (configuration.policy.loadDesignTime === true && !configuration.policy.allowExecutableImports && bundle.designTime) {\n diagnostics.push(`Package '${packageName}' provides executable design-time contributions, but host policy forbids them`);\n }\n\n const packageAssets = bundle.manifest.assets ?? [];\n if (!configuration.policy.allowNetworkAssets && packageAssets.some(asset => /^https?:\\/\\//.test(asset))) {\n diagnostics.push(`Package '${packageName}' declares network assets, but host policy forbids them`);\n }\n assets.push(...packageAssets);\n\n for (const dependency of bundle.manifest.runtimeSingletons ?? []) {\n const owner = runtimeSingletons.get(dependency);\n if (owner && owner !== packageName) {\n diagnostics.push(`Runtime singleton '${dependency}' is provided by both '${owner}' and '${packageName}'`);\n }\n runtimeSingletons.set(dependency, packageName);\n }\n\n bundles.push(bundle);\n }\n\n const blocked = diagnostics.length > 0;\n const approved = blocked ? [] : bundles;\n const approvedAssets = blocked ? [] : assets;\n\n return {\n bundles: approved,\n components: mergePackageRegistries(approved),\n layouts: approved.flatMap(bundle => bundle.layouts ?? []),\n screenTemplates: approved.flatMap(bundle => bundle.screenTemplates ?? []),\n dialogTemplates: approved.flatMap(bundle => bundle.dialogTemplates ?? []),\n themes: approved.flatMap(bundle => bundle.themes ?? []),\n templates: describeTemplateCatalog(approved, configuration.sceneVersion),\n icons: createIconAdapterRegistry(approved.map(bundle => bundle.iconLibrary?.adapter).filter(adapter => adapter !== undefined)),\n assets: approvedAssets,\n fonts: approvedAssets.filter(isFontAsset),\n blocked,\n diagnostics,\n };\n}\n\nfunction isFontAsset(asset: string): boolean {\n return /\\.(woff2?|otf|ttf)(\\?|$)/.test(asset) || asset.includes('/fonts/');\n}\n"],"names":["resolvePackageHost","configuration","diagnostics","names","Map","bundle","bundles","set","manifest","name","get","count","push","byName","map","selection","resolvePackageDependencies","profile","packages","missing","package","dependsOn","conflict","versionConflicts","requiredRange","actualVersion","cycle","cycles","join","runtimeSingletons","assets","packageName","validatePackageBundle","problem","policy","loadDesignTime","allowExecutableImports","designTime","packageAssets","allowNetworkAssets","some","asset","test","dependency","owner","blocked","length","approved","approvedAssets","components","mergePackageRegistries","layouts","flatMap","screenTemplates","dialogTemplates","themes","templates","describeTemplateCatalog","sceneVersion","icons","createIconAdapterRegistry","iconLibrary","adapter","filter","undefined","fonts","isFontAsset","includes"],"mappings":";;;;;;AAAA;AACA;AA4CA;;IAGO,SAASA,kBAAAA,CAAmBC,aAAuC,EAAA;AACtE,IAAA,MAAMC,cAAwB,EAAE;AAChC,IAAA,MAAMC,QAAQ,IAAIC,GAAAA,EAAAA;AAClB,IAAA,KAAK,MAAMC,MAAAA,IAAUJ,aAAAA,CAAcK,OAAO,CAAE;AACxCH,QAAAA,KAAAA,CAAMI,GAAG,CAACF,MAAAA,CAAOG,QAAQ,CAACC,IAAI,EAAE,CAACN,KAAAA,CAAMO,GAAG,CAACL,MAAAA,CAAOG,QAAQ,CAACC,IAAI,CAAA,IAAK,CAAA,IAAK,CAAA,CAAA;AAC7E,IAAA;AAEA,IAAA,KAAK,MAAM,CAACA,IAAAA,EAAME,KAAAA,CAAM,IAAIR,KAAAA,CAAO;QAC/B,IAAIQ,KAAAA,GAAQ,CAAA,EAAGT,WAAAA,CAAYU,IAAI,CAAC,CAAC,SAAS,EAAEH,IAAAA,CAAK,6DAA6D,CAAC,CAAA;AACnH,IAAA;IAEA,MAAMI,MAAAA,GAAS,IAAIT,GAAAA,CAAIH,aAAAA,CAAcK,OAAO,CAACQ,GAAG,CAACT,CAAAA,MAAAA,GAAU;YAACA,MAAAA,CAAOG,QAAQ,CAACC,IAAI;AAAEJ,YAAAA;AAAO,SAAA,CAAA,CAAA;AACzF,IAAA,MAAMU,SAAAA,GAAYC,uCAAAA,CAA2Bf,aAAAA,CAAcgB,OAAO,CAACC,QAAQ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J;AAEA,SAASgE,YAAYzB,KAAa,EAAA;AAC9B,IAAA,OAAO,2BAA2BC,IAAI,CAACD,KAAAA,CAAAA,IAAUA,KAAAA,CAAM0B,QAAQ,CAAC,SAAA,CAAA;AACpE;;"}
|
|
1
|
+
{"version":3,"file":"PackageHostConfiguration.js","sources":["../../../packages/PackageHostConfiguration.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DialogTemplate, Layout, ScreenTemplate, Theme, UiProfile } from '@cratis/scene.model';\nimport { TemplateCatalogEntry, describeTemplateCatalog, incompatiblePackages, resolvePackageDependencies } from '@cratis/scene.engine';\nimport { IconAdapterRegistry, createIconAdapterRegistry } from '../icons/IconAdapterRegistry';\nimport { ScenePackageBundle, mergePackageRegistries, validatePackageBundle } from './ScenePackageBundle';\nimport { isNetworkAsset } from './isNetworkAsset';\n\nexport interface PackageHostPolicy {\n allowExecutableImports: boolean;\n allowNetworkAssets: boolean;\n\n /** Whether this host is resolving optional design-time bundles in addition to runtime contributions. */\n loadDesignTime?: boolean;\n}\n\nexport interface PackageHostConfiguration {\n bundles: ScenePackageBundle[];\n profile: UiProfile;\n policy: PackageHostPolicy;\n\n /** The Scene version the host runs, checked against each template's compatibility range when given. */\n sceneVersion?: string;\n}\n\nexport interface ResolvedPackageHost {\n bundles: ScenePackageBundle[];\n components: ReturnType<typeof mergePackageRegistries>;\n layouts: Layout[];\n screenTemplates: ScreenTemplate[];\n dialogTemplates: DialogTemplate[];\n themes: Theme[];\n\n /** The layout the UI profile names, from the approved packages. Absent when the profile names none. */\n layout?: Layout;\n\n /** The theme the UI profile names, from the approved packages. Absent when the profile names none. */\n theme?: Theme;\n\n /**\n * Every template the approved packages provide, with compatibility, attribution and license metadata and\n * whether it can be used with this package set. Template browsers read this rather than the raw lists.\n */\n templates: TemplateCatalogEntry[];\n icons: IconAdapterRegistry;\n assets: string[];\n fonts: string[];\n blocked: boolean;\n diagnostics: string[];\n}\n\n/**\n * Resolves the approved package set a standalone or embedded React host uses.\n */\nexport function resolvePackageHost(configuration: PackageHostConfiguration): ResolvedPackageHost {\n const diagnostics: string[] = [];\n const names = new Map<string, number>();\n for (const bundle of configuration.bundles) {\n names.set(bundle.manifest.name, (names.get(bundle.manifest.name) ?? 0) + 1);\n }\n\n for (const [name, count] of names) {\n if (count > 1) diagnostics.push(`Package '${name}' is approved more than once; duplicate bundles are ambiguous`);\n }\n\n const byName = new Map(configuration.bundles.map(bundle => [bundle.manifest.name, bundle]));\n const selection = resolvePackageDependencies(configuration.profile.packages, configuration.bundles.map(bundle => bundle.manifest));\n for (const missing of selection.missing) diagnostics.push(`Package '${missing.package}' depends on missing package '${missing.dependsOn}'`);\n for (const conflict of selection.versionConflicts) {\n diagnostics.push(`Package '${conflict.package}' requires '${conflict.dependsOn}' ${conflict.requiredRange} but approved version is ${conflict.actualVersion}`);\n }\n for (const cycle of selection.cycles) diagnostics.push(`Package dependency cycle: ${cycle.join(' -> ')}`);\n\n const bundles: ScenePackageBundle[] = [];\n const runtimeSingletons = new Map<string, string>();\n const assets: string[] = [];\n\n for (const packageName of selection.packages) {\n const bundle = byName.get(packageName);\n if (!bundle) {\n diagnostics.push(`UI profile asks for '${packageName}' but the host did not approve a bundle for it`);\n continue;\n }\n\n diagnostics.push(...validatePackageBundle(bundle).map(problem => `${packageName}: ${problem}`));\n if (configuration.policy.loadDesignTime === true && !configuration.policy.allowExecutableImports && bundle.designTime) {\n diagnostics.push(`Package '${packageName}' provides executable design-time contributions, but host policy forbids them`);\n }\n\n const packageAssets = bundle.manifest.assets ?? [];\n const networkAssets = packageAssets.filter(isNetworkAsset);\n if (!configuration.policy.allowNetworkAssets && networkAssets.length > 0) {\n diagnostics.push(`Package '${packageName}' declares network assets (${networkAssets.join(', ')}), but host policy forbids them`);\n }\n assets.push(...packageAssets);\n\n for (const dependency of bundle.manifest.runtimeSingletons ?? []) {\n const owner = runtimeSingletons.get(dependency);\n if (owner && owner !== packageName) {\n diagnostics.push(`Runtime singleton '${dependency}' is provided by both '${owner}' and '${packageName}'`);\n }\n runtimeSingletons.set(dependency, packageName);\n }\n\n bundles.push(bundle);\n }\n\n const layouts = bundles.flatMap(bundle => bundle.layouts ?? []);\n const themes = bundles.flatMap(bundle => bundle.themes ?? []);\n const layout = configuration.profile.layout ? layouts.find(candidate => candidate.name === configuration.profile.layout) : undefined;\n const theme = configuration.profile.theme ? themes.find(candidate => candidate.name === configuration.profile.theme) : undefined;\n if (configuration.profile.layout && !layout) {\n diagnostics.push(`UI profile '${configuration.profile.name}' uses layout '${configuration.profile.layout}', which no approved package provides`);\n }\n if (configuration.profile.theme && !theme) {\n diagnostics.push(`UI profile '${configuration.profile.name}' uses theme '${configuration.profile.theme}', which no approved package provides`);\n } else if (theme && incompatiblePackages(theme, configuration.profile).length > 0) {\n diagnostics.push(`Theme '${theme.name}' is not compatible with ${incompatiblePackages(theme, configuration.profile).join(', ')} in UI profile '${configuration.profile.name}'`);\n }\n\n const blocked = diagnostics.length > 0;\n const approved = blocked ? [] : bundles;\n const approvedAssets = blocked ? [] : assets;\n\n return {\n bundles: approved,\n components: mergePackageRegistries(approved),\n layouts: approved.flatMap(bundle => bundle.layouts ?? []),\n screenTemplates: approved.flatMap(bundle => bundle.screenTemplates ?? []),\n dialogTemplates: approved.flatMap(bundle => bundle.dialogTemplates ?? []),\n themes: approved.flatMap(bundle => bundle.themes ?? []),\n layout: blocked ? undefined : layout,\n theme: blocked ? undefined : theme,\n templates: describeTemplateCatalog(approved, configuration.sceneVersion),\n icons: createIconAdapterRegistry(approved.map(bundle => bundle.iconLibrary?.adapter).filter(adapter => adapter !== undefined)),\n assets: approvedAssets,\n fonts: approvedAssets.filter(isFontAsset),\n blocked,\n diagnostics,\n };\n}\n\nfunction isFontAsset(asset: string): boolean {\n return /\\.(woff2?|otf|ttf)(\\?|$)/.test(asset) || asset.includes('/fonts/');\n}\n"],"names":["resolvePackageHost","configuration","diagnostics","names","Map","bundle","bundles","set","manifest","name","get","count","push","byName","map","selection","resolvePackageDependencies","profile","packages","missing","package","dependsOn","conflict","versionConflicts","requiredRange","actualVersion","cycle","cycles","join","runtimeSingletons","assets","packageName","validatePackageBundle","problem","policy","loadDesignTime","allowExecutableImports","designTime","packageAssets","networkAssets","filter","isNetworkAsset","allowNetworkAssets","length","dependency","owner","layouts","flatMap","themes","layout","find","candidate","undefined","theme","incompatiblePackages","blocked","approved","approvedAssets","components","mergePackageRegistries","screenTemplates","dialogTemplates","templates","describeTemplateCatalog","sceneVersion","icons","createIconAdapterRegistry","iconLibrary","adapter","fonts","isFontAsset","asset","test","includes"],"mappings":";;;;;;;AAAA;AACA;AAmDA;;IAGO,SAASA,kBAAAA,CAAmBC,aAAuC,EAAA;AACtE,IAAA,MAAMC,cAAwB,EAAE;AAChC,IAAA,MAAMC,QAAQ,IAAIC,GAAAA,EAAAA;AAClB,IAAA,KAAK,MAAMC,MAAAA,IAAUJ,aAAAA,CAAcK,OAAO,CAAE;AACxCH,QAAAA,KAAAA,CAAMI,GAAG,CAACF,MAAAA,CAAOG,QAAQ,CAACC,IAAI,EAAE,CAACN,KAAAA,CAAMO,GAAG,CAACL,MAAAA,CAAOG,QAAQ,CAACC,IAAI,CAAA,IAAK,CAAA,IAAK,CAAA,CAAA;AAC7E,IAAA;AAEA,IAAA,KAAK,MAAM,CAACA,IAAAA,EAAME,KAAAA,CAAM,IAAIR,KAAAA,CAAO;QAC/B,IAAIQ,KAAAA,GAAQ,CAAA,EAAGT,WAAAA,CAAYU,IAAI,CAAC,CAAC,SAAS,EAAEH,IAAAA,CAAK,6DAA6D,CAAC,CAAA;AACnH,IAAA;IAEA,MAAMI,MAAAA,GAAS,IAAIT,GAAAA,CAAIH,aAAAA,CAAcK,OAAO,CAACQ,GAAG,CAACT,CAAAA,MAAAA,GAAU;YAACA,MAAAA,CAAOG,QAAQ,CAACC,IAAI;AAAEJ,YAAAA;AAAO,SAAA,CAAA,CAAA;AACzF,IAAA,MAAMU,S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AAAA,GAAYH,MAAAA;AAC9BI,QAAAA,KAAAA,EAAOE,UAAUH,SAAAA,GAAYC,KAAAA;QAC7BS,SAAAA,EAAWC,oCAAAA,CAAwBP,QAAAA,EAAUvD,aAAAA,CAAc+D,YAAY,CAAA;AACvEC,QAAAA,KAAAA,EAAOC,6CAAAA,CAA0BV,QAAAA,CAAS1C,GAAG,CAACT,CAAAA,MAAAA,GAAUA,MAAAA,CAAO8D,WAAW,EAAEC,OAAAA,CAAAA,CAAS5B,MAAM,CAAC4B,CAAAA,UAAWA,OAAAA,KAAYhB,SAAAA,CAAAA,CAAAA;QACnHtB,MAAAA,EAAQ2B,cAAAA;QACRY,KAAAA,EAAOZ,cAAAA,CAAejB,MAAM,CAAC8B,WAAAA,CAAAA;AAC7Bf,QAAAA,OAAAA;AACArD,QAAAA;AACJ,KAAA;AACJ;AAEA,SAASoE,YAAYC,KAAa,EAAA;AAC9B,IAAA,OAAO,2BAA2BC,IAAI,CAACD,KAAAA,CAAAA,IAAUA,KAAAA,CAAME,QAAQ,CAAC,SAAA,CAAA;AACpE;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
/**
|
|
6
|
+
* Whether loading an asset reaches beyond the host: an absolute URL with any scheme other than `data:`
|
|
7
|
+
* or `blob:` (`https://`, `http://`, `ws://`, `ftp://`), or a protocol-relative `//host/...` reference. A
|
|
8
|
+
* package-relative path or a bare module specifier such as `@cratis/components/styles` is resolved by the
|
|
9
|
+
* host from what it bundled, so it is not a network asset.
|
|
10
|
+
*/ function isNetworkAsset(asset) {
|
|
11
|
+
const trimmed = asset.trim();
|
|
12
|
+
if (trimmed.startsWith('//')) return true;
|
|
13
|
+
const scheme = /^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(trimmed)?.[1]?.toLowerCase();
|
|
14
|
+
return scheme !== undefined && scheme !== 'data' && scheme !== 'blob';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.isNetworkAsset = isNetworkAsset;
|
|
18
|
+
//# sourceMappingURL=isNetworkAsset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isNetworkAsset.js","sources":["../../../packages/isNetworkAsset.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\n/**\n * Whether loading an asset reaches beyond the host: an absolute URL with any scheme other than `data:`\n * or `blob:` (`https://`, `http://`, `ws://`, `ftp://`), or a protocol-relative `//host/...` reference. A\n * package-relative path or a bare module specifier such as `@cratis/components/styles` is resolved by the\n * host from what it bundled, so it is not a network asset.\n */\nexport function isNetworkAsset(asset: string): boolean {\n const trimmed = asset.trim();\n if (trimmed.startsWith('//')) return true;\n const scheme = /^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(trimmed)?.[1]?.toLowerCase();\n return scheme !== undefined && scheme !== 'data' && scheme !== 'blob';\n}\n"],"names":["isNetworkAsset","asset","trimmed","trim","startsWith","scheme","exec","toLowerCase","undefined"],"mappings":";;AAAA;AACA;AAEA;;;;;IAMO,SAASA,cAAAA,CAAeC,KAAa,EAAA;IACxC,MAAMC,OAAAA,GAAUD,MAAME,IAAI,EAAA;AAC1B,IAAA,IAAID,OAAAA,CAAQE,UAAU,CAAC,IAAA,CAAA,EAAO,OAAO,IAAA;AACrC,IAAA,MAAMC,SAAS,6BAAA,CAA8BC,IAAI,CAACJ,OAAAA,CAAAA,GAAW,EAAE,EAAEK,WAAAA,EAAAA;AACjE,IAAA,OAAOF,MAAAA,KAAWG,SAAAA,IAAaH,MAAAA,KAAW,MAAA,IAAUA,MAAAA,KAAW,MAAA;AACnE;;"}
|
|
@@ -9,10 +9,16 @@ var BindingOutputContext = require('./BindingOutputContext.js');
|
|
|
9
9
|
const Context = /*#__PURE__*/ react.createContext(undefined);
|
|
10
10
|
/**
|
|
11
11
|
* Provides the inherited reactive binding scope for a rendered Scene tree.
|
|
12
|
+
*
|
|
13
|
+
* The outermost provider owns the component output scope. A provider rendered inside another - a nested
|
|
14
|
+
* template or region - nests its own data context, query results and component outputs over the inherited
|
|
15
|
+
* scope with `nestBindingScope`, so a detail region bound to the selected row reads that row while still
|
|
16
|
+
* seeing the screen's queries and every component's outputs.
|
|
12
17
|
*/ function RenderBindingScopeProvider(props) {
|
|
13
18
|
const current = react.useContext(Context);
|
|
14
|
-
if (current) return /*#__PURE__*/ jsxRuntime.jsx(
|
|
15
|
-
|
|
19
|
+
if (current) return /*#__PURE__*/ jsxRuntime.jsx(RenderBindingScopeInner, {
|
|
20
|
+
...props,
|
|
21
|
+
parent: current.scope
|
|
16
22
|
});
|
|
17
23
|
return /*#__PURE__*/ jsxRuntime.jsx(BindingOutputContext.BindingOutputProvider, {
|
|
18
24
|
onOutputsChanged: props.onComponentOutputsChanged,
|
|
@@ -21,20 +27,24 @@ const Context = /*#__PURE__*/ react.createContext(undefined);
|
|
|
21
27
|
})
|
|
22
28
|
});
|
|
23
29
|
}
|
|
24
|
-
function RenderBindingScopeInner({ children, dataContext, queryResults, componentOutputs, resolveBinding }) {
|
|
30
|
+
function RenderBindingScopeInner({ children, dataContext, queryResults, componentOutputs, resolveBinding, parent }) {
|
|
25
31
|
const outputs = BindingOutputContext.useBindingOutputScope();
|
|
26
32
|
const previousValues = react.useRef(new Map());
|
|
27
|
-
const scope = react.useMemo(()=>
|
|
33
|
+
const scope = react.useMemo(()=>{
|
|
34
|
+
const own = {
|
|
28
35
|
dataContext,
|
|
29
36
|
queryResults,
|
|
30
37
|
componentOutputs: {
|
|
31
38
|
...componentOutputs ?? {},
|
|
32
39
|
...outputs
|
|
33
40
|
}
|
|
34
|
-
}
|
|
41
|
+
};
|
|
42
|
+
return parent ? scene_engine.nestBindingScope(parent, own) : own;
|
|
43
|
+
}, [
|
|
35
44
|
componentOutputs,
|
|
36
45
|
dataContext,
|
|
37
46
|
outputs,
|
|
47
|
+
parent,
|
|
38
48
|
queryResults
|
|
39
49
|
]);
|
|
40
50
|
const resolver = react.useCallback((binding)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderBindingScopeContext.js","sources":["../../../renderer/RenderBindingScopeContext.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, createContext, useCallback, useContext, useMemo, useRef } from 'react';\nimport { BindingResolver, BindingScope, resolveBindingExpression } from '@cratis/scene.engine';\nimport { BindingExpression, BindingNullBehavior } from '@cratis/scene.model';\nimport { BindingOutputProvider, useBindingOutputScope } from './BindingOutputContext';\n\ninterface RenderBindingScopeValue {\n resolveBinding: BindingResolver;\n scope: BindingScope;\n}\n\nconst Context = createContext<RenderBindingScopeValue | undefined>(undefined);\n\nexport interface RenderBindingScopeProviderProps {\n children: ReactNode;\n dataContext?: unknown;\n queryResults?: Record<string, unknown>;\n componentOutputs?: Record<string, Record<string, unknown>>;\n resolveBinding?: BindingResolver;\n onComponentOutputsChanged?: (outputs: Record<string, Record<string, unknown>>) => void;\n}\n\n/**\n * Provides the inherited reactive binding scope for a rendered Scene tree.\n */\nexport function RenderBindingScopeProvider(props: RenderBindingScopeProviderProps) {\n const current = useContext(Context);\n if (current) return
|
|
1
|
+
{"version":3,"file":"RenderBindingScopeContext.js","sources":["../../../renderer/RenderBindingScopeContext.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, createContext, useCallback, useContext, useMemo, useRef } from 'react';\nimport { BindingResolver, BindingScope, nestBindingScope, resolveBindingExpression } from '@cratis/scene.engine';\nimport { BindingExpression, BindingNullBehavior } from '@cratis/scene.model';\nimport { BindingOutputProvider, useBindingOutputScope } from './BindingOutputContext';\n\ninterface RenderBindingScopeValue {\n resolveBinding: BindingResolver;\n scope: BindingScope;\n}\n\nconst Context = createContext<RenderBindingScopeValue | undefined>(undefined);\n\nexport interface RenderBindingScopeProviderProps {\n children: ReactNode;\n dataContext?: unknown;\n queryResults?: Record<string, unknown>;\n componentOutputs?: Record<string, Record<string, unknown>>;\n resolveBinding?: BindingResolver;\n onComponentOutputsChanged?: (outputs: Record<string, Record<string, unknown>>) => void;\n}\n\n/**\n * Provides the inherited reactive binding scope for a rendered Scene tree.\n *\n * The outermost provider owns the component output scope. A provider rendered inside another - a nested\n * template or region - nests its own data context, query results and component outputs over the inherited\n * scope with `nestBindingScope`, so a detail region bound to the selected row reads that row while still\n * seeing the screen's queries and every component's outputs.\n */\nexport function RenderBindingScopeProvider(props: RenderBindingScopeProviderProps) {\n const current = useContext(Context);\n if (current) return <RenderBindingScopeInner {...props} parent={current.scope} />;\n\n return (\n <BindingOutputProvider onOutputsChanged={props.onComponentOutputsChanged}>\n <RenderBindingScopeInner {...props} />\n </BindingOutputProvider>\n );\n}\n\nfunction RenderBindingScopeInner({ children, dataContext, queryResults, componentOutputs, resolveBinding, parent }: RenderBindingScopeProviderProps & { parent?: BindingScope }) {\n const outputs = useBindingOutputScope();\n const previousValues = useRef(new Map<string, unknown>());\n const scope = useMemo<BindingScope>(() => {\n const own = { dataContext, queryResults, componentOutputs: { ...(componentOutputs ?? {}), ...outputs } };\n return parent ? nestBindingScope(parent, own) : own;\n }, [componentOutputs, dataContext, outputs, parent, queryResults]);\n\n const resolver = useCallback<BindingResolver>((binding: BindingExpression) => {\n if (!binding.kind && resolveBinding) return resolveBinding(binding);\n\n const key = JSON.stringify(binding);\n const value = resolveBindingExpression(binding, scope);\n if (binding.nullBehavior === BindingNullBehavior.Preserve && value === undefined) {\n return previousValues.current.get(key);\n }\n\n if (value !== undefined) previousValues.current.set(key, value);\n return value;\n }, [resolveBinding, scope]);\n\n const value = useMemo<RenderBindingScopeValue>(() => ({ resolveBinding: resolver, scope }), [resolver, scope]);\n return <Context.Provider value={value}>{children}</Context.Provider>;\n}\n\nexport function useRenderBindingResolver(): BindingResolver {\n const context = useContext(Context);\n if (!context) throw new Error('No Scene render binding scope is available.');\n return context.resolveBinding;\n}\n\nexport function useRenderBindingScope(): BindingScope {\n return useContext(Context)?.scope ?? {};\n}\n"],"names":["Context","createContext","undefined","RenderBindingScopeProvider","props","current","useContext","_jsx","RenderBindingScopeInner","parent","scope","BindingOutputProvider","onOutputsChanged","onComponentOutputsChanged","children","dataContext","queryResults","componentOutputs","resolveBinding","outputs","useBindingOutputScope","previousValues","useRef","Map","useMemo","own","nestBindingScope","resolver","useCallback","binding","kind","key","JSON","stringify","value","resolveBindingExpression","nullBehavior","BindingNullBehavior","Preserve","get","set","Provider","useRenderBindingResolver","context","Error","useRenderBindingScope"],"mappings":";;;;;;;;AAaA,MAAMA,wBAAUC,mBAAAA,CAAmDC,SAAAA,CAAAA;AAWnE;;;;;;;IAQO,SAASC,0BAAAA,CAA2BC,KAAsC,EAAA;AAC7E,IAAA,MAAMC,UAAUC,gBAAAA,CAAWN,OAAAA,CAAAA;IAC3B,IAAIK,OAAAA,EAAS,qBAAOE,cAAA,CAACC,uBAAAA,EAAAA;AAAyB,QAAA,GAAGJ,KAAK;AAAEK,QAAAA,MAAAA,EAAQJ,QAAQK;;AAExE,IAAA,qBACIH,cAAA,CAACI,0CAAAA,EAAAA;AAAsBC,QAAAA,gBAAAA,EAAkBR,MAAMS,yBAAyB;AACpE,QAAA,QAAA,gBAAAN,cAAA,CAACC,uBAAAA,EAAAA;AAAyB,YAAA,GAAGJ;;;AAGzC;AAEA,SAASI,uBAAAA,CAAwB,EAAEM,QAAQ,EAAEC,WAAW,EAAEC,YAAY,EAAEC,gBAAgB,EAAEC,cAAc,EAAET,MAAM,EAA+D,EAAA;AAC3K,IAAA,MAAMU,OAAAA,GAAUC,0CAAAA,EAAAA;IAChB,MAAMC,cAAAA,GAAiBC,aAAO,IAAIC,GAAAA,EAAAA,CAAAA;AAClC,IAAA,MAAMb,QAAQc,aAAAA,CAAsB,IAAA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QAAAA;AAAM,KAAA,CAAA;IAC7G,qBAAOH,cAAA,CAACP,QAAQyC,QAAQ,EAAA;QAACP,KAAAA,EAAOA,KAAAA;AAAQpB,QAAAA,QAAAA,EAAAA;;AAC5C;AAEO,SAAS4B,wBAAAA,GAAAA;AACZ,IAAA,MAAMC,UAAUrC,gBAAAA,CAAWN,OAAAA,CAAAA;AAC3B,IAAA,IAAI,CAAC2C,OAAAA,EAAS,MAAM,IAAIC,KAAAA,CAAM,6CAAA,CAAA;AAC9B,IAAA,OAAOD,QAAQzB,cAAc;AACjC;AAEO,SAAS2B,qBAAAA,GAAAA;IACZ,OAAOvC,gBAAAA,CAAWN,OAAAA,CAAAA,EAAUU,KAAAA,IAAS,EAAC;AAC1C;;;;"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var scene_engine = require('@cratis/scene.engine');
|
|
5
|
+
|
|
6
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
7
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
8
|
+
/**
|
|
9
|
+
* Runs a bound query whenever its arguments change and returns the accepted query results.
|
|
10
|
+
*
|
|
11
|
+
* Each change of arguments rebinds the query: the previous run is aborted and, should its answer still
|
|
12
|
+
* arrive, discarded by `QueryBindingState` - a slow result for a previous selection never replaces the
|
|
13
|
+
* current one. Arguments of `undefined` mean the binding is cleared, as when a selection is cleared, so the
|
|
14
|
+
* result is removed, and so is it when the current run fails - a failed rebind must not leave the previous
|
|
15
|
+
* selection's data on screen. The results are keyed by `query`, ready to pass as a scope's `queryResults`.
|
|
16
|
+
*/ function useBoundQuery(query, argumentsValue, perform) {
|
|
17
|
+
const state = react.useMemo(()=>new scene_engine.QueryBindingState(), []);
|
|
18
|
+
const [results, setResults] = react.useState({});
|
|
19
|
+
const key = argumentsValue === undefined ? undefined : JSON.stringify(argumentsValue);
|
|
20
|
+
const latestArguments = react.useRef(argumentsValue);
|
|
21
|
+
latestArguments.current = argumentsValue;
|
|
22
|
+
// The arguments are compared by value through `key`; the effect reads them from `latestArguments`.
|
|
23
|
+
react.useEffect(()=>{
|
|
24
|
+
const argumentsForRun = latestArguments.current;
|
|
25
|
+
if (argumentsForRun === undefined) {
|
|
26
|
+
state.clear(query);
|
|
27
|
+
setResults(state.queryResults);
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const controller = new AbortController();
|
|
31
|
+
const ticket = state.begin(query);
|
|
32
|
+
perform(query, argumentsForRun, controller.signal).then((result)=>{
|
|
33
|
+
if (state.complete(ticket, result)) setResults(state.queryResults);
|
|
34
|
+
}, ()=>{
|
|
35
|
+
if (controller.signal.aborted || !state.complete(ticket, undefined)) return;
|
|
36
|
+
state.clear(query);
|
|
37
|
+
setResults(state.queryResults);
|
|
38
|
+
});
|
|
39
|
+
return ()=>controller.abort();
|
|
40
|
+
}, [
|
|
41
|
+
key,
|
|
42
|
+
perform,
|
|
43
|
+
query,
|
|
44
|
+
state
|
|
45
|
+
]);
|
|
46
|
+
return results;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
exports.useBoundQuery = useBoundQuery;
|
|
50
|
+
//# sourceMappingURL=useBoundQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBoundQuery.js","sources":["../../../renderer/useBoundQuery.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 { useEffect, useMemo, useRef, useState } from 'react';\nimport { QueryBindingState } from '@cratis/scene.engine';\nimport { QueryPerformer } from './AbortableQueryRunner';\n\n/**\n * Runs a bound query whenever its arguments change and returns the accepted query results.\n *\n * Each change of arguments rebinds the query: the previous run is aborted and, should its answer still\n * arrive, discarded by `QueryBindingState` - a slow result for a previous selection never replaces the\n * current one. Arguments of `undefined` mean the binding is cleared, as when a selection is cleared, so the\n * result is removed, and so is it when the current run fails - a failed rebind must not leave the previous\n * selection's data on screen. The results are keyed by `query`, ready to pass as a scope's `queryResults`.\n */\nexport function useBoundQuery(query: string, argumentsValue: unknown, perform: QueryPerformer): Record<string, unknown> {\n const state = useMemo(() => new QueryBindingState(), []);\n const [results, setResults] = useState<Record<string, unknown>>({});\n const key = argumentsValue === undefined ? undefined : JSON.stringify(argumentsValue);\n const latestArguments = useRef(argumentsValue);\n latestArguments.current = argumentsValue;\n\n // The arguments are compared by value through `key`; the effect reads them from `latestArguments`.\n useEffect(() => {\n const argumentsForRun = latestArguments.current;\n if (argumentsForRun === undefined) {\n state.clear(query);\n setResults(state.queryResults);\n return undefined;\n }\n\n const controller = new AbortController();\n const ticket = state.begin(query);\n perform(query, argumentsForRun, controller.signal).then(\n result => {\n if (state.complete(ticket, result)) setResults(state.queryResults);\n },\n () => {\n if (controller.signal.aborted || !state.complete(ticket, undefined)) return;\n state.clear(query);\n setResults(state.queryResults);\n },\n );\n\n return () => controller.abort();\n }, [key, perform, query, state]);\n\n return results;\n}\n"],"names":["useBoundQuery","query","argumentsValue","perform","state","useMemo","QueryBindingState","results","setResults","useState","key","undefined","JSON","stringify","latestArguments","useRef","current","useEffect","argumentsForRun","clear","queryResults","controller","AbortController","ticket","begin","signal","then","result","complete","aborted","abort"],"mappings":";;;;;AAAA;AACA;AAMA;;;;;;;;AAQC,IACM,SAASA,aAAAA,CAAcC,KAAa,EAAEC,cAAuB,EAAEC,OAAuB,EAAA;AACzF,IAAA,MAAMC,KAAAA,GAAQC,aAAAA,CAAQ,IAAM,IAAIC,kCAAqB,EAAE,CAAA;AACvD,IAAA,MAAM,CAACC,OAAAA,EAASC,UAAAA,CAAW,GAAGC,eAAkC,EAAC,CAAA;AACjE,IAAA,MAAMC,MAAMR,cAAAA,KAAmBS,SAAAA,GAAYA,SAAAA,GAAYC,IAAAA,CAAKC,SAAS,CAACX,cAAAA,CAAAA;AACtE,IAAA,MAAMY,kBAAkBC,YAAAA,CAAOb,cAAAA,CAAAA;AAC/BY,I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