qarpeo 0.1.7 → 0.1.8

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,196 +1,196 @@
1
- <script lang="ts" setup>
2
- import { ref, computed } from "vue"
3
- import { useUpload, type UploadedFile } from "../composables/storage"
4
-
5
- /**
6
- * `<FileUpload>` — Drag-and-drop file upload dropzone with progress and v-model support.
7
- * Supports custom slot for full UI control or uses a built-in dropzone UI.
8
- */
9
- const props = withDefaults(defineProps<{
10
- /** File types accepted (e.g. "image/*", ".pdf,.docx"). */
11
- accept?: string
12
- /** Allow multiple file selection. */
13
- multiple?: boolean
14
- /** Maximum file size allowed in bytes. */
15
- maxSize?: number
16
- /** Whether the dropzone is disabled. */
17
- disabled?: boolean
18
- /** Automatically trigger upload immediately on file selection. */
19
- autoUpload?: boolean
20
- /** Uploaded file(s) v-model. */
21
- modelValue?: UploadedFile | UploadedFile[] | null
22
- /** Use presigned direct-to-R2 upload ticket. */
23
- presigned?: boolean
24
- /** Additional CSS class for the wrapper container. */
25
- dropzoneClass?: string
26
- }>(), {
27
- multiple: false,
28
- disabled: false,
29
- autoUpload: true,
30
- modelValue: null,
31
- presigned: false,
32
- dropzoneClass: "",
33
- })
34
-
35
- const emit = defineEmits<{
36
- "update:modelValue": [value: UploadedFile | UploadedFile[] | null]
37
- change: [files: File | File[]]
38
- upload: [files: File[]]
39
- success: [result: UploadedFile | UploadedFile[]]
40
- error: [err: Error]
41
- progress: [percent: number]
42
- }>()
43
-
44
- const inputRef = ref<HTMLInputElement | null>(null)
45
- const isDragging = ref(false)
46
- const clientError = ref<string | null>(null)
47
-
48
- const { isUploading, progress, error, upload, uploadMultiple, reset } = useUpload()
49
-
50
- function open() {
51
- if (props.disabled || isUploading.value) return
52
- inputRef.value?.click()
53
- }
54
-
55
- function clear() {
56
- reset()
57
- clientError.value = null
58
- if (inputRef.value) inputRef.value.value = ""
59
- emit("update:modelValue", props.multiple ? [] : null)
60
- }
61
-
62
- async function processFiles(files: FileList | File[]) {
63
- clientError.value = null
64
- const fileList = Array.from(files)
65
- if (fileList.length === 0) return
66
-
67
- if (props.maxSize) {
68
- const oversized = fileList.find((f) => f.size > props.maxSize!)
69
- if (oversized) {
70
- const maxMb = (props.maxSize / (1024 * 1024)).toFixed(1)
71
- const msg = `File "${oversized.name}" exceeds maximum size of ${maxMb}MB`
72
- clientError.value = msg
73
- emit("error", new Error(msg))
74
- return
75
- }
76
- }
77
-
78
- emit("change", props.multiple ? fileList : fileList[0]!)
79
- if (!props.autoUpload) return
80
- emit("upload", fileList)
81
-
82
- try {
83
- if (props.multiple) {
84
- const results = await uploadMultiple(fileList)
85
- emit("update:modelValue", results)
86
- emit("success", results)
87
- } else {
88
- const result = await upload(fileList[0]!, { presigned: props.presigned })
89
- emit("update:modelValue", result)
90
- emit("success", result)
91
- }
92
- } catch (err: any) {
93
- clientError.value = err?.message || "Upload failed"
94
- emit("error", err)
95
- }
96
- }
97
-
98
- function onDrop(event: DragEvent) {
99
- event.preventDefault()
100
- isDragging.value = false
101
- if (props.disabled || isUploading.value) return
102
- if (event.dataTransfer?.files) processFiles(event.dataTransfer.files)
103
- }
104
-
105
- function onDragOver(event: DragEvent) {
106
- event.preventDefault()
107
- if (!props.disabled && !isUploading.value) isDragging.value = true
108
- }
109
-
110
- function onDragLeave(event: DragEvent) {
111
- event.preventDefault()
112
- isDragging.value = false
113
- }
114
-
115
- function onInputChange(event: Event) {
116
- const target = event.target as HTMLInputElement
117
- if (target.files) processFiles(target.files)
118
- }
119
-
120
- const displayError = computed(() => clientError.value || error.value?.message || null)
121
- </script>
122
-
123
- <template>
124
- <!-- Custom slot: users take full UI control -->
125
- <div
126
- v-if="$slots.default"
127
- :class="['qarpeo-file-upload', dropzoneClass]"
128
- @drop="onDrop"
129
- @dragover="onDragOver"
130
- @dragleave="onDragLeave"
131
- >
132
- <input
133
- ref="inputRef"
134
- type="file"
135
- :accept="accept"
136
- :multiple="multiple"
137
- class="hidden"
138
- @change="onInputChange"
139
- />
140
- <slot
141
- :is-dragging="isDragging"
142
- :is-uploading="isUploading"
143
- :progress="progress"
144
- :error="displayError"
145
- :open="open"
146
- :clear="clear"
147
- />
148
- </div>
149
-
150
- <!-- Built-in dropzone UI -->
151
- <div
152
- v-else
153
- class="qarpeo-file-upload-wrapper"
154
- @drop="onDrop"
155
- @dragover="onDragOver"
156
- @dragleave="onDragLeave"
157
- >
158
- <input
159
- ref="inputRef"
160
- type="file"
161
- :accept="accept"
162
- :multiple="multiple"
163
- class="hidden"
164
- @change="onInputChange"
165
- />
166
- <div
167
- :class="[
168
- 'rounded-lg border-2 border-dashed p-6 text-center transition-colors duration-200',
169
- isDragging
170
- ? 'border-primary-500 bg-primary-50/50 dark:bg-primary-950/20'
171
- : 'border-gray-300 dark:border-gray-700',
172
- disabled ? 'cursor-not-allowed opacity-60' : 'cursor-pointer',
173
- dropzoneClass,
174
- ]"
175
- @click="open"
176
- >
177
- <!-- Uploading state -->
178
- <div v-if="isUploading" class="space-y-2">
179
- <p class="text-sm text-gray-500">Uploading... {{ progress }}%</p>
180
- <UProgress :value="progress" size="xs" />
181
- </div>
182
-
183
- <!-- Idle / drag state -->
184
- <div v-else class="space-y-1">
185
- <UIcon name="i-lucide-upload-cloud" class="size-8 mx-auto text-gray-400" />
186
- <p class="text-sm font-medium text-gray-700 dark:text-gray-300">
187
- {{ isDragging ? "Drop files to upload" : "Click or drag files here to upload" }}
188
- </p>
189
- <p v-if="accept" class="text-xs text-gray-400">Accepted: {{ accept }}</p>
190
- </div>
191
-
192
- <!-- Error -->
193
- <p v-if="displayError" class="mt-2 text-xs text-red-500">{{ displayError }}</p>
194
- </div>
195
- </div>
196
- </template>
1
+ <script lang="ts" setup>
2
+ import { ref, computed } from "vue"
3
+ import { useUpload, type UploadedFile } from "../composables/storage"
4
+
5
+ /**
6
+ * `<FileUpload>` — Drag-and-drop file upload dropzone with progress and v-model support.
7
+ * Supports custom slot for full UI control or uses a built-in dropzone UI.
8
+ */
9
+ const props = withDefaults(defineProps<{
10
+ /** File types accepted (e.g. "image/*", ".pdf,.docx"). */
11
+ accept?: string
12
+ /** Allow multiple file selection. */
13
+ multiple?: boolean
14
+ /** Maximum file size allowed in bytes. */
15
+ maxSize?: number
16
+ /** Whether the dropzone is disabled. */
17
+ disabled?: boolean
18
+ /** Automatically trigger upload immediately on file selection. */
19
+ autoUpload?: boolean
20
+ /** Uploaded file(s) v-model. */
21
+ modelValue?: UploadedFile | UploadedFile[] | null
22
+ /** Use presigned direct-to-R2 upload ticket. */
23
+ presigned?: boolean
24
+ /** Additional CSS class for the wrapper container. */
25
+ dropzoneClass?: string
26
+ }>(), {
27
+ multiple: false,
28
+ disabled: false,
29
+ autoUpload: true,
30
+ modelValue: null,
31
+ presigned: false,
32
+ dropzoneClass: "",
33
+ })
34
+
35
+ const emit = defineEmits<{
36
+ "update:modelValue": [value: UploadedFile | UploadedFile[] | null]
37
+ change: [files: File | File[]]
38
+ upload: [files: File[]]
39
+ success: [result: UploadedFile | UploadedFile[]]
40
+ error: [err: Error]
41
+ progress: [percent: number]
42
+ }>()
43
+
44
+ const inputRef = ref<HTMLInputElement | null>(null)
45
+ const isDragging = ref(false)
46
+ const clientError = ref<string | null>(null)
47
+
48
+ const { isUploading, progress, error, upload, uploadMultiple, reset } = useUpload()
49
+
50
+ function open() {
51
+ if (props.disabled || isUploading.value) return
52
+ inputRef.value?.click()
53
+ }
54
+
55
+ function clear() {
56
+ reset()
57
+ clientError.value = null
58
+ if (inputRef.value) inputRef.value.value = ""
59
+ emit("update:modelValue", props.multiple ? [] : null)
60
+ }
61
+
62
+ async function processFiles(files: FileList | File[]) {
63
+ clientError.value = null
64
+ const fileList = Array.from(files)
65
+ if (fileList.length === 0) return
66
+
67
+ if (props.maxSize) {
68
+ const oversized = fileList.find((f) => f.size > props.maxSize!)
69
+ if (oversized) {
70
+ const maxMb = (props.maxSize / (1024 * 1024)).toFixed(1)
71
+ const msg = `File "${oversized.name}" exceeds maximum size of ${maxMb}MB`
72
+ clientError.value = msg
73
+ emit("error", new Error(msg))
74
+ return
75
+ }
76
+ }
77
+
78
+ emit("change", props.multiple ? fileList : fileList[0]!)
79
+ if (!props.autoUpload) return
80
+ emit("upload", fileList)
81
+
82
+ try {
83
+ if (props.multiple) {
84
+ const results = await uploadMultiple(fileList)
85
+ emit("update:modelValue", results)
86
+ emit("success", results)
87
+ } else {
88
+ const result = await upload(fileList[0]!, { presigned: props.presigned })
89
+ emit("update:modelValue", result)
90
+ emit("success", result)
91
+ }
92
+ } catch (err: any) {
93
+ clientError.value = err?.message || "Upload failed"
94
+ emit("error", err)
95
+ }
96
+ }
97
+
98
+ function onDrop(event: DragEvent) {
99
+ event.preventDefault()
100
+ isDragging.value = false
101
+ if (props.disabled || isUploading.value) return
102
+ if (event.dataTransfer?.files) processFiles(event.dataTransfer.files)
103
+ }
104
+
105
+ function onDragOver(event: DragEvent) {
106
+ event.preventDefault()
107
+ if (!props.disabled && !isUploading.value) isDragging.value = true
108
+ }
109
+
110
+ function onDragLeave(event: DragEvent) {
111
+ event.preventDefault()
112
+ isDragging.value = false
113
+ }
114
+
115
+ function onInputChange(event: Event) {
116
+ const target = event.target as HTMLInputElement
117
+ if (target.files) processFiles(target.files)
118
+ }
119
+
120
+ const displayError = computed(() => clientError.value || error.value?.message || null)
121
+ </script>
122
+
123
+ <template>
124
+ <!-- Custom slot: users take full UI control -->
125
+ <div
126
+ v-if="$slots.default"
127
+ :class="['qarpeo-file-upload', dropzoneClass]"
128
+ @drop="onDrop"
129
+ @dragover="onDragOver"
130
+ @dragleave="onDragLeave"
131
+ >
132
+ <input
133
+ ref="inputRef"
134
+ type="file"
135
+ :accept="accept"
136
+ :multiple="multiple"
137
+ class="hidden"
138
+ @change="onInputChange"
139
+ />
140
+ <slot
141
+ :is-dragging="isDragging"
142
+ :is-uploading="isUploading"
143
+ :progress="progress"
144
+ :error="displayError"
145
+ :open="open"
146
+ :clear="clear"
147
+ />
148
+ </div>
149
+
150
+ <!-- Built-in dropzone UI -->
151
+ <div
152
+ v-else
153
+ class="qarpeo-file-upload-wrapper"
154
+ @drop="onDrop"
155
+ @dragover="onDragOver"
156
+ @dragleave="onDragLeave"
157
+ >
158
+ <input
159
+ ref="inputRef"
160
+ type="file"
161
+ :accept="accept"
162
+ :multiple="multiple"
163
+ class="hidden"
164
+ @change="onInputChange"
165
+ />
166
+ <div
167
+ :class="[
168
+ 'rounded-lg border-2 border-dashed p-6 text-center transition-colors duration-200',
169
+ isDragging
170
+ ? 'border-primary-500 bg-primary-50/50 dark:bg-primary-950/20'
171
+ : 'border-gray-300 dark:border-gray-700',
172
+ disabled ? 'cursor-not-allowed opacity-60' : 'cursor-pointer',
173
+ dropzoneClass,
174
+ ]"
175
+ @click="open"
176
+ >
177
+ <!-- Uploading state -->
178
+ <div v-if="isUploading" class="space-y-2">
179
+ <p class="text-sm text-gray-500">Uploading... {{ progress }}%</p>
180
+ <UProgress :value="progress" size="xs" />
181
+ </div>
182
+
183
+ <!-- Idle / drag state -->
184
+ <div v-else class="space-y-1">
185
+ <UIcon name="i-lucide-upload-cloud" class="size-8 mx-auto text-gray-400" />
186
+ <p class="text-sm font-medium text-gray-700 dark:text-gray-300">
187
+ {{ isDragging ? "Drop files to upload" : "Click or drag files here to upload" }}
188
+ </p>
189
+ <p v-if="accept" class="text-xs text-gray-400">Accepted: {{ accept }}</p>
190
+ </div>
191
+
192
+ <!-- Error -->
193
+ <p v-if="displayError" class="mt-2 text-xs text-red-500">{{ displayError }}</p>
194
+ </div>
195
+ </div>
196
+ </template>
@@ -1,57 +1,57 @@
1
- <script lang="ts" setup>
2
- import { computed } from "vue"
3
- import { useUserSession } from "../composables/auth"
4
- import type { QarpeoUser, QarpeoSession } from "../../types/auth"
5
-
6
- /**
7
- * `<ImpersonationBanner>` Renders a dismissible banner when an admin is actively impersonating a
8
- * user. Shows who is being impersonated and provides a "Stop Impersonating" button.
9
- * Auto-hides when not in an impersonation session.
10
- * @emits stopped — when impersonation is stopped successfully
11
- */
12
- const emit = defineEmits<{ stopped: [] }>()
13
-
14
- const { session, fetch: refreshSession } = useUserSession()
15
-
16
- const isImpersonating = computed(() => Boolean((session.value as QarpeoSession | null)?.impersonator))
17
- const impersonator = computed<QarpeoUser | null>(
18
- () => ((session.value as QarpeoSession | null)?.impersonator as QarpeoUser) || null,
19
- )
20
- const impersonated = computed<QarpeoUser | null>(() => {
21
- if (!isImpersonating.value) return null
22
- return ((session.value as QarpeoSession | null)?.user as QarpeoUser) || null
23
- })
24
-
25
- async function stopImpersonating() {
26
- try {
27
- await $fetch("/api/auth/impersonate/stop", { method: "POST", credentials: "include" })
28
- await refreshSession()
29
- emit("stopped")
30
- } catch {}
31
- }
32
- </script>
33
-
34
- <template>
35
- <Teleport to="body">
36
- <div
37
- v-if="isImpersonating"
38
- class="fixed top-0 left-0 right-0 z-[9999] flex items-center justify-between gap-4 bg-amber-700 text-white px-4 py-2 text-sm font-sans"
39
- >
40
- <span>
41
- ⚠ Admin
42
- <strong>{{ impersonator?.email || impersonator?.name || "Unknown" }}</strong>
43
- is impersonating
44
- <strong>{{ impersonated?.email || impersonated?.name || "Unknown" }}</strong>
45
- </span>
46
- <UButton
47
- color="neutral"
48
- variant="outline"
49
- size="xs"
50
- class="border-white/50 text-white hover:bg-white/20"
51
- @click="stopImpersonating"
52
- >
53
- Stop Impersonating
54
- </UButton>
55
- </div>
56
- </Teleport>
57
- </template>
1
+ <script lang="ts" setup>
2
+ import { computed } from "vue"
3
+ import { useUserSession } from "../composables/auth"
4
+ import type { QarpeoUser, QarpeoSession } from "../../types/auth"
5
+
6
+ /**
7
+ * `<ImpersonationBanner>` Renders a dismissible banner when an admin is actively impersonating a
8
+ * user. Shows who is being impersonated and provides a "Stop Impersonating" button.
9
+ * Auto-hides when not in an impersonation session.
10
+ * @emits stopped — when impersonation is stopped successfully
11
+ */
12
+ const emit = defineEmits<{ stopped: [] }>()
13
+
14
+ const { session, fetch: refreshSession } = useUserSession()
15
+
16
+ const isImpersonating = computed(() => Boolean((session.value as QarpeoSession | null)?.impersonator))
17
+ const impersonator = computed<QarpeoUser | null>(
18
+ () => ((session.value as QarpeoSession | null)?.impersonator as QarpeoUser) || null,
19
+ )
20
+ const impersonated = computed<QarpeoUser | null>(() => {
21
+ if (!isImpersonating.value) return null
22
+ return ((session.value as QarpeoSession | null)?.user as QarpeoUser) || null
23
+ })
24
+
25
+ async function stopImpersonating() {
26
+ try {
27
+ await $fetch("/api/auth/impersonate/stop", { method: "POST", credentials: "include" })
28
+ await refreshSession()
29
+ emit("stopped")
30
+ } catch {}
31
+ }
32
+ </script>
33
+
34
+ <template>
35
+ <Teleport to="body">
36
+ <div
37
+ v-if="isImpersonating"
38
+ class="fixed top-0 left-0 right-0 z-[9999] flex items-center justify-between gap-4 bg-amber-700 text-white px-4 py-2 text-sm font-sans"
39
+ >
40
+ <span>
41
+ ⚠ Admin
42
+ <strong>{{ impersonator?.email || impersonator?.name || "Unknown" }}</strong>
43
+ is impersonating
44
+ <strong>{{ impersonated?.email || impersonated?.name || "Unknown" }}</strong>
45
+ </span>
46
+ <UButton
47
+ color="neutral"
48
+ variant="outline"
49
+ size="xs"
50
+ class="border-white/50 text-white hover:bg-white/20"
51
+ @click="stopImpersonating"
52
+ >
53
+ Stop Impersonating
54
+ </UButton>
55
+ </div>
56
+ </Teleport>
57
+ </template>
@@ -1,13 +1,13 @@
1
- <script lang="ts" setup>
2
- import { useAuth } from "../composables/auth"
3
- const { loggedIn, ready } = useAuth()
4
- </script>
5
-
6
- <template>
7
- <template v-if="ready && loggedIn">
8
- <slot />
9
- </template>
10
- <template v-else-if="!ready">
11
- <slot name="fallback" />
12
- </template>
13
- </template>
1
+ <script lang="ts" setup>
2
+ import { useAuth } from "../composables/auth"
3
+ const { loggedIn, ready } = useAuth()
4
+ </script>
5
+
6
+ <template>
7
+ <template v-if="ready && loggedIn">
8
+ <slot />
9
+ </template>
10
+ <template v-else-if="!ready">
11
+ <slot name="fallback" />
12
+ </template>
13
+ </template>
@@ -1,13 +1,13 @@
1
- <script lang="ts" setup>
2
- import { useAuth } from "../composables/auth"
3
- const { loggedIn, ready } = useAuth()
4
- </script>
5
-
6
- <template>
7
- <template v-if="ready && !loggedIn">
8
- <slot />
9
- </template>
10
- <template v-else-if="!ready">
11
- <slot name="fallback" />
12
- </template>
13
- </template>
1
+ <script lang="ts" setup>
2
+ import { useAuth } from "../composables/auth"
3
+ const { loggedIn, ready } = useAuth()
4
+ </script>
5
+
6
+ <template>
7
+ <template v-if="ready && !loggedIn">
8
+ <slot />
9
+ </template>
10
+ <template v-else-if="!ready">
11
+ <slot name="fallback" />
12
+ </template>
13
+ </template>
@@ -1,34 +1,34 @@
1
- /* Shiki dark mode styles. A colour swatch keeps the background and contrast
2
- foreground the transformer wrote, inline with Comark or as a generated
3
- class with the content pipeline. */
4
- html.dark .shiki span[style*="--shiki-dark"]:not(.shiki-color-highlight) {
5
- color: var(--shiki-dark) !important;
6
- font-style: var(--shiki-dark-font-style) !important;
7
- font-weight: var(--shiki-dark-font-weight) !important;
8
- text-decoration: var(--shiki-dark-text-decoration) !important;
9
- }
10
-
11
- /* Shiki icon highlight transformer styles */
12
- .shiki-icon-highlight {
13
- display: inline-block;
14
- width: 1.25em;
15
- height: 1.25em;
16
- vertical-align: -0.25em;
17
- margin-right: 0.125em;
18
- background-color: var(--ui-text-highlighted);
19
- -webkit-mask-repeat: no-repeat;
20
- mask-repeat: no-repeat;
21
- -webkit-mask-size: 100% 100%;
22
- mask-size: 100% 100%;
23
- -webkit-mask-image: var(--shiki-icon-url);
24
- mask-image: var(--shiki-icon-url);
25
- }
26
-
27
- /* Container background styling for dark & light mode */
28
- html.dark pre.shiki {
29
- background-color: #0f172a !important;
30
- }
31
-
32
- html:not(.dark) pre.shiki {
33
- background-color: #f8fafc !important;
34
- }
1
+ /* Shiki dark mode styles. A colour swatch keeps the background and contrast
2
+ foreground the transformer wrote, inline with Comark or as a generated
3
+ class with the content pipeline. */
4
+ html.dark .shiki span[style*="--shiki-dark"]:not(.shiki-color-highlight) {
5
+ color: var(--shiki-dark) !important;
6
+ font-style: var(--shiki-dark-font-style) !important;
7
+ font-weight: var(--shiki-dark-font-weight) !important;
8
+ text-decoration: var(--shiki-dark-text-decoration) !important;
9
+ }
10
+
11
+ /* Shiki icon highlight transformer styles */
12
+ .shiki-icon-highlight {
13
+ display: inline-block;
14
+ width: 1.25em;
15
+ height: 1.25em;
16
+ vertical-align: -0.25em;
17
+ margin-right: 0.125em;
18
+ background-color: var(--ui-text-highlighted);
19
+ -webkit-mask-repeat: no-repeat;
20
+ mask-repeat: no-repeat;
21
+ -webkit-mask-size: 100% 100%;
22
+ mask-size: 100% 100%;
23
+ -webkit-mask-image: var(--shiki-icon-url);
24
+ mask-image: var(--shiki-icon-url);
25
+ }
26
+
27
+ /* Container background styling for dark & light mode */
28
+ html.dark pre.shiki {
29
+ background-color: #0f172a !important;
30
+ }
31
+
32
+ html:not(.dark) pre.shiki {
33
+ background-color: #f8fafc !important;
34
+ }