@principal-ai/principal-view-react 0.16.53 → 0.16.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/pierre/PierreFileView.d.ts +16 -0
- package/dist/pierre/PierreFileView.d.ts.map +1 -0
- package/dist/pierre/PierreFileView.js +43 -0
- package/dist/pierre/PierreFileView.js.map +1 -0
- package/dist/pierre/PierreSnippetView.d.ts +27 -0
- package/dist/pierre/PierreSnippetView.d.ts.map +1 -0
- package/dist/pierre/PierreSnippetView.js +98 -0
- package/dist/pierre/PierreSnippetView.js.map +1 -0
- package/dist/pierre/index.d.ts +7 -0
- package/dist/pierre/index.d.ts.map +1 -0
- package/dist/pierre/index.js +4 -0
- package/dist/pierre/index.js.map +1 -0
- package/dist/pierre/pierreBackground.d.ts +15 -0
- package/dist/pierre/pierreBackground.d.ts.map +1 -0
- package/dist/pierre/pierreBackground.js +31 -0
- package/dist/pierre/pierreBackground.js.map +1 -0
- package/dist/pierre/scrollAnchor.d.ts +5 -0
- package/dist/pierre/scrollAnchor.d.ts.map +1 -0
- package/dist/pierre/scrollAnchor.js +9 -0
- package/dist/pierre/scrollAnchor.js.map +1 -0
- package/dist/pierre/sliceSnippet.d.ts +10 -0
- package/dist/pierre/sliceSnippet.d.ts.map +1 -0
- package/dist/pierre/sliceSnippet.js +16 -0
- package/dist/pierre/sliceSnippet.js.map +1 -0
- package/package.json +3 -1
- package/src/index.ts +8 -0
- package/src/pierre/PierreFileView.tsx +77 -0
- package/src/pierre/PierreSnippetView.tsx +176 -0
- package/src/pierre/index.ts +6 -0
- package/src/pierre/pierreBackground.ts +33 -0
- package/src/pierre/scrollAnchor.test.ts +13 -0
- package/src/pierre/scrollAnchor.ts +11 -0
- package/src/pierre/sliceSnippet.test.ts +21 -0
- package/src/pierre/sliceSnippet.ts +31 -0
- package/src/stories/SubsystemComponentGraph.stories.tsx +96 -0
package/dist/index.d.ts
CHANGED
|
@@ -66,4 +66,6 @@ export type { GraphLayoutCoverProps } from './subsystem/GraphLayoutCover';
|
|
|
66
66
|
export type { SubsystemComponent, SubsystemComponentEdge, SubsystemGraphDocument, SubsystemComponentKind, SubsystemEdgeMechanism, } from './subsystem/model';
|
|
67
67
|
export type { SubsystemDeclarationRef, SubsystemOpenFileOptions, DeclarationFreshness, } from './subsystem/declarationRef';
|
|
68
68
|
export { parseSourceLocation, normalizeDeclarationLine, extractDeclarationLine, DECLARATION_HASH_ALGO, } from './subsystem/declarationRef';
|
|
69
|
+
export { PierreFileView, PierreSnippetView, sliceSnippetWindow } from './pierre';
|
|
70
|
+
export type { PierreFileViewProps, PierreSnippetViewProps, SnippetSlice, } from './pierre';
|
|
69
71
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,YAAY,EACV,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,SAAS,EACT,OAAO,EACP,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,EACd,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,uBAAuB,EAEvB,gBAAgB,GACjB,MAAM,mCAAmC,CAAC;AAG3C,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,YAAY,EACV,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,GACf,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,YAAY,EAAE,4BAA4B,EAAE,MAAM,sCAAsC,CAAC;AAEzF,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,YAAY,EAA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AAe,EACf,SAAS,GACV,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,YAAY,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,YAAY,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC1E,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EACV,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACjF,YAAY,EACV,mBAAmB,EACnB,sBAAsB,EACtB,YAAY,GACb,MAAM,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -44,4 +44,6 @@ export { purlRepoKey, purlOwnerName, buildTreePathMapping, buildRepoGroups, repo
|
|
|
44
44
|
export { SubsystemFileTree } from './subsystem/SubsystemFileTree';
|
|
45
45
|
export { GraphLayoutCover } from './subsystem/GraphLayoutCover';
|
|
46
46
|
export { parseSourceLocation, normalizeDeclarationLine, extractDeclarationLine, DECLARATION_HASH_ALGO, } from './subsystem/declarationRef';
|
|
47
|
+
// Pierre code views (@pierre/diffs wrappers)
|
|
48
|
+
export { PierreFileView, PierreSnippetView, sliceSnippetWindow } from './pierre';
|
|
47
49
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;A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AiB,EACjB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAsChC,6DAA6D;AAC7D,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAmCrE,sEAAsE;AACtE,OAAO,EACL,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,6BAA6B,CAAC;AAyCrC,OAAO,EACL,sBAAsB,EACtB,0BAA0B,EAC1B,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACnB,iBAAiB,EACjB,UAAU,EACV,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAWpB,4BAA4B;AAC5B,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAO9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,EACL,WAAW,EACX,aAAa,EACb,oBAAoB,EACpB,eAAe,EACf,aAAa,GACd,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAElE,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAchE,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AAEpC,6CAA6C;AAC7C,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PierreFileView — host-injected full-file code view via `@pierre/diffs`.
|
|
3
|
+
*
|
|
4
|
+
* Ported from `@industry-theme/file-city-panel` so subsystem graphs and
|
|
5
|
+
* Storybook can render source without that panel package.
|
|
6
|
+
*/
|
|
7
|
+
export interface PierreFileViewProps {
|
|
8
|
+
filePath: string;
|
|
9
|
+
fileName: string;
|
|
10
|
+
/** Host-supplied file reader (closures bind any path-normalization). */
|
|
11
|
+
readFile: (path: string) => Promise<string>;
|
|
12
|
+
/** Override Pierre's container background. Any CSS color string. */
|
|
13
|
+
background?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function PierreFileView({ filePath, fileName, readFile, background, }: PierreFileViewProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
//# sourceMappingURL=PierreFileView.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PierreFileView.d.ts","sourceRoot":"","sources":["../../src/pierre/PierreFileView.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,wEAAwE;IACxE,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5C,oEAAoE;IACpE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,UAAU,GACX,EAAE,mBAAmB,2CAkDrB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* PierreFileView — host-injected full-file code view via `@pierre/diffs`.
|
|
4
|
+
*
|
|
5
|
+
* Ported from `@industry-theme/file-city-panel` so subsystem graphs and
|
|
6
|
+
* Storybook can render source without that panel package.
|
|
7
|
+
*/
|
|
8
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
9
|
+
import { File } from '@pierre/diffs/react';
|
|
10
|
+
import { useTheme } from '@principal-ade/industry-theme';
|
|
11
|
+
import { buildPierreOptions, PIERRE_FILE_STYLE } from './pierreBackground';
|
|
12
|
+
export function PierreFileView({ filePath, fileName, readFile, background, }) {
|
|
13
|
+
const { theme } = useTheme();
|
|
14
|
+
const [contents, setContents] = useState(null);
|
|
15
|
+
const [error, setError] = useState(null);
|
|
16
|
+
const fileObject = useMemo(() => (contents !== null ? { name: fileName, contents } : null), [fileName, contents]);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
let cancelled = false;
|
|
19
|
+
setContents(null);
|
|
20
|
+
setError(null);
|
|
21
|
+
void readFile(filePath)
|
|
22
|
+
.then((content) => {
|
|
23
|
+
if (!cancelled)
|
|
24
|
+
setContents(content);
|
|
25
|
+
})
|
|
26
|
+
.catch((err) => {
|
|
27
|
+
if (!cancelled) {
|
|
28
|
+
setError(err instanceof Error ? err.message : 'Failed to read file');
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return () => {
|
|
32
|
+
cancelled = true;
|
|
33
|
+
};
|
|
34
|
+
}, [filePath, readFile]);
|
|
35
|
+
if (error) {
|
|
36
|
+
return (_jsx("div", { style: { padding: 16, color: theme.colors.error ?? '#e5534b' }, children: error }));
|
|
37
|
+
}
|
|
38
|
+
if (fileObject === null) {
|
|
39
|
+
return (_jsx("div", { style: { padding: 16, color: theme.colors.textSecondary }, children: "Loading\u2026" }));
|
|
40
|
+
}
|
|
41
|
+
return (_jsx(File, { file: fileObject, options: buildPierreOptions(background), style: PIERRE_FILE_STYLE }));
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=PierreFileView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PierreFileView.js","sourceRoot":"","sources":["../../src/pierre/PierreFileView.tsx"],"names":[],"mappings":";AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CA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AC,CAAC;IAEzB,IAAI,KAAK,EAAE;QACT,OAAO,CACL,cAAK,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,SAAS,EAAE,YAChE,KAAK,GACF,CACP,CAAC;KACH;IACD,IAAI,UAAU,KAAK,IAAI,EAAE;QACvB,OAAO,CACL,cAAK,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,aAAa,EAAE,8BAExD,CACP,CAAC;KACH;IAED,OAAO,CACL,KAAC,IAAI,IACH,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,kBAAkB,CAAC,UAAU,CAAC,EACvC,KAAK,EAAE,iBAAiB,GACxB,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PierreSnippetView — focused line-range code view via `@pierre/diffs`.
|
|
3
|
+
*
|
|
4
|
+
* Ported from `@industry-theme/file-city-panel` so subsystem graphs and
|
|
5
|
+
* Storybook can scroll to a declaration line without that panel package.
|
|
6
|
+
*
|
|
7
|
+
* `File.selectedLines` highlights the focus line but does not scroll; we call
|
|
8
|
+
* `scrollIntoView` on the rendered line after Pierre paints.
|
|
9
|
+
*/
|
|
10
|
+
export interface PierreSnippetViewProps {
|
|
11
|
+
filePath: string;
|
|
12
|
+
fileName: string;
|
|
13
|
+
/** First line of the snippet (1-based, inclusive). */
|
|
14
|
+
startLine: number;
|
|
15
|
+
/** Last line of the snippet (1-based, inclusive). */
|
|
16
|
+
endLine: number;
|
|
17
|
+
/** Line to call out as the focus point; defaults to `startLine`. */
|
|
18
|
+
focusLine?: number;
|
|
19
|
+
/** Lines of context above/below the snippet; defaults to 2. */
|
|
20
|
+
contextLines?: number;
|
|
21
|
+
/** Host-supplied file reader. */
|
|
22
|
+
readFile: (path: string) => Promise<string>;
|
|
23
|
+
/** Override Pierre's container background. Any CSS color string. */
|
|
24
|
+
background?: string;
|
|
25
|
+
}
|
|
26
|
+
export declare function PierreSnippetView({ filePath, fileName, startLine, endLine, focusLine, contextLines, readFile, background, }: PierreSnippetViewProps): import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
//# sourceMappingURL=PierreSnippetView.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PierreSnippetView.d.ts","sourceRoot":"","sources":["../../src/pierre/PierreSnippetView.tsx"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAsBH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;IAClB,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iCAAiC;IACjC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5C,oEAAoE;IACpE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,iBAAiB,CAAC,EAChC,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,OAAO,EACP,SAAS,EACT,YAAgB,EAChB,QAAQ,EACR,UAAU,GACX,EAAE,sBAAsB,2CAuHxB"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* PierreSnippetView — focused line-range code view via `@pierre/diffs`.
|
|
4
|
+
*
|
|
5
|
+
* Ported from `@industry-theme/file-city-panel` so subsystem graphs and
|
|
6
|
+
* Storybook can scroll to a declaration line without that panel package.
|
|
7
|
+
*
|
|
8
|
+
* `File.selectedLines` highlights the focus line but does not scroll; we call
|
|
9
|
+
* `scrollIntoView` on the rendered line after Pierre paints.
|
|
10
|
+
*/
|
|
11
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
12
|
+
import { File } from '@pierre/diffs/react';
|
|
13
|
+
import { useTheme } from '@principal-ade/industry-theme';
|
|
14
|
+
import { buildPierreOptions, PIERRE_FILE_STYLE } from './pierreBackground';
|
|
15
|
+
import { sliceSnippetWindow } from './sliceSnippet';
|
|
16
|
+
import { scrollAnchorLine } from './scrollAnchor';
|
|
17
|
+
function scrollFocusLineIntoView(fileContainer, focusOffset) {
|
|
18
|
+
const root = fileContainer.shadowRoot ?? fileContainer;
|
|
19
|
+
const anchorLine = scrollAnchorLine(focusOffset);
|
|
20
|
+
const lineEl = root.querySelector(`[data-line="${anchorLine}"]`);
|
|
21
|
+
lineEl?.scrollIntoView({ block: 'start', behavior: 'auto' });
|
|
22
|
+
}
|
|
23
|
+
export function PierreSnippetView({ filePath, fileName, startLine, endLine, focusLine, contextLines = 2, readFile, background, }) {
|
|
24
|
+
const { theme } = useTheme();
|
|
25
|
+
const [contents, setContents] = useState(null);
|
|
26
|
+
const [error, setError] = useState(null);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
let cancelled = false;
|
|
29
|
+
setContents(null);
|
|
30
|
+
setError(null);
|
|
31
|
+
void readFile(filePath)
|
|
32
|
+
.then((content) => {
|
|
33
|
+
if (!cancelled)
|
|
34
|
+
setContents(content);
|
|
35
|
+
})
|
|
36
|
+
.catch((err) => {
|
|
37
|
+
if (!cancelled) {
|
|
38
|
+
setError(err instanceof Error ? err.message : 'Failed to read file');
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return () => {
|
|
42
|
+
cancelled = true;
|
|
43
|
+
};
|
|
44
|
+
}, [filePath, readFile]);
|
|
45
|
+
const slice = useMemo(() => {
|
|
46
|
+
if (contents == null)
|
|
47
|
+
return null;
|
|
48
|
+
return sliceSnippetWindow(contents, startLine, endLine, contextLines, focusLine ?? startLine);
|
|
49
|
+
}, [contents, startLine, endLine, contextLines, focusLine]);
|
|
50
|
+
const fileObject = useMemo(() => (slice ? { name: fileName, contents: slice.contents } : null), [fileName, slice]);
|
|
51
|
+
const lineNumberOffset = slice ? slice.sliceStart - 1 : 0;
|
|
52
|
+
const onPostRender = useCallback((fileContainer) => {
|
|
53
|
+
if (lineNumberOffset !== 0) {
|
|
54
|
+
const root = fileContainer.shadowRoot ?? fileContainer;
|
|
55
|
+
const items = root.querySelectorAll('[data-column-number][data-line-index]');
|
|
56
|
+
items.forEach((el) => {
|
|
57
|
+
const idxStr = el.dataset.lineIndex;
|
|
58
|
+
if (idxStr == null)
|
|
59
|
+
return;
|
|
60
|
+
const idx = Number.parseInt(idxStr, 10);
|
|
61
|
+
if (Number.isNaN(idx))
|
|
62
|
+
return;
|
|
63
|
+
const display = String(idx + 1 + lineNumberOffset);
|
|
64
|
+
const span = el.querySelector('[data-line-number-content]');
|
|
65
|
+
if (span && span.textContent !== display) {
|
|
66
|
+
span.textContent = display;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
if (slice?.focusOffset != null) {
|
|
71
|
+
scrollFocusLineIntoView(fileContainer, slice.focusOffset);
|
|
72
|
+
}
|
|
73
|
+
}, [lineNumberOffset, slice?.focusOffset]);
|
|
74
|
+
const options = useMemo(() => ({
|
|
75
|
+
...buildPierreOptions(background),
|
|
76
|
+
onPostRender,
|
|
77
|
+
}), [background, onPostRender]);
|
|
78
|
+
if (error) {
|
|
79
|
+
return (_jsx("div", { style: { padding: 16, color: theme.colors.error ?? '#e5534b' }, children: error }));
|
|
80
|
+
}
|
|
81
|
+
if (!fileObject || !slice) {
|
|
82
|
+
return (_jsx("div", { style: { padding: 16, color: theme.colors.textSecondary }, children: "Loading\u2026" }));
|
|
83
|
+
}
|
|
84
|
+
const rangeLabel = slice.sliceStart === slice.sliceEnd
|
|
85
|
+
? `Line ${slice.sliceStart}`
|
|
86
|
+
: `Lines ${slice.sliceStart}–${slice.sliceEnd}`;
|
|
87
|
+
return (_jsxs("div", { style: { display: 'flex', flexDirection: 'column', minHeight: 0 }, children: [_jsx("div", { style: {
|
|
88
|
+
padding: '4px 14px 6px',
|
|
89
|
+
fontFamily: theme.fonts.monospace,
|
|
90
|
+
fontSize: theme.fontSizes[0],
|
|
91
|
+
color: theme.colors.textSecondary,
|
|
92
|
+
letterSpacing: 0.4,
|
|
93
|
+
textTransform: 'uppercase',
|
|
94
|
+
}, children: rangeLabel }), _jsx(File, { file: fileObject, options: options, selectedLines: slice.focusOffset != null
|
|
95
|
+
? { start: slice.focusOffset, end: slice.focusOffset }
|
|
96
|
+
: undefined, style: PIERRE_FILE_STYLE })] }));
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=PierreSnippetView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PierreSnippetView.js","sourceRoot":"","sources":["../../src/pierre/PierreSnippetView.tsx"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,SAAS,uBAAuB,CAC9B,aAA0B,EAC1B,WAAmB;IAEnB,MAAM,IAAI,GAAG,aAAa,CAAC,UAAU,IAAI,aAAa,CAAC;IACvD,MAAM,UAAU,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAC/B,eAAe,UAAU,IAAI,CACR,CAAC;IACx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E,KAAK,CAAC,KAAK,CAAC,SAAS;oBACjC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;oBAC5B,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,aAAa;oBACjC,aAAa,EAAE,GAAG;oBAClB,aAAa,EAAE,WAAW;iBAC3B,YAEA,UAAU,GACP,EACN,KAAC,IAAI,IACH,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,OAAO,EAChB,aAAa,EACX,KAAK,CAAC,WAAW,IAAI,IAAI;oBACvB,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,GAAG,EAAE,KAAK,CAAC,WAAW,EAAE;oBACtD,CAAC,CAAC,SAAS,EAEf,KAAK,EAAE,iBAAiB,GACxB,IACE,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { PierreFileView } from './PierreFileView';
|
|
2
|
+
export type { PierreFileViewProps } from './PierreFileView';
|
|
3
|
+
export { PierreSnippetView } from './PierreSnippetView';
|
|
4
|
+
export type { PierreSnippetViewProps } from './PierreSnippetView';
|
|
5
|
+
export { sliceSnippetWindow } from './sliceSnippet';
|
|
6
|
+
export type { SnippetSlice } from './sliceSnippet';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pierre/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pierre/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Shared Pierre / @pierre/diffs option helpers for file + snippet views. */
|
|
2
|
+
export declare const PIERRE_FILE_STYLE: {
|
|
3
|
+
readonly display: "block";
|
|
4
|
+
};
|
|
5
|
+
export declare const PIERRE_BASE_OPTIONS: {
|
|
6
|
+
readonly disableFileHeader: true;
|
|
7
|
+
};
|
|
8
|
+
export declare function buildBackgroundCSS(background: string): string;
|
|
9
|
+
export declare function buildPierreOptions(background?: string): {
|
|
10
|
+
readonly disableFileHeader: true;
|
|
11
|
+
} | {
|
|
12
|
+
unsafeCSS: string;
|
|
13
|
+
disableFileHeader: true;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=pierreBackground.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pierreBackground.d.ts","sourceRoot":"","sources":["../../src/pierre/pierreBackground.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAE7E,eAAO,MAAM,iBAAiB;;CAAgC,CAAC;AAE/D,eAAO,MAAM,mBAAmB;;CAEtB,CAAC;AAEX,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAgB7D;AAED,wBAAgB,kBAAkB,CAAC,UAAU,CAAC,EAAE,MAAM;;;;;EAMrD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Shared Pierre / @pierre/diffs option helpers for file + snippet views. */
|
|
2
|
+
export const PIERRE_FILE_STYLE = { display: 'block' };
|
|
3
|
+
export const PIERRE_BASE_OPTIONS = {
|
|
4
|
+
disableFileHeader: true,
|
|
5
|
+
};
|
|
6
|
+
export function buildBackgroundCSS(background) {
|
|
7
|
+
return `
|
|
8
|
+
:host {
|
|
9
|
+
background: ${background} !important;
|
|
10
|
+
}
|
|
11
|
+
pre, code,
|
|
12
|
+
[data-gutter], [data-content],
|
|
13
|
+
[data-line], [data-column-number],
|
|
14
|
+
[data-gutter-buffer], [data-line-annotation], [data-no-newline],
|
|
15
|
+
[data-separator], [data-separator-wrapper] {
|
|
16
|
+
background: ${background} !important;
|
|
17
|
+
}
|
|
18
|
+
[data-line] span {
|
|
19
|
+
background: ${background} !important;
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
22
|
+
}
|
|
23
|
+
export function buildPierreOptions(background) {
|
|
24
|
+
if (!background)
|
|
25
|
+
return PIERRE_BASE_OPTIONS;
|
|
26
|
+
return {
|
|
27
|
+
...PIERRE_BASE_OPTIONS,
|
|
28
|
+
unsafeCSS: buildBackgroundCSS(background),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=pierreBackground.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pierreBackground.js","sourceRoot":"","sources":["../../src/pierre/pierreBackground.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAE7E,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,OAAO,EAAE,OAAO,EAAW,CAAC;AAE/D,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,iBAAiB,EAAE,IAAI;CACf,CAAC;AAEX,MAAM,UAAU,kBAAkB,CAAC,UAAkB;IACnD,OAAO;;kBAES,UAAU;;;;;;;kBAOV,UAAU;;;kBAGV,UAAU;;CAE3B,CAAC;AACF,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,UAAmB;IACpD,IAAI,CAAC,UAAU;QAAE,OAAO,mBAAmB,CAAC;IAC5C,OAAO;QACL,GAAG,mBAAmB;QACtB,SAAS,EAAE,kBAAkB,CAAC,UAAU,CAAC;KAC1C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Lines to keep visible above the focus line when scrolling. */
|
|
2
|
+
export declare const SCROLL_LEADING_LINES = 4;
|
|
3
|
+
/** 1-based line in the sliced snippet to align near the top of the viewport. */
|
|
4
|
+
export declare function scrollAnchorLine(focusOffset: number, leadingLines?: number): number;
|
|
5
|
+
//# sourceMappingURL=scrollAnchor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrollAnchor.d.ts","sourceRoot":"","sources":["../../src/pierre/scrollAnchor.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,eAAO,MAAM,oBAAoB,IAAI,CAAC;AAEtC,gFAAgF;AAChF,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,MAAM,EACnB,YAAY,SAAuB,GAClC,MAAM,CAGR"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Lines to keep visible above the focus line when scrolling. */
|
|
2
|
+
export const SCROLL_LEADING_LINES = 4;
|
|
3
|
+
/** 1-based line in the sliced snippet to align near the top of the viewport. */
|
|
4
|
+
export function scrollAnchorLine(focusOffset, leadingLines = SCROLL_LEADING_LINES) {
|
|
5
|
+
if (focusOffset <= 1)
|
|
6
|
+
return 1;
|
|
7
|
+
return Math.max(1, focusOffset - leadingLines);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=scrollAnchor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrollAnchor.js","sourceRoot":"","sources":["../../src/pierre/scrollAnchor.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAEtC,gFAAgF;AAChF,MAAM,UAAU,gBAAgB,CAC9B,WAAmB,EACnB,YAAY,GAAG,oBAAoB;IAEnC,IAAI,WAAW,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,GAAG,YAAY,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Slice a file's line range with surrounding context for snippet rendering. */
|
|
2
|
+
export interface SnippetSlice {
|
|
3
|
+
contents: string;
|
|
4
|
+
sliceStart: number;
|
|
5
|
+
sliceEnd: number;
|
|
6
|
+
/** 1-based line index within `contents` to highlight, or null. */
|
|
7
|
+
focusOffset: number | null;
|
|
8
|
+
}
|
|
9
|
+
export declare function sliceSnippetWindow(contents: string, startLine: number, endLine: number, contextLines: number, focusLine?: number | null): SnippetSlice;
|
|
10
|
+
//# sourceMappingURL=sliceSnippet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sliceSnippet.d.ts","sourceRoot":"","sources":["../../src/pierre/sliceSnippet.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAEhF,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,kEAAkE;IAClE,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GACxB,YAAY,CAcd"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Slice a file's line range with surrounding context for snippet rendering. */
|
|
2
|
+
export function sliceSnippetWindow(contents, startLine, endLine, contextLines, focusLine) {
|
|
3
|
+
const allLines = contents.split('\n');
|
|
4
|
+
const total = allLines.length;
|
|
5
|
+
const safeStart = Math.max(1, Math.min(startLine, total));
|
|
6
|
+
const safeEnd = Math.max(safeStart, Math.min(endLine, total));
|
|
7
|
+
const sliceStart = Math.max(1, safeStart - contextLines);
|
|
8
|
+
const sliceEnd = Math.min(total, safeEnd + contextLines);
|
|
9
|
+
return {
|
|
10
|
+
contents: allLines.slice(sliceStart - 1, sliceEnd).join('\n'),
|
|
11
|
+
sliceStart,
|
|
12
|
+
sliceEnd,
|
|
13
|
+
focusOffset: focusLine == null ? null : Math.max(1, focusLine - sliceStart + 1),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=sliceSnippet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sliceSnippet.js","sourceRoot":"","sources":["../../src/pierre/sliceSnippet.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAUhF,MAAM,UAAU,kBAAkB,CAChC,QAAgB,EAChB,SAAiB,EACjB,OAAe,EACf,YAAoB,EACpB,SAAyB;IAEzB,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC;IAC9B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;IAC9D,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,GAAG,YAAY,CAAC,CAAC;IACzD,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CAAC,CAAC;IACzD,OAAO;QACL,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAC7D,UAAU;QACV,QAAQ;QACR,WAAW,EACT,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,GAAG,UAAU,GAAG,CAAC,CAAC;KACrE,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@principal-ai/principal-view-react",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.54",
|
|
4
4
|
"description": "React components for graph-based principal view framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -33,12 +33,14 @@
|
|
|
33
33
|
"zustand": "4.5.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
+
"@pierre/diffs": ">=1.1.20",
|
|
36
37
|
"@principal-ade/industry-theme": "^0.1.7",
|
|
37
38
|
"@principal-ai/principal-view-core": ">=0.27.0",
|
|
38
39
|
"react": "^18.0.0 || ^19.0.0",
|
|
39
40
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
43
|
+
"@pierre/diffs": "^1.3.0",
|
|
42
44
|
"@principal-ade/industry-theme": "0.1.7",
|
|
43
45
|
"@principal-ai/agent-monitoring": "^0.3.38",
|
|
44
46
|
"@principal-ai/principal-view-core": "0.27.1",
|
package/src/index.ts
CHANGED
|
@@ -316,3 +316,11 @@ export {
|
|
|
316
316
|
extractDeclarationLine,
|
|
317
317
|
DECLARATION_HASH_ALGO,
|
|
318
318
|
} from './subsystem/declarationRef';
|
|
319
|
+
|
|
320
|
+
// Pierre code views (@pierre/diffs wrappers)
|
|
321
|
+
export { PierreFileView, PierreSnippetView, sliceSnippetWindow } from './pierre';
|
|
322
|
+
export type {
|
|
323
|
+
PierreFileViewProps,
|
|
324
|
+
PierreSnippetViewProps,
|
|
325
|
+
SnippetSlice,
|
|
326
|
+
} from './pierre';
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PierreFileView — host-injected full-file code view via `@pierre/diffs`.
|
|
3
|
+
*
|
|
4
|
+
* Ported from `@industry-theme/file-city-panel` so subsystem graphs and
|
|
5
|
+
* Storybook can render source without that panel package.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
9
|
+
import { File } from '@pierre/diffs/react';
|
|
10
|
+
import { useTheme } from '@principal-ade/industry-theme';
|
|
11
|
+
import { buildPierreOptions, PIERRE_FILE_STYLE } from './pierreBackground';
|
|
12
|
+
|
|
13
|
+
export interface PierreFileViewProps {
|
|
14
|
+
filePath: string;
|
|
15
|
+
fileName: string;
|
|
16
|
+
/** Host-supplied file reader (closures bind any path-normalization). */
|
|
17
|
+
readFile: (path: string) => Promise<string>;
|
|
18
|
+
/** Override Pierre's container background. Any CSS color string. */
|
|
19
|
+
background?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function PierreFileView({
|
|
23
|
+
filePath,
|
|
24
|
+
fileName,
|
|
25
|
+
readFile,
|
|
26
|
+
background,
|
|
27
|
+
}: PierreFileViewProps) {
|
|
28
|
+
const { theme } = useTheme();
|
|
29
|
+
const [contents, setContents] = useState<string | null>(null);
|
|
30
|
+
const [error, setError] = useState<string | null>(null);
|
|
31
|
+
|
|
32
|
+
const fileObject = useMemo(
|
|
33
|
+
() => (contents !== null ? { name: fileName, contents } : null),
|
|
34
|
+
[fileName, contents],
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
let cancelled = false;
|
|
39
|
+
setContents(null);
|
|
40
|
+
setError(null);
|
|
41
|
+
void readFile(filePath)
|
|
42
|
+
.then((content) => {
|
|
43
|
+
if (!cancelled) setContents(content);
|
|
44
|
+
})
|
|
45
|
+
.catch((err) => {
|
|
46
|
+
if (!cancelled) {
|
|
47
|
+
setError(err instanceof Error ? err.message : 'Failed to read file');
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return () => {
|
|
51
|
+
cancelled = true;
|
|
52
|
+
};
|
|
53
|
+
}, [filePath, readFile]);
|
|
54
|
+
|
|
55
|
+
if (error) {
|
|
56
|
+
return (
|
|
57
|
+
<div style={{ padding: 16, color: theme.colors.error ?? '#e5534b' }}>
|
|
58
|
+
{error}
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
if (fileObject === null) {
|
|
63
|
+
return (
|
|
64
|
+
<div style={{ padding: 16, color: theme.colors.textSecondary }}>
|
|
65
|
+
Loading…
|
|
66
|
+
</div>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<File
|
|
72
|
+
file={fileObject}
|
|
73
|
+
options={buildPierreOptions(background)}
|
|
74
|
+
style={PIERRE_FILE_STYLE}
|
|
75
|
+
/>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PierreSnippetView — focused line-range code view via `@pierre/diffs`.
|
|
3
|
+
*
|
|
4
|
+
* Ported from `@industry-theme/file-city-panel` so subsystem graphs and
|
|
5
|
+
* Storybook can scroll to a declaration line without that panel package.
|
|
6
|
+
*
|
|
7
|
+
* `File.selectedLines` highlights the focus line but does not scroll; we call
|
|
8
|
+
* `scrollIntoView` on the rendered line after Pierre paints.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
12
|
+
import { File } from '@pierre/diffs/react';
|
|
13
|
+
import { useTheme } from '@principal-ade/industry-theme';
|
|
14
|
+
import { buildPierreOptions, PIERRE_FILE_STYLE } from './pierreBackground';
|
|
15
|
+
import { sliceSnippetWindow } from './sliceSnippet';
|
|
16
|
+
|
|
17
|
+
import { scrollAnchorLine } from './scrollAnchor';
|
|
18
|
+
|
|
19
|
+
function scrollFocusLineIntoView(
|
|
20
|
+
fileContainer: HTMLElement,
|
|
21
|
+
focusOffset: number,
|
|
22
|
+
): void {
|
|
23
|
+
const root = fileContainer.shadowRoot ?? fileContainer;
|
|
24
|
+
const anchorLine = scrollAnchorLine(focusOffset);
|
|
25
|
+
const lineEl = root.querySelector(
|
|
26
|
+
`[data-line="${anchorLine}"]`,
|
|
27
|
+
) as HTMLElement | null;
|
|
28
|
+
lineEl?.scrollIntoView({ block: 'start', behavior: 'auto' });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface PierreSnippetViewProps {
|
|
32
|
+
filePath: string;
|
|
33
|
+
fileName: string;
|
|
34
|
+
/** First line of the snippet (1-based, inclusive). */
|
|
35
|
+
startLine: number;
|
|
36
|
+
/** Last line of the snippet (1-based, inclusive). */
|
|
37
|
+
endLine: number;
|
|
38
|
+
/** Line to call out as the focus point; defaults to `startLine`. */
|
|
39
|
+
focusLine?: number;
|
|
40
|
+
/** Lines of context above/below the snippet; defaults to 2. */
|
|
41
|
+
contextLines?: number;
|
|
42
|
+
/** Host-supplied file reader. */
|
|
43
|
+
readFile: (path: string) => Promise<string>;
|
|
44
|
+
/** Override Pierre's container background. Any CSS color string. */
|
|
45
|
+
background?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function PierreSnippetView({
|
|
49
|
+
filePath,
|
|
50
|
+
fileName,
|
|
51
|
+
startLine,
|
|
52
|
+
endLine,
|
|
53
|
+
focusLine,
|
|
54
|
+
contextLines = 2,
|
|
55
|
+
readFile,
|
|
56
|
+
background,
|
|
57
|
+
}: PierreSnippetViewProps) {
|
|
58
|
+
const { theme } = useTheme();
|
|
59
|
+
const [contents, setContents] = useState<string | null>(null);
|
|
60
|
+
const [error, setError] = useState<string | null>(null);
|
|
61
|
+
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
let cancelled = false;
|
|
64
|
+
setContents(null);
|
|
65
|
+
setError(null);
|
|
66
|
+
void readFile(filePath)
|
|
67
|
+
.then((content) => {
|
|
68
|
+
if (!cancelled) setContents(content);
|
|
69
|
+
})
|
|
70
|
+
.catch((err) => {
|
|
71
|
+
if (!cancelled) {
|
|
72
|
+
setError(err instanceof Error ? err.message : 'Failed to read file');
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return () => {
|
|
76
|
+
cancelled = true;
|
|
77
|
+
};
|
|
78
|
+
}, [filePath, readFile]);
|
|
79
|
+
|
|
80
|
+
const slice = useMemo(() => {
|
|
81
|
+
if (contents == null) return null;
|
|
82
|
+
return sliceSnippetWindow(
|
|
83
|
+
contents,
|
|
84
|
+
startLine,
|
|
85
|
+
endLine,
|
|
86
|
+
contextLines,
|
|
87
|
+
focusLine ?? startLine,
|
|
88
|
+
);
|
|
89
|
+
}, [contents, startLine, endLine, contextLines, focusLine]);
|
|
90
|
+
|
|
91
|
+
const fileObject = useMemo(
|
|
92
|
+
() => (slice ? { name: fileName, contents: slice.contents } : null),
|
|
93
|
+
[fileName, slice],
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const lineNumberOffset = slice ? slice.sliceStart - 1 : 0;
|
|
97
|
+
|
|
98
|
+
const onPostRender = useCallback(
|
|
99
|
+
(fileContainer: HTMLElement) => {
|
|
100
|
+
if (lineNumberOffset !== 0) {
|
|
101
|
+
const root = fileContainer.shadowRoot ?? fileContainer;
|
|
102
|
+
const items = root.querySelectorAll('[data-column-number][data-line-index]');
|
|
103
|
+
items.forEach((el) => {
|
|
104
|
+
const idxStr = (el as HTMLElement).dataset.lineIndex;
|
|
105
|
+
if (idxStr == null) return;
|
|
106
|
+
const idx = Number.parseInt(idxStr, 10);
|
|
107
|
+
if (Number.isNaN(idx)) return;
|
|
108
|
+
const display = String(idx + 1 + lineNumberOffset);
|
|
109
|
+
const span = el.querySelector('[data-line-number-content]');
|
|
110
|
+
if (span && span.textContent !== display) {
|
|
111
|
+
span.textContent = display;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
if (slice?.focusOffset != null) {
|
|
116
|
+
scrollFocusLineIntoView(fileContainer, slice.focusOffset);
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
[lineNumberOffset, slice?.focusOffset],
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const options = useMemo(
|
|
123
|
+
() => ({
|
|
124
|
+
...buildPierreOptions(background),
|
|
125
|
+
onPostRender,
|
|
126
|
+
}),
|
|
127
|
+
[background, onPostRender],
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
if (error) {
|
|
131
|
+
return (
|
|
132
|
+
<div style={{ padding: 16, color: theme.colors.error ?? '#e5534b' }}>
|
|
133
|
+
{error}
|
|
134
|
+
</div>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
if (!fileObject || !slice) {
|
|
138
|
+
return (
|
|
139
|
+
<div style={{ padding: 16, color: theme.colors.textSecondary }}>
|
|
140
|
+
Loading…
|
|
141
|
+
</div>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const rangeLabel =
|
|
146
|
+
slice.sliceStart === slice.sliceEnd
|
|
147
|
+
? `Line ${slice.sliceStart}`
|
|
148
|
+
: `Lines ${slice.sliceStart}–${slice.sliceEnd}`;
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<div style={{ display: 'flex', flexDirection: 'column', minHeight: 0 }}>
|
|
152
|
+
<div
|
|
153
|
+
style={{
|
|
154
|
+
padding: '4px 14px 6px',
|
|
155
|
+
fontFamily: theme.fonts.monospace,
|
|
156
|
+
fontSize: theme.fontSizes[0],
|
|
157
|
+
color: theme.colors.textSecondary,
|
|
158
|
+
letterSpacing: 0.4,
|
|
159
|
+
textTransform: 'uppercase',
|
|
160
|
+
}}
|
|
161
|
+
>
|
|
162
|
+
{rangeLabel}
|
|
163
|
+
</div>
|
|
164
|
+
<File
|
|
165
|
+
file={fileObject}
|
|
166
|
+
options={options}
|
|
167
|
+
selectedLines={
|
|
168
|
+
slice.focusOffset != null
|
|
169
|
+
? { start: slice.focusOffset, end: slice.focusOffset }
|
|
170
|
+
: undefined
|
|
171
|
+
}
|
|
172
|
+
style={PIERRE_FILE_STYLE}
|
|
173
|
+
/>
|
|
174
|
+
</div>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { PierreFileView } from './PierreFileView';
|
|
2
|
+
export type { PierreFileViewProps } from './PierreFileView';
|
|
3
|
+
export { PierreSnippetView } from './PierreSnippetView';
|
|
4
|
+
export type { PierreSnippetViewProps } from './PierreSnippetView';
|
|
5
|
+
export { sliceSnippetWindow } from './sliceSnippet';
|
|
6
|
+
export type { SnippetSlice } from './sliceSnippet';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Shared Pierre / @pierre/diffs option helpers for file + snippet views. */
|
|
2
|
+
|
|
3
|
+
export const PIERRE_FILE_STYLE = { display: 'block' } as const;
|
|
4
|
+
|
|
5
|
+
export const PIERRE_BASE_OPTIONS = {
|
|
6
|
+
disableFileHeader: true,
|
|
7
|
+
} as const;
|
|
8
|
+
|
|
9
|
+
export function buildBackgroundCSS(background: string): string {
|
|
10
|
+
return `
|
|
11
|
+
:host {
|
|
12
|
+
background: ${background} !important;
|
|
13
|
+
}
|
|
14
|
+
pre, code,
|
|
15
|
+
[data-gutter], [data-content],
|
|
16
|
+
[data-line], [data-column-number],
|
|
17
|
+
[data-gutter-buffer], [data-line-annotation], [data-no-newline],
|
|
18
|
+
[data-separator], [data-separator-wrapper] {
|
|
19
|
+
background: ${background} !important;
|
|
20
|
+
}
|
|
21
|
+
[data-line] span {
|
|
22
|
+
background: ${background} !important;
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function buildPierreOptions(background?: string) {
|
|
28
|
+
if (!background) return PIERRE_BASE_OPTIONS;
|
|
29
|
+
return {
|
|
30
|
+
...PIERRE_BASE_OPTIONS,
|
|
31
|
+
unsafeCSS: buildBackgroundCSS(background),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { scrollAnchorLine } from './scrollAnchor';
|
|
3
|
+
|
|
4
|
+
describe('scrollAnchorLine', () => {
|
|
5
|
+
test('first line stays at top', () => {
|
|
6
|
+
expect(scrollAnchorLine(1)).toBe(1);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
test('focus line keeps a few lines of leading context', () => {
|
|
10
|
+
expect(scrollAnchorLine(10, 4)).toBe(6);
|
|
11
|
+
expect(scrollAnchorLine(3, 4)).toBe(1);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Lines to keep visible above the focus line when scrolling. */
|
|
2
|
+
export const SCROLL_LEADING_LINES = 4;
|
|
3
|
+
|
|
4
|
+
/** 1-based line in the sliced snippet to align near the top of the viewport. */
|
|
5
|
+
export function scrollAnchorLine(
|
|
6
|
+
focusOffset: number,
|
|
7
|
+
leadingLines = SCROLL_LEADING_LINES,
|
|
8
|
+
): number {
|
|
9
|
+
if (focusOffset <= 1) return 1;
|
|
10
|
+
return Math.max(1, focusOffset - leadingLines);
|
|
11
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { sliceSnippetWindow } from './sliceSnippet';
|
|
3
|
+
|
|
4
|
+
describe('sliceSnippetWindow', () => {
|
|
5
|
+
const content = ['line1', 'line2', 'line3', 'line4', 'line5'].join('\n');
|
|
6
|
+
|
|
7
|
+
test('slices with context and focus offset', () => {
|
|
8
|
+
const s = sliceSnippetWindow(content, 3, 3, 1, 3);
|
|
9
|
+
expect(s.sliceStart).toBe(2);
|
|
10
|
+
expect(s.sliceEnd).toBe(4);
|
|
11
|
+
expect(s.contents).toBe(['line2', 'line3', 'line4'].join('\n'));
|
|
12
|
+
expect(s.focusOffset).toBe(2);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('clamps out-of-range lines', () => {
|
|
16
|
+
const s = sliceSnippetWindow(content, 99, 99, 0, 99);
|
|
17
|
+
expect(s.sliceStart).toBe(5);
|
|
18
|
+
expect(s.sliceEnd).toBe(5);
|
|
19
|
+
expect(s.focusOffset).toBe(95);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Slice a file's line range with surrounding context for snippet rendering. */
|
|
2
|
+
|
|
3
|
+
export interface SnippetSlice {
|
|
4
|
+
contents: string;
|
|
5
|
+
sliceStart: number;
|
|
6
|
+
sliceEnd: number;
|
|
7
|
+
/** 1-based line index within `contents` to highlight, or null. */
|
|
8
|
+
focusOffset: number | null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function sliceSnippetWindow(
|
|
12
|
+
contents: string,
|
|
13
|
+
startLine: number,
|
|
14
|
+
endLine: number,
|
|
15
|
+
contextLines: number,
|
|
16
|
+
focusLine?: number | null,
|
|
17
|
+
): SnippetSlice {
|
|
18
|
+
const allLines = contents.split('\n');
|
|
19
|
+
const total = allLines.length;
|
|
20
|
+
const safeStart = Math.max(1, Math.min(startLine, total));
|
|
21
|
+
const safeEnd = Math.max(safeStart, Math.min(endLine, total));
|
|
22
|
+
const sliceStart = Math.max(1, safeStart - contextLines);
|
|
23
|
+
const sliceEnd = Math.min(total, safeEnd + contextLines);
|
|
24
|
+
return {
|
|
25
|
+
contents: allLines.slice(sliceStart - 1, sliceEnd).join('\n'),
|
|
26
|
+
sliceStart,
|
|
27
|
+
sliceEnd,
|
|
28
|
+
focusOffset:
|
|
29
|
+
focusLine == null ? null : Math.max(1, focusLine - sliceStart + 1),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -3,8 +3,12 @@ import '@xyflow/react/dist/style.css';
|
|
|
3
3
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
4
4
|
import { ThemeProvider, defaultTheme, defaultEditorTheme } from '@principal-ade/industry-theme';
|
|
5
5
|
import { SubsystemComponentGraph } from '../subsystem/SubsystemComponentGraph';
|
|
6
|
+
import { PierreFileView, PierreSnippetView } from '../pierre';
|
|
6
7
|
import type { SubsystemComponent, SubsystemComponentEdge } from '../subsystem/model';
|
|
8
|
+
import type { SubsystemOpenFileOptions } from '../subsystem/declarationRef';
|
|
7
9
|
import type { GraphifyComponentDetail } from '../graphify';
|
|
10
|
+
import componentDeclarationSource from '../subsystem/ComponentDeclaration.tsx?raw';
|
|
11
|
+
import resolveSource from '../graphify/resolve.ts?raw';
|
|
8
12
|
const meta = {
|
|
9
13
|
title: 'Subsystem/Component Graph',
|
|
10
14
|
component: SubsystemComponentGraph,
|
|
@@ -1127,3 +1131,95 @@ function MultiRepoDemo() {
|
|
|
1127
1131
|
export const MultiRepoTrees: Story = {
|
|
1128
1132
|
render: () => <MultiRepoDemo />,
|
|
1129
1133
|
};
|
|
1134
|
+
|
|
1135
|
+
// ---------------------------------------------------------------------------
|
|
1136
|
+
// Declaration line open — Pierre snippet/file views + declarationRef.
|
|
1137
|
+
// Click the ComponentDeclaration node → toggle file → click path or L251.
|
|
1138
|
+
// ---------------------------------------------------------------------------
|
|
1139
|
+
const storyFileContents: Record<string, string> = {
|
|
1140
|
+
'packages/react/src/subsystem/ComponentDeclaration.tsx': componentDeclarationSource,
|
|
1141
|
+
'packages/react/src/graphify/resolve.ts': resolveSource,
|
|
1142
|
+
};
|
|
1143
|
+
|
|
1144
|
+
const declarationOpenComponents: SubsystemComponent[] = [
|
|
1145
|
+
{
|
|
1146
|
+
id: 'detail',
|
|
1147
|
+
name: 'ComponentDeclaration',
|
|
1148
|
+
kind: 'module',
|
|
1149
|
+
file: 'packages/react/src/subsystem/ComponentDeclaration.tsx',
|
|
1150
|
+
purl: 'pkg:github/principal-ai/principal-view-core-library',
|
|
1151
|
+
purpose: 'declaration panel — click file or L251 to open the drawer at the export line',
|
|
1152
|
+
symbol: 'ComponentDeclaration',
|
|
1153
|
+
declarationRef: {
|
|
1154
|
+
file: 'packages/react/src/subsystem/ComponentDeclaration.tsx',
|
|
1155
|
+
startLine: 251,
|
|
1156
|
+
lineHash: 'storybook-placeholder',
|
|
1157
|
+
capturedAt: new Date(0).toISOString(),
|
|
1158
|
+
},
|
|
1159
|
+
},
|
|
1160
|
+
{
|
|
1161
|
+
id: 'resolver',
|
|
1162
|
+
name: 'resolve.ts',
|
|
1163
|
+
kind: 'module',
|
|
1164
|
+
file: 'packages/react/src/graphify/resolve.ts',
|
|
1165
|
+
purl: 'pkg:github/principal-ai/principal-view-core-library',
|
|
1166
|
+
purpose: 'graphify type-ref resolver (second file for tree navigation)',
|
|
1167
|
+
symbol: 'resolveGraphifyTypeRef',
|
|
1168
|
+
declarationRef: {
|
|
1169
|
+
file: 'packages/react/src/graphify/resolve.ts',
|
|
1170
|
+
startLine: 1,
|
|
1171
|
+
lineHash: 'storybook-placeholder',
|
|
1172
|
+
capturedAt: new Date(0).toISOString(),
|
|
1173
|
+
},
|
|
1174
|
+
},
|
|
1175
|
+
];
|
|
1176
|
+
|
|
1177
|
+
function readStoryFile(path: string): Promise<string> {
|
|
1178
|
+
const content = storyFileContents[path];
|
|
1179
|
+
if (content == null) {
|
|
1180
|
+
return Promise.reject(new Error(`No story fixture for ${path}`));
|
|
1181
|
+
}
|
|
1182
|
+
return Promise.resolve(content);
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
function DeclarationLineOpenDemo() {
|
|
1186
|
+
const renderFileViewer = (file: string, opts?: SubsystemOpenFileOptions) => {
|
|
1187
|
+
const startLine = opts?.startLine;
|
|
1188
|
+
if (startLine != null) {
|
|
1189
|
+
return (
|
|
1190
|
+
<PierreSnippetView
|
|
1191
|
+
filePath={file}
|
|
1192
|
+
fileName={file.split('/').pop() ?? file}
|
|
1193
|
+
startLine={startLine}
|
|
1194
|
+
endLine={startLine}
|
|
1195
|
+
focusLine={startLine}
|
|
1196
|
+
contextLines={40}
|
|
1197
|
+
readFile={readStoryFile}
|
|
1198
|
+
/>
|
|
1199
|
+
);
|
|
1200
|
+
}
|
|
1201
|
+
return (
|
|
1202
|
+
<PierreFileView
|
|
1203
|
+
filePath={file}
|
|
1204
|
+
fileName={file.split('/').pop() ?? file}
|
|
1205
|
+
readFile={readStoryFile}
|
|
1206
|
+
/>
|
|
1207
|
+
);
|
|
1208
|
+
};
|
|
1209
|
+
|
|
1210
|
+
return (
|
|
1211
|
+
<div style={{ width: '100%', height: '100vh', display: 'flex', flexDirection: 'column' }}>
|
|
1212
|
+
<SubsystemComponentGraph
|
|
1213
|
+
title="Declaration line open (Storybook)"
|
|
1214
|
+
description="Uses bundled ?raw fixtures + PierreSnippetView from this package. Select ComponentDeclaration, toggle file, click the path or L251."
|
|
1215
|
+
components={declarationOpenComponents}
|
|
1216
|
+
edges={[]}
|
|
1217
|
+
renderFileViewer={renderFileViewer}
|
|
1218
|
+
/>
|
|
1219
|
+
</div>
|
|
1220
|
+
);
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
export const DeclarationLineOpen: Story = {
|
|
1224
|
+
render: () => <DeclarationLineOpenDemo />,
|
|
1225
|
+
};
|