Skip to content

Commit 3e5133e

Browse files
add docs code snippets (#4130)
## Description This PR is a rebased and squashed update of #4078 that I'm taking over. It adds code snippets for the docs to the repo and was previously approved, but the author hadn't signed their commits. Co-authored-by: Uttej V S K <[email protected]>
1 parent 695390c commit 3e5133e

File tree

76 files changed

+629
-316
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+629
-316
lines changed

.changeset/brown-avocados-dream.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@builder.io/sdk-angular": patch
3+
"@builder.io/sdk-react-nextjs": patch
4+
"@builder.io/sdk-qwik": patch
5+
"@builder.io/sdk-react": patch
6+
"@builder.io/sdk-react-native": patch
7+
"@builder.io/sdk-solid": patch
8+
"@builder.io/sdk-svelte": patch
9+
"@builder.io/sdk-vue": patch
10+
---
11+
12+
docs: document `getBuilderSearchParams` and `isPreviewing`

packages/sdks-tests/src/snippet-tests/advanced-child.spec.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@playwright/test';
2-
import { test, testClickAndVerifyVisibility } from '../helpers/index.js';
2+
import { findTextInPage, test, testClickAndVerifyVisibility } from '../helpers/index.js';
33

44
test.describe('Advanced child sub components', () => {
55
test('Display two buttons with label Tab 1 and Tab 2', async ({ page, packageName }) => {
@@ -62,4 +62,19 @@ test.describe('Advanced child sub components', () => {
6262
expect(Tab2ContentVisible).toBe(true);
6363
expect(await page.locator('div').filter({ hasText: 'Tab 1 Content' }).isVisible()).toBeFalsy();
6464
});
65+
66+
test('Advanced child components work in preview mode with isPreviewing', async ({
67+
page,
68+
packageName,
69+
}) => {
70+
test.skip(!['react-none-gen2'].includes(packageName));
71+
72+
await page.goto(
73+
'/advanced-child?builder.space=ee9f13b4981e489a9a1209887695ef2b&builder.cachebust=true&builder.preview=page&builder.noCache=true&builder.allowTextEdit=true&__builder_editing__=true&builder.overrides.page=91744fcdc9f04bb8884a5f4c9feb0dc1&builder.overrides.91744fcdc9f04bb8884a5f4c9feb0dc1=91744fcdc9f04bb8884a5f4c9feb0dc1&builder.overrides.page:/advanced-child=91744fcdc9f04bb8884a5f4c9feb0dc1'
74+
);
75+
76+
await page.waitForLoadState('networkidle');
77+
78+
await findTextInPage({ page, text: 'advanced child draft' });
79+
});
6580
});

packages/sdks-tests/src/snippet-tests/editable-regions.spec.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@playwright/test';
2-
import { test } from '../helpers/index.js';
2+
import { findTextInPage, test } from '../helpers/index.js';
33

44
test.describe('Editable regions in custom components', () => {
55
test('should render a div with two columns with builder-path attr', async ({
@@ -57,4 +57,19 @@ test.describe('Editable regions in custom components', () => {
5757
expect(columnTexts).toContain('column 1 text');
5858
expect(columnTexts).toContain('column 2 text');
5959
});
60+
61+
test('Editable regions show draft content in preview mode with isPreviewing', async ({
62+
page,
63+
packageName,
64+
}) => {
65+
test.skip(!['react-none-gen2'].includes(packageName));
66+
67+
await page.goto(
68+
'/editable-region?builder.space=ee9f13b4981e489a9a1209887695ef2b&builder.cachebust=true&builder.preview=page&builder.noCache=true&builder.allowTextEdit=true&__builder_editing__=true&builder.overrides.page=bb909e043ad34915b0075091911647e8&builder.overrides.bb909e043ad34915b0075091911647e8=bb909e043ad34915b0075091911647e8&builder.overrides.page:/editable-region=bb909e043ad34915b0075091911647e8'
69+
);
70+
await findTextInPage({ page, text: 'draft: column 1 text' });
71+
await findTextInPage({ page, text: 'draft: column 2 text' });
72+
73+
await page.waitForLoadState('networkidle');
74+
});
6075
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { ActivatedRouteSnapshot, ResolveFn } from '@angular/router';
2+
import { _processContentResult, fetchOneEntry } from '@builder.io/sdk-angular';
3+
import { getProps } from '@sdk/tests';
4+
5+
export const appResolver: ResolveFn<any> = (route: ActivatedRouteSnapshot) => {
6+
const urlPath = `/${route.url.join('/')}`;
7+
8+
return getProps({
9+
pathname: urlPath,
10+
_processContentResult,
11+
fetchOneEntry,
12+
});
13+
};
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { Component } from '@angular/core';
2+
import {
3+
_processContentResult,
4+
fetchOneEntry,
5+
type RegisteredComponent,
6+
} from '@builder.io/sdk-angular';
7+
import { getProps } from '@sdk/tests';
8+
import { customComponents } from './custom-components';
9+
10+
interface BuilderProps {
11+
apiVersion: string;
12+
canTrack?: boolean;
13+
trustedHosts?: undefined;
14+
apiKey: string;
15+
model: string;
16+
content: any;
17+
data?: any;
18+
apiHost?: string;
19+
locale?: string;
20+
}
21+
22+
@Component({
23+
selector: 'app-root',
24+
template: `
25+
<ng-container *ngIf="content; else notFound">
26+
<builder-content
27+
[model]="model"
28+
[content]="content"
29+
[apiKey]="apiKey"
30+
[trustedHosts]="trustedHosts"
31+
[canTrack]="canTrack"
32+
[customComponents]="customComponents"
33+
[data]="data"
34+
[apiHost]="apiHost"
35+
[locale]="locale"
36+
></builder-content>
37+
</ng-container>
38+
39+
<ng-template #notFound>
40+
<div>404 - Content not found</div>
41+
</ng-template>
42+
`,
43+
})
44+
export class AppComponent {
45+
title = 'angular';
46+
apiVersion: BuilderProps['apiVersion'] = 'v3';
47+
canTrack: BuilderProps['canTrack'];
48+
trustedHosts: BuilderProps['trustedHosts'];
49+
apiKey: BuilderProps['apiKey'] = 'abcd';
50+
model: BuilderProps['model'] = 'page';
51+
content: BuilderProps['content'];
52+
data: BuilderProps['data'];
53+
apiHost: BuilderProps['apiHost'];
54+
locale: BuilderProps['locale'];
55+
56+
customComponents: RegisteredComponent[] = customComponents;
57+
58+
async ngOnInit() {
59+
const urlPath = window.location.pathname || '';
60+
61+
const builderProps = await getProps({
62+
pathname: urlPath,
63+
_processContentResult,
64+
fetchOneEntry,
65+
});
66+
67+
if (!builderProps) {
68+
return;
69+
}
70+
71+
this.content = builderProps.content;
72+
this.canTrack = builderProps.canTrack;
73+
this.trustedHosts = builderProps.trustedHosts;
74+
this.apiKey = builderProps.apiKey;
75+
this.model = builderProps.model;
76+
this.apiVersion = builderProps.apiVersion;
77+
this.data = builderProps.data;
78+
this.apiHost = builderProps.apiHost;
79+
this.locale = builderProps.locale;
80+
}
81+
}

packages/sdks/e2e/angular-19-ssr/src/app/catch-all.component.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
Content,
88
_processContentResult,
99
fetchOneEntry,
10-
getBuilderSearchParams,
1110
registerAction,
1211
type RegisteredComponent,
1312
} from '@builder.io/sdk-angular';
@@ -95,7 +94,6 @@ export class CatchAllComponent {
9594
const builderProps = await getProps({
9695
pathname: urlPath,
9796
_processContentResult,
98-
options: getBuilderSearchParams(searchParams),
9997
fetchOneEntry: (args) => {
10098
return fetchOneEntry({
10199
...args,

packages/sdks/e2e/nextjs-sdk-next-app/src/app/[[...slug]]/page.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
Content,
66
_processContentResult,
77
fetchOneEntry,
8-
getBuilderSearchParams,
98
} from '@builder.io/sdk-react-nextjs';
109
import { getProps } from '@sdk/tests';
1110
import MyTextBox from '../../components/MyTextBox/MyTextBox';
@@ -73,7 +72,6 @@ export default async function Page(props: MyPageProps) {
7372
const builderProps = await getProps({
7473
pathname: urlPath,
7574
_processContentResult,
76-
options: getBuilderSearchParams(props.searchParams),
7775
fetchOneEntry,
7876
});
7977

packages/sdks/e2e/react-sdk-next-14-app/src/app/[[...slug]]/page.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
Content,
44
_processContentResult,
55
fetchOneEntry,
6-
getBuilderSearchParams,
76
} from '@builder.io/sdk-react';
87
import { getProps } from '@sdk/tests';
98

@@ -63,7 +62,6 @@ export default async function Page(props: PageProps) {
6362
const builderProps = await getProps({
6463
pathname: urlPath,
6564
_processContentResult,
66-
options: getBuilderSearchParams(props.searchParams),
6765
fetchOneEntry,
6866
});
6967

packages/sdks/e2e/react-sdk-next-15-app/src/app/[[...slug]]/page.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
Content,
55
_processContentResult,
66
fetchOneEntry,
7-
getBuilderSearchParams,
87
} from '@builder.io/sdk-react';
98
import { getProps } from '@sdk/tests';
109

@@ -22,7 +21,6 @@ export default async function Page(props: PageProps) {
2221
const builderProps = await getProps({
2322
pathname: urlPath,
2423
_processContentResult,
25-
options: getBuilderSearchParams(await props.searchParams),
2624
fetchOneEntry,
2725
});
2826

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { CommonModule } from '@angular/common';
22
import { Component, type OnInit } from '@angular/core';
33
import { ActivatedRoute } from '@angular/router';
4-
import { Content, type BuilderContent } from '@builder.io/sdk-angular';
4+
import {
5+
Content,
6+
isPreviewing,
7+
type BuilderContent,
8+
} from '@builder.io/sdk-angular';
59
import {
610
CustomTabsComponent,
711
customTabsInfo,
@@ -12,30 +16,32 @@ import {
1216
standalone: true,
1317
imports: [CommonModule, Content, CustomTabsComponent],
1418
template: `
15-
<div *ngIf="content">
19+
<div *ngIf="canShowContent; else notFound">
1620
<builder-content
1721
[content]="content"
1822
[model]="modelName"
1923
[apiKey]="apiKey"
2024
[customComponents]="customComponents"
2125
/>
2226
</div>
23-
<div *ngIf="notFound">404</div>
27+
<ng-template #notFound> 404 </ng-template>
2428
`,
2529
})
2630
export class AdvancedChildComponent implements OnInit {
2731
apiKey = 'ee9f13b4981e489a9a1209887695ef2b';
2832
modelName = 'page';
2933

3034
content: BuilderContent | null = null;
31-
notFound = false;
35+
canShowContent = false;
3236
customComponents = [customTabsInfo];
3337

3438
constructor(private route: ActivatedRoute) {}
3539

3640
ngOnInit() {
3741
this.route.data.subscribe((data: any) => {
3842
this.content = data.content;
43+
const searchParams = this.route.snapshot.queryParams;
44+
this.canShowContent = !!this.content || isPreviewing(searchParams);
3945
});
4046
}
4147
}

0 commit comments

Comments
 (0)