Skip to content

Commit 077e087

Browse files
authored
Merge pull request #1130 from privy-open-source/refactor/script-setup
refactor: rename `toast` to `popup`
2 parents fc34189 + 235a847 commit 077e087

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3083
-1755
lines changed

package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"@vitest/browser": "^0.25.3",
4747
"@vitest/coverage-c8": "0.24.5",
4848
"@vue/eslint-config-typescript": "12.0.0",
49-
"autoprefixer": "10.4.16",
49+
"autoprefixer": "10.4.17",
5050
"browserslist-to-esbuild": "^1.2.0",
5151
"eslint": "8.56.0",
5252
"eslint-config-standard-with-typescript": "latest",
@@ -69,13 +69,14 @@
6969
"tailwindcss": "3.4.1",
7070
"typescript": "5.3.3",
7171
"ufo": "^1.0.1",
72-
"vitepress": "1.0.0-rc.36",
72+
"vitepress": "1.0.0-rc.40",
7373
"vitest": "0.24.5",
7474
"vue-tsc": "1.8.27"
7575
},
7676
"dependencies": {
7777
"@floating-ui/dom": "^1.0.4",
7878
"@fontsource/dm-sans": "5.0.18",
79+
"@jill64/universal-sanitizer": "^1.0.2",
7980
"@juggle/resize-observer": "^3.4.0",
8081
"@privyid/persona-icon": "workspace:^",
8182
"@splidejs/splide": "^4.1.4",
@@ -92,19 +93,17 @@
9293
"fuse.js": "7.0.0",
9394
"interactjs": "1.10.26",
9495
"lodash-es": "4.17.21",
95-
"marked": "^5.0.0",
96+
"marked": "^11.0.0",
9697
"nanodelay": "2.0.2",
9798
"pdfjs-dist": "^3.10.111",
9899
"postcss-hexrgba": "^2.1.0",
99100
"postcss-lighten-darken": "^0.9.0",
100-
"sanitize-html": "^2.8.1",
101101
"scroll-into-view": "^1.16.2",
102102
"tabbable": "6.2.0",
103103
"vue-collapsed": "^1.2.5",
104104
"vue-content-loader": "^2.0.1",
105105
"vue-demi": "0.14.6",
106106
"vue-router": "4.2.5",
107-
"vue3-iframe": "^0.0.7",
108107
"vuedraggable": "next",
109108
"webfontloader": "1.6.28",
110109
"zxcvbn": "^4.4.2"
@@ -116,5 +115,8 @@
116115
},
117116
"workspaces": [
118117
"packages/*"
119-
]
118+
],
119+
"resolutions": {
120+
"@vue/runtime-core": "3.4.15"
121+
}
120122
}

packages/persona/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
},
6060
"dependencies": {
6161
"@floating-ui/dom": "1.5.4",
62+
"@jill64/universal-sanitizer": "^1.0.2",
6263
"@juggle/resize-observer": "3.4.0",
6364
"@nuxt/kit": "3.9.3",
6465
"@splidejs/splide": "4.1.4",
@@ -76,10 +77,9 @@
7677
"fuse.js": "7.0.0",
7778
"interactjs": "1.10.26",
7879
"lodash-es": "4.17.21",
79-
"marked": "5.1.2",
80+
"marked": "11.1.1",
8081
"nanodelay": "2.0.2",
8182
"pdfjs-dist": "3.11.174",
82-
"sanitize-html": "2.11.0",
8383
"scroll-into-view": "1.16.2",
8484
"tabbable": "6.2.0",
8585
"vue-collapsed": "1.2.9",

packages/persona/src/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default defineNuxtModule<ModuleOptions>({
6262
config.optimizeDeps?.include?.push(
6363
'@testing-library/user-event',
6464
'interactjs',
65-
'sanitize-html',
65+
'@jill64/universal-sanitizer',
6666
'scroll-into-view',
6767
'webfontloader',
6868
'zxcvbn',

packages/tailwind-preset/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ module.exports = {
317317
DEFAULT : 1085,
318318
backdrop: 1080,
319319
},
320-
toast: 1090,
320+
notify: 1090,
321321
},
322322
minWidth : ({ theme }) => ({ ...theme('spacing') }),
323323
maxWidth : ({ theme }) => ({ ...theme('spacing') }),

src/.vitepress/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,10 @@ export default defineConfig({
385385
text: 'Overlay',
386386
link: '/components/overlay/',
387387
},
388+
{
389+
text: 'Popup',
390+
link: '/components/popup/',
391+
},
388392
{
389393
text: 'Toast',
390394
link: '/components/toast/',

src/components/cropper/Cropper.spec.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { resolve } from 'node:path'
1313
import { delay } from 'nanodelay'
1414
import { nextTick, ref } from 'vue-demi'
1515
import { createSpinner } from '../avatar/utils/create-image'
16+
import type * as VueUse from '@vueuse/core'
1617

1718
// eslint-disable-next-line unicorn/prefer-module
1819
const blob = readFileSync(resolve(__dirname, '../../public/assets/images/img-sample-crop.jpg'))
@@ -24,6 +25,20 @@ vi.mock('./utils/use-pinch.ts', () => ({ usePinch }))
2425

2526
vi.mock('../input-range/utils/use-drag.ts', () => ({ default: vi.fn() }))
2627

28+
vi.mock('@vueuse/core', async () => {
29+
const vueuse = await vi.importActual('@vueuse/core')
30+
const useThrottleFn = (handler: () => void) => {
31+
return (...args: any[]) => {
32+
handler.apply(this, args)
33+
}
34+
}
35+
36+
return {
37+
...vueuse as typeof VueUse,
38+
useThrottleFn,
39+
}
40+
})
41+
2742
afterEach(() => {
2843
vi.restoreAllMocks()
2944
})
@@ -183,13 +198,13 @@ it('should able to zoomIn / zoomOut using mouse wheel', async () => {
183198
// Zoom in
184199
await fireEvent.wheel(container, { deltaY: 60 })
185200

186-
expect(preview).toHaveStyle({ transform: 'rotate(0deg) translate(0px, 0px) scale(1.1)' })
201+
expect(preview).toHaveStyle({ transform: 'rotate(0deg) translate(0px, 0px) scale(1.6)' })
187202

188203
// Zoom out
189204
await fireEvent.wheel(container, { deltaY: -60 })
190205
await fireEvent.wheel(container, { deltaY: -60 })
191206

192-
expect(preview).toHaveStyle({ transform: 'rotate(0deg) translate(0px, 0px) scale(0.9)' })
207+
expect(preview).toHaveStyle({ transform: 'rotate(0deg) translate(0px, 0px) scale(0.5)' })
193208
})
194209

195210
it('should able to move using keyboard arrow', async () => {

src/components/cropper/Cropper.vue

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
</template>
110110

111111
<script lang="ts" setup>
112-
import { watchDebounced } from '@vueuse/core'
112+
import { watchDebounced, useThrottleFn } from '@vueuse/core'
113113
import { useClamp } from '@vueuse/math'
114114
import type {
115115
PropType,
@@ -322,15 +322,12 @@ function crop (): string {
322322
}
323323
}
324324
325-
function onMouseWheel (event: WheelEvent) {
325+
const onMouseWheel = useThrottleFn((event: WheelEvent) => {
326326
if (image.value)
327327
image.value.focus()
328328
329-
if (event.deltaY > 0)
330-
zoomIn()
331-
else
332-
zoomOut()
333-
}
329+
scale.value += event.deltaY * 0.01
330+
}, 1000 / 30 /* Limit 30 Fps */)
334331
335332
function onImageLoaded () {
336333
emit('load')

src/components/cropper/index.ts

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,3 @@
1-
import { createSpinner } from '../avatar/utils/create-image'
2-
import type { MaybeRef } from '@vueuse/core'
3-
import {
4-
tryOnMounted,
5-
tryOnBeforeUnmount,
6-
} from '@vueuse/core'
7-
import type { Ref } from 'vue-demi'
8-
import {
9-
ref,
10-
unref,
11-
watch,
12-
} from 'vue-demi'
13-
14-
export function usePreview (file: MaybeRef<string | globalThis.File>, fallback = createSpinner(512, 512)): Ref<string> {
15-
const preview = ref(fallback)
16-
17-
watch(() => unref(file), (value) => {
18-
if (preview.value?.startsWith('blob'))
19-
window.URL.revokeObjectURL(preview.value)
20-
21-
preview.value = value instanceof globalThis.File
22-
? window.URL.createObjectURL(value)
23-
: (value ?? fallback)
24-
})
25-
26-
tryOnMounted(() => {
27-
const value = unref(file)
28-
29-
if (value) {
30-
preview.value = value instanceof globalThis.File
31-
? window.URL.createObjectURL(value)
32-
: value
33-
}
34-
})
35-
36-
tryOnBeforeUnmount(() => {
37-
if (preview.value?.startsWith('blob'))
38-
window.URL.revokeObjectURL(preview.value)
39-
})
40-
41-
return preview
42-
}
1+
export {
2+
usePreview,
3+
} from './utils/use-preview'
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { createSpinner } from '../../avatar/utils/create-image'
2+
import type { MaybeRef } from '@vueuse/core'
3+
import type { Ref } from 'vue-demi'
4+
import {
5+
ref,
6+
unref,
7+
watchEffect,
8+
} from 'vue-demi'
9+
10+
export function usePreview (file: MaybeRef<string | globalThis.File>, fallback = createSpinner(512, 512)): Ref<string> {
11+
const preview = ref(fallback)
12+
13+
watchEffect((onCleanup) => {
14+
const value = unref(file)
15+
16+
if (value instanceof globalThis.File) {
17+
const url = window.URL.createObjectURL(value)
18+
19+
onCleanup(() => {
20+
window.URL.revokeObjectURL(url)
21+
})
22+
23+
preview.value = url
24+
} else
25+
preview.value = value ?? fallback
26+
})
27+
28+
return preview
29+
}

src/components/dialog/Dialog.vue

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
v-if="context"
44
:key="id"
55
v-model="modal"
6+
v-bind="context.attrs"
67
class="dialog"
78
:title="context.title"
89
:size="context.size"
910
:centered="context.centered"
1011
:dismissable="context.dismissable"
1112
:no-close-on-backdrop="context.noCloseOnBackdrop"
13+
@show="onModalShow"
14+
@hide="onModalHide"
1215
@close="onCancel">
1316
<template #header>
1417
<Heading
@@ -32,11 +35,13 @@
3235
:cancel-color="context.cancel.color"
3336
:cancel-variant="context.cancel.variant"
3437
:cancel-text="context.cancel.text"
38+
:cancel-attrs="context.cancel.attrs"
3539
:confirm-class="context.confirm.className"
3640
:confirm-visible="context.confirm.visible"
3741
:confirm-color="context.confirm.color"
3842
:confirm-variant="context.confirm.variant"
3943
:confirm-text="context.confirm.text"
44+
:confirm-attrs="context.confirm.attrs"
4045
@confirm="onConfirm"
4146
@cancel="onCancel" />
4247
</template>
@@ -50,40 +55,52 @@ import Heading from '../heading/Heading.vue'
5055
import DialogFooter from './DialogFooter.vue'
5156
import type { DialogContext } from '.'
5257
import { vPMd } from '../markdown'
58+
import { until } from '@vueuse/core'
5359
54-
const id = ref<symbol>()
55-
const modal = ref(false)
56-
const context = ref<DialogContext>()
60+
const id = ref<symbol>()
61+
const modal = ref(false)
62+
const processing = ref(false)
63+
const context = ref<DialogContext>()
5764
58-
function show (options: DialogContext) {
65+
async function show (options: DialogContext) {
5966
id.value = Symbol('DialogId')
6067
context.value = options
6168
62-
nextTick(() => {
63-
modal.value = true
64-
})
65-
}
69+
await nextTick()
70+
71+
modal.value = true
72+
processing.value = true
6673
67-
function hide () {
68-
modal.value = false
74+
// Wait animation done
75+
await until(processing).toBe(false)
6976
}
7077
71-
function onConfirm () {
72-
hide()
78+
async function hide () {
79+
modal.value = false
80+
processing.value = true
7381
7482
// Wait animation done
75-
setTimeout(() => {
76-
context.value.onConfirm()
77-
}, 150)
83+
await until(processing).toBe(false)
7884
}
7985
80-
function onCancel () {
81-
hide()
86+
async function onConfirm () {
87+
await hide()
8288
83-
// Wait animation done
84-
setTimeout(() => {
85-
context.value.onCancel()
86-
}, 150)
89+
context.value.onConfirm()
90+
}
91+
92+
async function onCancel () {
93+
await hide()
94+
95+
context.value.onCancel()
96+
}
97+
98+
function onModalHide () {
99+
processing.value = false
100+
}
101+
102+
function onModalShow () {
103+
processing.value = false
87104
}
88105
89106
defineExpose({

0 commit comments

Comments
 (0)