@bigbinary/neeto-image-uploader-frontend 1.4.2 → 1.4.4
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 +36 -21
- package/dist/index.cjs.js +2019 -929
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +2020 -931
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/types.d.ts +23 -2
package/README.md
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
- [Components](#components)
|
|
12
12
|
- [1. AssetLibrary](#1-assetlibrary)
|
|
13
13
|
- [2. ImageUploader](#2-imageuploader)
|
|
14
|
+
- [Hooks](#hooks)
|
|
15
|
+
- [1. useImageUpload](#1-useimageuploader)
|
|
14
16
|
- [Development instructions](#development-instructions)
|
|
15
17
|
- [Engine development](#engine-development)
|
|
16
18
|
- [Frontend package development](#frontend-package-development)
|
|
@@ -35,27 +37,19 @@
|
|
|
35
37
|
end
|
|
36
38
|
```
|
|
37
39
|
|
|
38
|
-
2.
|
|
39
|
-
|
|
40
|
-
```ruby
|
|
41
|
-
gem "imagekitio"
|
|
42
|
-
|
|
43
|
-
gem "httparty"
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
3. Run the following command to install the engine:
|
|
40
|
+
2. Run the following command to install the engine:
|
|
47
41
|
|
|
48
42
|
```shell
|
|
49
43
|
bundle install
|
|
50
44
|
```
|
|
51
45
|
|
|
52
|
-
|
|
46
|
+
3. Add the following line to your application's `config/routes.rb`:
|
|
53
47
|
|
|
54
48
|
```ruby
|
|
55
49
|
mount NeetoImageUploaderEngine::Engine => "/neeto_image_uploader_engine"
|
|
56
50
|
```
|
|
57
51
|
|
|
58
|
-
|
|
52
|
+
4. Add the following keys to environment variables (all 6 keys are required):
|
|
59
53
|
|
|
60
54
|
```zsh
|
|
61
55
|
IMAGE_KIT_PUBLIC_KEY
|
|
@@ -66,7 +60,7 @@
|
|
|
66
60
|
UNSPLASH_ACCESS_KEY #(for fetching images from unsplash)
|
|
67
61
|
```
|
|
68
62
|
|
|
69
|
-
|
|
63
|
+
5. Add the following lines to `secrets.yml`:
|
|
70
64
|
|
|
71
65
|
```yml
|
|
72
66
|
image_kit_public_key: <%= ENV["IMAGE_KIT_PUBLIC_KEY"] %>
|
|
@@ -76,7 +70,7 @@
|
|
|
76
70
|
unsplash_access_key: <%= ENV["UNSPLASH_ACCESS_KEY"] %>
|
|
77
71
|
```
|
|
78
72
|
|
|
79
|
-
|
|
73
|
+
6. Add the folowing linse in `application_helper.rb` inside `app/helpers` folder:
|
|
80
74
|
|
|
81
75
|
```ruby
|
|
82
76
|
module ApplicationHelper
|
|
@@ -91,19 +85,12 @@
|
|
|
91
85
|
}
|
|
92
86
|
}
|
|
93
87
|
|
|
94
|
-
global_props.deep_merge!(
|
|
95
|
-
{
|
|
96
|
-
organization: {
|
|
97
|
-
subdomain: @organization.subdomain
|
|
98
|
-
}
|
|
99
|
-
}) # only required if organization subdomain information is not present in globalProps
|
|
100
|
-
|
|
101
88
|
global_props.deep_merge!(image_kit_props)
|
|
102
89
|
end
|
|
103
90
|
end
|
|
104
91
|
```
|
|
105
92
|
|
|
106
|
-
|
|
93
|
+
7. Add the following file `imagekitio.rb` inside `config/initializers`
|
|
107
94
|
|
|
108
95
|
```ruby
|
|
109
96
|
# frozen_string_literal: true
|
|
@@ -139,6 +126,34 @@ The frontend exports two components `AssetLibrary` and `ImageUploader`.
|
|
|
139
126
|
<img src="https://github.com/bigbinary/neeto-editor/assets/70290286/d293d887-38fd-4e55-a53d-dd591a52f053" alt="Image Uploader"/>
|
|
140
127
|
</div>
|
|
141
128
|
|
|
129
|
+
# Hooks
|
|
130
|
+
|
|
131
|
+
## 1. useImageUpload
|
|
132
|
+
|
|
133
|
+
The `useImageUpload` hook is a React custom hook that simplifies the process of uploading images in your application. It handles both development and production scenarios, tracks upload progress, and provides a clean interface for image uploading.
|
|
134
|
+
|
|
135
|
+
### Import the hook
|
|
136
|
+
|
|
137
|
+
```jsx
|
|
138
|
+
import { useImageUpload } from "@bigbinary/neeto-image-uploader-frontend";
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Invoke the hook
|
|
142
|
+
|
|
143
|
+
```jsx
|
|
144
|
+
const { uploadImage, uploadProgress, uploadedImage } = useImageUpload();
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Call uploadImage to Upload an Image
|
|
148
|
+
|
|
149
|
+
```jsx
|
|
150
|
+
const handleImageUpload = async (file) => {
|
|
151
|
+
uploadImage(file, (uploadedImageData) => {
|
|
152
|
+
// Handle the uploaded image data
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
```
|
|
156
|
+
|
|
142
157
|
# Development instructions
|
|
143
158
|
|
|
144
159
|
## Engine development
|