@capawesome/capacitor-clipboard 0.0.1
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.
- package/CapawesomeCapacitorClipboard.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +220 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/clipboard/Clipboard.java +141 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/clipboard/ClipboardPlugin.java +96 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/clipboard/classes/ClipboardContentType.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/clipboard/classes/CustomException.java +20 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/clipboard/classes/CustomExceptions.java +12 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/clipboard/classes/options/WriteOptions.java +60 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/clipboard/classes/results/ReadResult.java +29 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/clipboard/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/clipboard/interfaces/EmptyCallback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/clipboard/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/clipboard/interfaces/Result.java +7 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +249 -0
- package/dist/esm/definitions.d.ts +144 -0
- package/dist/esm/definitions.js +57 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +16 -0
- package/dist/esm/web.js +109 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +179 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +182 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Classes/Options/WriteOptions.swift +19 -0
- package/ios/Plugin/Classes/Results/ReadResult.swift +19 -0
- package/ios/Plugin/Clipboard.swift +74 -0
- package/ios/Plugin/ClipboardPlugin.swift +62 -0
- package/ios/Plugin/Enums/ClipboardContentType.swift +8 -0
- package/ios/Plugin/Enums/CustomError.swift +36 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Protocols/Result.swift +5 -0
- package/package.json +94 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc(ClipboardPlugin)
|
|
5
|
+
public class ClipboardPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
6
|
+
public let identifier = "ClipboardPlugin"
|
|
7
|
+
public let jsName = "Clipboard"
|
|
8
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
9
|
+
CAPPluginMethod(name: "read", returnType: CAPPluginReturnPromise),
|
|
10
|
+
CAPPluginMethod(name: "write", returnType: CAPPluginReturnPromise)
|
|
11
|
+
]
|
|
12
|
+
public static let tag = "ClipboardPlugin"
|
|
13
|
+
|
|
14
|
+
private var implementation: Clipboard?
|
|
15
|
+
|
|
16
|
+
override public func load() {
|
|
17
|
+
self.implementation = Clipboard(plugin: self)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@objc func read(_ call: CAPPluginCall) {
|
|
21
|
+
implementation?.read { result, error in
|
|
22
|
+
if let error = error {
|
|
23
|
+
self.rejectCall(call, error)
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
self.resolveCall(call, result)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@objc func write(_ call: CAPPluginCall) {
|
|
31
|
+
do {
|
|
32
|
+
let options = try WriteOptions(call)
|
|
33
|
+
implementation?.write(options) { error in
|
|
34
|
+
if let error = error {
|
|
35
|
+
self.rejectCall(call, error)
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
self.resolveCall(call)
|
|
39
|
+
}
|
|
40
|
+
} catch {
|
|
41
|
+
rejectCall(call, error)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private func rejectCall(_ call: CAPPluginCall, _ error: Error) {
|
|
46
|
+
CAPLog.print("[", ClipboardPlugin.tag, "] ", error)
|
|
47
|
+
let code = (error as? CustomError)?.code
|
|
48
|
+
call.reject(error.localizedDescription, code)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private func resolveCall(_ call: CAPPluginCall) {
|
|
52
|
+
call.resolve()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private func resolveCall(_ call: CAPPluginCall, _ result: Result?) {
|
|
56
|
+
if let result = result?.toJSObject() as? JSObject {
|
|
57
|
+
call.resolve(result)
|
|
58
|
+
} else {
|
|
59
|
+
call.resolve()
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
enum CustomError: Error {
|
|
4
|
+
case contentMissing
|
|
5
|
+
case emptyClipboard
|
|
6
|
+
case readFailed
|
|
7
|
+
case writeFailed
|
|
8
|
+
|
|
9
|
+
var code: String? {
|
|
10
|
+
switch self {
|
|
11
|
+
case .contentMissing:
|
|
12
|
+
return nil
|
|
13
|
+
case .emptyClipboard:
|
|
14
|
+
return "EMPTY_CLIPBOARD"
|
|
15
|
+
case .readFailed:
|
|
16
|
+
return "READ_FAILED"
|
|
17
|
+
case .writeFailed:
|
|
18
|
+
return "WRITE_FAILED"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
extension CustomError: LocalizedError {
|
|
24
|
+
public var errorDescription: String? {
|
|
25
|
+
switch self {
|
|
26
|
+
case .contentMissing:
|
|
27
|
+
return NSLocalizedString("One of text, html, image or url must be provided.", comment: "contentMissing")
|
|
28
|
+
case .emptyClipboard:
|
|
29
|
+
return NSLocalizedString("The clipboard is empty.", comment: "emptyClipboard")
|
|
30
|
+
case .readFailed:
|
|
31
|
+
return NSLocalizedString("The clipboard content could not be read.", comment: "readFailed")
|
|
32
|
+
case .writeFailed:
|
|
33
|
+
return NSLocalizedString("The content could not be written to the clipboard.", comment: "writeFailed")
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>CFBundleDevelopmentRegion</key>
|
|
6
|
+
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
|
7
|
+
<key>CFBundleExecutable</key>
|
|
8
|
+
<string>$(EXECUTABLE_NAME)</string>
|
|
9
|
+
<key>CFBundleIdentifier</key>
|
|
10
|
+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
|
11
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
|
12
|
+
<string>6.0</string>
|
|
13
|
+
<key>CFBundleName</key>
|
|
14
|
+
<string>$(PRODUCT_NAME)</string>
|
|
15
|
+
<key>CFBundlePackageType</key>
|
|
16
|
+
<string>FMWK</string>
|
|
17
|
+
<key>CFBundleShortVersionString</key>
|
|
18
|
+
<string>1.0</string>
|
|
19
|
+
<key>CFBundleVersion</key>
|
|
20
|
+
<string>$(CURRENT_PROJECT_VERSION)</string>
|
|
21
|
+
<key>NSPrincipalClass</key>
|
|
22
|
+
<string></string>
|
|
23
|
+
</dict>
|
|
24
|
+
</plist>
|
package/package.json
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capawesome/capacitor-clipboard",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Capacitor plugin to read from and write to the system clipboard.",
|
|
5
|
+
"main": "dist/plugin.cjs.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"unpkg": "dist/plugin.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"android/src/main/",
|
|
11
|
+
"android/build.gradle",
|
|
12
|
+
"dist/",
|
|
13
|
+
"ios/Plugin/",
|
|
14
|
+
"CapawesomeCapacitorClipboard.podspec",
|
|
15
|
+
"Package.swift"
|
|
16
|
+
],
|
|
17
|
+
"author": "Robin Genz <mail@robingenz.dev>",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/capawesome-team/capacitor-plugins.git"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/capawesome-team/capacitor-plugins/issues"
|
|
25
|
+
},
|
|
26
|
+
"funding": [
|
|
27
|
+
{
|
|
28
|
+
"type": "github",
|
|
29
|
+
"url": "https://github.com/sponsors/capawesome-team/"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"type": "opencollective",
|
|
33
|
+
"url": "https://opencollective.com/capawesome"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"homepage": "https://capawesome.io/docs/sdks/capacitor/clipboard/",
|
|
37
|
+
"keywords": [
|
|
38
|
+
"capacitor",
|
|
39
|
+
"plugin",
|
|
40
|
+
"native",
|
|
41
|
+
"clipboard",
|
|
42
|
+
"copy",
|
|
43
|
+
"paste"
|
|
44
|
+
],
|
|
45
|
+
"scripts": {
|
|
46
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
47
|
+
"verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
|
|
48
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
49
|
+
"verify:web": "npm run build",
|
|
50
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
51
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
52
|
+
"eslint": "eslint . --ext ts",
|
|
53
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
|
|
54
|
+
"swiftlint": "node-swiftlint",
|
|
55
|
+
"docgen": "docgen --api ClipboardPlugin --output-readme README.md --output-json dist/docs.json",
|
|
56
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
57
|
+
"clean": "rimraf ./dist",
|
|
58
|
+
"watch": "tsc --watch",
|
|
59
|
+
"ios:pod:install": "cd ios && pod install --repo-update && cd ..",
|
|
60
|
+
"ios:spm:install": "cd ios && swift package resolve && cd ..",
|
|
61
|
+
"prepublishOnly": "npm run build"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@capacitor/android": "8.0.0",
|
|
65
|
+
"@capacitor/cli": "8.0.0",
|
|
66
|
+
"@capacitor/core": "8.0.0",
|
|
67
|
+
"@capacitor/docgen": "0.3.1",
|
|
68
|
+
"@capacitor/ios": "8.0.0",
|
|
69
|
+
"@ionic/eslint-config": "0.4.0",
|
|
70
|
+
"eslint": "8.57.0",
|
|
71
|
+
"prettier-plugin-java": "2.6.7",
|
|
72
|
+
"rimraf": "6.1.2",
|
|
73
|
+
"rollup": "4.53.3",
|
|
74
|
+
"swiftlint": "2.0.0",
|
|
75
|
+
"typescript": "5.9.3"
|
|
76
|
+
},
|
|
77
|
+
"peerDependencies": {
|
|
78
|
+
"@capacitor/core": ">=8.0.0"
|
|
79
|
+
},
|
|
80
|
+
"eslintConfig": {
|
|
81
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
82
|
+
},
|
|
83
|
+
"capacitor": {
|
|
84
|
+
"ios": {
|
|
85
|
+
"src": "ios"
|
|
86
|
+
},
|
|
87
|
+
"android": {
|
|
88
|
+
"src": "android"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"publishConfig": {
|
|
92
|
+
"access": "public"
|
|
93
|
+
}
|
|
94
|
+
}
|