@principal-ai/subsystems-react 0.56.29 → 0.56.31

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.
Files changed (32) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/subsystem/C4ProjectionView.d.ts +3 -1
  6. package/dist/subsystem/C4ProjectionView.d.ts.map +1 -1
  7. package/dist/subsystem/C4ProjectionView.js +4 -3
  8. package/dist/subsystem/C4ProjectionView.js.map +1 -1
  9. package/dist/subsystem/C4SketchView.d.ts +3 -1
  10. package/dist/subsystem/C4SketchView.d.ts.map +1 -1
  11. package/dist/subsystem/C4SketchView.js +4 -3
  12. package/dist/subsystem/C4SketchView.js.map +1 -1
  13. package/dist/subsystem/DescriptionOverlay.d.ts.map +1 -1
  14. package/dist/subsystem/DescriptionOverlay.js +8 -2
  15. package/dist/subsystem/DescriptionOverlay.js.map +1 -1
  16. package/dist/subsystem/ShareButton.d.ts +6 -0
  17. package/dist/subsystem/ShareButton.d.ts.map +1 -0
  18. package/dist/subsystem/ShareButton.js +25 -0
  19. package/dist/subsystem/ShareButton.js.map +1 -0
  20. package/dist/subsystem/SubsystemComponentGraph.d.ts +2 -0
  21. package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
  22. package/dist/subsystem/SubsystemComponentGraph.js +2 -1
  23. package/dist/subsystem/SubsystemComponentGraph.js.map +1 -1
  24. package/package.json +3 -3
  25. package/src/index.ts +1 -0
  26. package/src/subsystem/C4ProjectionView.tsx +5 -0
  27. package/src/subsystem/C4SketchView.tsx +5 -0
  28. package/src/subsystem/DescriptionOverlay.test.tsx +1 -1
  29. package/src/subsystem/DescriptionOverlay.tsx +12 -6
  30. package/src/subsystem/ShareButton.tsx +38 -0
  31. package/src/subsystem/SubsystemComponentGraph.sidebar.test.tsx +6 -0
  32. package/src/subsystem/SubsystemComponentGraph.tsx +5 -1
@@ -12,6 +12,7 @@ import { useTheme } from '@principal-ade/industry-theme';
12
12
  import { PencilRuler } from 'lucide-react';
13
13
  import { C4Graph } from './C4Graph';
14
14
  import { C4ContainersPanel } from './C4ContainersPanel';
15
+ import { ShareButton } from './ShareButton';
15
16
  import { DescriptionOverlay } from './DescriptionOverlay';
16
17
  import { DescriptionPreview } from './DescriptionPreview';
17
18
  import { GraphWithSidebar } from './GraphWithSidebar';
@@ -26,6 +27,8 @@ export interface C4SketchViewProps {
26
27
  onOpenContainerIdsChange?: (ids: string[]) => void;
27
28
  /** Extra controls in the header. */
28
29
  headerActions?: ReactNode;
30
+ /** Show the standard Share button and delegate its action to the host. */
31
+ onShare?: () => void;
29
32
  /** Sidebar width persistence key. */
30
33
  persistKey?: string;
31
34
  /** Outer style for the flex fill. */
@@ -37,6 +40,7 @@ export function C4SketchView({
37
40
  openContainerIds,
38
41
  onOpenContainerIdsChange,
39
42
  headerActions,
43
+ onShare,
40
44
  persistKey,
41
45
  style,
42
46
  }: C4SketchViewProps) {
@@ -221,6 +225,7 @@ export function C4SketchView({
221
225
  }}
222
226
  >
223
227
  {headerActions}
228
+ {onShare && <ShareButton onClick={onShare} />}
224
229
  </div>
225
230
  </header>
226
231
 
@@ -62,7 +62,7 @@ describe('subsystem description overlay', () => {
62
62
  expect(more.textContent).toBe('Close');
63
63
  const close = view.getByRole('button', { name: 'Close description' });
64
64
  expect(document.activeElement).toBe(close);
65
- if (closeWithEscape) fireEvent.keyDown(close, { key: 'Escape' });
65
+ if (closeWithEscape) fireEvent.keyDown(document.body, { key: 'Escape' });
66
66
  else fireEvent.click(close);
67
67
  expect(view.queryByRole('dialog')).toBeNull();
68
68
  expect(more.getAttribute('aria-expanded')).toBe('false');
@@ -33,16 +33,22 @@ export function DescriptionOverlay({
33
33
  };
34
34
  }, []);
35
35
 
36
+ useEffect(() => {
37
+ const handleKeyDown = (event: KeyboardEvent) => {
38
+ if (event.key === 'Escape') {
39
+ event.preventDefault();
40
+ event.stopPropagation();
41
+ onClose();
42
+ }
43
+ };
44
+ window.addEventListener('keydown', handleKeyDown, true);
45
+ return () => window.removeEventListener('keydown', handleKeyDown, true);
46
+ }, [onClose]);
47
+
36
48
  return (
37
49
  <div
38
50
  role="dialog"
39
51
  aria-label={ariaLabel}
40
- onKeyDown={(event) => {
41
- if (event.key === 'Escape') {
42
- event.stopPropagation();
43
- onClose();
44
- }
45
- }}
46
52
  style={{
47
53
  position: 'absolute',
48
54
  inset: 0,
@@ -0,0 +1,38 @@
1
+ import { useState } from 'react';
2
+ import { Share2 } from 'lucide-react';
3
+ import { useTheme } from '@principal-ade/industry-theme';
4
+
5
+ /** Standard header affordance for host-owned sharing flows. */
6
+ export function ShareButton({ onClick }: { onClick: () => void }) {
7
+ const { theme } = useTheme();
8
+ const [hover, setHover] = useState(false);
9
+
10
+ return (
11
+ <button
12
+ type="button"
13
+ aria-label="Share"
14
+ title="Share"
15
+ onClick={onClick}
16
+ onMouseEnter={() => setHover(true)}
17
+ onMouseLeave={() => setHover(false)}
18
+ style={{
19
+ display: 'inline-flex',
20
+ alignItems: 'center',
21
+ justifyContent: 'center',
22
+ gap: 6,
23
+ height: 34,
24
+ padding: '0 10px',
25
+ borderRadius: 6,
26
+ border: `1px solid ${theme.colors.border}`,
27
+ background: hover ? theme.colors.backgroundSecondary ?? theme.colors.border : 'transparent',
28
+ color: theme.colors.textSecondary,
29
+ font: 'inherit',
30
+ fontSize: theme.fontSizes[1],
31
+ cursor: 'pointer',
32
+ }}
33
+ >
34
+ <Share2 size={14} aria-hidden="true" />
35
+ Share
36
+ </button>
37
+ );
38
+ }
@@ -49,6 +49,12 @@ describe('subsystem graph sidebar', () => {
49
49
  expect(header?.nextElementSibling?.textContent).toContain('Always visible description.');
50
50
  });
51
51
 
52
+ test('shows the host-configured Share button in the header', () => {
53
+ const body = renderGraph({ onShare: () => undefined });
54
+ const header = body.querySelector('header');
55
+ expect(header?.querySelector('button[aria-label="Share"]')?.textContent).toBe('Share');
56
+ });
57
+
52
58
  test('puts the name in a full-width header above the sidebar and graph', () => {
53
59
  const body = renderGraph();
54
60
  const header = body.querySelector('header');
@@ -99,6 +99,7 @@ import type { ComponentVerificationState } from './ComponentDeclaration';
99
99
  import type { DeclarationSymbolRef, SymbolInspection } from './symbolRefs';
100
100
  import { FileDrawer, FILE_DRAWER_HEIGHT_MS } from './FileDrawer';
101
101
  import { GraphWithSidebar } from './GraphWithSidebar';
102
+ import { ShareButton } from './ShareButton';
102
103
  import { DescriptionOverlay } from './DescriptionOverlay';
103
104
  import { DescriptionPreview } from './DescriptionPreview';
104
105
  import type { GraphSidebarTab } from './GraphSidebar';
@@ -394,6 +395,8 @@ export interface SubsystemComponentGraphProps {
394
395
  title?: string;
395
396
  /** Extra actions on the right side of the full-width graph header. */
396
397
  headerActions?: ReactNode;
398
+ /** Show the standard Share button and delegate its action to the host. */
399
+ onShare?: () => void;
397
400
  /**
398
401
  * Suppresses the header and sidebar entirely (title, description,
399
402
  * trails) for graph-only embeds. Pair with `graphTitle` to keep the
@@ -4035,6 +4038,7 @@ export function SubsystemComponentGraph(props: SubsystemComponentGraphProps) {
4035
4038
  )}
4036
4039
  </div>
4037
4040
  {props.headerActions}
4041
+ {props.onShare && <ShareButton onClick={props.onShare} />}
4038
4042
  </header>
4039
4043
  )}
4040
4044
  <div ref={wrapRef} style={{ flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column' }}>
@@ -4049,7 +4053,7 @@ export function SubsystemComponentGraph(props: SubsystemComponentGraphProps) {
4049
4053
  descriptionOpen={props.descriptionOpen}
4050
4054
  onDescriptionOpenChange={props.onDescriptionOpenChange}
4051
4055
  diagnostic={props.diagnostic}
4052
- sidebarExtra={props.headerActions ? <>{props.headerActions}{props.sidebarExtra}</> : props.sidebarExtra}
4056
+ sidebarExtra={props.onShare || props.headerActions ? <>{props.headerActions}{props.onShare && <ShareButton onClick={props.onShare} />}{props.sidebarExtra}</> : props.sidebarExtra}
4053
4057
  sidebarAfterDescription={props.sidebarAfterDescription}
4054
4058
  renderFileViewer={props.renderFileViewer}
4055
4059
  onFileSelect={props.onFileSelect}