Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions apps/docs/app/diff-examples/Annotations/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
DEFAULT_THEMES,
type DiffLineAnnotation,
type FileContents,
parseDiffFromFile,
Expand Down Expand Up @@ -69,7 +70,8 @@ def verify_token(token: str) -> Optional[dict]:
`,
},
options: {
theme: 'pierre-dark',
theme: DEFAULT_THEMES,
themeType: 'dark',
diffStyle: 'unified',
unsafeCSS: CustomScrollbarCSS,
},
Expand Down Expand Up @@ -141,7 +143,8 @@ export const ACCEPT_REJECT_EXAMPLE: PreloadFileDiffOptions<AcceptRejectMetadata>
{
fileDiff: parseDiffFromFile(ACCEPT_REJECT_OLD_FILE, ACCEPT_REJECT_NEW_FILE),
options: {
theme: 'pierre-dark',
theme: DEFAULT_THEMES,
themeType: 'dark',
diffStyle: 'unified',
},
annotations: ACCEPT_REJECT_ANNOTATIONS,
Expand Down
4 changes: 3 additions & 1 deletion apps/docs/app/diff-examples/ArbitraryFiles/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DEFAULT_THEMES } from '@pierre/diffs';
import type { PreloadMultiFileDiffOptions } from '@pierre/diffs/ssr';

import { CustomScrollbarCSS } from '@/components/CustomScrollbarCSS';
Expand All @@ -19,7 +20,8 @@ export const ARBITRARY_DIFF_EXAMPLE: PreloadMultiFileDiffOptions<undefined> = {
`,
},
options: {
theme: 'pierre-dark',
theme: DEFAULT_THEMES,
themeType: 'dark',
diffStyle: 'unified',
unsafeCSS: CustomScrollbarCSS,
},
Expand Down
42 changes: 17 additions & 25 deletions apps/docs/app/diff-examples/CustomHeader/CustomHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,23 @@ export function CustomHeader({ prerenderedDiff }: CustomHeaderProps) {
}
: undefined
}
renderHeaderPrefix={
headerMode === 'metadata'
? () => {
return (
<HeaderPrefix
toggleCollapsed={toggleCollapsed}
collapsed={collapsed}
/>
);
}
: undefined
}
renderHeaderMetadata={
headerMode === 'metadata'
? () => {
return (
<ViewedButton
isViewed={isViewed}
onClick={toggleViewed}
className="mr-[-8px]"
/>
);
}
: undefined
}
renderHeaderPrefix={() => {
return (
<HeaderPrefix
toggleCollapsed={toggleCollapsed}
collapsed={collapsed}
/>
);
}}
renderHeaderMetadata={() => {
return (
<ViewedButton
isViewed={isViewed}
onClick={toggleViewed}
className="mr-[-8px]"
/>
);
}}
Comment thread
amadeus marked this conversation as resolved.
/>
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/app/diff-examples/CustomHeader/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type FileContents } from '@pierre/diffs';
import { DEFAULT_THEMES, type FileContents } from '@pierre/diffs';
import type { PreloadMultiFileDiffOptions } from '@pierre/diffs/ssr';

import { CustomScrollbarCSS } from '@/components/CustomScrollbarCSS';
Expand Down Expand Up @@ -68,7 +68,7 @@ export const CUSTOM_HEADER_EXAMPLE: PreloadMultiFileDiffOptions<undefined> = {
oldFile: CUSTOM_HEADER_OLD_FILE,
newFile: CUSTOM_HEADER_NEW_FILE,
options: {
theme: { dark: 'pierre-dark', light: 'pierre-light' },
theme: DEFAULT_THEMES,
themeType: 'dark',
diffStyle: 'split',
disableBackground: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,6 @@ export function CustomHunkSeparators({
) : (
<MultiFileDiff
{...prerenderedDiff}
prerenderedHTML={
hunkSeparators === initialSeparator
? prerenderedDiff.prerenderedHTML
: undefined
}
className="overflow-hidden rounded-lg border dark:border-neutral-800"
options={{
...prerenderedDiff.options,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DEFAULT_THEMES } from '@pierre/diffs';
import type { PreloadMultiFileDiffOptions } from '@pierre/diffs/ssr';

import { CustomScrollbarCSS } from '@/components/CustomScrollbarCSS';
Expand Down Expand Up @@ -61,7 +62,8 @@ export const CUSTOM_HUNK_SEPARATORS_EXAMPLE: PreloadMultiFileDiffOptions<undefin
contents: createTaskSummarySource('new'),
},
options: {
theme: 'pierre-dark',
theme: DEFAULT_THEMES,
themeType: 'dark',
diffStyle: 'split',
expansionLineCount: 5,
hunkSeparators: 'line-info',
Expand Down
21 changes: 11 additions & 10 deletions apps/docs/app/diff-examples/DiffStyles/DiffStyles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ const diffStyleOptions = [
interface DiffStylesProps {
prerenderedDiff: PreloadMultiFileDiffResult<undefined>;
}

export function DiffStyles({
prerenderedDiff: { options, ...props },
}: DiffStylesProps) {
const [diffIndicators, setDiffStyle] = useState<'classic' | 'bars' | 'none'>(
'bars'
);
const [lineDiffStyle, setLineDiffStyle] = useState<
const [lineDiffType, setLineDiffType] = useState<
'word-alt' | 'word' | 'char' | 'none'
>('word-alt');
const [disableBackground, setDisableBackground] = useState(false);
Expand Down Expand Up @@ -110,8 +111,8 @@ export function DiffStyles({
>
<IconCodeStyleInline />
{}
{diffStyleOptions.find((opt) => opt.value === lineDiffStyle)
?.label ?? lineDiffStyle}
{diffStyleOptions.find((opt) => opt.value === lineDiffType)
?.label ?? lineDiffType}
<IconChevronSm className="text-muted-foreground ml-auto" />
</Button>
</DropdownMenuTrigger>
Expand All @@ -123,11 +124,11 @@ export function DiffStyles({
{diffStyleOptions.map((option) => (
<DropdownMenuItem
key={option.value}
onClick={() => setLineDiffStyle(option.value)}
selected={lineDiffStyle === option.value}
onClick={() => setLineDiffType(option.value)}
selected={lineDiffType === option.value}
className="flex items-start gap-2 py-2"
>
{lineDiffStyle === option.value ? (
{lineDiffType === option.value ? (
<IconCheck className="mt-[1px]" />
) : (
<div className="h-4 w-4" />
Expand Down Expand Up @@ -213,14 +214,14 @@ export function DiffStyles({
className="diff-container"
options={{
...options,
theme: 'pierre-dark',
diffStyle: 'split',
diffIndicators,
disableBackground,
overflow: overflow,
lineDiffType: lineDiffStyle,
overflow,
lineDiffType,
disableLineNumbers,
}}
// Because we need to change lineDiffType, we can't use the WorkerPool
disableWorkerPool
/>
</div>
);
Expand Down
4 changes: 3 additions & 1 deletion apps/docs/app/diff-examples/DiffStyles/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DEFAULT_THEMES } from '@pierre/diffs';
import type { PreloadMultiFileDiffOptions } from '@pierre/diffs/ssr';

import { CustomScrollbarCSS } from '@/components/CustomScrollbarCSS';
Expand Down Expand Up @@ -45,7 +46,8 @@ pub fn main() !void {
`,
},
options: {
theme: 'pierre-dark',
theme: DEFAULT_THEMES,
themeType: 'dark',
diffStyle: 'split',
overflow: 'wrap',
disableLineNumbers: false,
Expand Down
4 changes: 3 additions & 1 deletion apps/docs/app/diff-examples/FontStyles/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DEFAULT_THEMES } from '@pierre/diffs';
import type { PreloadMultiFileDiffOptions } from '@pierre/diffs/ssr';

import { CustomScrollbarCSS } from '@/components/CustomScrollbarCSS';
Expand Down Expand Up @@ -131,7 +132,8 @@ func (c *Cache) onEviction(key string, value interface{}) {
`,
},
options: {
theme: 'pierre-dark',
theme: DEFAULT_THEMES,
themeType: 'dark',
diffStyle: 'unified',
unsafeCSS: CustomScrollbarCSS,
},
Expand Down
3 changes: 2 additions & 1 deletion apps/docs/app/diff-examples/LineSelection/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DEFAULT_THEMES } from '@pierre/diffs';
import type { PreloadMultiFileDiffOptions } from '@pierre/diffs/ssr';

import { CustomScrollbarCSS } from '@/components/CustomScrollbarCSS';
Expand Down Expand Up @@ -118,7 +119,7 @@ public:
`,
},
options: {
theme: { dark: 'pierre-dark', light: 'pierre-light' },
theme: DEFAULT_THEMES,
themeType: 'dark',
diffStyle: 'split',
disableBackground: false,
Expand Down
25 changes: 21 additions & 4 deletions apps/docs/app/diff-examples/MergeConflict/MergeConflict.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import {
type UnresolvedFileReactOptions,
} from '@pierre/diffs/react';
import type { PreloadUnresolvedFileResult } from '@pierre/diffs/ssr';
import { IconColorDark, IconColorLight, IconRefresh } from '@pierre/icons';
import {
IconColorAuto,
IconColorDark,
IconColorLight,
IconRefresh,
} from '@pierre/icons';
import { useMemo, useState } from 'react';

import { FeatureHeader } from '../FeatureHeader';
Expand All @@ -21,8 +26,14 @@ export function MergeConflict({ prerenderedFile }: MergeConflictProps) {
const [hasResolved, setHasResolved] = useState(false);

const [themeType, setThemeType] = useState<'light' | 'dark' | 'system'>(
() => prerenderedFile.options?.themeType ?? 'dark'
() => prerenderedFile.options?.themeType ?? 'system'
);
const borderClass =
themeType === 'light'
? 'border-neutral-200'
: themeType === 'dark'
? 'border-neutral-800'
: 'border-neutral-200 dark:border-neutral-800';

// NOTE(amadeus): These server render APIs definitely suck, and it's
// something we need to take a pass at. Curious if it's something Nicolas
Expand Down Expand Up @@ -70,8 +81,14 @@ export function MergeConflict({ prerenderedFile }: MergeConflictProps) {
</Button>
<ButtonGroup
value={themeType}
onValueChange={(value) => setThemeType(value as 'light' | 'dark')}
onValueChange={(value) =>
setThemeType(value as 'light' | 'dark' | 'system')
}
>
<ButtonGroupItem value="system">
<IconColorAuto />
Auto
</ButtonGroupItem>
<ButtonGroupItem value="light">
<IconColorLight />
Light
Expand Down Expand Up @@ -103,7 +120,7 @@ export function MergeConflict({ prerenderedFile }: MergeConflictProps) {
file={prerenderedFile.file}
options={options}
prerenderedHTML={prerenderedFile.prerenderedHTML}
className={`overflow-hidden rounded-lg border ${themeType === 'light' ? 'border-neutral-200' : 'border-neutral-800'}`}
className={`overflow-hidden rounded-lg border ${borderClass}`}
// NOTE(amadeus): Test code, I need to better solve the whole server/vanilla/custom js thing with react
// renderMergeConflictUtility={(action, getInstance) => {
// return (
Expand Down
3 changes: 2 additions & 1 deletion apps/docs/app/diff-examples/MergeConflict/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DEFAULT_THEMES } from '@pierre/diffs';
import type { PreloadUnresolvedFileOptions } from '@pierre/diffs/ssr';

import { CustomScrollbarCSS } from '@/components/CustomScrollbarCSS';
Expand Down Expand Up @@ -95,8 +96,8 @@ export async function validateSession(token: string): Promise<Session | null> {
`,
},
options: {
theme: DEFAULT_THEMES,
themeType: 'dark',
theme: { light: 'pierre-light', dark: 'pierre-dark' },
overflow: 'wrap',
diffIndicators: 'none',
unsafeCSS: CustomScrollbarCSS,
Expand Down
7 changes: 5 additions & 2 deletions apps/docs/app/diff-examples/ShikiThemes/ShikiThemes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,13 @@ export function ShikiThemes({
{...props}
className="overflow-hidden rounded-lg border dark:border-neutral-800"
options={{
diffStyle: 'split',
themeType: selectedColorMode,
...options,
theme: { dark: selectedDarkTheme, light: selectedLightTheme },
themeType: selectedColorMode,
}}
// WorkerPool is disabled because we need to be able to change themes
// without changing our whole page
disableWorkerPool
/>
<PierreThemeFootnote />
</div>
Expand Down
3 changes: 2 additions & 1 deletion apps/docs/app/diff-examples/ShikiThemes/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DEFAULT_THEMES } from '@pierre/diffs';
import type { PreloadMultiFileDiffOptions } from '@pierre/diffs/ssr';

import { CustomScrollbarCSS } from '@/components/CustomScrollbarCSS';
Expand Down Expand Up @@ -37,7 +38,7 @@ fn add(a: i32, b: i32) -> i32 {
},
options: {
diffStyle: 'split',
theme: { dark: 'pierre-dark', light: 'pierre-light' },
theme: DEFAULT_THEMES,
unsafeCSS: CustomScrollbarCSS,
enableLineSelection: true,
},
Expand Down
9 changes: 4 additions & 5 deletions apps/docs/app/diff-examples/SplitUnified/SplitUnified.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ interface SplitUnifiedProps {
export function SplitUnified({
prerenderedDiff: { options, ...props },
}: SplitUnifiedProps) {
const [diffStyle, setDiffStyle] = useState<'split' | 'unified'>('split');
const [diffStyle, setDiffStyle] = useState<'split' | 'unified'>(
options?.diffStyle ?? 'split'
);
return (
<div className="scroll-mt-20 space-y-5" id="layout">
<FeatureHeader
Expand All @@ -39,10 +41,7 @@ export function SplitUnified({
<MultiFileDiff
{...props}
className="diff-container"
options={{
theme: options?.theme ?? 'pierre-dark',
diffStyle,
}}
options={{ ...options, diffStyle }}
/>
</div>
);
Expand Down
4 changes: 3 additions & 1 deletion apps/docs/app/diff-examples/SplitUnified/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DEFAULT_THEMES } from '@pierre/diffs';
import type { PreloadMultiFileDiffOptions } from '@pierre/diffs/ssr';

import { CustomScrollbarCSS } from '@/components/CustomScrollbarCSS';
Expand Down Expand Up @@ -143,7 +144,8 @@ export function createHunkSeparator() {
`,
},
options: {
theme: 'pierre-dark',
theme: DEFAULT_THEMES,
themeType: 'dark',
diffStyle: 'split',
unsafeCSS: CustomScrollbarCSS,
},
Expand Down
8 changes: 7 additions & 1 deletion apps/docs/app/docs/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,13 @@ export default function DocsPage() {
async function MergeConflictDemoSection() {
return (
<MergeConflict
prerenderedFile={await preloadUnresolvedFile(MERGE_CONFLICT_EXAMPLE)}
prerenderedFile={await preloadUnresolvedFile({
...MERGE_CONFLICT_EXAMPLE,
options: {
...MERGE_CONFLICT_EXAMPLE.options,
themeType: 'system',
},
})}
/>
);
}
Expand Down
Loading
Loading