@pixelvault-dev/paste-react 0.1.0 → 0.1.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/README.md +9 -3
- package/dist/index.d.ts +13 -4
- package/dist/index.js +17 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,14 +9,20 @@ import { usePaste } from "@pixelvault-dev/paste-react";
|
|
|
9
9
|
|
|
10
10
|
function Editor() {
|
|
11
11
|
const ref = useRef<HTMLTextAreaElement>(null);
|
|
12
|
-
usePaste(ref, { publishableKey: "pv_pub_xxxxxxxx" });
|
|
13
|
-
return
|
|
12
|
+
const { openFilePicker } = usePaste(ref, { publishableKey: "pv_pub_xxxxxxxx" });
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
<textarea ref={ref} />
|
|
16
|
+
<button onClick={openFilePicker}>Upload image</button>
|
|
17
|
+
</>
|
|
18
|
+
);
|
|
14
19
|
}
|
|
15
20
|
```
|
|
16
21
|
|
|
17
22
|
`usePaste(ref, options)` attaches on mount and detaches on unmount. It
|
|
18
23
|
re-attaches if any option changes, so memoize callback options (`useCallback`)
|
|
19
|
-
to avoid needless re-attaching.
|
|
24
|
+
to avoid needless re-attaching. It returns `{ openFilePicker }` — call it (e.g.
|
|
25
|
+
from a button) to open the OS file dialog and insert the chosen image(s).
|
|
20
26
|
|
|
21
27
|
See [`@pixelvault-dev/paste`](../paste) for the full `PasteOptions` reference. Get a
|
|
22
28
|
publishable key (`pv_pub_…`) in the PixelVault dashboard.
|
package/dist/index.d.ts
CHANGED
|
@@ -6,13 +6,22 @@ import { type PasteOptions, type PasteTarget } from "@pixelvault-dev/paste";
|
|
|
6
6
|
*
|
|
7
7
|
* ```tsx
|
|
8
8
|
* const ref = useRef<HTMLTextAreaElement>(null);
|
|
9
|
-
* usePaste(ref, { publishableKey: "pv_pub_…" });
|
|
10
|
-
* return
|
|
9
|
+
* const { openFilePicker } = usePaste(ref, { publishableKey: "pv_pub_…" });
|
|
10
|
+
* return (
|
|
11
|
+
* <>
|
|
12
|
+
* <textarea ref={ref} />
|
|
13
|
+
* <button onClick={openFilePicker}>Upload image</button>
|
|
14
|
+
* </>
|
|
15
|
+
* );
|
|
11
16
|
* ```
|
|
12
17
|
*
|
|
13
18
|
* The listeners are re-attached if any option changes, so memoize callback
|
|
14
|
-
* options (useCallback) to avoid needless re-attaching.
|
|
19
|
+
* options (useCallback) to avoid needless re-attaching. Returns
|
|
20
|
+
* `openFilePicker`, which opens the OS file dialog and inserts the chosen
|
|
21
|
+
* image(s) into the field.
|
|
15
22
|
*/
|
|
16
|
-
export declare function usePaste(ref: RefObject<PasteTarget | null>, options: PasteOptions):
|
|
23
|
+
export declare function usePaste(ref: RefObject<PasteTarget | null>, options: PasteOptions): {
|
|
24
|
+
openFilePicker: () => void;
|
|
25
|
+
};
|
|
17
26
|
export { PixelVaultPasteError } from "@pixelvault-dev/paste";
|
|
18
27
|
export type { PasteOptions, PasteTarget, UploadResult } from "@pixelvault-dev/paste";
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import { useEffect } from "react";
|
|
2
|
-
import { attachPaste } from "@pixelvault-dev/paste";
|
|
2
|
+
import { attachPaste, openFilePicker, } from "@pixelvault-dev/paste";
|
|
3
3
|
/**
|
|
4
4
|
* Add paste-and-host behavior to a textarea/input for the lifetime of the
|
|
5
5
|
* component. Pass a ref to the field and your publishable-key options.
|
|
6
6
|
*
|
|
7
7
|
* ```tsx
|
|
8
8
|
* const ref = useRef<HTMLTextAreaElement>(null);
|
|
9
|
-
* usePaste(ref, { publishableKey: "pv_pub_…" });
|
|
10
|
-
* return
|
|
9
|
+
* const { openFilePicker } = usePaste(ref, { publishableKey: "pv_pub_…" });
|
|
10
|
+
* return (
|
|
11
|
+
* <>
|
|
12
|
+
* <textarea ref={ref} />
|
|
13
|
+
* <button onClick={openFilePicker}>Upload image</button>
|
|
14
|
+
* </>
|
|
15
|
+
* );
|
|
11
16
|
* ```
|
|
12
17
|
*
|
|
13
18
|
* The listeners are re-attached if any option changes, so memoize callback
|
|
14
|
-
* options (useCallback) to avoid needless re-attaching.
|
|
19
|
+
* options (useCallback) to avoid needless re-attaching. Returns
|
|
20
|
+
* `openFilePicker`, which opens the OS file dialog and inserts the chosen
|
|
21
|
+
* image(s) into the field.
|
|
15
22
|
*/
|
|
16
23
|
export function usePaste(ref, options) {
|
|
17
24
|
const { publishableKey, endpoint, folder, render, onUploadStart, onUploadComplete, onError, } = options;
|
|
@@ -29,5 +36,11 @@ export function usePaste(ref, options) {
|
|
|
29
36
|
onError,
|
|
30
37
|
});
|
|
31
38
|
}, [ref, publishableKey, endpoint, folder, render, onUploadStart, onUploadComplete, onError]);
|
|
39
|
+
return {
|
|
40
|
+
openFilePicker: () => {
|
|
41
|
+
if (ref.current)
|
|
42
|
+
openFilePicker(ref.current, options);
|
|
43
|
+
},
|
|
44
|
+
};
|
|
32
45
|
}
|
|
33
46
|
export { PixelVaultPasteError } from "@pixelvault-dev/paste";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixelvault-dev/paste-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "React binding for @pixelvault-dev/paste — a usePaste hook that adds paste-and-host to a textarea/input ref.",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"prepack": "npm run build"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@pixelvault-dev/paste": "^0.1.
|
|
47
|
+
"@pixelvault-dev/paste": "^0.1.1"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"react": ">=17"
|