@wetransform/vue 2.0.0 → 2.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.
- package/README.md +3 -1
- package/dist/index.d.mts +78 -34
- package/dist/index.mjs +59 -38
- package/dist/internal.d.mts +2 -0
- package/dist/internal.mjs +1 -0
- package/package.json +24 -5
package/README.md
CHANGED
|
@@ -133,8 +133,10 @@ And re-exports these symbols from `@wetransform/core`:
|
|
|
133
133
|
|
|
134
134
|
## Notes
|
|
135
135
|
|
|
136
|
+
- Requires Vue `>= 3.5`.
|
|
136
137
|
- Wrapper lifecycle behavior forwards to core and does not modify core semantics.
|
|
138
|
+
- The SDK instance is created on mount (never during setup), so the component and composable are SSR-safe: server rendering only produces the container markup. Subscriptions registered with `on()` during setup attach automatically once the instance exists.
|
|
137
139
|
- Component: `config` is used at instantiation time. For structural config changes, remount with a Vue `:key`.
|
|
138
|
-
- Composable: `config` is read
|
|
140
|
+
- Composable: `config` (plain object, ref, or getter) is read each time an instance is created — on mount and again on a recreation after `destroy()`. A live instance does not react to config changes; call `destroy()` then `open()` to apply a new config.
|
|
139
141
|
- The component forces the SDK `mountElement` internally; do not pass `mountElement` in `config`.
|
|
140
142
|
- The `locale` prop (component) and `setLocale` (composable) can be called at any time, including before or while the SDK is open.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
import { SupportedLocales, SupportedLocales as SupportedLocales$1, WeTransformConfig, WeTransformConfig as WeTransformConfig$1, WeTransformEventMap, WeTransformEventMap as WeTransformEventMap$1, WeTransformInitialLocations, WeTransformInstance,
|
|
2
|
-
import {
|
|
1
|
+
import { SupportedLocales, SupportedLocales as SupportedLocales$1, WeTransformConfig, WeTransformConfig as WeTransformConfig$1, WeTransformEventMap, WeTransformEventMap as WeTransformEventMap$1, WeTransformInitialLocations, WeTransformInstance, WeTransformInstance as WeTransformInstance$1, WeTransformSDKCustomization, createWeTransform } from "@wetransform/core";
|
|
2
|
+
import { MaybeRefOrGetter, PropType } from "vue";
|
|
3
|
+
import { DistributiveOmit } from "@wetransform/core/internal";
|
|
3
4
|
|
|
4
5
|
//#region src/composables.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* The config is read (via `toValue`) each time an instance is created — on
|
|
8
|
+
* mount and again on a recreation after destroy() — so a recreation picks up
|
|
9
|
+
* current values. A live instance does not react to config changes; call
|
|
10
|
+
* destroy() then open() to apply a new config.
|
|
11
|
+
*/
|
|
5
12
|
declare const useWeTransform: (config: MaybeRefOrGetter<WeTransformConfig$1>) => {
|
|
6
|
-
weTransformInstance: Readonly<import("vue").
|
|
7
|
-
readonly open: () => Promise<void>;
|
|
8
|
-
readonly close: () => Promise<void>;
|
|
9
|
-
readonly destroy: () => Promise<void>;
|
|
10
|
-
readonly setLocale: (locale: SupportedLocales$1) => 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 setLocale: (locale: SupportedLocales$1) => Promise<void>;
|
|
17
|
-
readonly on: <K extends keyof WeTransformEventMap$1>(event: K, handler: WeTransformEventMap$1[K]) => () => void;
|
|
18
|
-
} | null>>;
|
|
13
|
+
weTransformInstance: Readonly<import("vue").ShallowRef<WeTransformInstance$1 | null, WeTransformInstance$1 | null>>;
|
|
19
14
|
isOpen: Readonly<import("vue").Ref<boolean, boolean>>;
|
|
20
15
|
open: () => Promise<void>;
|
|
21
16
|
close: () => Promise<void>;
|
|
@@ -25,24 +20,73 @@ declare const useWeTransform: (config: MaybeRefOrGetter<WeTransformConfig$1>) =>
|
|
|
25
20
|
};
|
|
26
21
|
//#endregion
|
|
27
22
|
//#region src/components/WeTransformSdk.d.ts
|
|
28
|
-
type WeTransformComponentConfig =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
locale
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
23
|
+
type WeTransformComponentConfig = DistributiveOmit<WeTransformConfig$1, 'mountElement' | 'locale'>;
|
|
24
|
+
declare const WeTransformSdk: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
25
|
+
config: {
|
|
26
|
+
type: PropType<WeTransformComponentConfig>;
|
|
27
|
+
required: true;
|
|
28
|
+
};
|
|
29
|
+
open: {
|
|
30
|
+
type: BooleanConstructor;
|
|
31
|
+
default: undefined;
|
|
32
|
+
};
|
|
33
|
+
autoOpen: {
|
|
34
|
+
type: BooleanConstructor;
|
|
35
|
+
default: boolean;
|
|
36
|
+
};
|
|
37
|
+
locale: {
|
|
38
|
+
type: PropType<SupportedLocales$1>;
|
|
39
|
+
required: false;
|
|
40
|
+
};
|
|
41
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
42
|
+
[key: string]: any;
|
|
43
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
44
|
+
'update:open': (_value: boolean) => true;
|
|
45
|
+
open: () => true;
|
|
46
|
+
close: () => true;
|
|
47
|
+
destroy: () => true;
|
|
48
|
+
ready: () => true;
|
|
49
|
+
successSubmit: (_payload: Parameters<WeTransformEventMap$1["successSubmit"]>[0]) => true;
|
|
50
|
+
error: (_payload: Parameters<WeTransformEventMap$1["error"]>[0]) => true;
|
|
51
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
52
|
+
config: {
|
|
53
|
+
type: PropType<WeTransformComponentConfig>;
|
|
54
|
+
required: true;
|
|
55
|
+
};
|
|
56
|
+
open: {
|
|
57
|
+
type: BooleanConstructor;
|
|
58
|
+
default: undefined;
|
|
59
|
+
};
|
|
60
|
+
autoOpen: {
|
|
61
|
+
type: BooleanConstructor;
|
|
62
|
+
default: boolean;
|
|
63
|
+
};
|
|
64
|
+
locale: {
|
|
65
|
+
type: PropType<SupportedLocales$1>;
|
|
66
|
+
required: false;
|
|
67
|
+
};
|
|
68
|
+
}>> & Readonly<{
|
|
69
|
+
onOpen?: (() => any) | undefined;
|
|
70
|
+
onClose?: (() => any) | undefined;
|
|
71
|
+
onDestroy?: (() => any) | undefined;
|
|
72
|
+
onReady?: (() => any) | undefined;
|
|
73
|
+
onSuccessSubmit?: ((_payload: {
|
|
74
|
+
customerId: string;
|
|
75
|
+
templateHandle: string;
|
|
76
|
+
fileUrl: string;
|
|
77
|
+
signature: string;
|
|
78
|
+
userFileName: string;
|
|
79
|
+
}) => any) | undefined;
|
|
80
|
+
onError?: ((_payload: {
|
|
81
|
+
code: string;
|
|
82
|
+
message: string;
|
|
83
|
+
stack?: string;
|
|
84
|
+
}) => any) | undefined;
|
|
85
|
+
"onUpdate:open"?: ((_value: boolean) => any) | undefined;
|
|
86
|
+
}>, {
|
|
87
|
+
open: boolean;
|
|
88
|
+
autoOpen: boolean;
|
|
89
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
46
90
|
type WeTransformSdkProps = InstanceType<typeof WeTransformSdk>['$props'];
|
|
47
91
|
//#endregion
|
|
48
|
-
export { type SupportedLocales, type WeTransformConfig, type WeTransformEventMap, type WeTransformInitialLocations, type WeTransformInstance, type WeTransformSDKCustomization, WeTransformSdk, type WeTransformSdkProps,
|
|
92
|
+
export { type SupportedLocales, type WeTransformConfig, type WeTransformEventMap, type WeTransformInitialLocations, type WeTransformInstance, type WeTransformSDKCustomization, WeTransformSdk, type WeTransformSdkProps, createWeTransform, useWeTransform };
|
package/dist/index.mjs
CHANGED
|
@@ -1,41 +1,56 @@
|
|
|
1
1
|
import { createWeTransform, createWeTransform as createWeTransform$1 } from "@wetransform/core";
|
|
2
|
-
import { defineComponent, h, onMounted, onUnmounted, readonly, ref, shallowRef, toValue, watch } from "vue";
|
|
2
|
+
import { defineComponent, getCurrentInstance, getCurrentScope, h, onMounted, onScopeDispose, onUnmounted, readonly, ref, shallowReadonly, shallowRef, toValue, useId, watch } from "vue";
|
|
3
3
|
//#region src/composables.ts
|
|
4
|
+
const noop = () => void 0;
|
|
5
|
+
/**
|
|
6
|
+
* The config is read (via `toValue`) each time an instance is created — on
|
|
7
|
+
* mount and again on a recreation after destroy() — so a recreation picks up
|
|
8
|
+
* current values. A live instance does not react to config changes; call
|
|
9
|
+
* destroy() then open() to apply a new config.
|
|
10
|
+
*/
|
|
4
11
|
const useWeTransform = (config) => {
|
|
5
12
|
const sdk = shallowRef(null);
|
|
6
13
|
const isOpen = ref(false);
|
|
14
|
+
let isDisposed = false;
|
|
7
15
|
let destroyPromise = null;
|
|
8
16
|
const internalEvents = [];
|
|
9
|
-
const
|
|
17
|
+
const externalSubs = /* @__PURE__ */ new Set();
|
|
18
|
+
const cleanupAllListeners = () => {
|
|
19
|
+
while (internalEvents.length) internalEvents.pop()?.();
|
|
20
|
+
externalSubs.forEach((sub) => sub.unsubscribe());
|
|
21
|
+
externalSubs.clear();
|
|
22
|
+
};
|
|
10
23
|
const initSdk = () => {
|
|
11
|
-
if (sdk.value) return sdk.value;
|
|
24
|
+
if (sdk.value && !destroyPromise) return sdk.value;
|
|
12
25
|
const instance = createWeTransform$1(toValue(config));
|
|
26
|
+
while (internalEvents.length) internalEvents.pop()?.();
|
|
13
27
|
internalEvents.push(instance.on("open", () => {
|
|
28
|
+
if (sdk.value !== instance) return;
|
|
14
29
|
isOpen.value = true;
|
|
15
30
|
}), instance.on("close", () => {
|
|
31
|
+
if (sdk.value !== instance) return;
|
|
16
32
|
isOpen.value = false;
|
|
17
33
|
}), instance.on("destroy", () => {
|
|
34
|
+
if (sdk.value !== instance) return;
|
|
18
35
|
isOpen.value = false;
|
|
19
36
|
sdk.value = null;
|
|
20
37
|
}));
|
|
38
|
+
externalSubs.forEach((sub) => {
|
|
39
|
+
sub.unsubscribe();
|
|
40
|
+
sub.unsubscribe = instance.on(sub.event, sub.handler);
|
|
41
|
+
});
|
|
21
42
|
sdk.value = instance;
|
|
22
43
|
return instance;
|
|
23
44
|
};
|
|
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
45
|
const open = async () => {
|
|
35
|
-
|
|
46
|
+
if (isDisposed) return;
|
|
47
|
+
await initSdk().open();
|
|
36
48
|
};
|
|
37
49
|
const close = async () => {
|
|
38
|
-
await
|
|
50
|
+
await sdk.value?.close();
|
|
51
|
+
};
|
|
52
|
+
const setLocale = async (locale) => {
|
|
53
|
+
await sdk.value?.setLocale(locale);
|
|
39
54
|
};
|
|
40
55
|
const destroy = async () => {
|
|
41
56
|
if (destroyPromise) return destroyPromise;
|
|
@@ -44,29 +59,35 @@ const useWeTransform = (config) => {
|
|
|
44
59
|
destroyPromise = (async () => {
|
|
45
60
|
await activeSdk.destroy();
|
|
46
61
|
})().finally(() => {
|
|
62
|
+
destroyPromise = null;
|
|
63
|
+
if (sdk.value && sdk.value !== activeSdk) return;
|
|
47
64
|
cleanupAllListeners();
|
|
48
65
|
sdk.value = null;
|
|
49
66
|
isOpen.value = false;
|
|
50
|
-
destroyPromise = null;
|
|
51
67
|
});
|
|
52
68
|
return destroyPromise;
|
|
53
69
|
};
|
|
54
|
-
const setLocale = async (locale) => {
|
|
55
|
-
await getActiveSdk().setLocale(locale);
|
|
56
|
-
};
|
|
57
70
|
const on = (event, handler) => {
|
|
58
|
-
|
|
59
|
-
|
|
71
|
+
if (isDisposed) return noop;
|
|
72
|
+
const sub = {
|
|
73
|
+
event,
|
|
74
|
+
handler,
|
|
75
|
+
unsubscribe: noop
|
|
76
|
+
};
|
|
77
|
+
if (sdk.value && !destroyPromise) sub.unsubscribe = sdk.value.on(event, handler);
|
|
78
|
+
externalSubs.add(sub);
|
|
60
79
|
return () => {
|
|
61
|
-
unsubscribe();
|
|
62
|
-
|
|
80
|
+
sub.unsubscribe();
|
|
81
|
+
externalSubs.delete(sub);
|
|
63
82
|
};
|
|
64
83
|
};
|
|
65
|
-
|
|
84
|
+
if (getCurrentInstance()) onMounted(initSdk);
|
|
85
|
+
if (getCurrentScope()) onScopeDispose(() => {
|
|
86
|
+
isDisposed = true;
|
|
66
87
|
destroy();
|
|
67
88
|
});
|
|
68
89
|
return {
|
|
69
|
-
weTransformInstance:
|
|
90
|
+
weTransformInstance: shallowReadonly(sdk),
|
|
70
91
|
isOpen: readonly(isOpen),
|
|
71
92
|
open,
|
|
72
93
|
close,
|
|
@@ -86,7 +107,7 @@ const WeTransformSdk = defineComponent({
|
|
|
86
107
|
},
|
|
87
108
|
open: {
|
|
88
109
|
type: Boolean,
|
|
89
|
-
|
|
110
|
+
default: void 0
|
|
90
111
|
},
|
|
91
112
|
autoOpen: {
|
|
92
113
|
type: Boolean,
|
|
@@ -97,17 +118,17 @@ const WeTransformSdk = defineComponent({
|
|
|
97
118
|
required: false
|
|
98
119
|
}
|
|
99
120
|
},
|
|
100
|
-
emits:
|
|
101
|
-
"update:open",
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
121
|
+
emits: {
|
|
122
|
+
"update:open": (_value) => true,
|
|
123
|
+
open: () => true,
|
|
124
|
+
close: () => true,
|
|
125
|
+
destroy: () => true,
|
|
126
|
+
ready: () => true,
|
|
127
|
+
successSubmit: (_payload) => true,
|
|
128
|
+
error: (_payload) => true
|
|
129
|
+
},
|
|
109
130
|
setup(props, { emit }) {
|
|
110
|
-
const mountElementId = `weTransform_iframeContainer_${
|
|
131
|
+
const mountElementId = `weTransform_iframeContainer_${useId()}`;
|
|
111
132
|
const { isOpen, open, close, setLocale, on } = useWeTransform({
|
|
112
133
|
...props.config,
|
|
113
134
|
mountElement: mountElementId,
|
|
@@ -132,10 +153,10 @@ const WeTransformSdk = defineComponent({
|
|
|
132
153
|
return;
|
|
133
154
|
}
|
|
134
155
|
close();
|
|
135
|
-
}
|
|
156
|
+
});
|
|
136
157
|
watch(isOpen, (next) => emit("update:open", next));
|
|
137
158
|
onMounted(() => {
|
|
138
|
-
if (props.autoOpen && !isOpen.value) open();
|
|
159
|
+
if ((props.open !== void 0 ? props.open : props.autoOpen) && !isOpen.value) open();
|
|
139
160
|
});
|
|
140
161
|
return () => h("div", {
|
|
141
162
|
id: mountElementId,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wetransform/vue",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "Vue 3 wrapper for the WeTransform browser SDK.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"AI data importer",
|
|
7
|
+
"embed",
|
|
8
|
+
"sdk",
|
|
9
|
+
"vue",
|
|
10
|
+
"wetransform"
|
|
11
|
+
],
|
|
4
12
|
"homepage": "https://wetransform.com",
|
|
5
13
|
"license": "ISC",
|
|
6
14
|
"files": [
|
|
@@ -8,14 +16,20 @@
|
|
|
8
16
|
],
|
|
9
17
|
"type": "module",
|
|
10
18
|
"exports": {
|
|
11
|
-
".":
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.mts",
|
|
21
|
+
"default": "./dist/index.mjs"
|
|
22
|
+
},
|
|
23
|
+
"./internal": {
|
|
24
|
+
"types": "./dist/internal.d.mts",
|
|
25
|
+
"default": "./dist/internal.mjs"
|
|
26
|
+
}
|
|
12
27
|
},
|
|
13
28
|
"publishConfig": {
|
|
14
29
|
"access": "public"
|
|
15
30
|
},
|
|
16
31
|
"dependencies": {
|
|
17
|
-
"
|
|
18
|
-
"@wetransform/core": "2.0.0"
|
|
32
|
+
"@wetransform/core": "2.1.0"
|
|
19
33
|
},
|
|
20
34
|
"devDependencies": {
|
|
21
35
|
"@types/node": "^24.12.4",
|
|
@@ -24,7 +38,12 @@
|
|
|
24
38
|
"jsdom": "^29.1.1",
|
|
25
39
|
"typescript": "^6.0.3",
|
|
26
40
|
"vite": "npm:@voidzero-dev/vite-plus-core@0.2.1",
|
|
27
|
-
"vite-plus": "0.2.1"
|
|
41
|
+
"vite-plus": "0.2.1",
|
|
42
|
+
"vue": "^3.5.38",
|
|
43
|
+
"@wetransform/test-utils": "0.0.0"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"vue": "^3.5.0"
|
|
28
47
|
},
|
|
29
48
|
"scripts": {
|
|
30
49
|
"build": "VITE_MODE=production vp pack",
|