@pixelvault-dev/paste-vue 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 +5 -1
- package/dist/index.d.ts +11 -3
- package/dist/index.js +15 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -12,14 +12,18 @@ import { ref } from "vue";
|
|
|
12
12
|
import { usePaste } from "@pixelvault-dev/paste-vue";
|
|
13
13
|
|
|
14
14
|
const field = ref<HTMLTextAreaElement | null>(null);
|
|
15
|
-
usePaste(field, { publishableKey: "pv_pub_xxxxxxxx" });
|
|
15
|
+
const { openFilePicker } = usePaste(field, { publishableKey: "pv_pub_xxxxxxxx" });
|
|
16
16
|
</script>
|
|
17
17
|
|
|
18
18
|
<template>
|
|
19
19
|
<textarea ref="field" />
|
|
20
|
+
<button @click="openFilePicker">Upload image</button>
|
|
20
21
|
</template>
|
|
21
22
|
```
|
|
22
23
|
|
|
24
|
+
`usePaste` returns `{ openFilePicker }` — call it to open the OS file dialog and
|
|
25
|
+
insert the chosen image(s).
|
|
26
|
+
|
|
23
27
|
## Directive
|
|
24
28
|
|
|
25
29
|
```vue
|
package/dist/index.d.ts
CHANGED
|
@@ -9,12 +9,20 @@ import { type PasteOptions, type PasteTarget } from "@pixelvault-dev/paste";
|
|
|
9
9
|
* import { ref } from "vue";
|
|
10
10
|
* import { usePaste } from "@pixelvault-dev/paste-vue";
|
|
11
11
|
* const field = ref<HTMLTextAreaElement | null>(null);
|
|
12
|
-
* usePaste(field, { publishableKey: "pv_pub_…" });
|
|
12
|
+
* const { openFilePicker } = usePaste(field, { publishableKey: "pv_pub_…" });
|
|
13
13
|
* </script>
|
|
14
|
-
* <template
|
|
14
|
+
* <template>
|
|
15
|
+
* <textarea ref="field" />
|
|
16
|
+
* <button @click="openFilePicker">Upload image</button>
|
|
17
|
+
* </template>
|
|
15
18
|
* ```
|
|
19
|
+
*
|
|
20
|
+
* Returns `openFilePicker`, which opens the OS file dialog and inserts the
|
|
21
|
+
* chosen image(s) into the field.
|
|
16
22
|
*/
|
|
17
|
-
export declare function usePaste(target: Ref<PasteTarget | null | undefined>, options: PasteOptions):
|
|
23
|
+
export declare function usePaste(target: Ref<PasteTarget | null | undefined>, options: PasteOptions): {
|
|
24
|
+
openFilePicker: () => void;
|
|
25
|
+
};
|
|
18
26
|
/**
|
|
19
27
|
* Directive form: `<textarea v-paste="{ publishableKey: 'pv_pub_…' }" />`.
|
|
20
28
|
* Re-attaches when the bound options change.
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { onMounted, onBeforeUnmount, watch } from "vue";
|
|
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 referenced by a template ref,
|
|
5
5
|
* for the lifetime of the component. Re-attaches if the element changes.
|
|
@@ -9,10 +9,16 @@ import { attachPaste } from "@pixelvault-dev/paste";
|
|
|
9
9
|
* import { ref } from "vue";
|
|
10
10
|
* import { usePaste } from "@pixelvault-dev/paste-vue";
|
|
11
11
|
* const field = ref<HTMLTextAreaElement | null>(null);
|
|
12
|
-
* usePaste(field, { publishableKey: "pv_pub_…" });
|
|
12
|
+
* const { openFilePicker } = usePaste(field, { publishableKey: "pv_pub_…" });
|
|
13
13
|
* </script>
|
|
14
|
-
* <template
|
|
14
|
+
* <template>
|
|
15
|
+
* <textarea ref="field" />
|
|
16
|
+
* <button @click="openFilePicker">Upload image</button>
|
|
17
|
+
* </template>
|
|
15
18
|
* ```
|
|
19
|
+
*
|
|
20
|
+
* Returns `openFilePicker`, which opens the OS file dialog and inserts the
|
|
21
|
+
* chosen image(s) into the field.
|
|
16
22
|
*/
|
|
17
23
|
export function usePaste(target, options) {
|
|
18
24
|
let detach = null;
|
|
@@ -29,6 +35,12 @@ export function usePaste(target, options) {
|
|
|
29
35
|
onMounted(start);
|
|
30
36
|
watch(target, start);
|
|
31
37
|
onBeforeUnmount(stop);
|
|
38
|
+
return {
|
|
39
|
+
openFilePicker: () => {
|
|
40
|
+
if (target.value)
|
|
41
|
+
openFilePicker(target.value, options);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
32
44
|
}
|
|
33
45
|
// Track each directive-bound element's detach fn without polluting the DOM node.
|
|
34
46
|
const detachers = new WeakMap();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixelvault-dev/paste-vue",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Vue 3 binding for @pixelvault-dev/paste — a usePaste composable and vPaste directive for paste-and-host.",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"prepack": "npm run build"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@pixelvault-dev/paste": "^0.1.
|
|
48
|
+
"@pixelvault-dev/paste": "^0.1.1"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"vue": ">=3"
|