Skip to content

Commit

Permalink
fix(plugin-watermark): fix option reactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed May 6, 2024
1 parent 969b03b commit 5d3cdf1
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions plugins/plugin-watermark/src/client/composables/setupWatermark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,18 @@ export const setupWatermark = (
enabled: Ref<boolean>,
delay = 500,
): void => {
const isInsideApp = (target?: string | Element): boolean => {
const el =
typeof target === 'string' ? document.querySelector(target) : target

return Boolean(
el &&
(getCurrentInstance()?.appContext.app._container as Element).contains?.(
el,
),
)
}

onMounted(() => {
const appContainer: Element | null =
getCurrentInstance()?.appContext.app._container
const watermark = new Watermark()

const isInsideApp = (target?: string | Element): boolean => {
const el =
typeof target === 'string' ? document.querySelector(target) : target

return Boolean(el && appContainer?.contains(el))
}

const updateWaterMark = (
// shadow clone options object so that we can modify later
{ ...options }: WatermarkOptions,
Expand All @@ -50,14 +47,7 @@ export const setupWatermark = (
else watermark.changeOptions(options, 'overwrite', false)
}

if (isRef(options))
watch(
() => options,
() => {
updateWaterMark(options.value)
},
{ immediate: true },
)
if (isRef(options)) watch(options, updateWaterMark, { immediate: true })
else updateWaterMark(options)

watch(enabled, () =>
Expand Down

0 comments on commit 5d3cdf1

Please sign in to comment.