paint_box_react_native 0.1.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 (82) hide show
  1. package/LICENSE +20 -0
  2. package/PaintBoxReactNative.podspec +20 -0
  3. package/README.md +161 -0
  4. package/android/build.gradle +70 -0
  5. package/android/gradle.properties +45 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/com/paintboxreactnative/NativeViewHandler.kt +26 -0
  8. package/android/src/main/java/com/paintboxreactnative/PaintBoxNativeView.kt +61 -0
  9. package/android/src/main/java/com/paintboxreactnative/PaintBoxNativeViewManager.kt +105 -0
  10. package/android/src/main/java/com/paintboxreactnative/PaintBoxReactNativeModule.kt +74 -0
  11. package/android/src/main/java/com/paintboxreactnative/PaintBoxReactNativePackage.kt +41 -0
  12. package/android/src/main/java/com/paintboxreactnative/dto/ColorDTO.kt +37 -0
  13. package/ios/PaintBoxReactNative.h +5 -0
  14. package/ios/PaintBoxReactNative.mm +21 -0
  15. package/lib/module/IPaintEditor.js +7 -0
  16. package/lib/module/IPaintEditor.js.map +1 -0
  17. package/lib/module/NativePaintBoxReactNative.js +5 -0
  18. package/lib/module/NativePaintBoxReactNative.js.map +1 -0
  19. package/lib/module/PaintBoxContext.js +50 -0
  20. package/lib/module/PaintBoxContext.js.map +1 -0
  21. package/lib/module/PaintBoxRNView.js +90 -0
  22. package/lib/module/PaintBoxRNView.js.map +1 -0
  23. package/lib/module/PaintBoxViewNativeComponent.ts +63 -0
  24. package/lib/module/PaintEditor.js +121 -0
  25. package/lib/module/PaintEditor.js.map +1 -0
  26. package/lib/module/dto/BaseDTO.js +8 -0
  27. package/lib/module/dto/BaseDTO.js.map +1 -0
  28. package/lib/module/dto/ColorDTO.js +33 -0
  29. package/lib/module/dto/ColorDTO.js.map +1 -0
  30. package/lib/module/index.js +6 -0
  31. package/lib/module/index.js.map +2 -0
  32. package/lib/module/model/Color.js +12 -0
  33. package/lib/module/model/Color.js.map +1 -0
  34. package/lib/module/model/MimeType.js +12 -0
  35. package/lib/module/model/MimeType.js.map +1 -0
  36. package/lib/module/model/PaintMode.js +11 -0
  37. package/lib/module/model/PaintMode.js.map +1 -0
  38. package/lib/module/model/index.js +6 -0
  39. package/lib/module/model/index.js.map +1 -0
  40. package/lib/module/package.json +1 -0
  41. package/lib/typescript/package.json +1 -0
  42. package/lib/typescript/src/IPaintEditor.d.ts +18 -0
  43. package/lib/typescript/src/IPaintEditor.d.ts.map +1 -0
  44. package/lib/typescript/src/NativePaintBoxReactNative.d.ts +11 -0
  45. package/lib/typescript/src/NativePaintBoxReactNative.d.ts.map +1 -0
  46. package/lib/typescript/src/PaintBoxContext.d.ts +18 -0
  47. package/lib/typescript/src/PaintBoxContext.d.ts.map +1 -0
  48. package/lib/typescript/src/PaintBoxRNView.d.ts +11 -0
  49. package/lib/typescript/src/PaintBoxRNView.d.ts.map +1 -0
  50. package/lib/typescript/src/PaintBoxViewNativeComponent.d.ts +24 -0
  51. package/lib/typescript/src/PaintBoxViewNativeComponent.d.ts.map +1 -0
  52. package/lib/typescript/src/PaintEditor.d.ts +22 -0
  53. package/lib/typescript/src/PaintEditor.d.ts.map +1 -0
  54. package/lib/typescript/src/dto/BaseDTO.d.ts +5 -0
  55. package/lib/typescript/src/dto/BaseDTO.d.ts.map +1 -0
  56. package/lib/typescript/src/dto/ColorDTO.d.ts +19 -0
  57. package/lib/typescript/src/dto/ColorDTO.d.ts.map +1 -0
  58. package/lib/typescript/src/index.d.ts +5 -0
  59. package/lib/typescript/src/index.d.ts.map +1 -0
  60. package/lib/typescript/src/model/Color.d.ts +8 -0
  61. package/lib/typescript/src/model/Color.d.ts.map +1 -0
  62. package/lib/typescript/src/model/MimeType.d.ts +9 -0
  63. package/lib/typescript/src/model/MimeType.d.ts.map +1 -0
  64. package/lib/typescript/src/model/PaintMode.d.ts +8 -0
  65. package/lib/typescript/src/model/PaintMode.d.ts.map +1 -0
  66. package/lib/typescript/src/model/index.d.ts +4 -0
  67. package/lib/typescript/src/model/index.d.ts.map +1 -0
  68. package/package.json +175 -0
  69. package/src/IPaintEditor.ts +32 -0
  70. package/src/NativePaintBoxReactNative.ts +20 -0
  71. package/src/PaintBoxContext.ts +67 -0
  72. package/src/PaintBoxRNView.tsx +98 -0
  73. package/src/PaintBoxViewNativeComponent.ts +63 -0
  74. package/src/PaintEditor.ts +152 -0
  75. package/src/dto/BaseDTO.ts +7 -0
  76. package/src/dto/ColorDTO.ts +44 -0
  77. package/src/index.ts +5 -0
  78. package/src/index.tsx +3 -0
  79. package/src/model/Color.ts +13 -0
  80. package/src/model/MimeType.ts +8 -0
  81. package/src/model/PaintMode.ts +7 -0
  82. package/src/model/index.ts +3 -0
@@ -0,0 +1,152 @@
1
+ import { IPaintEditor } from './IPaintEditor';
2
+ import { PaintBoxContext } from './PaintBoxContext';
3
+ import { Commands, type PaintBoxRef } from './PaintBoxViewNativeComponent';
4
+ import { Color, MimeType, PaintMode } from './model';
5
+ import { ColorDTO } from './dto/ColorDTO';
6
+ import NativePaintBoxReactNative from './NativePaintBoxReactNative';
7
+ import { findNodeHandle } from 'react-native';
8
+ import React from 'react';
9
+
10
+ export class PaintEditor implements IPaintEditor {
11
+ id: string | undefined;
12
+
13
+ _ref(): React.RefObject<PaintBoxRef> | null | undefined {
14
+ return PaintBoxContext.getInstance().getRef(this) as
15
+ | React.RefObject<PaintBoxRef>
16
+ | null
17
+ | undefined;
18
+ }
19
+
20
+ undo() {
21
+ const refObj = this._ref();
22
+ if (refObj?.current) {
23
+ Commands.undo(refObj.current);
24
+ }
25
+ }
26
+
27
+ redo() {
28
+ const refObj = this._ref();
29
+ if (refObj?.current) {
30
+ Commands.redo(refObj.current);
31
+ }
32
+ }
33
+
34
+ reset() {
35
+ const refObj = this._ref();
36
+ if (refObj?.current) {
37
+ Commands.reset(refObj.current);
38
+ }
39
+ }
40
+
41
+ import(path: string, width?: number, height?: number) {
42
+ const refObj = this._ref();
43
+ if (refObj?.current) {
44
+ Commands.importImage(refObj?.current, path, width ?? -1, height ?? -1);
45
+ }
46
+ }
47
+
48
+ export(path: string, fileName: string, mimeType: MimeType): void {
49
+ const refObj = this._ref();
50
+ if (refObj?.current) {
51
+ const viewTag = findNodeHandle(refObj.current);
52
+
53
+ // @ts-ignore
54
+ NativePaintBoxReactNative.export(viewTag, path, fileName, mimeType);
55
+ } else {
56
+ throw new Error(
57
+ 'Reference not found! Please ensure that the paint box has been created.'
58
+ );
59
+ }
60
+ }
61
+
62
+ isEnable(): Promise<boolean> {
63
+ const refObj = this._ref();
64
+ if (refObj?.current) {
65
+ const viewTag = findNodeHandle(refObj.current);
66
+ // @ts-ignore
67
+ return NativePaintBoxReactNative.isEnable(viewTag);
68
+ } else {
69
+ throw new Error(
70
+ 'Reference not found! Please ensure that the paint box has been created.'
71
+ );
72
+ }
73
+ }
74
+
75
+ setEnable(value: boolean) {
76
+ const refObj = this._ref();
77
+ if (refObj?.current) {
78
+ Commands.setEnable(refObj?.current, value);
79
+ }
80
+ }
81
+
82
+ setPaintMode(paintMode: PaintMode) {
83
+ const refObj = this._ref();
84
+ if (refObj?.current) {
85
+ Commands.setPaintMode(refObj?.current, paintMode);
86
+ }
87
+ }
88
+
89
+ async getPaintMode(): Promise<PaintMode> {
90
+ const refObj = this._ref();
91
+ if (refObj?.current) {
92
+ const viewTag = findNodeHandle(refObj.current);
93
+ // @ts-ignore
94
+ const response = await NativePaintBoxReactNative.getPaintMode(viewTag);
95
+ const paintMode = Object.values(PaintMode).find((it) => it === response);
96
+ if (paintMode) {
97
+ return Promise.resolve(paintMode);
98
+ } else {
99
+ return Promise.reject(undefined);
100
+ }
101
+ } else {
102
+ throw new Error(
103
+ 'Reference not found! Please ensure that the paint box has been created.'
104
+ );
105
+ }
106
+ }
107
+
108
+ setStrokeColor(strokeColor: Color) {
109
+ const refObj = this._ref();
110
+ console.log("heree:", JSON.stringify(ColorDTO.fromDataModel(strokeColor).toJSON()));
111
+ if (refObj?.current) {
112
+ Commands.setStrokeColor(
113
+ refObj?.current,
114
+ JSON.stringify(ColorDTO.fromDataModel(strokeColor).toJSON())
115
+ );
116
+ }
117
+ }
118
+
119
+ async getStrokeColor(): Promise<Color> {
120
+ const refObj = this._ref();
121
+ if (refObj?.current) {
122
+ const viewTag = findNodeHandle(refObj.current);
123
+ // @ts-ignore
124
+ const response = await NativePaintBoxReactNative.getStrokeColor(viewTag);
125
+ return Promise.resolve(ColorDTO.fromJSON(response).toDataModel());
126
+ } else {
127
+ throw new Error(
128
+ 'Reference not found! Please ensure that the paint box has been created.'
129
+ );
130
+ }
131
+ }
132
+
133
+ setStrokeSize(size: number) {
134
+ const refObj = this._ref();
135
+ if (refObj?.current) {
136
+ Commands.setStrokeSize(refObj?.current, size);
137
+ }
138
+ }
139
+
140
+ getStrokeSize(): Promise<number> {
141
+ const refObj = this._ref();
142
+ if (refObj?.current) {
143
+ const viewTag = findNodeHandle(refObj.current);
144
+ // @ts-ignore
145
+ return NativePaintBoxReactNative.getStrokeSize(viewTag);
146
+ } else {
147
+ throw new Error(
148
+ 'Reference not found! Please ensure that the paint box has been created.'
149
+ );
150
+ }
151
+ }
152
+ }
@@ -0,0 +1,7 @@
1
+ export abstract class BaseDTO {
2
+ abstract toJSON(): void;
3
+
4
+ toJSONString() {
5
+ return JSON.stringify(this.toJSON());
6
+ }
7
+ }
@@ -0,0 +1,44 @@
1
+ import { BaseDTO } from './BaseDTO';
2
+ import { Color } from '../model';
3
+
4
+ export class ColorDTO extends BaseDTO {
5
+ red: number;
6
+ green: number;
7
+ blue: number;
8
+ alpha?: number = 255.0;
9
+
10
+ constructor(red: number, green: number, blue: number, alpha?: number) {
11
+ super();
12
+ this.red = red;
13
+ this.green = green;
14
+ this.blue = blue;
15
+ this.alpha = alpha;
16
+ }
17
+
18
+ static fromDataModel(color: Color) {
19
+ return new ColorDTO(color.red, color.green, color.blue, color.alpha);
20
+ }
21
+
22
+ static fromJSON(json: string) {
23
+ const parsedJson = JSON.parse(json);
24
+ return new ColorDTO(
25
+ parsedJson.red,
26
+ parsedJson.green,
27
+ parsedJson.blue,
28
+ parsedJson.alpha
29
+ );
30
+ }
31
+
32
+ toDataModel(): Color {
33
+ return new Color(this.red, this.green, this.blue, this.alpha);
34
+ }
35
+
36
+ toJSON() {
37
+ return {
38
+ red: this.red,
39
+ green: this.green,
40
+ blue: this.blue,
41
+ alpha: this.alpha,
42
+ };
43
+ }
44
+ }
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export { PaintEditor } from './PaintEditor';
2
+ export { PaintBoxRNView } from './PaintBoxRNView';
3
+ //export { Commands } from './PaintBoxViewNativeComponent';
4
+ export { default as PaintBoxView } from './PaintBoxViewNativeComponent';
5
+ export { type PaintBoxRef } from './PaintBoxViewNativeComponent';
package/src/index.tsx ADDED
@@ -0,0 +1,3 @@
1
+ // export { PaintBoxRNView } from './PaintBoxRNView';
2
+ // export { default as PaintBoxView } from './PaintBoxViewNativeComponent';
3
+ // //
@@ -0,0 +1,13 @@
1
+ export class Color {
2
+ red: number;
3
+ green: number;
4
+ blue: number;
5
+ alpha?: number = 255.0;
6
+
7
+ constructor(red: number, green: number, blue: number, alpha?: number) {
8
+ this.red = red;
9
+ this.green = green;
10
+ this.blue = blue;
11
+ this.alpha = alpha ?? 255.0;
12
+ }
13
+ }
@@ -0,0 +1,8 @@
1
+ export enum MimeType {
2
+ jpeg = 'jpeg',
3
+ png = 'png',
4
+ gif = 'gif',
5
+ tif = 'tif',
6
+ bmp = 'bmp',
7
+ pdf = 'pdf',
8
+ }
@@ -0,0 +1,7 @@
1
+ export enum PaintMode {
2
+ PEN = 'PEN',
3
+ MARKER = 'MARKER',
4
+ BUCKET = 'BUCKET',
5
+ BRUSH = 'BRUSH',
6
+ ERASER = 'ERASER',
7
+ }
@@ -0,0 +1,3 @@
1
+ export { Color } from './Color';
2
+ export { PaintMode } from './PaintMode';
3
+ export { MimeType } from './MimeType';