@astryxdesign/lab 0.7.1-canary.ff40b78 → 0.7.2-canary.c68f5e8
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/blocks/DiffViewerShowcase.doc.mjs +22 -0
- package/blocks/DiffViewerShowcase.tsx +81 -0
- package/dist/DiffViewer/DiffViewer.d.ts +132 -0
- package/dist/DiffViewer/DiffViewer.d.ts.map +1 -0
- package/dist/DiffViewer/DiffViewer.js +1254 -0
- package/dist/DiffViewer/createDiffFile.d.ts +51 -0
- package/dist/DiffViewer/createDiffFile.d.ts.map +1 -0
- package/dist/DiffViewer/createDiffFile.js +283 -0
- package/dist/DiffViewer/diffTypes.d.ts +66 -0
- package/dist/DiffViewer/diffTypes.d.ts.map +1 -0
- package/dist/DiffViewer/diffTypes.js +1 -0
- package/dist/DiffViewer/index.d.ts +15 -0
- package/dist/DiffViewer/index.d.ts.map +1 -0
- package/dist/DiffViewer/index.js +15 -0
- package/dist/DiffViewer/inlineDiff.d.ts +33 -0
- package/dist/DiffViewer/inlineDiff.d.ts.map +1 -0
- package/dist/DiffViewer/inlineDiff.js +171 -0
- package/dist/DiffViewer/parseUnifiedDiff.d.ts +32 -0
- package/dist/DiffViewer/parseUnifiedDiff.d.ts.map +1 -0
- package/dist/DiffViewer/parseUnifiedDiff.js +380 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/lab.css +46 -0
- package/package.json +7 -5
- package/src/DiffViewer/DiffViewer.doc.mjs +217 -0
- package/src/DiffViewer/DiffViewer.test.tsx +575 -0
- package/src/DiffViewer/DiffViewer.tsx +1746 -0
- package/src/DiffViewer/createDiffFile.test.ts +180 -0
- package/src/DiffViewer/createDiffFile.ts +316 -0
- package/src/DiffViewer/diffTypes.ts +74 -0
- package/src/DiffViewer/index.ts +32 -0
- package/src/DiffViewer/inlineDiff.test.ts +88 -0
- package/src/DiffViewer/inlineDiff.ts +199 -0
- package/src/DiffViewer/parseUnifiedDiff.test.ts +397 -0
- package/src/DiffViewer/parseUnifiedDiff.ts +437 -0
- package/src/ListInput/ListInput.test.tsx +9 -1
- package/src/Schedule/Schedule.test.tsx +97 -0
- package/src/Schedule/__tests__/ScheduleTimeGridSkippedMidnight.a11y.chromium.spec.ts +113 -0
- package/src/index.ts +21 -3
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
|
|
4
|
+
export default {
|
|
5
|
+
type: 'block',
|
|
6
|
+
name: 'Unified diff from a patch',
|
|
7
|
+
displayName: 'Unified diff from a patch',
|
|
8
|
+
description:
|
|
9
|
+
'A patch parsed with parseUnifiedDiff and rendered in unified or split view. Clicking a line number selects that line and opens an annotation row under it, the way a review comment would appear.',
|
|
10
|
+
exampleFor: 'DiffViewer',
|
|
11
|
+
isReady: true,
|
|
12
|
+
isShowcase: true,
|
|
13
|
+
aspectRatio: 16 / 9,
|
|
14
|
+
componentsUsed: [
|
|
15
|
+
'DiffViewer',
|
|
16
|
+
'Button',
|
|
17
|
+
'HStack',
|
|
18
|
+
'StackItem',
|
|
19
|
+
'VStack',
|
|
20
|
+
'Text',
|
|
21
|
+
],
|
|
22
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @input A unified diff string parsed with parseUnifiedDiff
|
|
7
|
+
* @output One DiffViewer with a unified/split toggle and click-to-comment line numbers
|
|
8
|
+
* @position Lab DiffViewer's docsite showcase and copyable CLI block
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {useState} from 'react';
|
|
12
|
+
import {
|
|
13
|
+
DiffViewer,
|
|
14
|
+
parseUnifiedDiff,
|
|
15
|
+
type DiffViewerLineRef,
|
|
16
|
+
} from '@astryxdesign/lab';
|
|
17
|
+
import {Button} from '@astryxdesign/core/Button';
|
|
18
|
+
import {HStack, StackItem, VStack} from '@astryxdesign/core/Stack';
|
|
19
|
+
import {Text} from '@astryxdesign/core/Text';
|
|
20
|
+
|
|
21
|
+
const PATCH = `diff --git a/src/cart/total.ts b/src/cart/total.ts
|
|
22
|
+
--- a/src/cart/total.ts
|
|
23
|
+
+++ b/src/cart/total.ts
|
|
24
|
+
@@ -1,9 +1,11 @@
|
|
25
|
+
import type {CartItem} from './types';
|
|
26
|
+
+import {roundCurrency} from '../money';
|
|
27
|
+
|
|
28
|
+
-export function cartTotal(items: CartItem[], discount = 0) {
|
|
29
|
+
- let total = 0;
|
|
30
|
+
- for (const item of items) {
|
|
31
|
+
- total += item.price * item.quantity * (1 - discount);
|
|
32
|
+
- }
|
|
33
|
+
- return total;
|
|
34
|
+
+export function cartTotal(items: CartItem[], discount = 0): number {
|
|
35
|
+
+ const subtotal = items.reduce(
|
|
36
|
+
+ (sum, item) => sum + item.price * item.quantity,
|
|
37
|
+
+ 0,
|
|
38
|
+
+ );
|
|
39
|
+
+ return roundCurrency(subtotal * (1 - discount));
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
|
|
43
|
+
const [FILE] = parseUnifiedDiff(PATCH);
|
|
44
|
+
|
|
45
|
+
export default function DiffViewerShowcase() {
|
|
46
|
+
const [viewMode, setViewMode] = useState<'unified' | 'split'>('unified');
|
|
47
|
+
const [selected, setSelected] = useState<DiffViewerLineRef | null>(null);
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<VStack gap={3}>
|
|
51
|
+
<HStack gap={2} vAlign="center">
|
|
52
|
+
<StackItem size="fill">
|
|
53
|
+
<Text type="supporting" color="secondary">
|
|
54
|
+
{selected == null
|
|
55
|
+
? 'Click a line number to select a line.'
|
|
56
|
+
: `Selected ${selected.side} line ${selected.lineNumber}`}
|
|
57
|
+
</Text>
|
|
58
|
+
</StackItem>
|
|
59
|
+
<Button
|
|
60
|
+
label={viewMode === 'unified' ? 'Split view' : 'Unified view'}
|
|
61
|
+
variant="secondary"
|
|
62
|
+
onClick={() =>
|
|
63
|
+
setViewMode(mode => (mode === 'unified' ? 'split' : 'unified'))
|
|
64
|
+
}
|
|
65
|
+
/>
|
|
66
|
+
</HStack>
|
|
67
|
+
<DiffViewer
|
|
68
|
+
file={FILE}
|
|
69
|
+
viewMode={viewMode}
|
|
70
|
+
onLineNumberClick={ref => setSelected(ref)}
|
|
71
|
+
renderLineAnnotation={ref =>
|
|
72
|
+
selected != null &&
|
|
73
|
+
ref.side === selected.side &&
|
|
74
|
+
ref.lineNumber === selected.lineNumber ? (
|
|
75
|
+
<Text>{`Comment on ${ref.side} line ${ref.lineNumber}`}</Text>
|
|
76
|
+
) : null
|
|
77
|
+
}
|
|
78
|
+
/>
|
|
79
|
+
</VStack>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { type MouseEvent, type ReactNode, type Ref } from 'react';
|
|
2
|
+
import type { BaseProps } from '@astryxdesign/core';
|
|
3
|
+
import { type SyntaxThemeDefinition } from '@astryxdesign/core/theme/syntax';
|
|
4
|
+
import type { DiffViewerFile, DiffViewerLineRef } from './diffTypes';
|
|
5
|
+
/** How hunks are laid out: one column, or old and new side by side. */
|
|
6
|
+
export type DiffViewerViewMode = 'unified' | 'split';
|
|
7
|
+
/**
|
|
8
|
+
* How a changed line is marked beside its code: `classic` `+`/`-` glyphs,
|
|
9
|
+
* `bars` (a solid bar for added lines and a dashed one for removed lines), or
|
|
10
|
+
* `none`. Screen readers hear "Added"/"Removed" in every mode.
|
|
11
|
+
*/
|
|
12
|
+
export type DiffViewerChangeIndicator = 'classic' | 'bars' | 'none';
|
|
13
|
+
/**
|
|
14
|
+
* How finely to highlight what changed inside a removed line and the added
|
|
15
|
+
* line that replaced it: by `word`, by `char`acter, or `none`.
|
|
16
|
+
*/
|
|
17
|
+
export type DiffViewerInlineHighlight = 'word' | 'char' | 'none';
|
|
18
|
+
export interface DiffViewerProps extends BaseProps<HTMLDivElement> {
|
|
19
|
+
/** Ref forwarded to the root element. */
|
|
20
|
+
ref?: Ref<HTMLDivElement>;
|
|
21
|
+
/**
|
|
22
|
+
* The file to render. Build one with `parseUnifiedDiff(patch)` (one per
|
|
23
|
+
* file in the patch) or `createDiffFile({oldValue, newValue})`.
|
|
24
|
+
*/
|
|
25
|
+
file: DiffViewerFile;
|
|
26
|
+
/**
|
|
27
|
+
* `unified` shows one column with removed lines above their replacements;
|
|
28
|
+
* `split` shows the old file on the left and the new file on the right,
|
|
29
|
+
* pairing each removed line with the added line that replaced it. The hunk
|
|
30
|
+
* area reads left-to-right in every page direction, like a code editor;
|
|
31
|
+
* the file header and annotation content follow the page, and annotation
|
|
32
|
+
* rows scroll with the code.
|
|
33
|
+
* @default 'unified'
|
|
34
|
+
*/
|
|
35
|
+
viewMode?: DiffViewerViewMode;
|
|
36
|
+
/**
|
|
37
|
+
* Syntax-highlighting language. Defaults to one inferred from the file's
|
|
38
|
+
* extension; unknown extensions render as plain text.
|
|
39
|
+
*/
|
|
40
|
+
language?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Show the old and new line-number gutters.
|
|
43
|
+
* @default true
|
|
44
|
+
*/
|
|
45
|
+
hasLineNumbers?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Wrap long lines instead of scrolling them horizontally. Unwrapped, line
|
|
48
|
+
* numbers and change indicators stay pinned while the code scrolls; in
|
|
49
|
+
* split view each side is its own scroller, the split stays fixed at half
|
|
50
|
+
* and half, and the two sides scroll sideways in lockstep. While code
|
|
51
|
+
* overflows sideways, sideways overscroll (elastic bounce, swipe
|
|
52
|
+
* navigation) is off.
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
55
|
+
isWrapped?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* How changed lines are marked beside their code.
|
|
58
|
+
* @default 'classic'
|
|
59
|
+
*/
|
|
60
|
+
changeIndicator?: DiffViewerChangeIndicator;
|
|
61
|
+
/**
|
|
62
|
+
* Highlight the changed words (or characters) inside each removed line and
|
|
63
|
+
* the added line that replaced it. Lines that share nothing but whitespace
|
|
64
|
+
* get no inline highlight; the row tint already marks them.
|
|
65
|
+
* @default 'word'
|
|
66
|
+
*/
|
|
67
|
+
inlineHighlight?: DiffViewerInlineHighlight;
|
|
68
|
+
/**
|
|
69
|
+
* Tint the rows of added and removed lines. Without it only the change
|
|
70
|
+
* indicator, the line numbers, and the inline highlight mark a change.
|
|
71
|
+
* @default true
|
|
72
|
+
*/
|
|
73
|
+
hasChangeBackground?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Make the file header a disclosure that hides and shows the hunks. Needs a
|
|
76
|
+
* file path to name the control.
|
|
77
|
+
* @default true
|
|
78
|
+
*/
|
|
79
|
+
isCollapsible?: boolean;
|
|
80
|
+
/** Controlled collapsed state. Pair with `onCollapsedChange`. */
|
|
81
|
+
isCollapsed?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Initial collapsed state when uncontrolled.
|
|
84
|
+
* @default false
|
|
85
|
+
*/
|
|
86
|
+
defaultIsCollapsed?: boolean;
|
|
87
|
+
/** Called with the next collapsed state when the header is toggled. */
|
|
88
|
+
onCollapsedChange?: (isCollapsed: boolean) => void;
|
|
89
|
+
/**
|
|
90
|
+
* Content at the end of the file header, e.g. a "Viewed" checkbox or a menu
|
|
91
|
+
* of file actions.
|
|
92
|
+
*/
|
|
93
|
+
headerEnd?: ReactNode;
|
|
94
|
+
/**
|
|
95
|
+
* Render content in a full-width row under a line, e.g. review comments.
|
|
96
|
+
* Return `null` (or `false`) for lines with nothing to show. Called once per line with
|
|
97
|
+
* its {@link DiffViewerLineRef}; in split view the row sits under the
|
|
98
|
+
* line's own side.
|
|
99
|
+
*/
|
|
100
|
+
renderLineAnnotation?: (ref: DiffViewerLineRef) => ReactNode;
|
|
101
|
+
/**
|
|
102
|
+
* Makes each line's number a button (e.g. to start a comment on that line).
|
|
103
|
+
* Receives the line's {@link DiffViewerLineRef}. Only the number on the
|
|
104
|
+
* line's anchor side is a button, so an unchanged line's original number
|
|
105
|
+
* stays plain text. Each button is its own Tab stop, like any other set of
|
|
106
|
+
* independent buttons.
|
|
107
|
+
*/
|
|
108
|
+
onLineNumberClick?: (ref: DiffViewerLineRef, event: MouseEvent<HTMLButtonElement>) => void;
|
|
109
|
+
/** Maximum height of the hunk area before it scrolls. */
|
|
110
|
+
maxHeight?: number | string;
|
|
111
|
+
/**
|
|
112
|
+
* Per-instance syntax theme, as on CodeBlock. Without it the nearest
|
|
113
|
+
* `SyntaxTheme` or the theme's syntax colors apply.
|
|
114
|
+
*/
|
|
115
|
+
syntaxTheme?: SyntaxThemeDefinition;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Read-only, syntax-highlighted diff of one file, in unified or split view,
|
|
119
|
+
* for code review surfaces. Supports review-comment annotation rows under any
|
|
120
|
+
* line and actionable line numbers.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```
|
|
124
|
+
* const [file] = parseUnifiedDiff(patch);
|
|
125
|
+
* <DiffViewer file={file} viewMode="split" />
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export declare function DiffViewer({ ref, file, viewMode, language: languageProp, hasLineNumbers, isWrapped, changeIndicator, inlineHighlight, hasChangeBackground, isCollapsible, isCollapsed: isCollapsedProp, defaultIsCollapsed, onCollapsedChange, headerEnd, renderLineAnnotation, onLineNumberClick, maxHeight, syntaxTheme, xstyle, className, style, ...props }: DiffViewerProps): import("react").JSX.Element;
|
|
129
|
+
export declare namespace DiffViewer {
|
|
130
|
+
var displayName: string;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=DiffViewer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DiffViewer.d.ts","sourceRoot":"","sources":["../../src/DiffViewer/DiffViewer.tsx"],"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