@react-native-clipboard/clipboard 1.14.3 → 1.16.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.
Files changed (36) hide show
  1. package/README.md +1 -4
  2. package/dist/Clipboard.d.ts +2 -2
  3. package/dist/Clipboard.js +27 -23
  4. package/dist/Clipboard.web.js +13 -15
  5. package/dist/NativeClipboard.d.ts +1 -1
  6. package/dist/NativeClipboard.js +9 -9
  7. package/dist/NativeClipboardModule.d.ts +3 -3
  8. package/dist/NativeClipboardModule.js +9 -9
  9. package/dist/index.d.ts +2 -2
  10. package/dist/index.js +1 -1
  11. package/dist/useClipboard.js +11 -9
  12. package/ios/RNCClipboard.mm +18 -2
  13. package/jest/clipboard-mock.js +14 -14
  14. package/package.json +112 -97
  15. package/src/Clipboard.ts +199 -199
  16. package/src/Clipboard.web.ts +29 -32
  17. package/src/NativeClipboardModule.ts +172 -172
  18. package/src/index.ts +2 -2
  19. package/src/useClipboard.ts +17 -15
  20. package/windows/Clipboard/Clipboard.cpp +11 -5
  21. package/windows/Clipboard/Clipboard.h +17 -8
  22. package/windows/Clipboard/Clipboard.rc +0 -0
  23. package/windows/Clipboard/Clipboard.vcxproj +89 -93
  24. package/windows/Clipboard/Clipboard.vcxproj.filters +32 -27
  25. package/windows/Clipboard/ReactPackageProvider.cpp +17 -10
  26. package/windows/Clipboard/ReactPackageProvider.h +14 -10
  27. package/windows/Clipboard/ReactPackageProvider.idl +8 -9
  28. package/windows/Clipboard/codegen/.clang-format +2 -0
  29. package/windows/Clipboard/codegen/NativeClipboardModuleSpec.g.h +130 -0
  30. package/windows/Clipboard/pch.cpp +1 -1
  31. package/windows/Clipboard/pch.h +29 -3
  32. package/windows/Clipboard/resource.h +5 -0
  33. package/windows/Clipboard/targetver.h +8 -0
  34. package/windows/Clipboard.sln +43 -0
  35. package/windows/README.md +2 -2
  36. package/windows/windows.sln +0 -295
package/README.md CHANGED
@@ -215,7 +215,6 @@ _setContent() {
215
215
  | ------- | -------- | -------- | ----------------------------------------- |
216
216
  | content | string[] | Yes | The content to be stored in the clipboard |
217
217
 
218
-
219
218
  #### `hasString()`
220
219
 
221
220
  ```jsx
@@ -255,8 +254,6 @@ static hasWebURL()
255
254
  Returns whether the clipboard has a WebURL(UIPasteboardDetectionPatternProbableWebURL) content.
256
255
  Can check if there is a WebURL content in clipboard without triggering PasteBoard notification for iOS 14+
257
256
 
258
-
259
-
260
257
  ### useClipboard
261
258
 
262
259
  `useClipboard` is a utility hooks for the `Clipboard` module. `data` contains the content stored in the clipboard.
@@ -283,7 +280,7 @@ export const HooksSample = () => {
283
280
  static getImage()
284
281
  ```
285
282
 
286
- Get content of image in base64 string type, this method returns a `Promise`, so you can use following code to get clipboard content (ANDROID only)
283
+ Get content of image in base64 string type, this method returns a `Promise`, so you can use following code to get clipboard content (iOS and Android Only)
287
284
 
288
285
  ```jsx
289
286
  async _getContent() {
@@ -1,4 +1,4 @@
1
- import { EmitterSubscription } from 'react-native';
1
+ import { type EmitterSubscription } from "react-native";
2
2
  /**
3
3
  * `Clipboard` gives you an interface for setting and getting content from Clipboard on both iOS and Android
4
4
  */
@@ -52,7 +52,7 @@ export declare const Clipboard: {
52
52
  */
53
53
  setImage(content: string): void;
54
54
  /**
55
- * (Android Only)
55
+ * (iOS and Android Only)
56
56
  * Get clipboard image in base64, this method returns a `Promise`, so you can use following code to get clipboard content
57
57
  * ```javascript
58
58
  * async _getContent() {
package/dist/Clipboard.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -20,8 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
20
24
  };
21
25
  Object.defineProperty(exports, "__esModule", { value: true });
22
26
  exports.Clipboard = void 0;
23
- var react_native_1 = require("react-native");
24
- var NativeClipboardModule_1 = __importStar(require("./NativeClipboardModule"));
27
+ const react_native_1 = require("react-native");
28
+ const NativeClipboardModule_1 = __importStar(require("./NativeClipboardModule"));
25
29
  /**
26
30
  * `Clipboard` gives you an interface for setting and getting content from Clipboard on both iOS and Android
27
31
  */
@@ -34,7 +38,7 @@ exports.Clipboard = {
34
38
  * }
35
39
  * ```
36
40
  */
37
- getString: function () {
41
+ getString() {
38
42
  return NativeClipboardModule_1.default.getString();
39
43
  },
40
44
  /**
@@ -46,7 +50,7 @@ exports.Clipboard = {
46
50
  * }
47
51
  * ```
48
52
  */
49
- getStrings: function () {
53
+ getStrings() {
50
54
  return NativeClipboardModule_1.default.getStrings();
51
55
  },
52
56
  /**
@@ -57,7 +61,7 @@ exports.Clipboard = {
57
61
  * }
58
62
  * ```
59
63
  */
60
- getImagePNG: function () {
64
+ getImagePNG() {
61
65
  return NativeClipboardModule_1.default.getImagePNG();
62
66
  },
63
67
  /**
@@ -68,7 +72,7 @@ exports.Clipboard = {
68
72
  * }
69
73
  * ```
70
74
  */
71
- getImageJPG: function () {
75
+ getImageJPG() {
72
76
  return NativeClipboardModule_1.default.getImageJPG();
73
77
  },
74
78
  /**
@@ -81,14 +85,14 @@ exports.Clipboard = {
81
85
  * ```
82
86
  * @param the content to be stored in the clipboard.
83
87
  */
84
- setImage: function (content) {
85
- if (react_native_1.Platform.OS !== 'ios') {
88
+ setImage(content) {
89
+ if (react_native_1.Platform.OS !== "ios") {
86
90
  return;
87
91
  }
88
92
  NativeClipboardModule_1.default.setImage(content);
89
93
  },
90
94
  /**
91
- * (Android Only)
95
+ * (iOS and Android Only)
92
96
  * Get clipboard image in base64, this method returns a `Promise`, so you can use following code to get clipboard content
93
97
  * ```javascript
94
98
  * async _getContent() {
@@ -96,7 +100,7 @@ exports.Clipboard = {
96
100
  * }
97
101
  * ```
98
102
  */
99
- getImage: function () {
103
+ getImage() {
100
104
  return NativeClipboardModule_1.default.getImage();
101
105
  },
102
106
  /**
@@ -108,7 +112,7 @@ exports.Clipboard = {
108
112
  * ```
109
113
  * @param the content to be stored in the clipboard.
110
114
  */
111
- setString: function (content) {
115
+ setString(content) {
112
116
  NativeClipboardModule_1.default.setString(content);
113
117
  },
114
118
  /**
@@ -120,7 +124,7 @@ exports.Clipboard = {
120
124
  * ```
121
125
  * @param the content to be stored in the clipboard.
122
126
  */
123
- setStrings: function (content) {
127
+ setStrings(content) {
124
128
  NativeClipboardModule_1.default.setStrings(content);
125
129
  },
126
130
  /**
@@ -132,7 +136,7 @@ exports.Clipboard = {
132
136
  * }
133
137
  * ```
134
138
  */
135
- hasString: function () {
139
+ hasString() {
136
140
  return NativeClipboardModule_1.default.hasString();
137
141
  },
138
142
  /**
@@ -144,7 +148,7 @@ exports.Clipboard = {
144
148
  * }
145
149
  * ```
146
150
  */
147
- hasImage: function () {
151
+ hasImage() {
148
152
  return NativeClipboardModule_1.default.hasImage();
149
153
  },
150
154
  /**
@@ -158,8 +162,8 @@ exports.Clipboard = {
158
162
  * }
159
163
  * ```
160
164
  */
161
- hasURL: function () {
162
- if (react_native_1.Platform.OS !== 'ios') {
165
+ hasURL() {
166
+ if (react_native_1.Platform.OS !== "ios") {
163
167
  return;
164
168
  }
165
169
  return NativeClipboardModule_1.default.hasURL();
@@ -175,8 +179,8 @@ exports.Clipboard = {
175
179
  * }
176
180
  * ```
177
181
  */
178
- hasNumber: function () {
179
- if (react_native_1.Platform.OS !== 'ios') {
182
+ hasNumber() {
183
+ if (react_native_1.Platform.OS !== "ios") {
180
184
  return;
181
185
  }
182
186
  return NativeClipboardModule_1.default.hasNumber();
@@ -192,8 +196,8 @@ exports.Clipboard = {
192
196
  * }
193
197
  * ```
194
198
  */
195
- hasWebURL: function () {
196
- if (react_native_1.Platform.OS !== 'ios') {
199
+ hasWebURL() {
200
+ if (react_native_1.Platform.OS !== "ios") {
197
201
  return;
198
202
  }
199
203
  return NativeClipboardModule_1.default.hasWebURL();
@@ -208,7 +212,7 @@ exports.Clipboard = {
208
212
  * Clipboard.addListener(listener);
209
213
  * ```
210
214
  */
211
- addListener: function (callback) {
215
+ addListener(callback) {
212
216
  return (0, NativeClipboardModule_1.addListener)(callback);
213
217
  },
214
218
  /**
@@ -218,7 +222,7 @@ exports.Clipboard = {
218
222
  * Clipboard.removeAllListeners();
219
223
  * ```
220
224
  */
221
- removeAllListeners: function () {
225
+ removeAllListeners() {
222
226
  (0, NativeClipboardModule_1.removeAllListeners)();
223
227
  },
224
228
  };
@@ -2,30 +2,28 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Clipboard = void 0;
4
4
  exports.Clipboard = {
5
- getString: function () {
6
- if (navigator && navigator.clipboard) {
5
+ getString() {
6
+ if (navigator === null || navigator === void 0 ? void 0 : navigator.clipboard) {
7
7
  return navigator.clipboard.readText();
8
8
  }
9
- else {
10
- var el = document.createElement('textarea');
11
- document.body.appendChild(el);
12
- el.select();
13
- document.execCommand('paste');
14
- var value = el.innerText;
15
- document.body.removeChild(el);
16
- return Promise.resolve(value);
17
- }
9
+ const el = document.createElement("textarea");
10
+ document.body.appendChild(el);
11
+ el.select();
12
+ document.execCommand("paste");
13
+ const value = el.innerText;
14
+ document.body.removeChild(el);
15
+ return Promise.resolve(value);
18
16
  },
19
- setString: function (content) {
20
- if (navigator && navigator.clipboard) {
17
+ setString(content) {
18
+ if (navigator === null || navigator === void 0 ? void 0 : navigator.clipboard) {
21
19
  navigator.clipboard.writeText(content);
22
20
  }
23
21
  else {
24
- var el = document.createElement('textarea');
22
+ const el = document.createElement("textarea");
25
23
  el.value = content;
26
24
  document.body.appendChild(el);
27
25
  el.select();
28
- document.execCommand('copy');
26
+ document.execCommand("copy");
29
27
  document.body.removeChild(el);
30
28
  }
31
29
  },
@@ -1,4 +1,4 @@
1
- import { EmitterSubscription } from 'react-native';
1
+ import type { EmitterSubscription } from 'react-native';
2
2
  import type { TurboModule } from 'react-native';
3
3
  export interface Spec extends TurboModule {
4
4
  getConstants: () => {};
@@ -1,15 +1,15 @@
1
- 'use strict';
1
+
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.removeAllListeners = exports.addListener = void 0;
4
- var react_native_1 = require("react-native");
4
+ const react_native_1 = require("react-native");
5
5
  exports.default = react_native_1.TurboModuleRegistry.get('RNCClipboard');
6
- var EVENT_NAME = 'RNCClipboard_TEXT_CHANGED';
7
- var eventEmitter = new react_native_1.NativeEventEmitter(react_native_1.NativeModules.RNCClipboard);
8
- var listenerCount = eventEmitter.listenerCount;
6
+ const EVENT_NAME = 'RNCClipboard_TEXT_CHANGED';
7
+ const eventEmitter = new react_native_1.NativeEventEmitter(react_native_1.NativeModules.RNCClipboard);
8
+ let listenerCount = eventEmitter.listenerCount;
9
9
  // listenerCount is only available from RN 0.64
10
10
  // Older versions only have `listeners`
11
11
  if (!listenerCount) {
12
- listenerCount = function (eventType) {
12
+ listenerCount = (eventType) => {
13
13
  // @ts-ignore
14
14
  return eventEmitter.listeners(eventType).length;
15
15
  };
@@ -17,11 +17,11 @@ if (!listenerCount) {
17
17
  else {
18
18
  listenerCount = eventEmitter.listenerCount.bind(eventEmitter);
19
19
  }
20
- var addListener = function (callback) {
20
+ const addListener = (callback) => {
21
21
  if (listenerCount(EVENT_NAME) === 0) {
22
22
  react_native_1.NativeModules.RNCClipboard.setListener();
23
23
  }
24
- var res = eventEmitter.addListener(EVENT_NAME, callback);
24
+ const res = eventEmitter.addListener(EVENT_NAME, callback);
25
25
  // Path the remove call to also remove the native listener
26
26
  // if we no longer have listeners
27
27
  // @ts-ignore
@@ -36,7 +36,7 @@ var addListener = function (callback) {
36
36
  return res;
37
37
  };
38
38
  exports.addListener = addListener;
39
- var removeAllListeners = function () {
39
+ const removeAllListeners = () => {
40
40
  eventEmitter.removeAllListeners(EVENT_NAME);
41
41
  react_native_1.NativeModules.RNCClipboard.removeListener();
42
42
  };
@@ -1,5 +1,5 @@
1
- import { TurboModule, EmitterSubscription } from 'react-native';
2
- import type { Int32 } from 'react-native/Libraries/Types/CodegenTypes';
1
+ import { type TurboModule, type EmitterSubscription } from "react-native";
2
+ import type { Int32 } from "react-native/Libraries/Types/CodegenTypes";
3
3
  export interface Spec extends TurboModule {
4
4
  /**
5
5
  * Get content of string type, this method returns a `Promise`, so you can use following code to get clipboard content
@@ -50,7 +50,7 @@ export interface Spec extends TurboModule {
50
50
  */
51
51
  setImage(content: string): Promise<void>;
52
52
  /**
53
- * (Android Only)
53
+ * (iOS and Android Only)
54
54
  * Get clipboard image in base64, this method returns a `Promise`, so you can use following code to get clipboard content
55
55
  * ```javascript
56
56
  * async _getContent() {
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.removeAllListeners = exports.addListener = void 0;
4
- var react_native_1 = require("react-native");
5
- var ClipboardTurboModule = react_native_1.TurboModuleRegistry.getEnforcing('RNCClipboard');
4
+ const react_native_1 = require("react-native");
5
+ const ClipboardTurboModule = react_native_1.TurboModuleRegistry.getEnforcing("RNCClipboard");
6
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;
7
+ const EVENT_NAME = "RNCClipboard_TEXT_CHANGED";
8
+ const eventEmitter = new react_native_1.NativeEventEmitter(ClipboardTurboModule);
9
+ let listenerCount = eventEmitter.listenerCount;
10
10
  // listenerCount is only available from RN 0.64
11
11
  // Older versions only have `listeners`
12
12
  if (!listenerCount) {
13
- listenerCount = function (eventType) {
13
+ listenerCount = (eventType) => {
14
14
  // @ts-ignore
15
15
  return eventEmitter.listeners(eventType).length;
16
16
  };
@@ -18,11 +18,11 @@ if (!listenerCount) {
18
18
  else {
19
19
  listenerCount = eventEmitter.listenerCount.bind(eventEmitter);
20
20
  }
21
- var addListener = function (callback) {
21
+ const addListener = (callback) => {
22
22
  if (listenerCount(EVENT_NAME) === 0) {
23
23
  ClipboardTurboModule.setListener();
24
24
  }
25
- var res = eventEmitter.addListener(EVENT_NAME, callback);
25
+ const res = eventEmitter.addListener(EVENT_NAME, callback);
26
26
  // Path the remove call to also remove the native listener
27
27
  // if we no longer have listeners
28
28
  // @ts-ignore
@@ -37,7 +37,7 @@ var addListener = function (callback) {
37
37
  return res;
38
38
  };
39
39
  exports.addListener = addListener;
40
- var removeAllListeners = function () {
40
+ const removeAllListeners = () => {
41
41
  eventEmitter.removeAllListeners(EVENT_NAME);
42
42
  ClipboardTurboModule.removeListener();
43
43
  };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { Clipboard } from './Clipboard';
2
- export { useClipboard } from './useClipboard';
1
+ import { Clipboard } from "./Clipboard";
2
+ export { useClipboard } from "./useClipboard";
3
3
  export default Clipboard;
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useClipboard = void 0;
4
- var Clipboard_1 = require("./Clipboard");
4
+ const Clipboard_1 = require("./Clipboard");
5
5
  var useClipboard_1 = require("./useClipboard");
6
6
  Object.defineProperty(exports, "useClipboard", { enumerable: true, get: function () { return useClipboard_1.useClipboard; } });
7
7
  exports.default = Clipboard_1.Clipboard;
@@ -7,21 +7,23 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.useClipboard = void 0;
10
- var react_1 = require("react");
11
- var Clipboard_1 = require("./Clipboard");
12
- var listeners = new Set();
10
+ const react_1 = require("react");
11
+ const Clipboard_1 = require("./Clipboard");
12
+ const listeners = new Set();
13
13
  function setString(content) {
14
14
  Clipboard_1.Clipboard.setString(content);
15
- listeners.forEach(function (listener) { return listener(content); });
15
+ for (const listener of listeners) {
16
+ listener(content);
17
+ }
16
18
  }
17
- var useClipboard = function () {
18
- var _a = (0, react_1.useState)(''), data = _a[0], updateClipboardData = _a[1];
19
- (0, react_1.useEffect)(function () {
19
+ const useClipboard = () => {
20
+ const [data, updateClipboardData] = (0, react_1.useState)("");
21
+ (0, react_1.useEffect)(() => {
20
22
  Clipboard_1.Clipboard.getString().then(updateClipboardData);
21
23
  }, []);
22
- (0, react_1.useEffect)(function () {
24
+ (0, react_1.useEffect)(() => {
23
25
  listeners.add(updateClipboardData);
24
- return function () {
26
+ return () => {
25
27
  listeners.delete(updateClipboardData);
26
28
  };
27
29
  }, []);
@@ -1,6 +1,7 @@
1
1
  #import "RNCClipboard.h"
2
2
 
3
-
3
+ #import <MobileCoreServices/MobileCoreServices.h>
4
+ #import <MobileCoreServices/UTType.h>
4
5
  #import <UIKit/UIKit.h>
5
6
  #import <React/RCTBridge.h>
6
7
  #import <React/RCTEventDispatcher.h>
@@ -215,7 +216,22 @@ RCT_EXPORT_METHOD(hasWebURL:(RCTPromiseResolveBlock)resolve
215
216
 
216
217
  RCT_EXPORT_METHOD(getImage:(RCTPromiseResolveBlock)resolve
217
218
  reject:(__unused RCTPromiseRejectBlock)reject){
218
- reject(@"Clipboard:getImage", @"getImage is not supported on iOS", nil);
219
+ UIPasteboard *clipboard = [UIPasteboard generalPasteboard];
220
+ NSString *withPrefix;
221
+ for (NSItemProvider *itemProvider in clipboard.itemProviders) {
222
+ if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeImage]) {
223
+ for (NSString *identifier in itemProvider.registeredTypeIdentifiers) {
224
+ if (UTTypeConformsTo((__bridge CFStringRef)identifier, kUTTypeImage)) {
225
+ NSString *MIMEType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)identifier, kUTTagClassMIMEType);
226
+ NSString *imageDataBase64 = [[clipboard dataForPasteboardType:identifier] base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
227
+ withPrefix = [NSString stringWithFormat:@"data:%@;base64,%@", MIMEType, imageDataBase64];
228
+ break;
229
+ }
230
+ }
231
+ break;
232
+ }
233
+ }
234
+ resolve((withPrefix ? : NULL));
219
235
  }
220
236
 
221
237
  RCT_EXPORT_METHOD(addListener : (NSString *)eventName) {
@@ -4,24 +4,24 @@
4
4
  /* eslint-env jest */
5
5
 
6
6
  const ClipboardMock = {
7
- getString: jest.fn().mockResolvedValue('mockString'),
8
- getImagePNG: jest.fn(),
9
- getImageJPG: jest.fn(),
10
- setImage: jest.fn(),
11
- setString: jest.fn(),
12
- hasString: jest.fn().mockResolvedValue(true),
13
- hasImage: jest.fn().mockResolvedValue(true),
14
- hasURL: jest.fn().mockResolvedValue(true),
15
- addListener: jest.fn(),
16
- removeAllListeners: jest.fn(),
17
- getEnforcing: jest.fn(),
7
+ getString: jest.fn().mockResolvedValue("mockString"),
8
+ getImagePNG: jest.fn(),
9
+ getImageJPG: jest.fn(),
10
+ setImage: jest.fn(),
11
+ setString: jest.fn(),
12
+ hasString: jest.fn().mockResolvedValue(true),
13
+ hasImage: jest.fn().mockResolvedValue(true),
14
+ hasURL: jest.fn().mockResolvedValue(true),
15
+ addListener: jest.fn(),
16
+ removeAllListeners: jest.fn(),
17
+ getEnforcing: jest.fn(),
18
18
  };
19
19
 
20
- const useClipboard = jest.fn(() => ['mockString', jest.fn()]);
20
+ const useClipboard = jest.fn(() => ["mockString", jest.fn()]);
21
21
 
22
22
  const RNCClipboardMock = {
23
- ...ClipboardMock,
24
- useClipboard,
23
+ ...ClipboardMock,
24
+ useClipboard,
25
25
  };
26
26
 
27
27
  module.exports = RNCClipboardMock;