react-native-rn-story-editor 0.2.1 → 0.2.2
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/README.md +39 -28
- package/android/src/main/java/com/rnstoryeditor/RnStoryEditorEventEmitter.kt +86 -5
- package/android/src/main/java/com/rnstoryeditor/RnStoryEditorView.kt +136 -95
- package/android/src/main/java/com/rnstoryeditor/RnStoryEditorViewManager.kt +48 -8
- package/android/src/main/java/com/rnstoryeditor/StoryEditorErrors.kt +169 -0
- package/lib/module/errors.js +89 -0
- package/lib/module/errors.js.map +1 -0
- package/lib/module/index.js +179 -19
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/errors.d.ts +46 -0
- package/lib/typescript/src/errors.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +53 -4
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/errors.ts +154 -0
- package/src/index.ts +246 -31
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
package com.rnstoryeditor
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Error codes for Story Editor operations
|
|
5
|
+
* Matches the TypeScript error codes for consistency
|
|
6
|
+
*/
|
|
7
|
+
object StoryEditorErrorCodes {
|
|
8
|
+
const val NATIVE_MODULE_NOT_FOUND = "NATIVE_MODULE_NOT_FOUND"
|
|
9
|
+
const val VIEW_MANAGER_NOT_FOUND = "VIEW_MANAGER_NOT_FOUND"
|
|
10
|
+
const val INVALID_REF = "INVALID_REF"
|
|
11
|
+
const val NODE_HANDLE_NOT_FOUND = "NODE_HANDLE_NOT_FOUND"
|
|
12
|
+
const val COMMAND_NOT_SUPPORTED = "COMMAND_NOT_SUPPORTED"
|
|
13
|
+
const val IMAGE_EXPORT_FAILED = "IMAGE_EXPORT_FAILED"
|
|
14
|
+
const val INVALID_BASE64 = "INVALID_BASE64"
|
|
15
|
+
const val INVALID_COLOR = "INVALID_COLOR"
|
|
16
|
+
const val LAYER_OPERATION_FAILED = "LAYER_OPERATION_FAILED"
|
|
17
|
+
const val TEXT_INPUT_FAILED = "TEXT_INPUT_FAILED"
|
|
18
|
+
const val PLATFORM_NOT_SUPPORTED = "PLATFORM_NOT_SUPPORTED"
|
|
19
|
+
const val INITIALIZATION_FAILED = "INITIALIZATION_FAILED"
|
|
20
|
+
const val UNKNOWN_ERROR = "UNKNOWN_ERROR"
|
|
21
|
+
const val BITMAP_DECODE_FAILED = "BITMAP_DECODE_FAILED"
|
|
22
|
+
const val FILE_SAVE_FAILED = "FILE_SAVE_FAILED"
|
|
23
|
+
const val MEMORY_ERROR = "MEMORY_ERROR"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Data class representing a Story Editor error
|
|
28
|
+
*/
|
|
29
|
+
data class StoryEditorError(
|
|
30
|
+
val code: String,
|
|
31
|
+
val message: String,
|
|
32
|
+
val nativeError: Throwable? = null
|
|
33
|
+
) : Exception(message, nativeError) {
|
|
34
|
+
|
|
35
|
+
companion object {
|
|
36
|
+
fun nativeModuleNotFound(platform: String): StoryEditorError {
|
|
37
|
+
return StoryEditorError(
|
|
38
|
+
StoryEditorErrorCodes.NATIVE_MODULE_NOT_FOUND,
|
|
39
|
+
"RnStoryEditor native module not found for platform: $platform. " +
|
|
40
|
+
"Please ensure the library is properly linked. " +
|
|
41
|
+
"Run 'cd android && ./gradlew clean' and rebuild."
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
fun viewManagerNotFound(): StoryEditorError {
|
|
46
|
+
return StoryEditorError(
|
|
47
|
+
StoryEditorErrorCodes.VIEW_MANAGER_NOT_FOUND,
|
|
48
|
+
"RnStoryEditorView native component not found. " +
|
|
49
|
+
"Ensure the app was rebuilt after installing the library. " +
|
|
50
|
+
"Run 'cd android && ./gradlew clean && ./gradlew assembleDebug'"
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
fun invalidBase64(): StoryEditorError {
|
|
55
|
+
return StoryEditorError(
|
|
56
|
+
StoryEditorErrorCodes.INVALID_BASE64,
|
|
57
|
+
"Invalid base64 image data provided. " +
|
|
58
|
+
"Ensure the base64 string is properly formatted " +
|
|
59
|
+
"and includes the data URI prefix (e.g., data:image/png;base64,)"
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
fun invalidColor(color: String): StoryEditorError {
|
|
64
|
+
return StoryEditorError(
|
|
65
|
+
StoryEditorErrorCodes.INVALID_COLOR,
|
|
66
|
+
"Invalid color value: \"$color\". " +
|
|
67
|
+
"Use hex format (#RRGGBB or #RRGGBBAA) or React Native color constants."
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
fun bitmapDecodeFailed(reason: String): StoryEditorError {
|
|
72
|
+
return StoryEditorError(
|
|
73
|
+
StoryEditorErrorCodes.BITMAP_DECODE_FAILED,
|
|
74
|
+
"Failed to decode bitmap: $reason. " +
|
|
75
|
+
"Ensure the image data is valid and not corrupted."
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
fun imageExportFailed(reason: String, cause: Throwable? = null): StoryEditorError {
|
|
80
|
+
return StoryEditorError(
|
|
81
|
+
StoryEditorErrorCodes.IMAGE_EXPORT_FAILED,
|
|
82
|
+
"Failed to export image: $reason. " +
|
|
83
|
+
"Common causes: no content to export, insufficient memory, or invalid base64 data.",
|
|
84
|
+
cause
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
fun fileSaveFailed(reason: String, cause: Throwable? = null): StoryEditorError {
|
|
89
|
+
return StoryEditorError(
|
|
90
|
+
StoryEditorErrorCodes.FILE_SAVE_FAILED,
|
|
91
|
+
"Failed to save image to gallery: $reason. " +
|
|
92
|
+
"Check storage permissions and available space.",
|
|
93
|
+
cause
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
fun memoryError(operation: String, cause: OutOfMemoryError): StoryEditorError {
|
|
98
|
+
return StoryEditorError(
|
|
99
|
+
StoryEditorErrorCodes.MEMORY_ERROR,
|
|
100
|
+
"Out of memory during $operation. " +
|
|
101
|
+
"Try reducing image size or closing other apps.",
|
|
102
|
+
cause
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
fun layerOperationFailed(operation: String, reason: String): StoryEditorError {
|
|
107
|
+
return StoryEditorError(
|
|
108
|
+
StoryEditorErrorCodes.LAYER_OPERATION_FAILED,
|
|
109
|
+
"Failed to $operation layer: $reason. " +
|
|
110
|
+
"Ensure the layer exists and the editor is properly initialized."
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
fun textInputFailed(reason: String): StoryEditorError {
|
|
115
|
+
return StoryEditorError(
|
|
116
|
+
StoryEditorErrorCodes.TEXT_INPUT_FAILED,
|
|
117
|
+
"Text input operation failed: $reason. " +
|
|
118
|
+
"Check that the editor has focus and text layers are enabled."
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
fun unknownError(operation: String, cause: Throwable): StoryEditorError {
|
|
123
|
+
return StoryEditorError(
|
|
124
|
+
StoryEditorErrorCodes.UNKNOWN_ERROR,
|
|
125
|
+
"Unexpected error during $operation: ${cause.message}",
|
|
126
|
+
cause
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Result type for operations that can fail
|
|
134
|
+
*/
|
|
135
|
+
sealed class StoryEditorResult<out T> {
|
|
136
|
+
data class Success<T>(val data: T) : StoryEditorResult<T>()
|
|
137
|
+
data class Error(val error: StoryEditorError) : StoryEditorResult<Nothing>()
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Extension function to handle Result with callbacks
|
|
142
|
+
*/
|
|
143
|
+
inline fun <T> StoryEditorResult<T>.onSuccess(action: (T) -> Unit): StoryEditorResult<T> {
|
|
144
|
+
if (this is StoryEditorResult.Success) action(data)
|
|
145
|
+
return this
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
inline fun <T> StoryEditorResult<T>.onError(action: (StoryEditorError) -> Unit): StoryEditorResult<T> {
|
|
149
|
+
if (this is StoryEditorResult.Error) action(error)
|
|
150
|
+
return this
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Wraps a block in try-catch with proper error conversion
|
|
155
|
+
*/
|
|
156
|
+
inline fun <T> safeStoryEditorCall(
|
|
157
|
+
operation: String,
|
|
158
|
+
block: () -> T
|
|
159
|
+
): StoryEditorResult<T> {
|
|
160
|
+
return try {
|
|
161
|
+
StoryEditorResult.Success(block())
|
|
162
|
+
} catch (e: OutOfMemoryError) {
|
|
163
|
+
StoryEditorResult.Error(StoryEditorError.memoryError(operation, e))
|
|
164
|
+
} catch (e: StoryEditorError) {
|
|
165
|
+
StoryEditorResult.Error(e)
|
|
166
|
+
} catch (e: Exception) {
|
|
167
|
+
StoryEditorResult.Error(StoryEditorError.unknownError(operation, e))
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Error types for React Native Story Editor
|
|
5
|
+
* Provides specific error classes for different failure scenarios
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export class StoryEditorError extends Error {
|
|
9
|
+
constructor(message, code, nativeError) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.code = code;
|
|
12
|
+
this.nativeError = nativeError;
|
|
13
|
+
this.name = 'StoryEditorError';
|
|
14
|
+
Object.setPrototypeOf(this, StoryEditorError.prototype);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export class NativeModuleNotFoundError extends StoryEditorError {
|
|
18
|
+
constructor(platform) {
|
|
19
|
+
super(`RnStoryEditor native module not found for platform: ${platform}. ` + `Please ensure the library is properly linked. ` + `Run 'cd android && ./gradlew clean' and rebuild.`, 'NATIVE_MODULE_NOT_FOUND');
|
|
20
|
+
this.name = 'NativeModuleNotFoundError';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class ViewManagerNotFoundError extends StoryEditorError {
|
|
24
|
+
constructor() {
|
|
25
|
+
super('RnStoryEditorView native component not found. ' + 'Ensure the app was rebuilt after installing the library. ' + 'For iOS: cd ios && pod install. For Android: cd android && ./gradlew clean', 'VIEW_MANAGER_NOT_FOUND');
|
|
26
|
+
this.name = 'ViewManagerNotFoundError';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export class InvalidRefError extends StoryEditorError {
|
|
30
|
+
constructor(operation) {
|
|
31
|
+
super(`Cannot ${operation}: Invalid or null component ref. ` + `Ensure the ref is properly attached to a StoryEditorView component. ` + `Example: <StoryEditorView ref={editorRef} />`, 'INVALID_REF');
|
|
32
|
+
this.name = 'InvalidRefError';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class NodeHandleNotFoundError extends StoryEditorError {
|
|
36
|
+
constructor() {
|
|
37
|
+
super('Could not find node handle for StoryEditorView. ' + 'The component may not be mounted yet. ' + 'Wait for onLayout or use a timeout.', 'NODE_HANDLE_NOT_FOUND');
|
|
38
|
+
this.name = 'NodeHandleNotFoundError';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export class CommandNotSupportedError extends StoryEditorError {
|
|
42
|
+
constructor(command, platform) {
|
|
43
|
+
super(`Command '${command}' is not supported on ${platform}. ` + `This may indicate an outdated native implementation. ` + `Please update to the latest version of react-native-rn-story-editor.`, 'COMMAND_NOT_SUPPORTED');
|
|
44
|
+
this.name = 'CommandNotSupportedError';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export class ImageExportError extends StoryEditorError {
|
|
48
|
+
constructor(reason, nativeError) {
|
|
49
|
+
super(`Failed to export image: ${reason}. ` + `Common causes: no content to export, insufficient memory, or invalid base64 data.`, 'IMAGE_EXPORT_FAILED', nativeError);
|
|
50
|
+
this.name = 'ImageExportError';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export class InvalidBase64Error extends StoryEditorError {
|
|
54
|
+
constructor() {
|
|
55
|
+
super('Invalid base64 image data provided. ' + 'Ensure the base64 string is properly formatted and includes the data URI prefix (e.g., data:image/png;base64,)', 'INVALID_BASE64');
|
|
56
|
+
this.name = 'InvalidBase64Error';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export class InvalidColorError extends StoryEditorError {
|
|
60
|
+
constructor(color) {
|
|
61
|
+
super(`Invalid color value: "${color}". ` + `Use hex format (#RRGGBB or #RRGGBBAA) or React Native color constants.`, 'INVALID_COLOR');
|
|
62
|
+
this.name = 'InvalidColorError';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export class LayerOperationError extends StoryEditorError {
|
|
66
|
+
constructor(operation, reason) {
|
|
67
|
+
super(`Failed to ${operation} layer: ${reason}. ` + `Ensure the layer exists and the editor is properly initialized.`, 'LAYER_OPERATION_FAILED');
|
|
68
|
+
this.name = 'LayerOperationError';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export class TextInputError extends StoryEditorError {
|
|
72
|
+
constructor(reason) {
|
|
73
|
+
super(`Text input operation failed: ${reason}. ` + `Check that the editor has focus and text layers are enabled.`, 'TEXT_INPUT_FAILED');
|
|
74
|
+
this.name = 'TextInputError';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export class PlatformNotSupportedError extends StoryEditorError {
|
|
78
|
+
constructor(platform) {
|
|
79
|
+
super(`Platform '${platform}' is not supported. ` + `This library only supports iOS and Android.`, 'PLATFORM_NOT_SUPPORTED');
|
|
80
|
+
this.name = 'PlatformNotSupportedError';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export class InitializationError extends StoryEditorError {
|
|
84
|
+
constructor(reason) {
|
|
85
|
+
super(`StoryEditor initialization failed: ${reason}. ` + `Try clearing caches: watchman watch-del-all && rm -rf node_modules && npm install`, 'INITIALIZATION_FAILED');
|
|
86
|
+
this.name = 'InitializationError';
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["StoryEditorError","Error","constructor","message","code","nativeError","name","Object","setPrototypeOf","prototype","NativeModuleNotFoundError","platform","ViewManagerNotFoundError","InvalidRefError","operation","NodeHandleNotFoundError","CommandNotSupportedError","command","ImageExportError","reason","InvalidBase64Error","InvalidColorError","color","LayerOperationError","TextInputError","PlatformNotSupportedError","InitializationError"],"sourceRoot":"../../src","sources":["errors.ts"],"mappings":";;AAAA;AACA;AACA;AACA;;AAEA,OAAO,MAAMA,gBAAgB,SAASC,KAAK,CAAC;EAC1CC,WAAWA,CACTC,OAAe,EACRC,IAAY,EACZC,WAAiB,EACxB;IACA,KAAK,CAACF,OAAO,CAAC;IAAC,KAHRC,IAAY,GAAZA,IAAY;IAAA,KACZC,WAAiB,GAAjBA,WAAiB;IAGxB,IAAI,CAACC,IAAI,GAAG,kBAAkB;IAC9BC,MAAM,CAACC,cAAc,CAAC,IAAI,EAAER,gBAAgB,CAACS,SAAS,CAAC;EACzD;AACF;AAEA,OAAO,MAAMC,yBAAyB,SAASV,gBAAgB,CAAC;EAC9DE,WAAWA,CAACS,QAAgB,EAAE;IAC5B,KAAK,CACH,uDAAuDA,QAAQ,IAAI,GACjE,gDAAgD,GAChD,kDAAkD,EACpD,yBACF,CAAC;IACD,IAAI,CAACL,IAAI,GAAG,2BAA2B;EACzC;AACF;AAEA,OAAO,MAAMM,wBAAwB,SAASZ,gBAAgB,CAAC;EAC7DE,WAAWA,CAAA,EAAG;IACZ,KAAK,CACH,gDAAgD,GAC9C,2DAA2D,GAC3D,4EAA4E,EAC9E,wBACF,CAAC;IACD,IAAI,CAACI,IAAI,GAAG,0BAA0B;EACxC;AACF;AAEA,OAAO,MAAMO,eAAe,SAASb,gBAAgB,CAAC;EACpDE,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O,MAAMiB,mBAAmB,SAASvB,gBAAgB,CAAC;EACxDE,WAAWA,CAACY,SAAiB,EAAEK,MAAc,EAAE;IAC7C,KAAK,CACH,aAAaL,SAAS,WAAWK,MAAM,IAAI,GACzC,iEAAiE,EACnE,wBACF,CAAC;IACD,IAAI,CAACb,IAAI,GAAG,qBAAqB;EACnC;AACF;AAEA,OAAO,MAAMkB,cAAc,SAASxB,gBAAgB,CAAC;EACnDE,WAAWA,CAACiB,MAAc,EAAE;IAC1B,KAAK,CACH,gCAAgCA,MAAM,IAAI,GACxC,8DAA8D,EAChE,mBACF,CAAC;IACD,IAAI,CAACb,IAAI,GAAG,gBAAgB;EAC9B;AACF;AAEA,OAAO,MAAMmB,yBAAyB,SAASzB,gBAAgB,CAAC;EAC9DE,WAAWA,CAACS,QAAgB,EAAE;IAC5B,KAAK,CACH,aAAaA,QAAQ,sBAAsB,GACzC,6CAA6C,EAC/C,wBACF,CAAC;IACD,IAAI,CAACL,IAAI,GAAG,2BAA2B;EACzC;AACF;AAEA,OAAO,MAAMoB,mBAAmB,SAAS1B,gBAAgB,CAAC;EACxDE,WAAWA,CAACiB,MAAc,EAAE;IAC1B,KAAK,CACH,sCAAsCA,MAAM,IAAI,GAC9C,mFAAmF,EACrF,uBACF,CAAC;IACD,IAAI,CAACb,IAAI,GAAG,qBAAqB;EACnC;AACF","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,39 +1,199 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { requireNativeComponent, UIManager, findNodeHandle } from 'react-native';
|
|
3
|
+
import { requireNativeComponent, UIManager, findNodeHandle, Platform } from 'react-native';
|
|
4
|
+
import { StoryEditorError, ViewManagerNotFoundError, InvalidRefError, NodeHandleNotFoundError, CommandNotSupportedError, InvalidBase64Error, InvalidColorError, PlatformNotSupportedError } from "./errors.js";
|
|
4
5
|
const COMPONENT_NAME = 'RnStoryEditorView';
|
|
5
6
|
|
|
7
|
+
// Extended native props with event callbacks
|
|
8
|
+
|
|
6
9
|
// Type definition for view manager commands
|
|
7
10
|
|
|
8
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Validates a base64 image string
|
|
13
|
+
* @param base64 - The base64 string to validate
|
|
14
|
+
* @throws InvalidBase64Error if the string is invalid
|
|
15
|
+
*/
|
|
16
|
+
function validateBase64(base64) {
|
|
17
|
+
if (base64 === undefined || base64 === null) {
|
|
18
|
+
return; // Optional prop
|
|
19
|
+
}
|
|
20
|
+
if (typeof base64 !== 'string') {
|
|
21
|
+
throw new InvalidBase64Error();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Check for data URI prefix and remove it for validation
|
|
25
|
+
let cleanBase64 = base64;
|
|
26
|
+
if (base64.includes(',')) {
|
|
27
|
+
const parts = base64.split(',');
|
|
28
|
+
if (parts.length !== 2 || !parts[1]) {
|
|
29
|
+
throw new InvalidBase64Error();
|
|
30
|
+
}
|
|
31
|
+
cleanBase64 = parts[1];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Validate base64 characters
|
|
35
|
+
const base64Regex = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
36
|
+
if (!base64Regex.test(cleanBase64)) {
|
|
37
|
+
throw new InvalidBase64Error();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Validates a color value
|
|
43
|
+
* @param color - The color string to validate
|
|
44
|
+
* @throws InvalidColorError if the color is invalid
|
|
45
|
+
*/
|
|
46
|
+
function validateColor(color) {
|
|
47
|
+
if (color === undefined || color === null) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (typeof color !== 'string') {
|
|
51
|
+
throw new InvalidColorError(String(color));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Hex color validation (#RGB, #RRGGBB, #RRGGBBAA)
|
|
55
|
+
const hexRegex = /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/;
|
|
56
|
+
if (!hexRegex.test(color)) {
|
|
57
|
+
throw new InvalidColorError(color);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Validates platform support
|
|
63
|
+
* @throws PlatformNotSupportedError if platform is not iOS or Android
|
|
64
|
+
*/
|
|
65
|
+
function validatePlatform() {
|
|
66
|
+
if (Platform.OS !== 'ios' && Platform.OS !== 'android') {
|
|
67
|
+
throw new PlatformNotSupportedError(Platform.OS);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Gets view manager configuration with error handling
|
|
73
|
+
* @returns View manager config or throws ViewManagerNotFoundError
|
|
74
|
+
*/
|
|
75
|
+
function getViewManagerConfig() {
|
|
76
|
+
validatePlatform();
|
|
77
|
+
const config = UIManager.getViewManagerConfig(COMPONENT_NAME);
|
|
78
|
+
if (!config) {
|
|
79
|
+
throw new ViewManagerNotFoundError();
|
|
80
|
+
}
|
|
81
|
+
return config;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Gets node handle from component ref with validation
|
|
86
|
+
* @param ref - Component ref
|
|
87
|
+
* @param operation - Operation name for error messages
|
|
88
|
+
* @returns Node handle number
|
|
89
|
+
* @throws InvalidRefError or NodeHandleNotFoundError
|
|
90
|
+
*/
|
|
91
|
+
function getNodeHandle(ref, operation) {
|
|
92
|
+
if (!ref || typeof ref !== 'object') {
|
|
93
|
+
throw new InvalidRefError(operation);
|
|
94
|
+
}
|
|
95
|
+
const nodeHandle = findNodeHandle(ref);
|
|
96
|
+
if (nodeHandle == null) {
|
|
97
|
+
throw new NodeHandleNotFoundError();
|
|
98
|
+
}
|
|
99
|
+
return nodeHandle;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Validates that a command is supported
|
|
104
|
+
* @param _config - View manager config (for future use)
|
|
105
|
+
* @param command - Command name
|
|
106
|
+
* @param commandId - Command ID from config
|
|
107
|
+
* @throws CommandNotSupportedError if command not available
|
|
108
|
+
*/
|
|
109
|
+
function validateCommand(_config, command, commandId) {
|
|
110
|
+
if (commandId === undefined || commandId === null) {
|
|
111
|
+
throw new CommandNotSupportedError(command, Platform.OS);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
9
114
|
|
|
10
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Commands for controlling the StoryEditorView
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* const editorRef = useRef(null);
|
|
120
|
+
*
|
|
121
|
+
* // Export image
|
|
122
|
+
* StoryEditorCommands.exportImage(editorRef.current);
|
|
123
|
+
*
|
|
124
|
+
* // Show text input
|
|
125
|
+
* StoryEditorCommands.showTextInput(editorRef.current);
|
|
126
|
+
*/
|
|
11
127
|
export const StoryEditorCommands = {
|
|
128
|
+
/**
|
|
129
|
+
* Exports the current canvas as a base64 encoded image
|
|
130
|
+
* @param ref - Reference to the StoryEditorView component
|
|
131
|
+
* @throws {InvalidRefError} If ref is invalid
|
|
132
|
+
* @throws {NodeHandleNotFoundError} If component is not mounted
|
|
133
|
+
* @throws {CommandNotSupportedError} If command not supported on platform
|
|
134
|
+
* @throws {ViewManagerNotFoundError} If native module not found
|
|
135
|
+
*/
|
|
12
136
|
exportImage: ref => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
137
|
+
try {
|
|
138
|
+
const viewManagerConfig = getViewManagerConfig();
|
|
139
|
+
const commandId = viewManagerConfig.Commands?.exportImage;
|
|
140
|
+
validateCommand(viewManagerConfig, 'exportImage', commandId);
|
|
141
|
+
const nodeHandle = getNodeHandle(ref, 'export image');
|
|
142
|
+
UIManager.dispatchViewManagerCommand(nodeHandle, commandId, []);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
if (error instanceof StoryEditorError) {
|
|
145
|
+
throw error;
|
|
18
146
|
}
|
|
147
|
+
throw new StoryEditorError(`Unexpected error during exportImage: ${error}`, 'UNKNOWN_ERROR', error);
|
|
19
148
|
}
|
|
20
149
|
},
|
|
150
|
+
/**
|
|
151
|
+
* Shows the text input overlay for adding text layers
|
|
152
|
+
* @param ref - Reference to the StoryEditorView component
|
|
153
|
+
* @throws {InvalidRefError} If ref is invalid
|
|
154
|
+
* @throws {NodeHandleNotFoundError} If component is not mounted
|
|
155
|
+
* @throws {CommandNotSupportedError} If command not supported on platform
|
|
156
|
+
* @throws {ViewManagerNotFoundError} If native module not found
|
|
157
|
+
*/
|
|
21
158
|
showTextInput: ref => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
159
|
+
try {
|
|
160
|
+
const viewManagerConfig = getViewManagerConfig();
|
|
161
|
+
const commandId = viewManagerConfig.Commands?.showTextInput;
|
|
162
|
+
validateCommand(viewManagerConfig, 'showTextInput', commandId);
|
|
163
|
+
const nodeHandle = getNodeHandle(ref, 'show text input');
|
|
164
|
+
UIManager.dispatchViewManagerCommand(nodeHandle, commandId, []);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
if (error instanceof StoryEditorError) {
|
|
167
|
+
throw error;
|
|
27
168
|
}
|
|
169
|
+
throw new StoryEditorError(`Unexpected error during showTextInput: ${error}`, 'UNKNOWN_ERROR', error);
|
|
28
170
|
}
|
|
29
171
|
}
|
|
30
172
|
};
|
|
31
173
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
174
|
+
/**
|
|
175
|
+
* Validates props before passing to native component
|
|
176
|
+
* @param props - Props to validate
|
|
177
|
+
* @throws {InvalidColorError} If color is invalid
|
|
178
|
+
* @throws {InvalidBase64Error} If base64 image data is invalid
|
|
179
|
+
*/
|
|
180
|
+
export function validateProps(props) {
|
|
181
|
+
if (props.colorString) {
|
|
182
|
+
validateColor(props.colorString);
|
|
183
|
+
}
|
|
184
|
+
if (props.baseImage) {
|
|
185
|
+
validateBase64(props.baseImage);
|
|
186
|
+
}
|
|
187
|
+
if (props.addImage) {
|
|
188
|
+
validateBase64(props.addImage);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
37
191
|
|
|
38
|
-
//
|
|
192
|
+
// Re-export error types
|
|
193
|
+
export { StoryEditorError, NativeModuleNotFoundError, ViewManagerNotFoundError, InvalidRefError, NodeHandleNotFoundError, CommandNotSupportedError, ImageExportError, InvalidBase64Error, InvalidColorError, LayerOperationError, TextInputError, PlatformNotSupportedError, InitializationError } from "./errors.js";
|
|
194
|
+
|
|
195
|
+
// Export types
|
|
196
|
+
|
|
197
|
+
// Export the native view component
|
|
198
|
+
export const StoryEditorView = requireNativeComponent(COMPONENT_NAME);
|
|
39
199
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["requireNativeComponent","UIManager","findNodeHandle","COMPONENT_NAME","
|
|
1
|
+
{"version":3,"names":["requireNativeComponent","UIManager","findNodeHandle","Platform","StoryEditorError","ViewManagerNotFoundError","InvalidRefError","NodeHandleNotFoundError","CommandNotSupportedError","InvalidBase64Error","InvalidColorError","PlatformNotSupportedError","COMPONENT_NAME","validateBase64","base64","undefined","cleanBase64","includes","parts","split","length","base64Regex","test","validateColor","color","String","hexRegex","validatePlatform","OS","getViewManagerConfig","config","getNodeHandle","ref","operation","nodeHandle","validateCommand","_config","command","commandId","StoryEditorCommands","exportImage","viewManagerConfig","Commands","dispatchViewManagerCommand","error","showTextInput","validateProps","props","colorString","baseImage","addImage","NativeModuleNotFoundError","ImageExportError","LayerOperationError","TextInputError","InitializationError","StoryEditorView"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SACEA,sBAAsB,EACtBC,SAAS,EACTC,cAAc,EACdC,QAAQ,QACH,cAAc;AAErB,SACEC,gBAAgB,EAChBC,wBAAwB,EACxBC,eAAe,EACfC,uBAAuB,EACvBC,wBAAwB,EACxBC,kBAAkB,EAClBC,iBAAiB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KAA2B,EAAQ;EAC/D,IAAIA,KAAK,CAACC,WAAW,EAAE;IACrBzB,aAAa,CAACwB,KAAK,CAACC,WAAW,CAAC;EAClC;EACA,IAAID,KAAK,CAACE,SAAS,EAAE;IACnBpC,cAAc,CAACkC,KAAK,CAACE,SAAS,CAAC;EACjC;EACA,IAAIF,KAAK,CAACG,QAAQ,EAAE;IAClBrC,cAAc,CAACkC,KAAK,CAACG,QAAQ,CAAC;EAChC;AACF;;AAEA;AACA,SACE9C,gBAAgB,EAChB+C,yBAAyB,EACzB9C,wBAAwB,EACxBC,eAAe,EACfC,uBAAuB,EACvBC,wBAAwB,EACxB4C,gBAAgB,EAChB3C,kBAAkB,EAClBC,iBAAiB,EACjB2C,mBAAmB,EACnBC,cAAc,EACd3C,yBAAyB,EACzB4C,mBAAmB,QACd,aAAU;;AAEjB;;AAGA;AACA,OAAO,MAAMC,eAAe,GAC1BxD,sBAAsB,CAAcY,cAAc,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error types for React Native Story Editor
|
|
3
|
+
* Provides specific error classes for different failure scenarios
|
|
4
|
+
*/
|
|
5
|
+
export declare class StoryEditorError extends Error {
|
|
6
|
+
code: string;
|
|
7
|
+
nativeError?: any | undefined;
|
|
8
|
+
constructor(message: string, code: string, nativeError?: any | undefined);
|
|
9
|
+
}
|
|
10
|
+
export declare class NativeModuleNotFoundError extends StoryEditorError {
|
|
11
|
+
constructor(platform: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class ViewManagerNotFoundError extends StoryEditorError {
|
|
14
|
+
constructor();
|
|
15
|
+
}
|
|
16
|
+
export declare class InvalidRefError extends StoryEditorError {
|
|
17
|
+
constructor(operation: string);
|
|
18
|
+
}
|
|
19
|
+
export declare class NodeHandleNotFoundError extends StoryEditorError {
|
|
20
|
+
constructor();
|
|
21
|
+
}
|
|
22
|
+
export declare class CommandNotSupportedError extends StoryEditorError {
|
|
23
|
+
constructor(command: string, platform: string);
|
|
24
|
+
}
|
|
25
|
+
export declare class ImageExportError extends StoryEditorError {
|
|
26
|
+
constructor(reason: string, nativeError?: any);
|
|
27
|
+
}
|
|
28
|
+
export declare class InvalidBase64Error extends StoryEditorError {
|
|
29
|
+
constructor();
|
|
30
|
+
}
|
|
31
|
+
export declare class InvalidColorError extends StoryEditorError {
|
|
32
|
+
constructor(color: string);
|
|
33
|
+
}
|
|
34
|
+
export declare class LayerOperationError extends StoryEditorError {
|
|
35
|
+
constructor(operation: string, reason: string);
|
|
36
|
+
}
|
|
37
|
+
export declare class TextInputError extends StoryEditorError {
|
|
38
|
+
constructor(reason: string);
|
|
39
|
+
}
|
|
40
|
+
export declare class PlatformNotSupportedError extends StoryEditorError {
|
|
41
|
+
constructor(platform: string);
|
|
42
|
+
}
|
|
43
|
+
export declare class InitializationError extends StoryEditorError {
|
|
44
|
+
constructor(reason: string);
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,qBAAa,gBAAiB,SAAQ,KAAK;IAGhC,IAAI,EAAE,MAAM;IACZ,WAAW,CAAC,EAAE,GAAG;gBAFxB,OAAO,EAAE,MAAM,EACR,IAAI,EAAE,MAAM,EACZ,WAAW,CAAC,EAAE,GAAG,YAAA;CAM3B;AAED,qBAAa,yBAA0B,SAAQ,gBAAgB;gBACjD,QAAQ,EAAE,MAAM;CAS7B;AAED,qBAAa,wBAAyB,SAAQ,gBAAgB;;CAU7D;AAED,qBAAa,eAAgB,SAAQ,gBAAgB;gBACvC,SAAS,EAAE,MAAM;CAS9B;AAED,qBAAa,uBAAwB,SAAQ,gBAAgB;;CAU5D;AAED,qBAAa,wBAAyB,SAAQ,gBAAgB;gBAChD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAS9C;AAED,qBAAa,gBAAiB,SAAQ,gBAAgB;gBACxC,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,GAAG;CAS9C;AAED,qBAAa,kBAAmB,SAAQ,gBAAgB;;CASvD;AAED,qBAAa,iBAAkB,SAAQ,gBAAgB;gBACzC,KAAK,EAAE,MAAM;CAQ1B;AAED,qBAAa,mBAAoB,SAAQ,gBAAgB;gBAC3C,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAQ9C;AAED,qBAAa,cAAe,SAAQ,gBAAgB;gBACtC,MAAM,EAAE,MAAM;CAQ3B;AAED,qBAAa,yBAA0B,SAAQ,gBAAgB;gBACjD,QAAQ,EAAE,MAAM;CAQ7B;AAED,qBAAa,mBAAoB,SAAQ,gBAAgB;gBAC3C,MAAM,EAAE,MAAM;CAQ3B"}
|
|
@@ -1,9 +1,58 @@
|
|
|
1
|
-
import type { NativeProps } from './RnStoryEditorViewNativeComponent';
|
|
2
|
-
export
|
|
1
|
+
import type { NativeProps as BaseNativeProps } from './RnStoryEditorViewNativeComponent';
|
|
2
|
+
export interface NativeProps extends BaseNativeProps {
|
|
3
|
+
onExportImage?: (event: {
|
|
4
|
+
nativeEvent: {
|
|
5
|
+
base64: string;
|
|
6
|
+
error?: string;
|
|
7
|
+
};
|
|
8
|
+
}) => void;
|
|
9
|
+
onError?: (event: {
|
|
10
|
+
nativeEvent: {
|
|
11
|
+
code: string;
|
|
12
|
+
message: string;
|
|
13
|
+
};
|
|
14
|
+
}) => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Commands for controlling the StoryEditorView
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const editorRef = useRef(null);
|
|
21
|
+
*
|
|
22
|
+
* // Export image
|
|
23
|
+
* StoryEditorCommands.exportImage(editorRef.current);
|
|
24
|
+
*
|
|
25
|
+
* // Show text input
|
|
26
|
+
* StoryEditorCommands.showTextInput(editorRef.current);
|
|
27
|
+
*/
|
|
3
28
|
export declare const StoryEditorCommands: {
|
|
29
|
+
/**
|
|
30
|
+
* Exports the current canvas as a base64 encoded image
|
|
31
|
+
* @param ref - Reference to the StoryEditorView component
|
|
32
|
+
* @throws {InvalidRefError} If ref is invalid
|
|
33
|
+
* @throws {NodeHandleNotFoundError} If component is not mounted
|
|
34
|
+
* @throws {CommandNotSupportedError} If command not supported on platform
|
|
35
|
+
* @throws {ViewManagerNotFoundError} If native module not found
|
|
36
|
+
*/
|
|
4
37
|
exportImage: (ref: any) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Shows the text input overlay for adding text layers
|
|
40
|
+
* @param ref - Reference to the StoryEditorView component
|
|
41
|
+
* @throws {InvalidRefError} If ref is invalid
|
|
42
|
+
* @throws {NodeHandleNotFoundError} If component is not mounted
|
|
43
|
+
* @throws {CommandNotSupportedError} If command not supported on platform
|
|
44
|
+
* @throws {ViewManagerNotFoundError} If native module not found
|
|
45
|
+
*/
|
|
5
46
|
showTextInput: (ref: any) => void;
|
|
6
47
|
};
|
|
7
|
-
|
|
8
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Validates props before passing to native component
|
|
50
|
+
* @param props - Props to validate
|
|
51
|
+
* @throws {InvalidColorError} If color is invalid
|
|
52
|
+
* @throws {InvalidBase64Error} If base64 image data is invalid
|
|
53
|
+
*/
|
|
54
|
+
export declare function validateProps(props: Partial<NativeProps>): void;
|
|
55
|
+
export { StoryEditorError, NativeModuleNotFoundError, ViewManagerNotFoundError, InvalidRefError, NodeHandleNotFoundError, CommandNotSupportedError, ImageExportError, InvalidBase64Error, InvalidColorError, LayerOperationError, TextInputError, PlatformNotSupportedError, InitializationError, } from './errors';
|
|
56
|
+
export type { NativeProps as StoryEditorProps };
|
|
57
|
+
export declare const StoryEditorView: import("react-native").HostComponent<NativeProps>;
|
|
9
58
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,IAAI,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAezF,MAAM,WAAW,WAAY,SAAQ,eAAe;IAClD,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE;QACtB,WAAW,EAAE;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;KACjD,KAAK,IAAI,CAAC;IACX,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,KAAK,IAAI,CAAC;CAC/E;AAkID;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB;IAC9B;;;;;;;OAOG;uBACgB,GAAG,KAAG,IAAI;IAsB7B;;;;;;;OAOG;yBACkB,GAAG,KAAG,IAAI;CAqBhC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI,CAU/D;AAGD,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,wBAAwB,EACxB,eAAe,EACf,uBAAuB,EACvB,wBAAwB,EACxB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,UAAU,CAAC;AAGlB,YAAY,EAAE,WAAW,IAAI,gBAAgB,EAAE,CAAC;AAGhD,eAAO,MAAM,eAAe,mDACyB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-rn-story-editor",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "A React Native story editor with layers, drag-drop, text/image overlays, and export functionality",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|