@cratis/scene.components 4.16.0 → 4.17.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/cratisComponentsDescriptors.ts +16 -0
- package/dist/cjs/cratisComponentsDescriptors.js +68 -1
- package/dist/cjs/cratisComponentsDescriptors.js.map +1 -1
- package/dist/cjs/toolbar/SceneToolbarButton.js +34 -2
- package/dist/cjs/toolbar/SceneToolbarButton.js.map +1 -1
- package/dist/esm/cratisComponentsDescriptors.d.ts.map +1 -1
- package/dist/esm/cratisComponentsDescriptors.js +68 -1
- package/dist/esm/cratisComponentsDescriptors.js.map +1 -1
- package/dist/esm/toolbar/SceneToolbarButton.d.ts +1 -1
- package/dist/esm/toolbar/SceneToolbarButton.d.ts.map +1 -1
- package/dist/esm/toolbar/SceneToolbarButton.js +34 -2
- package/dist/esm/toolbar/SceneToolbarButton.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/toolbar/SceneToolbarButton.tsx +24 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cratis/scene.components",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.17.0",
|
|
4
4
|
"description": "The Cratis Components package: exposes @cratis/components' Arc-bound data, form and dialog composites as Scene components. Built on PrimeReact and Tailwind, and declares both as dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cratis",
|
|
@@ -59,17 +59,17 @@
|
|
|
59
59
|
"build-storybook": "storybook build"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@cratis/scene.engine": "4.
|
|
63
|
-
"@cratis/scene.model": "4.
|
|
64
|
-
"@cratis/scene.react": "4.
|
|
62
|
+
"@cratis/scene.engine": "4.17.0",
|
|
63
|
+
"@cratis/scene.model": "4.17.0",
|
|
64
|
+
"@cratis/scene.react": "4.17.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@cratis/arc": "22.50.5",
|
|
68
68
|
"@cratis/arc.react": "22.50.5",
|
|
69
69
|
"@cratis/components": "4.25.0",
|
|
70
|
-
"@cratis/scene.engine": "4.
|
|
71
|
-
"@cratis/scene.model": "4.
|
|
72
|
-
"@cratis/scene.react": "4.
|
|
70
|
+
"@cratis/scene.engine": "4.17.0",
|
|
71
|
+
"@cratis/scene.model": "4.17.0",
|
|
72
|
+
"@cratis/scene.react": "4.17.0",
|
|
73
73
|
"@storybook/addon-links": "^10.6.1",
|
|
74
74
|
"@storybook/react": "^10.6.1",
|
|
75
75
|
"@storybook/react-vite": "^10.6.1",
|
|
@@ -1,8 +1,10 @@
|
|
|
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 { useContext } from 'react';
|
|
4
5
|
import { ToolbarButton } from '@cratis/components/Toolbar';
|
|
5
|
-
import {
|
|
6
|
+
import { DestinationReference } from '@cratis/scene.model';
|
|
7
|
+
import { RegisteredComponentProps, SceneNavigationContextInternal } from '@cratis/scene.react';
|
|
6
8
|
import { booleanProperty, stringProperty, unionProperty } from '../properties';
|
|
7
9
|
|
|
8
10
|
/** Which side of the button its tooltip appears on. */
|
|
@@ -16,8 +18,21 @@ const tooltipPositions = ['top', 'right', 'bottom', 'left'] as const;
|
|
|
16
18
|
* icons. It defaults to the `text` property rather than to an empty string, so a button that has a
|
|
17
19
|
* visible label is never left nameless.
|
|
18
20
|
*/
|
|
19
|
-
|
|
21
|
+
/**
|
|
22
|
+
* A toolbar button. Its authored `destination` - a screen in an outlet, or a dialog - is executed by the
|
|
23
|
+
* enclosing navigation host; outside one it is announced with the host-neutral `cratis.scene.navigate` event.
|
|
24
|
+
* Interactions attached by the document run first.
|
|
25
|
+
*/
|
|
26
|
+
export function SceneToolbarButton({ element, interactions }: RegisteredComponentProps) {
|
|
20
27
|
const text = stringProperty(element.properties, 'text');
|
|
28
|
+
const navigation = useContext(SceneNavigationContextInternal);
|
|
29
|
+
const destination = isDestination(element.properties.destination) ? element.properties.destination : undefined;
|
|
30
|
+
const onClick = () => {
|
|
31
|
+
interactions?.onClick?.({ stopPropagation: () => undefined });
|
|
32
|
+
if (!destination) return;
|
|
33
|
+
if (navigation) navigation.navigate(destination);
|
|
34
|
+
else globalThis.dispatchEvent(new CustomEvent('cratis.scene.navigate', { detail: { destination, element } }));
|
|
35
|
+
};
|
|
21
36
|
|
|
22
37
|
return (
|
|
23
38
|
<ToolbarButton
|
|
@@ -26,6 +41,13 @@ export function SceneToolbarButton({ element }: RegisteredComponentProps) {
|
|
|
26
41
|
title={stringProperty(element.properties, 'title') ?? text ?? ''}
|
|
27
42
|
active={booleanProperty(element.properties, 'active')}
|
|
28
43
|
tooltipPosition={unionProperty(element.properties, 'tooltipPosition', tooltipPositions)}
|
|
44
|
+
onClick={onClick}
|
|
29
45
|
/>
|
|
30
46
|
);
|
|
31
47
|
}
|
|
48
|
+
|
|
49
|
+
function isDestination(value: unknown): value is DestinationReference {
|
|
50
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
51
|
+
const candidate = value as Record<string, unknown>;
|
|
52
|
+
return ['screen', 'module', 'route', 'dialog'].some(key => typeof candidate[key] === 'string');
|
|
53
|
+
}
|