@react-native-clipboard/clipboard 1.11.2 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,147 @@
1
+ import { TurboModule, EmitterSubscription } from 'react-native';
2
+ import type { Int32 } from 'react-native/Libraries/Types/CodegenTypes';
3
+ export interface Spec extends TurboModule {
4
+ /**
5
+ * Get content of string type, this method returns a `Promise`, so you can use following code to get clipboard content
6
+ * ```javascript
7
+ * async _getContent() {
8
+ * var content = await Clipboard.getString();
9
+ * }
10
+ * ```
11
+ */
12
+ getString(): Promise<string>;
13
+ /**
14
+ * (iOS Only)
15
+ * Get contents of string array type, this method returns a `Promise`, so you can use following code to get clipboard content
16
+ * ```javascript
17
+ * async _getContent() {
18
+ * var content = await Clipboard.getStrings();
19
+ * }
20
+ * ```
21
+ */
22
+ getStrings(): Promise<string[]>;
23
+ /**
24
+ * Get clipboard image as PNG in base64, this method returns a `Promise`, so you can use following code to get clipboard content
25
+ * ```javascript
26
+ * async _getContent() {
27
+ * var content = await Clipboard.getImagePNG();
28
+ * }
29
+ * ```
30
+ */
31
+ getImagePNG(): Promise<string>;
32
+ /**
33
+ * Get clipboard image as JPG in base64, this method returns a `Promise`, so you can use following code to get clipboard content
34
+ * ```javascript
35
+ * async _getContent() {
36
+ * var content = await Clipboard.getImageJPG();
37
+ * }
38
+ * ```
39
+ */
40
+ getImageJPG(): Promise<string>;
41
+ /**
42
+ * (iOS Only)
43
+ * Set content of base64 image type. You can use following code to set clipboard content
44
+ * ```javascript
45
+ * _setContent() {
46
+ * Clipboard.setImage(...);
47
+ * }
48
+ * ```
49
+ * @param the content to be stored in the clipboard.
50
+ */
51
+ setImage(content: string): Promise<void>;
52
+ /**
53
+ * (Android Only)
54
+ * Get clipboard image in base64, this method returns a `Promise`, so you can use following code to get clipboard content
55
+ * ```javascript
56
+ * async _getContent() {
57
+ * var content = await Clipboard.getImage();
58
+ * }
59
+ * ```
60
+ */
61
+ getImage(): Promise<string>;
62
+ /**
63
+ * Set content of string type. You can use following code to set clipboard content
64
+ * ```javascript
65
+ * _setContent() {
66
+ * Clipboard.setString('hello world');
67
+ * }
68
+ * ```
69
+ * @param the content to be stored in the clipboard.
70
+ */
71
+ setString(content: string): void;
72
+ /**
73
+ * Set content of string array type. You can use following code to set clipboard content
74
+ * ```javascript
75
+ * _setContent() {
76
+ * Clipboard.setStrings(['hello world', 'second string']);
77
+ * }
78
+ * ```
79
+ * @param the content to be stored in the clipboard.
80
+ */
81
+ setStrings(content: string[]): void;
82
+ /**
83
+ * Returns whether the clipboard has content or is empty.
84
+ * This method returns a `Promise`, so you can use following code to get clipboard content
85
+ * ```javascript
86
+ * async _hasContent() {
87
+ * var hasContent = await Clipboard.hasString();
88
+ * }
89
+ * ```
90
+ */
91
+ hasString(): Promise<boolean>;
92
+ /**
93
+ * Returns whether the clipboard has an image or is empty.
94
+ * This method returns a `Promise`, so you can use following code to check clipboard content
95
+ * ```javascript
96
+ * async _hasContent() {
97
+ * var hasContent = await Clipboard.hasImage();
98
+ * }
99
+ * ```
100
+ */
101
+ hasImage(): Promise<boolean>;
102
+ /**
103
+ * (iOS Only)
104
+ * Returns whether the clipboard has a URL content. Can check
105
+ * if there is a URL content in clipboard without triggering PasteBoard notification for iOS 14+
106
+ * This method returns a `Promise`, so you can use following code to check for url content in clipboard.
107
+ * ```javascript
108
+ * async _hasURL() {
109
+ * var hasURL = await Clipboard.hasURL();
110
+ * }
111
+ * ```
112
+ */
113
+ hasURL(): Promise<boolean>;
114
+ /**
115
+ * (iOS 14+ Only)
116
+ * Returns whether the clipboard has a Number(UIPasteboardDetectionPatternNumber) content. Can check
117
+ * if there is a Number content in clipboard without triggering PasteBoard notification for iOS 14+
118
+ * This method returns a `Promise`, so you can use following code to check for Number content in clipboard.
119
+ * ```javascript
120
+ * async _hasNumber() {
121
+ * var hasNumber = await Clipboard.hasNumber();
122
+ * }
123
+ * ```
124
+ */
125
+ hasNumber(): Promise<boolean>;
126
+ /**
127
+ * (iOS 14+ Only)
128
+ * Returns whether the clipboard has a WebURL(UIPasteboardDetectionPatternProbableWebURL) content. Can check
129
+ * if there is a WebURL content in clipboard without triggering PasteBoard notification for iOS 14+
130
+ * This method returns a `Promise`, so you can use following code to check for WebURL content in clipboard.
131
+ * ```javascript
132
+ * async _hasWebURL() {
133
+ * var hasWebURL = await Clipboard.hasWebURL();
134
+ * }
135
+ * ```
136
+ */
137
+ hasWebURL(): Promise<boolean>;
138
+ setListener(): void;
139
+ removeListener(): void;
140
+ addListener(eventName: string): void;
141
+ removeListeners(count: Int32): void;
142
+ }
143
+ declare const ClipboardTurboModule: Spec;
144
+ export default ClipboardTurboModule;
145
+ declare const addListener: (callback: () => void) => EmitterSubscription;
146
+ declare const removeAllListeners: () => void;
147
+ export { addListener, removeAllListeners };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeAllListeners = exports.addListener = void 0;
4
+ var react_native_1 = require("react-native");
5
+ var ClipboardTurboModule = react_native_1.TurboModuleRegistry.getEnforcing('RNCClipboard');
6
+ exports.default = ClipboardTurboModule;
7
+ var EVENT_NAME = 'RNCClipboard_TEXT_CHANGED';
8
+ var eventEmitter = new react_native_1.NativeEventEmitter(ClipboardTurboModule);
9
+ var listenerCount = eventEmitter.listenerCount;
10
+ // listenerCount is only available from RN 0.64
11
+ // Older versions only have `listeners`
12
+ if (!listenerCount) {
13
+ listenerCount = function (eventType) {
14
+ // @ts-ignore
15
+ return eventEmitter.listeners(eventType).length;
16
+ };
17
+ }
18
+ else {
19
+ listenerCount = eventEmitter.listenerCount.bind(eventEmitter);
20
+ }
21
+ var addListener = function (callback) {
22
+ if (listenerCount(EVENT_NAME) === 0) {
23
+ ClipboardTurboModule.setListener();
24
+ }
25
+ var res = eventEmitter.addListener(EVENT_NAME, callback);
26
+ // Path the remove call to also remove the native listener
27
+ // if we no longer have listeners
28
+ // @ts-ignore
29
+ res._remove = res.remove;
30
+ res.remove = function () {
31
+ // @ts-ignore
32
+ this._remove();
33
+ if (listenerCount(EVENT_NAME) === 0) {
34
+ ClipboardTurboModule.removeListener();
35
+ }
36
+ };
37
+ return res;
38
+ };
39
+ exports.addListener = addListener;
40
+ var removeAllListeners = function () {
41
+ eventEmitter.removeAllListeners(EVENT_NAME);
42
+ ClipboardTurboModule.removeListener();
43
+ };
44
+ exports.removeAllListeners = removeAllListeners;
@@ -1,11 +1,21 @@
1
1
  #ifndef RNCClipboard_h
2
2
  #define RNCClipboard_h
3
3
 
4
- #import <React/RCTBridgeModule.h>
4
+ #ifdef RCT_NEW_ARCH_ENABLED
5
+ #import <rnclipboard/rnclipboard.h>
6
+ #else
7
+ #import <React/RCTBridge.h>
8
+ #endif
9
+
5
10
  #import <React/RCTEventEmitter.h>
6
11
 
7
- @interface RNCClipboard : RCTEventEmitter <RCTBridgeModule>
12
+ @interface RNCClipboard : RCTEventEmitter
8
13
 
14
+ #ifdef RCT_NEW_ARCH_ENABLED
15
+ <NativeClipboardModuleSpec>
16
+ #else
17
+ <RCTBridgeModule>
18
+ #endif
9
19
  @end
10
20
 
11
21
  #endif
@@ -213,7 +213,26 @@ RCT_EXPORT_METHOD(hasWebURL:(RCTPromiseResolveBlock)resolve
213
213
 
214
214
  }
215
215
 
216
+ RCT_EXPORT_METHOD(getImage:(RCTPromiseResolveBlock)resolve
217
+ reject:(__unused RCTPromiseRejectBlock)reject){
218
+ reject(@"Clipboard:getImage", @"getImage is not supported on iOS", nil);
219
+ }
220
+
221
+ RCT_EXPORT_METHOD(addListener : (NSString *)eventName) {
222
+ // Keep: Required for RN built in Event Emitter Calls.
223
+ }
216
224
 
225
+ RCT_EXPORT_METHOD(removeListeners : (NSInteger)count) {
226
+ // Keep: Required for RN built in Event Emitter Calls.
227
+ }
228
+
229
+ #if RCT_NEW_ARCH_ENABLED
230
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
231
+ (const facebook::react::ObjCTurboModule::InitParams &)params
232
+ {
233
+ return std::make_shared<facebook::react::NativeClipboardModuleSpecJSI>(params);
234
+ }
235
+ #endif
217
236
 
218
237
 
219
238
  @end
@@ -31,4 +31,12 @@ RCT_EXPORT_METHOD(getString:(RCTPromiseResolveBlock)resolve
31
31
  resolve(([pasteboard stringForType:NSPasteboardTypeString] ? : @""));
32
32
  }
33
33
 
34
+ RCT_EXPORT_METHOD(addListener : (NSString *)eventName) {
35
+ // Keep: Required for RN built in Event Emitter Calls.
36
+ }
37
+
38
+ RCT_EXPORT_METHOD(removeListeners : (NSInteger)count) {
39
+ // Keep: Required for RN built in Event Emitter Calls.
40
+ }
41
+
34
42
  @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-clipboard/clipboard",
3
- "version": "1.11.2",
3
+ "version": "1.13.0",
4
4
  "description": "React Native Clipboard API for macOS, iOS, Android, and Windows",
5
5
  "keywords": [
6
6
  "Clipboard",
@@ -28,6 +28,7 @@
28
28
  "android",
29
29
  "windows",
30
30
  "jest",
31
+ "src",
31
32
  "!android/**/build/*"
32
33
  ],
33
34
  "scripts": {
@@ -47,7 +48,7 @@
47
48
  "devDependencies": {
48
49
  "@babel/core": "^7.12.9",
49
50
  "@react-native-community/eslint-config": "^2.0.0",
50
- "@types/react-native": "^0.64.8",
51
+ "@types/react-native": "^0.70.0",
51
52
  "babel-jest": "^26.1.0",
52
53
  "eslint": "^7.32.0",
53
54
  "eslint-plugin-prettier": "^3.1.2",
@@ -55,7 +56,7 @@
55
56
  "metro-react-native-babel-preset": "^0.64.0",
56
57
  "prettier": "^2.4.1",
57
58
  "react": "17.0.1",
58
- "react-native": "0.64.1",
59
+ "react-native": "0.68.0",
59
60
  "react-native-macos": "^0.62.0-0",
60
61
  "react-native-windows": "^0.64.0",
61
62
  "react-test-renderer": "16.9.0",
@@ -67,5 +68,13 @@
67
68
  },
68
69
  "publishConfig": {
69
70
  "access": "public"
71
+ },
72
+ "codegenConfig": {
73
+ "name": "rnclipboard",
74
+ "type": "modules",
75
+ "jsSrcsDir": "./src",
76
+ "android": {
77
+ "javaPackageName": "com.reactnativecommunity.clipboard"
78
+ }
70
79
  }
71
80
  }
@@ -0,0 +1,208 @@
1
+ import {EmitterSubscription, Platform} from 'react-native';
2
+ import NativeClipboard, {
3
+ addListener,
4
+ removeAllListeners,
5
+ } from './NativeClipboardModule';
6
+
7
+ /**
8
+ * `Clipboard` gives you an interface for setting and getting content from Clipboard on both iOS and Android
9
+ */
10
+ export const Clipboard = {
11
+ /**
12
+ * Get content of string type, this method returns a `Promise`, so you can use following code to get clipboard content
13
+ * ```javascript
14
+ * async _getContent() {
15
+ * var content = await Clipboard.getString();
16
+ * }
17
+ * ```
18
+ */
19
+ getString(): Promise<string> {
20
+ return NativeClipboard.getString();
21
+ },
22
+ /**
23
+ * (iOS Only)
24
+ * Get contents of string array type, this method returns a `Promise`, so you can use following code to get clipboard content
25
+ * ```javascript
26
+ * async _getContent() {
27
+ * var content = await Clipboard.getStrings();
28
+ * }
29
+ * ```
30
+ */
31
+ getStrings(): Promise<string[]> {
32
+ return NativeClipboard.getStrings();
33
+ },
34
+ /**
35
+ * Get clipboard image as PNG in base64, this method returns a `Promise`, so you can use following code to get clipboard content
36
+ * ```javascript
37
+ * async _getContent() {
38
+ * var content = await Clipboard.getImagePNG();
39
+ * }
40
+ * ```
41
+ */
42
+ getImagePNG(): Promise<string> {
43
+ return NativeClipboard.getImagePNG();
44
+ },
45
+ /**
46
+ * Get clipboard image as JPG in base64, this method returns a `Promise`, so you can use following code to get clipboard content
47
+ * ```javascript
48
+ * async _getContent() {
49
+ * var content = await Clipboard.getImageJPG();
50
+ * }
51
+ * ```
52
+ */
53
+ getImageJPG(): Promise<string> {
54
+ return NativeClipboard.getImageJPG();
55
+ },
56
+ /**
57
+ * (iOS Only)
58
+ * Set content of base64 image type. You can use following code to set clipboard content
59
+ * ```javascript
60
+ * _setContent() {
61
+ * Clipboard.setImage(...);
62
+ * }
63
+ * ```
64
+ * @param the content to be stored in the clipboard.
65
+ */
66
+ setImage(content: string) {
67
+ if (Platform.OS !== 'ios') {
68
+ return;
69
+ }
70
+
71
+ NativeClipboard.setImage(content);
72
+ },
73
+ /**
74
+ * (Android Only)
75
+ * Get clipboard image in base64, this method returns a `Promise`, so you can use following code to get clipboard content
76
+ * ```javascript
77
+ * async _getContent() {
78
+ * var content = await Clipboard.getImage();
79
+ * }
80
+ * ```
81
+ */
82
+ getImage(): Promise<string> {
83
+ return NativeClipboard.getImage();
84
+ },
85
+ /**
86
+ * Set content of string type. You can use following code to set clipboard content
87
+ * ```javascript
88
+ * _setContent() {
89
+ * Clipboard.setString('hello world');
90
+ * }
91
+ * ```
92
+ * @param the content to be stored in the clipboard.
93
+ */
94
+ setString(content: string) {
95
+ NativeClipboard.setString(content);
96
+ },
97
+ /**
98
+ * Set content of string array type. You can use following code to set clipboard content
99
+ * ```javascript
100
+ * _setContent() {
101
+ * Clipboard.setStrings(['hello world', 'second string']);
102
+ * }
103
+ * ```
104
+ * @param the content to be stored in the clipboard.
105
+ */
106
+ setStrings(content: string[]) {
107
+ NativeClipboard.setStrings(content);
108
+ },
109
+ /**
110
+ * Returns whether the clipboard has content or is empty.
111
+ * This method returns a `Promise`, so you can use following code to get clipboard content
112
+ * ```javascript
113
+ * async _hasContent() {
114
+ * var hasContent = await Clipboard.hasString();
115
+ * }
116
+ * ```
117
+ */
118
+ hasString() {
119
+ return NativeClipboard.hasString();
120
+ },
121
+ /**
122
+ * Returns whether the clipboard has an image or is empty.
123
+ * This method returns a `Promise`, so you can use following code to check clipboard content
124
+ * ```javascript
125
+ * async _hasContent() {
126
+ * var hasContent = await Clipboard.hasImage();
127
+ * }
128
+ * ```
129
+ */
130
+ hasImage() {
131
+ return NativeClipboard.hasImage();
132
+ },
133
+ /**
134
+ * (iOS Only)
135
+ * Returns whether the clipboard has a URL content. Can check
136
+ * if there is a URL content in clipboard without triggering PasteBoard notification for iOS 14+
137
+ * This method returns a `Promise`, so you can use following code to check for url content in clipboard.
138
+ * ```javascript
139
+ * async _hasURL() {
140
+ * var hasURL = await Clipboard.hasURL();
141
+ * }
142
+ * ```
143
+ */
144
+ hasURL() {
145
+ if (Platform.OS !== 'ios') {
146
+ return;
147
+ }
148
+ return NativeClipboard.hasURL();
149
+ },
150
+ /**
151
+ * (iOS 14+ Only)
152
+ * Returns whether the clipboard has a Number(UIPasteboardDetectionPatternNumber) content. Can check
153
+ * if there is a Number content in clipboard without triggering PasteBoard notification for iOS 14+
154
+ * This method returns a `Promise`, so you can use following code to check for Number content in clipboard.
155
+ * ```javascript
156
+ * async _hasNumber() {
157
+ * var hasNumber = await Clipboard.hasNumber();
158
+ * }
159
+ * ```
160
+ */
161
+ hasNumber() {
162
+ if (Platform.OS !== 'ios') {
163
+ return;
164
+ }
165
+ return NativeClipboard.hasNumber();
166
+ },
167
+ /**
168
+ * (iOS 14+ Only)
169
+ * Returns whether the clipboard has a WebURL(UIPasteboardDetectionPatternProbableWebURL) content. Can check
170
+ * if there is a WebURL content in clipboard without triggering PasteBoard notification for iOS 14+
171
+ * This method returns a `Promise`, so you can use following code to check for WebURL content in clipboard.
172
+ * ```javascript
173
+ * async _hasWebURL() {
174
+ * var hasWebURL = await Clipboard.hasWebURL();
175
+ * }
176
+ * ```
177
+ */
178
+ hasWebURL() {
179
+ if (Platform.OS !== 'ios') {
180
+ return;
181
+ }
182
+ return NativeClipboard.hasWebURL();
183
+ },
184
+ /**
185
+ * (iOS and Android Only)
186
+ * Adds a listener to get notifications when the clipboard has changed.
187
+ * If this is the first listener, turns on clipboard notifications on the native side.
188
+ * It returns EmitterSubscription where you can call "remove" to remove listener
189
+ * ```javascript
190
+ * const listener = () => console.log("changed!");
191
+ * Clipboard.addListener(listener);
192
+ * ```
193
+ */
194
+ addListener(callback: () => void): EmitterSubscription {
195
+ return addListener(callback);
196
+ },
197
+
198
+ /**
199
+ * (iOS and Android Only)
200
+ * Removes all previously registered listeners and turns off notifications on the native side.
201
+ * ```javascript
202
+ * Clipboard.removeAllListeners();
203
+ * ```
204
+ */
205
+ removeAllListeners() {
206
+ removeAllListeners();
207
+ },
208
+ };
@@ -0,0 +1,37 @@
1
+ declare var navigator: {
2
+ clipboard: {
3
+ readText(): Promise<string>;
4
+ writeText(data: string): Promise<void>;
5
+ };
6
+ };
7
+
8
+ declare var document: any;
9
+
10
+ export const Clipboard = {
11
+ getString(): Promise<string> {
12
+ if (navigator && navigator.clipboard) {
13
+ return navigator.clipboard.readText();
14
+ } else {
15
+ const el = document.createElement('textarea');
16
+ document.body.appendChild(el);
17
+ el.select();
18
+ document.execCommand('paste');
19
+ const value = el.innerText;
20
+ document.body.removeChild(el);
21
+ return Promise.resolve(value);
22
+ }
23
+ },
24
+
25
+ setString(content: string) {
26
+ if (navigator && navigator.clipboard) {
27
+ navigator.clipboard.writeText(content);
28
+ } else {
29
+ const el = document.createElement('textarea');
30
+ el.value = content;
31
+ document.body.appendChild(el);
32
+ el.select();
33
+ document.execCommand('copy');
34
+ document.body.removeChild(el);
35
+ }
36
+ },
37
+ };