@dargmuesli/nuxt-vio 20.1.0 → 21.0.0-beta.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.
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <span v-if="url" class="flex items-center gap-2">
3
3
  <slot />
4
- <VioButtonColored :aria-label="t('share')" @click="copy(url)">
4
+ <VioButtonColored :aria-label="t('share')" @click="copy2(url)">
5
5
  <template #prefix>
6
6
  <VioIconShare />
7
7
  </template>
@@ -19,17 +19,21 @@ interface Props {
19
19
  withDefaults(defineProps<Props>(), {})
20
20
 
21
21
  const { t } = useI18n()
22
+ const { copy } = useCopy()
23
+ const alertError = useAlertError()
22
24
 
23
25
  // methods
24
- const copy = async (string: string) => {
26
+ const copy2 = async (string: string) => {
25
27
  if (typeof window === 'undefined') return
26
28
 
27
29
  try {
28
- await copyText(string)
30
+ await copy(string)
29
31
  toast.success(t('donationUrlCopySuccess'))
30
32
  } catch (error: unknown) {
31
- console.error(error)
32
- alert(t('donationUrlCopyError'))
33
+ alertError({
34
+ ...(error instanceof Error ? { error } : {}),
35
+ messageI18n: t('donationUrlCopyError'),
36
+ })
33
37
  }
34
38
  }
35
39
  </script>
@@ -1,3 +1,5 @@
1
+ import { useNow as useNowVueUse, syncRef } from '@vueuse/core'
2
+
1
3
  export const useTimeZone = () =>
2
4
  useNuxtApp().ssrContext?.event.context.$timeZone ||
3
5
  useCookie(TIMEZONE_COOKIE_NAME, {
@@ -9,15 +11,47 @@ export const useTimeZone = () =>
9
11
  ? Intl.DateTimeFormat().resolvedOptions().timeZone
10
12
  : undefined)
11
13
 
12
- export const useNow = () => useState(STATE_KEY_NOW, () => new Date())
14
+ // TODO: evaluate custom scheduler (https://github.com/vueuse/vueuse/pull/5129)
15
+ export const useNow = (options?: { live?: boolean }) => {
16
+ const { live = true } = options || {}
17
+
18
+ const nowState = useState(STATE_KEY_NOW, () => new Date())
19
+
20
+ if (live) {
21
+ const now = useNowVueUse()
22
+ syncRef(now, nowState, { direction: 'ltr', immediate: false })
23
+ }
24
+
25
+ return nowState
26
+ }
27
+
28
+ // TODO: import from vueuse once reactive locale can be passed in (no issue or PR created yet)
29
+ export const useTimeAgoIntl = (options: {
30
+ live?: boolean
31
+ to: MaybeRef<Date>
32
+ }) => {
33
+ const { live = true, to } = options
34
+
35
+ const { locale } = useI18n({ useScope: 'global' })
36
+ const now = useNow({ live })
37
+
38
+ const formatter = computed(
39
+ () =>
40
+ new Intl.RelativeTimeFormat(locale.value, {
41
+ numeric: 'auto',
42
+ }),
43
+ )
44
+
45
+ const toAsRef = toRef(to)
46
+ const fromTo = computed(() =>
47
+ getFromTo(now.value, toAsRef.value, formatter.value),
48
+ )
13
49
 
14
- export const useFromNow = () => {
15
- const { locale } = useI18n()
16
- const now = useNow()
50
+ const fromToState = useState(STATE_KEY_FROM_TO, () => fromTo)
17
51
 
18
- const formatter = new Intl.RelativeTimeFormat(locale.value, {
19
- numeric: 'auto',
20
- })
52
+ if (live) {
53
+ syncRef(fromTo, fromToState, { direction: 'ltr', immediate: false })
54
+ }
21
55
 
22
- return (to: Date) => getFromTo(now.value, to, formatter)
56
+ return fromToState
23
57
  }
package/package.json CHANGED
@@ -23,7 +23,6 @@
23
23
  "@vuelidate/validators": "2.0.4",
24
24
  "@vueuse/core": "14.1.0",
25
25
  "class-variance-authority": "0.7.1",
26
- "clipboardy": "5.0.1",
27
26
  "clsx": "2.1.1",
28
27
  "eslint": "9.39.1",
29
28
  "eslint-config-prettier": "10.1.8",
@@ -114,5 +113,5 @@
114
113
  "start:static": "serve playground/.output/public --ssl-cert ./.config/certificates/ssl.crt --ssl-key ./.config/certificates/ssl.key"
115
114
  },
116
115
  "type": "module",
117
- "version": "20.1.0"
116
+ "version": "21.0.0-beta.1"
118
117
  }
@@ -157,6 +157,7 @@ export const POLYFILLS = [
157
157
  export const REGEX_UUID =
158
158
  /^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/
159
159
  export const STATE_KEY_NOW = 'dateTimeNow'
160
+ export const STATE_KEY_FROM_TO = 'dateTimeFromTo'
160
161
  export const TESTING_COOKIE_NAME = 'vio_is-testing'
161
162
  export const TIMEZONE_COOKIE_NAME = [COOKIE_PREFIX, 'tz'].join(COOKIE_SEPARATOR)
162
163
  export const TIMEZONE_HEADER_KEY = `X-${VIO_SITE_NAME}-Timezone`
@@ -1,2 +0,0 @@
1
- export const copyText = async (text: string) =>
2
- (await import('clipboardy')).default.write(text)