Skip to content

Commit aa988fd

Browse files
Merge branch 'ThiagoBussola-feat-clipboard'
2 parents 94364bc + fa074ae commit aa988fd

File tree

8 files changed

+81
-7
lines changed

8 files changed

+81
-7
lines changed

src/app/homepage/pages/faq/faq.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const routes: Routes = [
7171
RequestLifecycleComponent,
7272
ErrorsComponent,
7373
ServerlessComponent,
74+
RawBodyComponent,
7475
],
7576
})
7677
export class FaqModule {}

src/app/homepage/pages/graphql/graphql.module.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { QuickStartComponent } from './quick-start/quick-start.component';
1818
import { ResolversMapComponent } from './resolvers-map/resolvers-map.component';
1919
import { ScalarsComponent } from './scalars/scalars.component';
2020
import { SchemaGeneratorComponent } from './schema-generator/schema-generator.component';
21-
import { SharingModelsComponent } from "./sharing-models/sharing-models.component";
21+
import { SharingModelsComponent } from './sharing-models/sharing-models.component';
2222
import { SubscriptionsComponent } from './subscriptions/subscriptions.component';
2323
import { UnionsAndEnumsComponent } from './unions-and-enums/unions.component';
2424

@@ -121,7 +121,7 @@ const routes: Routes = [
121121
{
122122
path: 'sharing-models',
123123
component: SharingModelsComponent,
124-
data: { title: "GraphQL + TypeScript - Sharing models"}
124+
data: { title: 'GraphQL + TypeScript - Sharing models' },
125125
},
126126
{
127127
path: 'mapped-types',
@@ -161,6 +161,7 @@ const routes: Routes = [
161161
ExtensionsComponent,
162162
FieldMiddlewareComponent,
163163
MigrationComponent,
164+
InterfacesComponent,
164165
],
165166
})
166167
export class GraphqlModule {}

src/app/homepage/pages/openapi/openapi.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const routes: Routes = [
7171
IntroductionComponent,
7272
DecoratorsComponent,
7373
CliPluginComponent,
74+
OpenApiSecurityComponent,
7475
],
7576
})
7677
export class OpenApiModule {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<button
2+
class="clipboard"
3+
[class.copied]="copied"
4+
(click)="onCopy()"
5+
>
6+
<mat-icon>{{ copied ? 'check': 'content_copy' }}</mat-icon>
7+
</button>
8+
<ng-content></ng-content>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
:host {
2+
display: block;
3+
position: relative;
4+
5+
.clipboard {
6+
color: #dfdfdf;
7+
cursor: pointer;
8+
background: transparent;
9+
border: none;
10+
padding: 10px;
11+
position: absolute;
12+
right: 10px;
13+
top: 65px;
14+
z-index: 10;
15+
opacity: 0.7;
16+
17+
&:hover:not(.copied) {
18+
opacity: 1;
19+
}
20+
21+
& > * {
22+
width: 18px;
23+
height: 18px;
24+
font-size: 18px;
25+
}
26+
}
27+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Component, ElementRef, inject } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-copy-button',
5+
templateUrl: './copy-button.component.html',
6+
styleUrls: ['./copy-button.component.scss'],
7+
})
8+
export class CopyButtonComponent {
9+
public elRef = inject<ElementRef<HTMLElement>>(ElementRef<HTMLElement>);
10+
public copied = false;
11+
12+
onCopy() {
13+
const preRef = this.elRef.nativeElement.querySelector('pre:not(.hide)');
14+
if (!preRef) {
15+
return;
16+
}
17+
navigator.clipboard.writeText(preRef.firstChild.textContent);
18+
this.copied = true;
19+
}
20+
}

src/app/shared/shared.module.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ import { TabsComponent } from './components/tabs/tabs.component';
1212
import { TocComponent } from './components/toc/toc.component';
1313
import { HeaderAnchorDirective } from './directives/header-anchor.directive';
1414
import { ExtensionPipe } from './pipes/extension.pipe';
15+
import { CopyButtonComponent } from './components/copy-button/copy-button.component';
16+
import { ClipboardModule } from '@angular/cdk/clipboard';
17+
import { MatIconModule } from '@angular/material/icon';
1518

1619
@NgModule({
17-
imports: [CommonModule],
20+
imports: [CommonModule, ClipboardModule, MatIconModule],
1821
declarations: [
1922
ExtensionPipe,
2023
TabsComponent,
@@ -27,6 +30,7 @@ import { ExtensionPipe } from './pipes/extension.pipe';
2730
BannerDevtoolsComponent,
2831
BannerCoursesAuthComponent,
2932
ThemeModeToggleComponent,
33+
CopyButtonComponent,
3034
],
3135
exports: [
3236
ExtensionPipe,
@@ -40,6 +44,7 @@ import { ExtensionPipe } from './pipes/extension.pipe';
4044
BannerDevtoolsComponent,
4145
BannerCoursesAuthComponent,
4246
ThemeModeToggleComponent,
47+
CopyButtonComponent
4348
],
4449
providers: [StorageService],
4550
})

tools/transforms/content-package/services/renderer/code.renderer.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,28 @@ export function applyCodeRenderer(renderer: Renderer) {
2626
language: string,
2727
isEscaped: boolean,
2828
switcherKey?: string,
29+
skipCopyButton?: boolean,
2930
) {
3031
const filenameKey = '@@filename';
3132
const filenameIndex = code.indexOf(filenameKey);
3233
if (filenameIndex >= 0) {
33-
return replaceFilename(
34+
const output = replaceFilename(
3435
(text, directiveRef) =>
3536
// @ts-ignore
36-
renderer.code(text, language, isEscaped, directiveRef),
37+
renderer.code(text, language, isEscaped, directiveRef, true),
3738
code,
3839
filenameKey,
3940
filenameIndex,
4041
);
42+
43+
return `<app-copy-button>${output}</app-copy-button>`;
4144
}
4245

4346
const switchKey = '@@switch';
4447
const switchIndex = code.indexOf(switchKey);
4548
if (switchIndex >= 0) {
4649
const result = parseSwitcher(
47-
(text, lang) => renderer.code(text, lang, isEscaped),
50+
(text, lang) => renderer.code(text, lang, isEscaped, undefined, true),
4851
code,
4952
switchKey,
5053
switchIndex,
@@ -59,6 +62,14 @@ export function applyCodeRenderer(renderer: Renderer) {
5962
isEscaped,
6063
);
6164
output = switcherKey ? output : appendEmptyLine(output);
62-
return escapeAts(escapeBrackets(output));
65+
66+
const escaped = escapeAts(escapeBrackets(output));
67+
if (language === 'typescript' || language === 'ts') {
68+
if (!skipCopyButton) {
69+
return `<app-copy-button>${escaped}</app-copy-button>`;
70+
}
71+
return escaped;
72+
}
73+
return escaped;
6374
};
6475
}

0 commit comments

Comments
 (0)