@wetransform/vue 1.0.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.
- package/README.md +110 -0
- package/dist/index.d.mts +68 -0
- package/dist/index.mjs +131 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# @wetransform/vue
|
|
2
|
+
|
|
3
|
+
Vue 3 wrapper around `@wetransform/core` with a composable API and a renderless integration component.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @wetransform/vue
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Composable usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { useWeTransform } from '@wetransform/vue'
|
|
15
|
+
|
|
16
|
+
const { open, close, destroy, isOpen, weTransformInstance, on } = useWeTransform({
|
|
17
|
+
organizationHandle: 'acme',
|
|
18
|
+
authentication: {
|
|
19
|
+
customerId: 'customer-id',
|
|
20
|
+
signature: 'signed-token',
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
on('successSubmit', ({ redirectUrl }) => {
|
|
25
|
+
window.location.href = redirectUrl
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
await open()
|
|
29
|
+
await close()
|
|
30
|
+
await destroy()
|
|
31
|
+
|
|
32
|
+
console.log(isOpen.value)
|
|
33
|
+
console.log(weTransformInstance.value)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`useWeTransform(config)` returns:
|
|
37
|
+
|
|
38
|
+
- `weTransformInstance`: readonly `Ref<WeTransformInstance | null>`
|
|
39
|
+
- `isOpen`: readonly `Ref<boolean>`
|
|
40
|
+
- `open()`: opens the SDK
|
|
41
|
+
- `close()`: closes the SDK
|
|
42
|
+
- `destroy()`: destroys the SDK instance (idempotent)
|
|
43
|
+
- `on(event, handler)`: subscribes to SDK events and returns an unsubscribe function
|
|
44
|
+
|
|
45
|
+
## Component usage
|
|
46
|
+
|
|
47
|
+
```vue
|
|
48
|
+
<script setup lang="ts">
|
|
49
|
+
import { ref } from 'vue'
|
|
50
|
+
import { WeTransformSdk, type WeTransformConfig } from '@wetransform/vue'
|
|
51
|
+
|
|
52
|
+
const isSdkOpen = ref(false)
|
|
53
|
+
|
|
54
|
+
const config: WeTransformConfig = {
|
|
55
|
+
organizationHandle: 'acme',
|
|
56
|
+
authentication: {
|
|
57
|
+
customerId: 'customer-id',
|
|
58
|
+
signature: 'signed-token',
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const onSuccessSubmit = ({ redirectUrl }: { redirectUrl: string }) => {
|
|
63
|
+
window.location.href = redirectUrl
|
|
64
|
+
}
|
|
65
|
+
</script>
|
|
66
|
+
|
|
67
|
+
<template>
|
|
68
|
+
<button type="button" @click="isSdkOpen = true">Open Sender</button>
|
|
69
|
+
|
|
70
|
+
<WeTransformSdk
|
|
71
|
+
:config="config"
|
|
72
|
+
v-model:open="isSdkOpen"
|
|
73
|
+
:autoOpen="false"
|
|
74
|
+
@successSubmit="onSuccessSubmit"
|
|
75
|
+
/>
|
|
76
|
+
</template>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`WeTransformSdk` is renderless except for its internal mount container and does not expose slots.
|
|
80
|
+
|
|
81
|
+
Props:
|
|
82
|
+
|
|
83
|
+
- `config` (required): SDK configuration
|
|
84
|
+
- `open` (optional): controlled open state (for `v-model:open`)
|
|
85
|
+
- `autoOpen` (optional, default `false`): opens on mount
|
|
86
|
+
|
|
87
|
+
Emits:
|
|
88
|
+
|
|
89
|
+
- `update:open`
|
|
90
|
+
- `open`
|
|
91
|
+
- `close`
|
|
92
|
+
- `destroy`
|
|
93
|
+
- `onReady`
|
|
94
|
+
- `successSubmit`
|
|
95
|
+
- `error`
|
|
96
|
+
|
|
97
|
+
## Re-exports
|
|
98
|
+
|
|
99
|
+
`@wetransform/vue` also re-exports these symbols from `@wetransform/core`:
|
|
100
|
+
|
|
101
|
+
- `createWeTransform`
|
|
102
|
+
- `WeTransformConfig`
|
|
103
|
+
- `WeTransformEventMap`
|
|
104
|
+
- `WeTransformInstance`
|
|
105
|
+
|
|
106
|
+
## Notes
|
|
107
|
+
|
|
108
|
+
- Wrapper lifecycle behavior forwards to core and does not modify core semantics.
|
|
109
|
+
- `config` is used at instantiation time. For structural config changes, remount with a Vue `:key`.
|
|
110
|
+
- The component forces the SDK `mountElement` to `weTransform_iframeContainer`.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { WeTransformConfig, WeTransformConfig as WeTransformConfig$1, WeTransformEventMap, WeTransformEventMap as WeTransformEventMap$1, WeTransformInstance, createWeTransform } from "@wetransform/core";
|
|
2
|
+
import * as vue from "vue";
|
|
3
|
+
import { PropType } from "vue";
|
|
4
|
+
|
|
5
|
+
//#region src/composables.d.ts
|
|
6
|
+
declare const useWeTransform: (config: WeTransformConfig$1) => {
|
|
7
|
+
weTransformInstance: Readonly<vue.Ref<{
|
|
8
|
+
readonly open: () => Promise<void>;
|
|
9
|
+
readonly close: () => Promise<void>;
|
|
10
|
+
readonly destroy: () => Promise<void>;
|
|
11
|
+
readonly on: <K extends keyof WeTransformEventMap$1>(event: K, handler: WeTransformEventMap$1[K]) => () => void;
|
|
12
|
+
} | null, {
|
|
13
|
+
readonly open: () => Promise<void>;
|
|
14
|
+
readonly close: () => Promise<void>;
|
|
15
|
+
readonly destroy: () => Promise<void>;
|
|
16
|
+
readonly on: <K extends keyof WeTransformEventMap$1>(event: K, handler: WeTransformEventMap$1[K]) => () => void;
|
|
17
|
+
} | null>>;
|
|
18
|
+
isOpen: Readonly<vue.Ref<boolean, boolean>>;
|
|
19
|
+
open: () => Promise<void>;
|
|
20
|
+
close: () => Promise<void>;
|
|
21
|
+
destroy: () => Promise<void>;
|
|
22
|
+
on: <K extends keyof WeTransformEventMap$1>(event: K, handler: WeTransformEventMap$1[K]) => (() => void);
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/components/WeTransformSdk.d.ts
|
|
26
|
+
type WeTransformComponentConfig = Omit<WeTransformConfig$1, 'mountElement'>;
|
|
27
|
+
declare const WeTransformSdk: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
28
|
+
config: {
|
|
29
|
+
type: PropType<WeTransformComponentConfig>;
|
|
30
|
+
required: true;
|
|
31
|
+
};
|
|
32
|
+
open: {
|
|
33
|
+
type: BooleanConstructor;
|
|
34
|
+
required: false;
|
|
35
|
+
};
|
|
36
|
+
autoOpen: {
|
|
37
|
+
type: BooleanConstructor;
|
|
38
|
+
default: boolean;
|
|
39
|
+
};
|
|
40
|
+
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
41
|
+
[key: string]: any;
|
|
42
|
+
}>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("update:open" | "open" | "close" | "destroy" | "onReady" | "successSubmit" | "error")[], "update:open" | "open" | "close" | "destroy" | "onReady" | "successSubmit" | "error", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
43
|
+
config: {
|
|
44
|
+
type: PropType<WeTransformComponentConfig>;
|
|
45
|
+
required: true;
|
|
46
|
+
};
|
|
47
|
+
open: {
|
|
48
|
+
type: BooleanConstructor;
|
|
49
|
+
required: false;
|
|
50
|
+
};
|
|
51
|
+
autoOpen: {
|
|
52
|
+
type: BooleanConstructor;
|
|
53
|
+
default: boolean;
|
|
54
|
+
};
|
|
55
|
+
}>> & Readonly<{
|
|
56
|
+
"onUpdate:open"?: ((...args: any[]) => any) | undefined;
|
|
57
|
+
onOpen?: ((...args: any[]) => any) | undefined;
|
|
58
|
+
onClose?: ((...args: any[]) => any) | undefined;
|
|
59
|
+
onDestroy?: ((...args: any[]) => any) | undefined;
|
|
60
|
+
onOnReady?: ((...args: any[]) => any) | undefined;
|
|
61
|
+
onSuccessSubmit?: ((...args: any[]) => any) | undefined;
|
|
62
|
+
onError?: ((...args: any[]) => any) | undefined;
|
|
63
|
+
}>, {
|
|
64
|
+
open: boolean;
|
|
65
|
+
autoOpen: boolean;
|
|
66
|
+
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
67
|
+
//#endregion
|
|
68
|
+
export { type WeTransformConfig, type WeTransformEventMap, type WeTransformInstance, WeTransformSdk, createWeTransform, useWeTransform };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { createWeTransform, createWeTransform as createWeTransform$1 } from "@wetransform/core";
|
|
2
|
+
import { defineComponent, h, onMounted, onUnmounted, readonly, ref, shallowRef, watch } from "vue";
|
|
3
|
+
//#region src/composables.ts
|
|
4
|
+
const useWeTransform = (config) => {
|
|
5
|
+
const sdk = shallowRef(null);
|
|
6
|
+
const isOpen = ref(false);
|
|
7
|
+
let destroyPromise = null;
|
|
8
|
+
const internalEvents = [];
|
|
9
|
+
const externalEvents = /* @__PURE__ */ new Set();
|
|
10
|
+
const initSdk = () => {
|
|
11
|
+
if (sdk.value) return sdk.value;
|
|
12
|
+
const instance = createWeTransform$1(config);
|
|
13
|
+
internalEvents.push(instance.on("open", () => {
|
|
14
|
+
isOpen.value = true;
|
|
15
|
+
}), instance.on("close", () => {
|
|
16
|
+
isOpen.value = false;
|
|
17
|
+
}), instance.on("destroy", () => {
|
|
18
|
+
isOpen.value = false;
|
|
19
|
+
sdk.value = null;
|
|
20
|
+
}));
|
|
21
|
+
sdk.value = instance;
|
|
22
|
+
return instance;
|
|
23
|
+
};
|
|
24
|
+
initSdk();
|
|
25
|
+
const getActiveSdk = () => {
|
|
26
|
+
if (!sdk.value) throw new Error("WeTransform instance is not initialized");
|
|
27
|
+
return sdk.value;
|
|
28
|
+
};
|
|
29
|
+
const cleanupAllListeners = () => {
|
|
30
|
+
while (internalEvents.length) internalEvents.pop()?.();
|
|
31
|
+
externalEvents.forEach((unSub) => unSub());
|
|
32
|
+
externalEvents.clear();
|
|
33
|
+
};
|
|
34
|
+
const open = async () => {
|
|
35
|
+
await (sdk.value || initSdk()).open();
|
|
36
|
+
};
|
|
37
|
+
const close = async () => {
|
|
38
|
+
await getActiveSdk().close();
|
|
39
|
+
};
|
|
40
|
+
const destroy = async () => {
|
|
41
|
+
if (destroyPromise) return destroyPromise;
|
|
42
|
+
if (!sdk.value) return;
|
|
43
|
+
const activeSdk = sdk.value;
|
|
44
|
+
destroyPromise = (async () => {
|
|
45
|
+
await activeSdk.destroy();
|
|
46
|
+
})().finally(() => {
|
|
47
|
+
cleanupAllListeners();
|
|
48
|
+
sdk.value = null;
|
|
49
|
+
isOpen.value = false;
|
|
50
|
+
destroyPromise = null;
|
|
51
|
+
});
|
|
52
|
+
return destroyPromise;
|
|
53
|
+
};
|
|
54
|
+
const on = (event, handler) => {
|
|
55
|
+
const unsubscribe = (sdk.value || initSdk()).on(event, handler);
|
|
56
|
+
externalEvents.add(unsubscribe);
|
|
57
|
+
return () => {
|
|
58
|
+
unsubscribe();
|
|
59
|
+
externalEvents.delete(unsubscribe);
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
onUnmounted(() => {
|
|
63
|
+
destroy();
|
|
64
|
+
});
|
|
65
|
+
return {
|
|
66
|
+
weTransformInstance: readonly(sdk),
|
|
67
|
+
isOpen: readonly(isOpen),
|
|
68
|
+
open,
|
|
69
|
+
close,
|
|
70
|
+
destroy,
|
|
71
|
+
on
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/components/WeTransformSdk.ts
|
|
76
|
+
const WeTransformSdk = defineComponent({
|
|
77
|
+
name: "WeTransformSdk",
|
|
78
|
+
props: {
|
|
79
|
+
config: {
|
|
80
|
+
type: Object,
|
|
81
|
+
required: true
|
|
82
|
+
},
|
|
83
|
+
open: {
|
|
84
|
+
type: Boolean,
|
|
85
|
+
required: false
|
|
86
|
+
},
|
|
87
|
+
autoOpen: {
|
|
88
|
+
type: Boolean,
|
|
89
|
+
default: false
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
emits: [
|
|
93
|
+
"update:open",
|
|
94
|
+
"open",
|
|
95
|
+
"close",
|
|
96
|
+
"destroy",
|
|
97
|
+
"onReady",
|
|
98
|
+
"successSubmit",
|
|
99
|
+
"error"
|
|
100
|
+
],
|
|
101
|
+
setup(props, { emit }) {
|
|
102
|
+
const { isOpen, open, close, on } = useWeTransform({
|
|
103
|
+
...props.config,
|
|
104
|
+
mountElement: "weTransform_iframeContainer"
|
|
105
|
+
});
|
|
106
|
+
const events = [
|
|
107
|
+
on("open", () => emit("open")),
|
|
108
|
+
on("close", () => emit("close")),
|
|
109
|
+
on("destroy", () => emit("destroy")),
|
|
110
|
+
on("onReady", () => emit("onReady")),
|
|
111
|
+
on("successSubmit", (payload) => emit("successSubmit", payload)),
|
|
112
|
+
on("error", (payload) => emit("error", payload))
|
|
113
|
+
];
|
|
114
|
+
onUnmounted(() => events.forEach((unSub) => unSub()));
|
|
115
|
+
watch(() => props.open, (nextOpen) => {
|
|
116
|
+
if (nextOpen === void 0 || nextOpen === isOpen.value) return;
|
|
117
|
+
if (nextOpen) {
|
|
118
|
+
open();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
close();
|
|
122
|
+
}, { immediate: true });
|
|
123
|
+
watch(isOpen, (next) => emit("update:open", next));
|
|
124
|
+
onMounted(() => {
|
|
125
|
+
if (props.autoOpen && !isOpen.value) open();
|
|
126
|
+
});
|
|
127
|
+
return () => h("div", { id: "weTransform_iframeContainer" });
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
//#endregion
|
|
131
|
+
export { WeTransformSdk, createWeTransform, useWeTransform };
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wetransform/vue",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "ISC",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist/**"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./dist/index.mjs"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "VITE_MODE=production vp pack",
|
|
17
|
+
"dev": "vp pack --watch",
|
|
18
|
+
"lint": "vp lint --type-aware --type-check .",
|
|
19
|
+
"test": "vp test run",
|
|
20
|
+
"publish": "vp run build && npm publish"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@wetransform/core": "workspace:*",
|
|
24
|
+
"vue": "^3.5.30"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "catalog:",
|
|
28
|
+
"@vitejs/plugin-vue": "^6.0.5",
|
|
29
|
+
"@vue/test-utils": "^2.4.6",
|
|
30
|
+
"jsdom": "catalog:",
|
|
31
|
+
"typescript": "catalog:",
|
|
32
|
+
"vite": "catalog:",
|
|
33
|
+
"vite-plus": "catalog:",
|
|
34
|
+
"vitest": "catalog:"
|
|
35
|
+
}
|
|
36
|
+
}
|