Skip to content

Commit 00a8cfc

Browse files
committed
feat: copy to clipboard created and block code edited
1 parent 80b8f75 commit 00a8cfc

9 files changed

+95
-16
lines changed

projects/ngx-notion-cms/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-notion-cms",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"peerDependencies": {
55
"@angular/common": "^18.2.0",
66
"@angular/core": "^18.2.0",

projects/ngx-notion-cms/src/lib/components/copy-to-clipboard/copy-to-clipboard.component.css

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<span
2+
class="hover:bg-fuchsia-200 aspect-square dark:bg-fuchsia-400"
3+
(click)="setCopied()">
4+
@if (copied()) {
5+
<svg
6+
width="20px"
7+
height="20px"
8+
viewBox="0 0 24 24"
9+
fill="none"
10+
xmlns="http://www.w3.org/2000/svg">
11+
<path
12+
d="M4 12.6111L8.92308 17.5L20 6.5"
13+
stroke="currentColor"
14+
stroke-width="2"
15+
stroke-linecap="round"
16+
stroke-linejoin="round" />
17+
</svg>
18+
} @else {
19+
<svg
20+
width="20px"
21+
height="20px"
22+
viewBox="0 0 24 24"
23+
fill="none"
24+
xmlns="http://www.w3.org/2000/svg">
25+
<path
26+
fill-rule="evenodd"
27+
clip-rule="evenodd"
28+
d="M15 1.25H10.9436C9.10583 1.24998 7.65019 1.24997 6.51098 1.40314C5.33856 1.56076 4.38961 1.89288 3.64124 2.64124C2.89288 3.38961 2.56076 4.33856 2.40314 5.51098C2.24997 6.65019 2.24998 8.10582 2.25 9.94357V16C2.25 17.8722 3.62205 19.424 5.41551 19.7047C5.55348 20.4687 5.81753 21.1208 6.34835 21.6517C6.95027 22.2536 7.70814 22.5125 8.60825 22.6335C9.47522 22.75 10.5775 22.75 11.9451 22.75H15.0549C16.4225 22.75 17.5248 22.75 18.3918 22.6335C19.2919 22.5125 20.0497 22.2536 20.6517 21.6517C21.2536 21.0497 21.5125 20.2919 21.6335 19.3918C21.75 18.5248 21.75 17.4225 21.75 16.0549V10.9451C21.75 9.57754 21.75 8.47522 21.6335 7.60825C21.5125 6.70814 21.2536 5.95027 20.6517 5.34835C20.1208 4.81753 19.4687 4.55348 18.7047 4.41551C18.424 2.62205 16.8722 1.25 15 1.25ZM17.1293 4.27117C16.8265 3.38623 15.9876 2.75 15 2.75H11C9.09318 2.75 7.73851 2.75159 6.71085 2.88976C5.70476 3.02502 5.12511 3.27869 4.7019 3.7019C4.27869 4.12511 4.02502 4.70476 3.88976 5.71085C3.75159 6.73851 3.75 8.09318 3.75 10V16C3.75 16.9876 4.38624 17.8265 5.27117 18.1293C5.24998 17.5194 5.24999 16.8297 5.25 16.0549V10.9451C5.24998 9.57754 5.24996 8.47522 5.36652 7.60825C5.48754 6.70814 5.74643 5.95027 6.34835 5.34835C6.95027 4.74643 7.70814 4.48754 8.60825 4.36652C9.47522 4.24996 10.5775 4.24998 11.9451 4.25H15.0549C15.8297 4.24999 16.5194 4.24998 17.1293 4.27117ZM7.40901 6.40901C7.68577 6.13225 8.07435 5.9518 8.80812 5.85315C9.56347 5.75159 10.5646 5.75 12 5.75H15C16.4354 5.75 17.4365 5.75159 18.1919 5.85315C18.9257 5.9518 19.3142 6.13225 19.591 6.40901C19.8678 6.68577 20.0482 7.07435 20.1469 7.80812C20.2484 8.56347 20.25 9.56458 20.25 11V16C20.25 17.4354 20.2484 18.4365 20.1469 19.1919C20.0482 19.9257 19.8678 20.3142 19.591 20.591C19.3142 20.8678 18.9257 21.0482 18.1919 21.1469C17.4365 21.2484 16.4354 21.25 15 21.25H12C10.5646 21.25 9.56347 21.2484 8.80812 21.1469C8.07435 21.0482 7.68577 20.8678 7.40901 20.591C7.13225 20.3142 6.9518 19.9257 6.85315 19.1919C6.75159 18.4365 6.75 17.4354 6.75 16V11C6.75 9.56458 6.75159 8.56347 6.85315 7.80812C6.9518 7.07435 7.13225 6.68577 7.40901 6.40901Z"
29+
fill="currentColor" />
30+
</svg>
31+
}
32+
</span>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { CommonModule, NgIf } from '@angular/common';
2+
import { ChangeDetectionStrategy, Component, inject, input, signal } from '@angular/core';
3+
import { CopyToClipboardDirective } from '../../directives/copy-to-clipboard';
4+
5+
@Component({
6+
selector: 'ngx-copy-to-clipboard',
7+
standalone: true,
8+
imports: [
9+
NgIf,
10+
],
11+
providers: [
12+
CopyToClipboardDirective,
13+
],
14+
templateUrl: './copy-to-clipboard.component.html',
15+
styleUrl: './copy-to-clipboard.component.css',
16+
changeDetection: ChangeDetectionStrategy.OnPush,
17+
})
18+
export class CopyToClipboardComponent {
19+
20+
private copyToClipboard = inject(CopyToClipboardDirective);
21+
22+
public value = input.required<string>();
23+
public copied = signal(false);
24+
25+
setCopied() {
26+
this.copyToClipboard.copy(this.value());
27+
this.copied.set(true)
28+
29+
setTimeout(() => {
30+
this.copied.set(false);
31+
}, 2000);
32+
}
33+
}

projects/ngx-notion-cms/src/lib/components/notion-block-code/notion-block-code.component.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<pre
22
class="relative max-w-80 sm:max-w-full whitespace-pre-wrap flex flex-col sm:min-w-80 overflow-auto">
3-
<div class="h-fit absolute top-2 right-2 flex gap-2 justify-end">
4-
<span >{{languange}}</span>
5-
<!-- <bm-copy-to-clipboard [displayText]="'Copy'" [value]="codeForHighlight" /> -->
3+
<div class="h-fit absolute top-2 right-2 flex gap-2 justify-end w-full items-center">
4+
<span class="text-sm font-mono text-neutral-400">{{languange}}</span>
5+
<ngx-copy-to-clipboard [value]="codeForHighlight" class="text-white" />
66
</div>
7-
<code class="" [highlightAuto]="codeForHighlight"
7+
<code [highlightAuto]="codeForHighlight"
88
language="ts"
99
lineNumbers>
1010
</code>

projects/ngx-notion-cms/src/lib/components/notion-block-code/notion-block-code.component.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
provideHighlightOptions,
66
} from 'ngx-highlightjs';
77
import { NotionBlock } from '../../types/block.type';
8+
import { CopyToClipboardComponent } from '../copy-to-clipboard/copy-to-clipboard.component';
89

910
@Component({
1011
selector: 'ngx-notion-block-code',
@@ -17,7 +18,8 @@ import { NotionBlock } from '../../types/block.type';
1718
lineNumbersLoader: () => import('ngx-highlightjs/line-numbers'),
1819
}),
1920
],
20-
imports: [HighlightAuto, Highlight],
21+
imports: [HighlightAuto, Highlight, CopyToClipboardComponent],
22+
2123
})
2224
export class NotionBlockCodeComponent implements OnInit {
2325
codeForHighlight = '';
@@ -31,4 +33,5 @@ export class NotionBlockCodeComponent implements OnInit {
3133
this.codeForHighlight = this.notionBlock.properties.title[0][0];
3234
}
3335
}
36+
3437
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Directive, ElementRef, HostListener, inject, input } from '@angular/core';
2+
3+
@Directive({
4+
standalone: true,
5+
})
6+
export class CopyToClipboardDirective {
7+
copy(text: string) {
8+
9+
if (!text) {
10+
console.error('No text provided to copy or empty element content');
11+
return;
12+
}
13+
navigator.clipboard.writeText(text)
14+
.catch(err => {
15+
console.error('Error copying text: ', err);
16+
});
17+
}
18+
}

projects/ngx-notion-cms/src/lib/directives/post-tag.directive.ts

-9
This file was deleted.

projects/ngx-notion-cms/src/lib/providers/global-settings.provider.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ export const defaultGlobalSettings: GlobalSettings = {
1212
},
1313
database: {
1414
showImage: true,
15+
showStatus: true
1516
},
1617
page: {
17-
showTableOfContents: true
18+
showTableOfContents: true,
19+
showStatus: true
1820
}
1921

2022
}

0 commit comments

Comments
 (0)