@nuxt/scripts 0.11.0 → 0.11.2
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 +71 -71
- package/dist/client/200.html +9 -9
- package/dist/client/404.html +9 -9
- package/dist/client/_nuxt/BwTzWwlf.js +21 -0
- package/dist/client/_nuxt/{BSA2bgdb.js → CJaqyBTv.js} +1 -1
- package/dist/client/_nuxt/{CtQNcfGE.js → XZaFTD3R.js} +1 -1
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/ccdd3650-9466-4597-a4e4-6464577f0b3e.json +1 -0
- package/dist/client/_nuxt/{entry.ipQkUTQD.css → entry.CJckMUzn.css} +1 -1
- package/dist/client/_nuxt/error-404.kHO_CZtx.css +1 -0
- package/dist/client/_nuxt/error-500.CICk5yq7.css +1 -0
- package/dist/client/_nuxt/{BFM-Ncmx.js → gy_iwf94.js} +1 -1
- package/dist/client/index.html +9 -9
- package/dist/module.json +1 -1
- package/dist/module.mjs +3 -1
- package/dist/runtime/components/ScriptAriaLoadingIndicator.vue +5 -5
- package/dist/runtime/components/ScriptCarbonAds.vue +83 -83
- package/dist/runtime/components/ScriptCrisp.vue +94 -94
- package/dist/runtime/components/ScriptGoogleAdsense.vue +93 -93
- package/dist/runtime/components/ScriptGoogleMaps.vue +470 -469
- package/dist/runtime/components/ScriptIntercom.vue +103 -103
- package/dist/runtime/components/ScriptLemonSqueezy.vue +52 -52
- package/dist/runtime/components/ScriptLoadingIndicator.vue +22 -22
- package/dist/runtime/components/ScriptStripePricingTable.vue +74 -74
- package/dist/runtime/components/ScriptVimeoPlayer.vue +288 -289
- package/dist/runtime/components/ScriptYouTubePlayer.vue +215 -215
- package/dist/runtime/composables/useScript.d.ts +1 -5
- package/dist/runtime/composables/useScriptEventPage.js +1 -2
- package/dist/runtime/registry/clarity.d.ts +1 -1
- package/dist/runtime/registry/cloudflare-web-analytics.d.ts +1 -1
- package/dist/runtime/registry/google-adsense.js +1 -1
- package/dist/runtime/registry/google-maps.d.ts +1 -1
- package/dist/runtime/registry/google-maps.js +4 -2
- package/dist/runtime/types.d.ts +6 -10
- package/dist/runtime/utils.d.ts +2 -2
- package/dist/runtime/utils.js +1 -1
- package/dist/runtime/validation/mock.d.ts +13 -13
- package/dist/runtime/validation/mock.js +7 -1
- package/package.json +11 -11
- package/dist/client/_nuxt/DuCkB5R-.js +0 -21
- package/dist/client/_nuxt/builds/meta/e03354ab-f2ce-4d6b-8542-7b38262b3671.json +0 -1
- package/dist/client/_nuxt/error-404.BdjopNsg.css +0 -1
- package/dist/client/_nuxt/error-500.Bd7Z7Q7I.css +0 -1
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { ref, onMounted, watch, onBeforeUnmount, computed } from 'vue'
|
|
3
|
-
import { useScriptIntercom } from '../registry/intercom'
|
|
4
|
-
import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
|
|
5
|
-
import type { ElementScriptTrigger } from '#nuxt-scripts/types'
|
|
6
|
-
|
|
7
|
-
const props = withDefaults(defineProps<{
|
|
8
|
-
appId: string
|
|
9
|
-
apiBase?: string
|
|
10
|
-
name?: string
|
|
11
|
-
email?: string
|
|
12
|
-
userId?: string
|
|
13
|
-
// customizing the messenger
|
|
14
|
-
alignment?: 'left' | 'right'
|
|
15
|
-
horizontalPadding?: number
|
|
16
|
-
verticalPadding?: number
|
|
17
|
-
/**
|
|
18
|
-
* Defines the trigger event to load the script.
|
|
19
|
-
*/
|
|
20
|
-
trigger?: ElementScriptTrigger
|
|
21
|
-
}>(), {
|
|
22
|
-
trigger: 'click',
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
const emits = defineEmits<{
|
|
26
|
-
// our emit
|
|
27
|
-
ready: [e: ReturnType<typeof useScriptIntercom>]
|
|
28
|
-
error: []
|
|
29
|
-
}>()
|
|
30
|
-
|
|
31
|
-
const rootEl = ref(null)
|
|
32
|
-
const trigger = useScriptTriggerElement({ trigger: props.trigger, el: rootEl })
|
|
33
|
-
|
|
34
|
-
const isReady = ref(false)
|
|
35
|
-
const intercom = useScriptIntercom({
|
|
36
|
-
app_id: props.appId,
|
|
37
|
-
// @ts-expect-error untyped
|
|
38
|
-
app_base: props.apiBase,
|
|
39
|
-
name: props.name,
|
|
40
|
-
email: props.email,
|
|
41
|
-
user_id: props.userId,
|
|
42
|
-
alignment: props.alignment,
|
|
43
|
-
horizontal_padding: props.horizontalPadding,
|
|
44
|
-
vertical_padding: props.verticalPadding,
|
|
45
|
-
scriptOptions: {
|
|
46
|
-
trigger,
|
|
47
|
-
},
|
|
48
|
-
})
|
|
49
|
-
const { status, onLoaded } = intercom
|
|
50
|
-
if (props.trigger === 'click') {
|
|
51
|
-
onLoaded((instance) => {
|
|
52
|
-
instance.Intercom('show')
|
|
53
|
-
})
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
defineExpose({
|
|
57
|
-
intercom,
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
let observer: MutationObserver
|
|
61
|
-
onMounted(() => {
|
|
62
|
-
watch(status, (status) => {
|
|
63
|
-
if (status === 'loading') {
|
|
64
|
-
observer = new MutationObserver(() => {
|
|
65
|
-
if (document.getElementById('intercom-frame')) {
|
|
66
|
-
isReady.value = true
|
|
67
|
-
emits('ready', intercom)
|
|
68
|
-
observer.disconnect()
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
observer.observe(document.body, { childList: true, subtree: true })
|
|
72
|
-
}
|
|
73
|
-
else if (status === 'error')
|
|
74
|
-
emits('error')
|
|
75
|
-
})
|
|
76
|
-
})
|
|
77
|
-
onBeforeUnmount(() => {
|
|
78
|
-
observer?.disconnect()
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
const rootAttrs = computed(() => {
|
|
82
|
-
return {
|
|
83
|
-
style: {
|
|
84
|
-
display: isReady.value ? 'none' : 'block',
|
|
85
|
-
bottom: `${props.verticalPadding || 20}px`,
|
|
86
|
-
[props.alignment || 'right']: `${props.horizontalPadding || 20}px`,
|
|
87
|
-
},
|
|
88
|
-
...(trigger instanceof Promise ? trigger.ssrAttrs || {} : {}),
|
|
89
|
-
}
|
|
90
|
-
})
|
|
91
|
-
</script>
|
|
92
|
-
|
|
93
|
-
<template>
|
|
94
|
-
<div
|
|
95
|
-
ref="rootEl"
|
|
96
|
-
v-bind="rootAttrs"
|
|
97
|
-
>
|
|
98
|
-
<slot :ready="isReady" />
|
|
99
|
-
<slot v-if="status === 'awaitingLoad'" name="awaitingLoad" />
|
|
100
|
-
<slot v-else-if="status === 'loading' || !isReady" name="loading" />
|
|
101
|
-
<slot v-else-if="status === 'error'" name="error" />
|
|
102
|
-
</div>
|
|
103
|
-
</template>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, onMounted, watch, onBeforeUnmount, computed } from 'vue'
|
|
3
|
+
import { useScriptIntercom } from '../registry/intercom'
|
|
4
|
+
import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
|
|
5
|
+
import type { ElementScriptTrigger } from '#nuxt-scripts/types'
|
|
6
|
+
|
|
7
|
+
const props = withDefaults(defineProps<{
|
|
8
|
+
appId: string
|
|
9
|
+
apiBase?: string
|
|
10
|
+
name?: string
|
|
11
|
+
email?: string
|
|
12
|
+
userId?: string
|
|
13
|
+
// customizing the messenger
|
|
14
|
+
alignment?: 'left' | 'right'
|
|
15
|
+
horizontalPadding?: number
|
|
16
|
+
verticalPadding?: number
|
|
17
|
+
/**
|
|
18
|
+
* Defines the trigger event to load the script.
|
|
19
|
+
*/
|
|
20
|
+
trigger?: ElementScriptTrigger
|
|
21
|
+
}>(), {
|
|
22
|
+
trigger: 'click',
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const emits = defineEmits<{
|
|
26
|
+
// our emit
|
|
27
|
+
ready: [e: ReturnType<typeof useScriptIntercom>]
|
|
28
|
+
error: []
|
|
29
|
+
}>()
|
|
30
|
+
|
|
31
|
+
const rootEl = ref(null)
|
|
32
|
+
const trigger = useScriptTriggerElement({ trigger: props.trigger, el: rootEl })
|
|
33
|
+
|
|
34
|
+
const isReady = ref(false)
|
|
35
|
+
const intercom = useScriptIntercom({
|
|
36
|
+
app_id: props.appId,
|
|
37
|
+
// @ts-expect-error untyped
|
|
38
|
+
app_base: props.apiBase,
|
|
39
|
+
name: props.name,
|
|
40
|
+
email: props.email,
|
|
41
|
+
user_id: props.userId,
|
|
42
|
+
alignment: props.alignment,
|
|
43
|
+
horizontal_padding: props.horizontalPadding,
|
|
44
|
+
vertical_padding: props.verticalPadding,
|
|
45
|
+
scriptOptions: {
|
|
46
|
+
trigger,
|
|
47
|
+
},
|
|
48
|
+
})
|
|
49
|
+
const { status, onLoaded } = intercom
|
|
50
|
+
if (props.trigger === 'click') {
|
|
51
|
+
onLoaded((instance) => {
|
|
52
|
+
instance.Intercom('show')
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
defineExpose({
|
|
57
|
+
intercom,
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
let observer: MutationObserver
|
|
61
|
+
onMounted(() => {
|
|
62
|
+
watch(status, (status) => {
|
|
63
|
+
if (status === 'loading') {
|
|
64
|
+
observer = new MutationObserver(() => {
|
|
65
|
+
if (document.getElementById('intercom-frame')) {
|
|
66
|
+
isReady.value = true
|
|
67
|
+
emits('ready', intercom)
|
|
68
|
+
observer.disconnect()
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
observer.observe(document.body, { childList: true, subtree: true })
|
|
72
|
+
}
|
|
73
|
+
else if (status === 'error')
|
|
74
|
+
emits('error')
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
onBeforeUnmount(() => {
|
|
78
|
+
observer?.disconnect()
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
const rootAttrs = computed(() => {
|
|
82
|
+
return {
|
|
83
|
+
style: {
|
|
84
|
+
display: isReady.value ? 'none' : 'block',
|
|
85
|
+
bottom: `${props.verticalPadding || 20}px`,
|
|
86
|
+
[props.alignment || 'right']: `${props.horizontalPadding || 20}px`,
|
|
87
|
+
},
|
|
88
|
+
...(trigger instanceof Promise ? trigger.ssrAttrs || {} : {}),
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
</script>
|
|
92
|
+
|
|
93
|
+
<template>
|
|
94
|
+
<div
|
|
95
|
+
ref="rootEl"
|
|
96
|
+
v-bind="rootAttrs"
|
|
97
|
+
>
|
|
98
|
+
<slot :ready="isReady" />
|
|
99
|
+
<slot v-if="status === 'awaitingLoad'" name="awaitingLoad" />
|
|
100
|
+
<slot v-else-if="status === 'loading' || !isReady" name="loading" />
|
|
101
|
+
<slot v-else-if="status === 'error'" name="error" />
|
|
102
|
+
</div>
|
|
103
|
+
</template>
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import { computed, onMounted, ref } from 'vue'
|
|
3
|
-
import type { ElementScriptTrigger } from '../types'
|
|
4
|
-
import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
|
|
5
|
-
import { useScriptLemonSqueezy } from '../registry/lemon-squeezy'
|
|
6
|
-
import type { LemonSqueezyEventPayload } from '../registry/lemon-squeezy'
|
|
7
|
-
|
|
8
|
-
const props = withDefaults(defineProps<{
|
|
9
|
-
trigger?: ElementScriptTrigger
|
|
10
|
-
}>(), {
|
|
11
|
-
trigger: 'visible',
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
const emits = defineEmits<{
|
|
15
|
-
ready: [ReturnType<typeof useScriptLemonSqueezy>]
|
|
16
|
-
lemonSqueezyEvent: [LemonSqueezyEventPayload]
|
|
17
|
-
}>()
|
|
18
|
-
|
|
19
|
-
const rootEl = ref<HTMLElement | null>(null)
|
|
20
|
-
const trigger = useScriptTriggerElement({ trigger: props.trigger, el: rootEl })
|
|
21
|
-
const instance = useScriptLemonSqueezy({
|
|
22
|
-
scriptOptions: {
|
|
23
|
-
trigger,
|
|
24
|
-
},
|
|
25
|
-
})
|
|
26
|
-
onMounted(() => {
|
|
27
|
-
rootEl.value?.querySelectorAll('a[href]').forEach((a) => {
|
|
28
|
-
a.classList.add('lemonsqueezy-button')
|
|
29
|
-
})
|
|
30
|
-
instance.onLoaded(({ Setup, Refresh }) => {
|
|
31
|
-
Setup({
|
|
32
|
-
eventHandler(event) {
|
|
33
|
-
emits('lemonSqueezyEvent', event)
|
|
34
|
-
},
|
|
35
|
-
})
|
|
36
|
-
Refresh()
|
|
37
|
-
emits('ready', instance)
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
const rootAttrs = computed(() => {
|
|
42
|
-
return {
|
|
43
|
-
...(trigger instanceof Promise ? trigger.ssrAttrs || {} : {}),
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
</script>
|
|
47
|
-
|
|
48
|
-
<template>
|
|
49
|
-
<div ref="rootEl" v-bind="rootAttrs">
|
|
50
|
-
<slot />
|
|
51
|
-
</div>
|
|
52
|
-
</template>
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { computed, onMounted, ref } from 'vue'
|
|
3
|
+
import type { ElementScriptTrigger } from '../types'
|
|
4
|
+
import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
|
|
5
|
+
import { useScriptLemonSqueezy } from '../registry/lemon-squeezy'
|
|
6
|
+
import type { LemonSqueezyEventPayload } from '../registry/lemon-squeezy'
|
|
7
|
+
|
|
8
|
+
const props = withDefaults(defineProps<{
|
|
9
|
+
trigger?: ElementScriptTrigger
|
|
10
|
+
}>(), {
|
|
11
|
+
trigger: 'visible',
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const emits = defineEmits<{
|
|
15
|
+
ready: [ReturnType<typeof useScriptLemonSqueezy>]
|
|
16
|
+
lemonSqueezyEvent: [LemonSqueezyEventPayload]
|
|
17
|
+
}>()
|
|
18
|
+
|
|
19
|
+
const rootEl = ref<HTMLElement | null>(null)
|
|
20
|
+
const trigger = useScriptTriggerElement({ trigger: props.trigger, el: rootEl })
|
|
21
|
+
const instance = useScriptLemonSqueezy({
|
|
22
|
+
scriptOptions: {
|
|
23
|
+
trigger,
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
onMounted(() => {
|
|
27
|
+
rootEl.value?.querySelectorAll('a[href]').forEach((a) => {
|
|
28
|
+
a.classList.add('lemonsqueezy-button')
|
|
29
|
+
})
|
|
30
|
+
instance.onLoaded(({ Setup, Refresh }) => {
|
|
31
|
+
Setup({
|
|
32
|
+
eventHandler(event) {
|
|
33
|
+
emits('lemonSqueezyEvent', event)
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
Refresh()
|
|
37
|
+
emits('ready', instance)
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const rootAttrs = computed(() => {
|
|
42
|
+
return {
|
|
43
|
+
...(trigger instanceof Promise ? trigger.ssrAttrs || {} : {}),
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<template>
|
|
49
|
+
<div ref="rootEl" v-bind="rootAttrs">
|
|
50
|
+
<slot />
|
|
51
|
+
</div>
|
|
52
|
+
</template>
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { computed } from 'vue'
|
|
3
|
-
|
|
4
|
-
const props = withDefaults(defineProps<{
|
|
5
|
-
color?: string
|
|
6
|
-
size?: number
|
|
7
|
-
}>(), {
|
|
8
|
-
color: 'currentColor',
|
|
9
|
-
size: 30,
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
const styles = computed(() => ({
|
|
13
|
-
width: `${props.size}px`,
|
|
14
|
-
height: `${props.size}px`,
|
|
15
|
-
}))
|
|
16
|
-
</script>
|
|
17
|
-
|
|
18
|
-
<template>
|
|
19
|
-
<div class="loader" :styles="styles" aria-label="Loading..." role="status" />
|
|
20
|
-
</template>
|
|
21
|
-
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
|
|
4
|
+
const props = withDefaults(defineProps<{
|
|
5
|
+
color?: string
|
|
6
|
+
size?: number
|
|
7
|
+
}>(), {
|
|
8
|
+
color: 'currentColor',
|
|
9
|
+
size: 30,
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
const styles = computed(() => ({
|
|
13
|
+
width: `${props.size}px`,
|
|
14
|
+
height: `${props.size}px`,
|
|
15
|
+
}))
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<template>
|
|
19
|
+
<div class="loader" :styles="styles" aria-label="Loading..." role="status" />
|
|
20
|
+
</template>
|
|
21
|
+
|
|
22
22
|
<style scoped>
|
|
23
23
|
.loader{animation:rotation 1s linear infinite;border:5px solid v-bind(color);border-bottom-color:transparent;border-radius:50%;box-sizing:border-box;display:inline-block;opacity:.5}@keyframes rotation{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}
|
|
24
|
-
</style>
|
|
24
|
+
</style>
|
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { ref, computed, onBeforeUnmount, onMounted, watch } from 'vue'
|
|
3
|
-
import type { ElementScriptTrigger } from '../types'
|
|
4
|
-
import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
|
|
5
|
-
import { useScript } from '#imports'
|
|
6
|
-
|
|
7
|
-
const props = withDefaults(defineProps<{
|
|
8
|
-
trigger?: ElementScriptTrigger
|
|
9
|
-
publishableKey: string
|
|
10
|
-
pricingTableId: string
|
|
11
|
-
clientReferenceId?: string
|
|
12
|
-
customerEmail?: string
|
|
13
|
-
customerSessionClientSecret?: string
|
|
14
|
-
}>(), {
|
|
15
|
-
trigger: 'visible',
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
const emit = defineEmits<{
|
|
19
|
-
ready: [ReturnType<typeof useScript>]
|
|
20
|
-
error: []
|
|
21
|
-
}>()
|
|
22
|
-
|
|
23
|
-
const rootEl = ref<HTMLDivElement | undefined>()
|
|
24
|
-
const containerEl = ref<HTMLDivElement | undefined>()
|
|
25
|
-
const trigger = useScriptTriggerElement({ trigger: props.trigger, el: rootEl })
|
|
26
|
-
const instance = useScript(`https://js.stripe.com/v3/pricing-table.js`, {
|
|
27
|
-
trigger,
|
|
28
|
-
})
|
|
29
|
-
const { onLoaded, status } = instance
|
|
30
|
-
|
|
31
|
-
const pricingTable = ref<HTMLElement | undefined>()
|
|
32
|
-
onMounted(() => {
|
|
33
|
-
onLoaded(() => {
|
|
34
|
-
const StripePricingTable = window.customElements.get('stripe-pricing-table')!
|
|
35
|
-
const stripePricingTable = new StripePricingTable()
|
|
36
|
-
stripePricingTable.setAttribute('publishable-key', props.publishableKey)
|
|
37
|
-
stripePricingTable.setAttribute('pricing-table-id', props.pricingTableId)
|
|
38
|
-
if (props.clientReferenceId)
|
|
39
|
-
stripePricingTable.setAttribute('client-reference-id', props.clientReferenceId)
|
|
40
|
-
if (props.customerEmail)
|
|
41
|
-
stripePricingTable.setAttribute('customer-email', props.customerEmail)
|
|
42
|
-
if (props.customerSessionClientSecret)
|
|
43
|
-
stripePricingTable.setAttribute('customer-session-client-secret', props.customerSessionClientSecret)
|
|
44
|
-
pricingTable.value = stripePricingTable
|
|
45
|
-
rootEl.value!.appendChild(stripePricingTable)
|
|
46
|
-
emit('ready', instance)
|
|
47
|
-
})
|
|
48
|
-
watch(status, (status) => {
|
|
49
|
-
if (status === 'error') {
|
|
50
|
-
emit('error')
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
onBeforeUnmount(() => {
|
|
56
|
-
pricingTable.value?.remove()
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
const rootAttrs = computed(() => {
|
|
60
|
-
return {
|
|
61
|
-
...(trigger instanceof Promise ? trigger.ssrAttrs || {} : {}),
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
</script>
|
|
65
|
-
|
|
66
|
-
<template>
|
|
67
|
-
<div ref="rootEl" v-bind="rootAttrs">
|
|
68
|
-
<div ref="containerEl" />
|
|
69
|
-
<slot v-if="status === 'loading'" name="loading" />
|
|
70
|
-
<slot v-if="status === 'awaitingLoad'" name="awaitingLoad" />
|
|
71
|
-
<slot v-else-if="status === 'error'" name="error" />
|
|
72
|
-
<slot />
|
|
73
|
-
</div>
|
|
74
|
-
</template>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, computed, onBeforeUnmount, onMounted, watch } from 'vue'
|
|
3
|
+
import type { ElementScriptTrigger } from '../types'
|
|
4
|
+
import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
|
|
5
|
+
import { useScript } from '#imports'
|
|
6
|
+
|
|
7
|
+
const props = withDefaults(defineProps<{
|
|
8
|
+
trigger?: ElementScriptTrigger
|
|
9
|
+
publishableKey: string
|
|
10
|
+
pricingTableId: string
|
|
11
|
+
clientReferenceId?: string
|
|
12
|
+
customerEmail?: string
|
|
13
|
+
customerSessionClientSecret?: string
|
|
14
|
+
}>(), {
|
|
15
|
+
trigger: 'visible',
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const emit = defineEmits<{
|
|
19
|
+
ready: [ReturnType<typeof useScript>]
|
|
20
|
+
error: []
|
|
21
|
+
}>()
|
|
22
|
+
|
|
23
|
+
const rootEl = ref<HTMLDivElement | undefined>()
|
|
24
|
+
const containerEl = ref<HTMLDivElement | undefined>()
|
|
25
|
+
const trigger = useScriptTriggerElement({ trigger: props.trigger, el: rootEl })
|
|
26
|
+
const instance = useScript(`https://js.stripe.com/v3/pricing-table.js`, {
|
|
27
|
+
trigger,
|
|
28
|
+
})
|
|
29
|
+
const { onLoaded, status } = instance
|
|
30
|
+
|
|
31
|
+
const pricingTable = ref<HTMLElement | undefined>()
|
|
32
|
+
onMounted(() => {
|
|
33
|
+
onLoaded(() => {
|
|
34
|
+
const StripePricingTable = window.customElements.get('stripe-pricing-table')!
|
|
35
|
+
const stripePricingTable = new StripePricingTable()
|
|
36
|
+
stripePricingTable.setAttribute('publishable-key', props.publishableKey)
|
|
37
|
+
stripePricingTable.setAttribute('pricing-table-id', props.pricingTableId)
|
|
38
|
+
if (props.clientReferenceId)
|
|
39
|
+
stripePricingTable.setAttribute('client-reference-id', props.clientReferenceId)
|
|
40
|
+
if (props.customerEmail)
|
|
41
|
+
stripePricingTable.setAttribute('customer-email', props.customerEmail)
|
|
42
|
+
if (props.customerSessionClientSecret)
|
|
43
|
+
stripePricingTable.setAttribute('customer-session-client-secret', props.customerSessionClientSecret)
|
|
44
|
+
pricingTable.value = stripePricingTable
|
|
45
|
+
rootEl.value!.appendChild(stripePricingTable)
|
|
46
|
+
emit('ready', instance)
|
|
47
|
+
})
|
|
48
|
+
watch(status, (status) => {
|
|
49
|
+
if (status === 'error') {
|
|
50
|
+
emit('error')
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
onBeforeUnmount(() => {
|
|
56
|
+
pricingTable.value?.remove()
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
const rootAttrs = computed(() => {
|
|
60
|
+
return {
|
|
61
|
+
...(trigger instanceof Promise ? trigger.ssrAttrs || {} : {}),
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<template>
|
|
67
|
+
<div ref="rootEl" v-bind="rootAttrs">
|
|
68
|
+
<div ref="containerEl" />
|
|
69
|
+
<slot v-if="status === 'loading'" name="loading" />
|
|
70
|
+
<slot v-if="status === 'awaitingLoad'" name="awaitingLoad" />
|
|
71
|
+
<slot v-else-if="status === 'error'" name="error" />
|
|
72
|
+
<slot />
|
|
73
|
+
</div>
|
|
74
|
+
</template>
|