wip bsky client for the web & android
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(popover): make unwraptoelement more robust + properly typed

vi cf852a78 e1fc8b27

+64 -6
+41
diff
··· 1 + diff --git a/src/components/UI/BasePopover.vue b/src/components/UI/BasePopover.vue 2 + index 89a50e1..1251ba2 100644 3 + --- a/src/components/UI/BasePopover.vue 4 + +++ b/src/components/UI/BasePopover.vue 5 + @@ -38,13 +38,30 @@ const emit = defineEmits<{ 6 + (e: 'close'): void 7 + }>() 8 + 9 + -const unwrapToElement = (maybeEl: unknown): HTMLElement | null => { 10 + - if (!maybeEl) return null 11 + - 12 + +function unwrapToElement(maybeEl: unknown): HTMLElement | null { 13 + if (maybeEl instanceof HTMLElement) return maybeEl 14 + - if (maybeEl.$el instanceof HTMLElement) return maybeEl.$el as HTMLElement 15 + - if (maybeEl.$el?.value instanceof HTMLElement) return maybeEl.$el.value as HTMLElement 16 + - if (maybeEl.value instanceof HTMLElement) return maybeEl.value as HTMLElement 17 + + 18 + + if (maybeEl && typeof maybeEl === 'object') { 19 + + const obj = maybeEl as Record<string, unknown> 20 + + 21 + + if ('$el' in obj) { 22 + + const $el = (obj as { $el?: unknown }).$el 23 + + if ($el instanceof HTMLElement) return $el 24 + + if ($el && typeof $el === 'object' && 'value' in ($el as Record<string, unknown>)) { 25 + + const v = ($el as { value?: unknown }).value 26 + + if (v instanceof HTMLElement) return v 27 + + } 28 + + } 29 + + 30 + + if ('value' in obj) { 31 + + const v = (obj as { value?: unknown }).value 32 + + if (v instanceof HTMLElement) return v 33 + + if (v && typeof v === 'object' && '$el' in (v as Record<string, unknown>)) { 34 + + const nested = (v as { $el?: unknown }).$el 35 + + if (nested instanceof HTMLElement) return nested 36 + + } 37 + + } 38 + + } 39 + 40 + return null 41 + }
+23 -6
src/components/UI/BasePopover.vue
··· 38 38 (e: 'close'): void 39 39 }>() 40 40 41 - const unwrapToElement = (maybeEl: unknown): HTMLElement | null => { 42 - if (!maybeEl) return null 41 + function unwrapToElement(maybeEl: unknown): HTMLElement | null { 42 + if (maybeEl instanceof HTMLElement) return maybeEl 43 + 44 + if (maybeEl && typeof maybeEl === 'object') { 45 + const obj = maybeEl as Record<string, unknown> 46 + 47 + if ('$el' in obj) { 48 + const $el = (obj as { $el?: unknown }).$el 49 + if ($el instanceof HTMLElement) return $el 50 + if ($el && typeof $el === 'object' && 'value' in ($el as Record<string, unknown>)) { 51 + const v = ($el as { value?: unknown }).value 52 + if (v instanceof HTMLElement) return v 53 + } 54 + } 43 55 44 - if (maybeEl instanceof HTMLElement) return maybeEl 45 - if (maybeEl.$el instanceof HTMLElement) return maybeEl.$el as HTMLElement 46 - if (maybeEl.$el?.value instanceof HTMLElement) return maybeEl.$el.value as HTMLElement 47 - if (maybeEl.value instanceof HTMLElement) return maybeEl.value as HTMLElement 56 + if ('value' in obj) { 57 + const v = (obj as { value?: unknown }).value 58 + if (v instanceof HTMLElement) return v 59 + if (v && typeof v === 'object' && '$el' in (v as Record<string, unknown>)) { 60 + const nested = (v as { $el?: unknown }).$el 61 + if (nested instanceof HTMLElement) return nested 62 + } 63 + } 64 + } 48 65 49 66 return null 50 67 }