Skip to content

Commit 05113af

Browse files
committed
feat: move clipboard module into cdk
Moves the `clipboard` module into CDK stable, sets up the API goldens, adjusts some APIs to be more consistent and sets up a live example.
1 parent 8c98013 commit 05113af

23 files changed

+131
-27
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
/src/cdk/a11y/** @jelbourn @devversion
6767
/src/cdk/accordion/** @jelbourn
6868
/src/cdk/bidi/** @jelbourn
69+
/src/cdk/clipboard/** @jelbourn
6970
/src/cdk/coercion/** @jelbourn
7071
/src/cdk/collections/** @jelbourn @crisbeto @andrewseguin
7172
/src/cdk/drag-drop/** @crisbeto
@@ -114,7 +115,7 @@
114115
/src/material-experimental/select/** @crisbeto
115116

116117
# CDK experimental package
117-
/src/cdk-experimental/** @jelbourn
118+
/src/cdk-experimental/* @jelbourn
118119
/src/cdk-experimental/dialog/** @jelbourn @crisbeto
119120
/src/cdk-experimental/popover-edit/** @kseamon @andrewseguin
120121
/src/cdk-experimental/scrolling/** @mmalerba
@@ -244,6 +245,7 @@
244245
/tools/public_api_guard/cdk/accordion.d.ts @jelbourn
245246
/tools/public_api_guard/cdk/bidi.d.ts @jelbourn
246247
/tools/public_api_guard/cdk/cdk.d.ts @jelbourn
248+
/tools/public_api_guard/cdk/clipboard.d.ts @jelbourn
247249
/tools/public_api_guard/cdk/coercion.d.ts @jelbourn
248250
/tools/public_api_guard/cdk/collections.d.ts @jelbourn @crisbeto @andrewseguin
249251
/tools/public_api_guard/cdk/drag-drop.d.ts @crisbeto

src/cdk-experimental/config.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# List of all entry-points of the Angular cdk-experimental package.
22
CDK_EXPERIMENTAL_ENTRYPOINTS = [
3-
"clipboard",
43
"dialog",
54
"popover-edit",
65
"scrolling",

src/cdk-experimental/clipboard/BUILD.bazel renamed to src/cdk/clipboard/BUILD.bazel

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")
3+
load("//tools:defaults.bzl", "markdown_to_html", "ng_module", "ng_test_library", "ng_web_test_suite")
44

55
ng_module(
66
name = "clipboard",
@@ -9,7 +9,7 @@ ng_module(
99
exclude = ["**/*.spec.ts"],
1010
),
1111
assets = glob(["**/*.html"]),
12-
module_name = "@angular/cdk-experimental/clipboard",
12+
module_name = "@angular/cdk/clipboard",
1313
deps = [
1414
"@npm//@angular/common",
1515
"@npm//@angular/core",
@@ -35,3 +35,13 @@ ng_web_test_suite(
3535
name = "unit_tests",
3636
deps = [":unit_test_sources"],
3737
)
38+
39+
markdown_to_html(
40+
name = "overview",
41+
srcs = [":clipboard.md"],
42+
)
43+
44+
filegroup(
45+
name = "source-files",
46+
srcs = glob(["**/*.ts"]),
47+
)

src/cdk-experimental/clipboard/clipboard.md renamed to src/cdk/clipboard/clipboard.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
**Warning: this service is still experimental. It may have bugs and the API may change at any
2-
time**
3-
41
The clipboard package provides helpers for working with the system clipboard.
52

3+
## `cdkCopyToClipboard` directive
4+
5+
The `cdkCopyToClipboard` directive can be used to easily add copy-on-click
6+
functionality to an existing element. The directive selector doubles as an
7+
`@Input()` for the text to be copied.
8+
9+
```html
10+
<img src="avatar.jpg" alt="Hero avatar" [cdkCopyToClipboard]="getShortBio()">
11+
```
12+
13+
<!-- example(cdk-platform-overview) -->
14+
615
## `Clipboard` service
716

817
The `Clipboard` service copies text to the
@@ -50,13 +59,3 @@ class HeroProfile {
5059
}
5160
}
5261
```
53-
54-
## `cdkCopyToClipboard` directive
55-
56-
The `cdkCopyToClipboard` directive can be used to easily add copy-on-click
57-
functionality to an existing element. The directive selector doubles as an
58-
`@Input()` for the text to be copied.
59-
60-
```html
61-
<img src="avatar.jpg" alt="Hero avatar" [cdkCopyToClipboard]="getShortBio()">
62-
```

src/cdk-experimental/clipboard/copy-to-clipboard.ts renamed to src/cdk/clipboard/copy-to-clipboard.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,23 @@ import {Clipboard} from './clipboard';
2121
@Directive({
2222
selector: '[cdkCopyToClipboard]',
2323
host: {
24-
'(click)': 'doCopy()',
24+
'(click)': 'copy()',
2525
}
2626
})
2727
export class CdkCopyToClipboard {
2828
/** Content to be copied. */
2929
@Input('cdkCopyToClipboard') text = '';
3030

31+
/**
32+
* Emits when some text is copied to the clipboard. The
33+
* emitted value indicates whether copying was successful.
34+
*/
3135
@Output() copied = new EventEmitter<boolean>();
3236

33-
constructor(private readonly clipboard: Clipboard) {}
37+
constructor(private readonly _clipboard: Clipboard) {}
3438

35-
doCopy() {
36-
this.copied.emit(this.clipboard.copy(this.text));
39+
/** Copies the current text to the clipboard. */
40+
copy() {
41+
this.copied.emit(this._clipboard.copy(this.text));
3742
}
3843
}
File renamed without changes.

src/cdk-experimental/clipboard/tsconfig-build.json renamed to src/cdk/clipboard/tsconfig-build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"annotateForClosureCompiler": true,
99
"strictMetadataEmit": true,
1010
"flatModuleOutFile": "index.js",
11-
"flatModuleId": "@angular/cdk-experimental/clipboard",
11+
"flatModuleId": "@angular/cdk/clipboard",
1212
"skipTemplateCodegen": true,
1313
"fullTemplateTypeCheck": true
1414
}

src/cdk/config.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ CDK_ENTRYPOINTS = [
33
"a11y",
44
"accordion",
55
"bidi",
6+
"clipboard",
67
"coercion",
78
"collections",
89
"drag-drop",

src/dev-app/system-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var CDK_PACKAGES = [
1212
'a11y',
1313
'accordion',
1414
'bidi',
15+
'clipboard',
1516
'coercion',
1617
'collections',
1718
'drag-drop',

src/material-examples/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ EXAMPLE_PACKAGES = [
1010
"//src/material-examples/cdk/a11y",
1111
"//src/material-examples/cdk/drag-drop",
1212
"//src/material-examples/cdk/platform",
13+
"//src/material-examples/cdk/clipboard",
1314
"//src/material-examples/cdk-experimental/popover-edit",
1415
"//src/material-examples/cdk/portal",
1516
"//src/material-examples/cdk/scrolling",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("//tools:defaults.bzl", "ng_module")
4+
5+
ng_module(
6+
name = "clipboard",
7+
srcs = glob(["**/*.ts"]),
8+
assets = glob([
9+
"**/*.html",
10+
"**/*.css",
11+
]),
12+
module_name = "@angular/material-examples/cdk/clipboard",
13+
deps = [
14+
"//src/cdk/clipboard",
15+
"@npm//@angular/forms",
16+
],
17+
)
18+
19+
filegroup(
20+
name = "source-files",
21+
srcs = glob([
22+
"*/*.html",
23+
"*/*.css",
24+
"*/*.ts",
25+
]),
26+
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
textarea {
2+
display: block;
3+
margin: 4px 0 8px;
4+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<label for="clipboard-example-textarea">Text to be copied</label>
2+
<textarea id="clipboard-example-textarea" cols="30" rows="10" [(ngModel)]="value"></textarea>
3+
<button [cdkCopyToClipboard]="value">Copy to clipboard</button>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {Component} from '@angular/core';
2+
3+
/**
4+
* @title Clipboard overview
5+
*/
6+
@Component({
7+
selector: 'cdk-clipboard-overview-example',
8+
templateUrl: 'cdk-clipboard-overview-example.html',
9+
styleUrls: ['cdk-clipboard-overview-example.css'],
10+
})
11+
export class CdkClipboardOverviewExample {
12+
value = 'Lorem, ipsum dolor sit amet consectetur adipisicing elit. Ex fugiat recusandae ' +
13+
'consectetur illoet alias. Quia, numquam alias. Modi dolorum hic perferendis ' +
14+
'reiciendis doloribus officiis aliquid asperiores repellat deleniti rerum.';
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {NgModule} from '@angular/core';
2+
import {FormsModule} from '@angular/forms';
3+
import {ClipboardModule} from '@angular/cdk/clipboard';
4+
import {CdkClipboardOverviewExample} from './cdk-clipboard-overview/cdk-clipboard-overview-example';
5+
6+
export {CdkClipboardOverviewExample};
7+
8+
const EXAMPLES = [CdkClipboardOverviewExample];
9+
10+
@NgModule({
11+
imports: [ClipboardModule, FormsModule],
12+
declarations: EXAMPLES,
13+
exports: EXAMPLES,
14+
})
15+
export class CdkClipboardExamplesModule {
16+
}

src/material-examples/example-module.ts

Lines changed: 5 additions & 5 deletions
Large diffs are not rendered by default.

test/karma-system-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ System.config({
7272
'@angular/cdk/a11y': 'dist/packages/cdk/a11y/index.js',
7373
'@angular/cdk/accordion': 'dist/packages/cdk/accordion/index.js',
7474
'@angular/cdk/bidi': 'dist/packages/cdk/bidi/index.js',
75+
'@angular/cdk/cliboard': 'dist/packages/cdk/cliboard/index.js',
7576
'@angular/cdk/coercion': 'dist/packages/cdk/coercion/index.js',
7677
'@angular/cdk/collections': 'dist/packages/cdk/collections/index.js',
7778
'@angular/cdk/drag-drop': 'dist/packages/cdk/drag-drop/index.js',
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export declare class CdkCopyToClipboard {
2+
copied: EventEmitter<boolean>;
3+
text: string;
4+
constructor(_clipboard: Clipboard);
5+
copy(): void;
6+
}
7+
8+
export declare class Clipboard {
9+
constructor(document: any);
10+
beginCopy(text: string): PendingCopy;
11+
copy(text: string): boolean;
12+
}
13+
14+
export declare class ClipboardModule {
15+
}
16+
17+
export declare class PendingCopy {
18+
constructor(text: string, _document: Document);
19+
copy(): boolean;
20+
destroy(): void;
21+
}

0 commit comments

Comments
 (0)