Skip to content

Commit 0588bab

Browse files
committed
Merge branch 'main' into steeve/rnd-5337-show-placeholder-gitbook-ad-when-previewing-published
2 parents f4f1425 + 2982b6a commit 0588bab

File tree

7 files changed

+84
-4
lines changed

7 files changed

+84
-4
lines changed

bun.lockb

392 Bytes
Binary file not shown.

packages/gitbook/e2e/pages.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,10 @@ const testCases: TestsCase[] = [
395395
await page.click('[data-testid="annotation-button"]');
396396
},
397397
},
398+
{
399+
name: 'Stepper',
400+
url: 'blocks/stepper',
401+
},
398402
],
399403
},
400404
{

packages/gitbook/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"clean": "rm -rf ./.next && rm -rf ./public/~gitbook/static"
1717
},
1818
"dependencies": {
19-
"@gitbook/api": "^0.66.0",
19+
"@gitbook/api": "^0.69.0",
2020
"@gitbook/cache-do": "workspace:*",
2121
"@gitbook/emoji-codepoints": "workspace:*",
2222
"@gitbook/icons": "workspace:*",

packages/gitbook/src/components/DocumentView/Block.tsx

+12-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import { BlockMath } from './Math';
3232
import { OpenAPI } from './OpenAPI';
3333
import { Paragraph } from './Paragraph';
3434
import { Quote } from './Quote';
35+
import { Stepper } from './Stepper';
36+
import { StepperStep } from './StepperStep';
3537
import { Table } from './Table';
3638
import { Tabs } from './Tabs';
3739

@@ -104,6 +106,12 @@ export function Block<T extends DocumentBlock>(props: BlockProps<T>) {
104106
return <IntegrationBlock {...props} {...contextProps} block={block} />;
105107
case 'synced-block':
106108
return <BlockSyncedBlock {...props} {...contextProps} block={block} />;
109+
case 'reusable-content':
110+
return null;
111+
case 'stepper':
112+
return <Stepper {...props} {...contextProps} block={block} />;
113+
case 'stepper-step':
114+
return <StepperStep {...props} {...contextProps} block={block} />;
107115
default:
108116
return nullIfNever(block);
109117
}
@@ -136,7 +144,6 @@ function BlockPlaceholder(props: { block: DocumentBlock; style: ClassValue }) {
136144
case 'code':
137145
case 'hint':
138146
case 'tabs':
139-
case 'synced-block':
140147
return <SkeletonParagraph id={id} style={style} />;
141148
case 'expandable':
142149
case 'table':
@@ -145,6 +152,9 @@ function BlockPlaceholder(props: { block: DocumentBlock; style: ClassValue }) {
145152
case 'divider':
146153
case 'content-ref':
147154
case 'integration':
155+
case 'stepper':
156+
case 'synced-block':
157+
case 'reusable-content':
148158
return <SkeletonCard id={id} style={style} />;
149159
case 'embed':
150160
case 'images':
@@ -153,6 +163,7 @@ function BlockPlaceholder(props: { block: DocumentBlock; style: ClassValue }) {
153163
case 'image':
154164
case 'code-line':
155165
case 'tabs-item':
166+
case 'stepper-step':
156167
throw new Error('Blocks should be directly rendered by parent');
157168
default:
158169
return nullIfNever(block);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { DocumentBlockStepper } from '@gitbook/api';
2+
3+
import { BlockProps } from './Block';
4+
import { Blocks } from './Blocks';
5+
6+
export function Stepper(props: BlockProps<DocumentBlockStepper>) {
7+
const { block, style, ancestorBlocks, ...contextProps } = props;
8+
9+
return (
10+
<Blocks {...contextProps} nodes={block.nodes} ancestorBlocks={[...ancestorBlocks, block]} />
11+
);
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { DocumentBlockStepperStep } from '@gitbook/api';
2+
import { assert } from 'ts-essentials';
3+
4+
import { tcls } from '@/lib/tailwind';
5+
6+
import { BlockProps } from './Block';
7+
import { Blocks } from './Blocks';
8+
9+
export function StepperStep(props: BlockProps<DocumentBlockStepperStep>) {
10+
const { block, style, ancestorBlocks, ...contextProps } = props;
11+
12+
const ancestor = ancestorBlocks[ancestorBlocks.length - 1];
13+
assert(ancestor.type === 'stepper', 'Ancestor block must be a stepper');
14+
15+
const index = ancestor.nodes.indexOf(block);
16+
17+
const firstChild = block.nodes[0];
18+
const marginAdjustClassName = (() => {
19+
if (!firstChild) {
20+
return '';
21+
}
22+
switch (firstChild.type) {
23+
case 'heading-1':
24+
return '-mt-9';
25+
case 'heading-2':
26+
return '-mt-[calc(1.25rem+1px)]';
27+
default:
28+
return '';
29+
}
30+
})();
31+
32+
return (
33+
<div className="flex flex-row gap-4 md:gap-8 max-w-3xl w-full mx-auto">
34+
<div className="relative select-none">
35+
<div
36+
className={tcls(
37+
'flex size-[calc(1.75rem+1px)] items-center justify-center rounded-full bg-primary-50 dark:bg-primary-900 tabular-nums',
38+
'font-medium text-primary-800 dark:text-primary-200',
39+
)}
40+
>
41+
{index + 1}
42+
</div>
43+
<div className="absolute bottom-2 left-[0.875rem] top-9 w-px bg-primary-50 dark:bg-primary-900" />
44+
</div>
45+
<Blocks
46+
{...contextProps}
47+
nodes={block.nodes}
48+
ancestorBlocks={[...ancestorBlocks, block]}
49+
style={['flex-1 pb-6 [&>*+*]:mt-5', marginAdjustClassName]}
50+
/>
51+
</div>
52+
);
53+
}

packages/gitbook/src/lib/references.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ export async function resolveContentRef(
255255
};
256256
}
257257

258-
case 'synced-block': {
258+
case 'reusable-content':
259+
case 'synced-block':
259260
return null;
260-
}
261261

262262
default:
263263
assertNever(contentRef);

0 commit comments

Comments
 (0)