@astryxdesign/lab 0.7.1-canary.4a17409 → 0.7.1-canary.4eaefd4
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 +98 -0
- package/dist/DiffViewer/DiffViewer.d.ts.map +1 -0
- package/dist/DiffViewer/DiffViewer.js +837 -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 +13 -0
- package/dist/DiffViewer/index.d.ts.map +1 -0
- package/dist/DiffViewer/index.js +14 -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 +33 -0
- package/package.json +7 -5
- package/src/DiffViewer/DiffViewer.doc.mjs +177 -0
- package/src/DiffViewer/DiffViewer.test.tsx +326 -0
- package/src/DiffViewer/DiffViewer.tsx +1146 -0
- package/src/DiffViewer/diffTypes.ts +74 -0
- package/src/DiffViewer/index.ts +25 -0
- package/src/DiffViewer/parseUnifiedDiff.test.ts +397 -0
- package/src/DiffViewer/parseUnifiedDiff.ts +437 -0
- package/src/Schedule/Schedule.test.tsx +97 -0
- package/src/Schedule/__tests__/ScheduleTimeGridSkippedMidnight.a11y.chromium.spec.ts +113 -0
- package/src/index.ts +17 -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,98 @@
|
|
|
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
|
+
export interface DiffViewerProps extends BaseProps<HTMLDivElement> {
|
|
8
|
+
/** Ref forwarded to the root element. */
|
|
9
|
+
ref?: Ref<HTMLDivElement>;
|
|
10
|
+
/**
|
|
11
|
+
* The file to render. Build one with `parseUnifiedDiff(patch)` (one per
|
|
12
|
+
* file in the patch).
|
|
13
|
+
*/
|
|
14
|
+
file: DiffViewerFile;
|
|
15
|
+
/**
|
|
16
|
+
* `unified` shows one column with removed lines above their replacements;
|
|
17
|
+
* `split` shows the old file on the left and the new file on the right,
|
|
18
|
+
* pairing each removed line with the added line that replaced it. The hunk
|
|
19
|
+
* area reads left-to-right in every page direction, like a code editor;
|
|
20
|
+
* the file header and annotation content follow the page, and annotation
|
|
21
|
+
* rows scroll with the code.
|
|
22
|
+
* @default 'unified'
|
|
23
|
+
*/
|
|
24
|
+
viewMode?: DiffViewerViewMode;
|
|
25
|
+
/**
|
|
26
|
+
* Syntax-highlighting language. Defaults to one inferred from the file's
|
|
27
|
+
* extension; unknown extensions render as plain text.
|
|
28
|
+
*/
|
|
29
|
+
language?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Show the old and new line-number gutters.
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
hasLineNumbers?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Wrap long lines instead of scrolling them horizontally.
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
isWrapped?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Make the file header a disclosure that hides and shows the hunks. Needs a
|
|
42
|
+
* file path to name the control.
|
|
43
|
+
* @default true
|
|
44
|
+
*/
|
|
45
|
+
isCollapsible?: boolean;
|
|
46
|
+
/** Controlled collapsed state. Pair with `onCollapsedChange`. */
|
|
47
|
+
isCollapsed?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Initial collapsed state when uncontrolled.
|
|
50
|
+
* @default false
|
|
51
|
+
*/
|
|
52
|
+
defaultIsCollapsed?: boolean;
|
|
53
|
+
/** Called with the next collapsed state when the header is toggled. */
|
|
54
|
+
onCollapsedChange?: (isCollapsed: boolean) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Content at the end of the file header, e.g. a "Viewed" checkbox or a menu
|
|
57
|
+
* of file actions.
|
|
58
|
+
*/
|
|
59
|
+
headerEnd?: ReactNode;
|
|
60
|
+
/**
|
|
61
|
+
* Render content in a full-width row under a line, e.g. review comments.
|
|
62
|
+
* Return `null` (or `false`) for lines with nothing to show. Called once per line with
|
|
63
|
+
* its {@link DiffViewerLineRef}; in split view the row sits under the
|
|
64
|
+
* line's own side.
|
|
65
|
+
*/
|
|
66
|
+
renderLineAnnotation?: (ref: DiffViewerLineRef) => ReactNode;
|
|
67
|
+
/**
|
|
68
|
+
* Makes each line's number a button (e.g. to start a comment on that line).
|
|
69
|
+
* Receives the line's {@link DiffViewerLineRef}. Only the number on the
|
|
70
|
+
* line's anchor side is a button, so an unchanged line's original number
|
|
71
|
+
* stays plain text. Each button is its own Tab stop, like any other set of
|
|
72
|
+
* independent buttons.
|
|
73
|
+
*/
|
|
74
|
+
onLineNumberClick?: (ref: DiffViewerLineRef, event: MouseEvent<HTMLButtonElement>) => void;
|
|
75
|
+
/** Maximum height of the hunk area before it scrolls. */
|
|
76
|
+
maxHeight?: number | string;
|
|
77
|
+
/**
|
|
78
|
+
* Per-instance syntax theme, as on CodeBlock. Without it the nearest
|
|
79
|
+
* `SyntaxTheme` or the theme's syntax colors apply.
|
|
80
|
+
*/
|
|
81
|
+
syntaxTheme?: SyntaxThemeDefinition;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Read-only, syntax-highlighted diff of one file, in unified or split view,
|
|
85
|
+
* for code review surfaces. Supports review-comment annotation rows under any
|
|
86
|
+
* line and actionable line numbers.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```
|
|
90
|
+
* const [file] = parseUnifiedDiff(patch);
|
|
91
|
+
* <DiffViewer file={file} viewMode="split" />
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export declare function DiffViewer({ ref, file, viewMode, language: languageProp, hasLineNumbers, isWrapped, isCollapsible, isCollapsed: isCollapsedProp, defaultIsCollapsed, onCollapsedChange, headerEnd, renderLineAnnotation, onLineNumberClick, maxHeight, syntaxTheme, xstyle, className, style, ...props }: DiffViewerProps): import("react").JSX.Element;
|
|
95
|
+
export declare namespace DiffViewer {
|
|
96
|
+
var displayName: string;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=DiffViewer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DiffViewer.d.ts","sourceRoot":"","sources":["../../src/DiffViewer/DiffViewer.tsx"],"names":[],"mappings":"AA8BA,OAAO,EAOL,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,GAAG,EACT,MAAM,OAAO,CAAC;AAGf,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAUlD,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,iCAAiC,CAAC;AAqBzC,OAAO,KAAK,EACV,cAAc,EAGd,iBAAiB,EAElB,MAAM,aA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