@passui/tanstack 0.2.4 → 0.2.6
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.
- package/README.md +3 -42
- package/dist/types/src/auth-shell/auth-shell.d.ts +5 -0
- package/dist/types/src/document/compose-viewport.d.ts +20 -0
- package/dist/types/src/form-fields/fields.d.ts +24 -0
- package/dist/types/src/form-fields/index.d.ts +2 -0
- package/dist/types/src/form-fields/selection.d.ts +21 -0
- package/dist/types/src/form-fields/submit.d.ts +3 -0
- package/dist/types/src/forms/contexts.d.ts +1 -0
- package/dist/types/src/forms/elements/form-alert.d.ts +6 -0
- package/dist/types/src/forms/elements/submit.d.ts +1 -0
- package/dist/types/src/forms/fields/avatar-picker.d.ts +30 -0
- package/dist/types/src/forms/fields/avatar.d.ts +30 -0
- package/dist/types/src/forms/fields/checkbox.d.ts +1 -0
- package/dist/types/src/forms/fields/index.d.ts +21 -0
- package/dist/types/src/forms/fields/input.d.ts +1 -0
- package/dist/types/src/forms/fields/multiselect.d.ts +1 -0
- package/dist/types/src/forms/fields/otp.d.ts +1 -0
- package/dist/types/src/forms/fields/radio-card.d.ts +1 -0
- package/dist/types/src/forms/fields/switch.d.ts +1 -0
- package/dist/types/src/forms/fields/textarea.d.ts +1 -0
- package/dist/types/src/forms/index.d.ts +41 -0
- package/dist/types/src/mutation/index.d.ts +1 -0
- package/dist/types/src/mutation/use-app-mutation.d.ts +22 -0
- package/dist/types/src/route-boundary/default-boundary.d.ts +2 -0
- package/dist/types/src/route-boundary/default-loader.d.ts +6 -0
- package/dist/types/src/route-boundary/index.d.ts +3 -0
- package/dist/types/src/route-boundary/not-founder.d.ts +4 -0
- package/dist/types/src/settings/setting-list.d.ts +51 -0
- package/dist/types/src/shared/index.d.ts +2 -0
- package/dist/types/src/shared/optimistic.d.ts +3 -0
- package/dist/types/src/shared/table.d.ts +11 -0
- package/dist/types/src/{solid/tables → tables}/columns.d.ts +1 -2
- package/dist/types/src/tables/data-table.d.ts +76 -0
- package/dist/types/src/tables/filter-row.d.ts +9 -0
- package/dist/types/src/{solid/tables → tables}/index.d.ts +0 -1
- package/dist/types/src/tables/pagination.d.ts +8 -0
- package/dist/types/src/tables/utils.d.ts +1 -0
- package/package.json +8 -93
- package/src/document/compose-viewport.tsx +4 -20
- package/src/form-fields/fields.tsx +17 -62
- package/src/form-fields/selection.tsx +12 -52
- package/src/form-fields/submit.tsx +1 -6
- package/src/forms/contexts.ts +2 -6
- package/src/forms/elements/form-alert.tsx +2 -11
- package/src/forms/fields/avatar-picker.tsx +39 -119
- package/src/forms/fields/avatar.tsx +13 -43
- package/src/forms/fields/index.ts +1 -4
- package/src/forms/index.ts +1 -5
- package/src/mutation/use-app-mutation.ts +32 -88
- package/src/route-boundary/default-boundary.tsx +4 -19
- package/src/route-boundary/default-loader.tsx +14 -10
- package/src/route-boundary/not-founder.tsx +3 -14
- package/src/settings/setting-list.tsx +10 -41
- package/src/shared/optimistic.ts +15 -3
- package/src/shared/table.ts +6 -24
- package/src/tables/columns.tsx +4 -13
- package/src/tables/data-table.tsx +130 -225
- package/src/tables/filter-row.tsx +19 -83
- package/src/tables/pagination.tsx +4 -12
- package/dist/client/chunks/form-fields-DlWu70u5.js +0 -630
- package/dist/client/src/solid/auth-shell/index.js +0 -15
- package/dist/client/src/solid/document/index.js +0 -51
- package/dist/client/src/solid/form-fields/index.js +0 -1
- package/dist/client/src/solid/forms/index.js +0 -33
- package/dist/client/src/solid/mutation/index.js +0 -46
- package/dist/client/src/solid/route-boundary/index.js +0 -73
- package/dist/client/src/solid/settings/index.js +0 -173
- package/dist/client/src/solid/tables/index.js +0 -500
- package/dist/server/src/solid/auth-shell/index.js +0 -15
- package/dist/server/src/solid/document/index.js +0 -55
- package/dist/server/src/solid/form-fields/index.js +0 -598
- package/dist/server/src/solid/forms/index.js +0 -33
- package/dist/server/src/solid/mutation/index.js +0 -46
- package/dist/server/src/solid/route-boundary/index.js +0 -73
- package/dist/server/src/solid/settings/index.js +0 -169
- package/dist/server/src/solid/tables/index.js +0 -480
- package/dist/types/src/solid/auth-shell/auth-shell.d.ts +0 -4
- package/dist/types/src/solid/document/compose-viewport.d.ts +0 -14
- package/dist/types/src/solid/form-fields/avatar.d.ts +0 -26
- package/dist/types/src/solid/form-fields/fields.d.ts +0 -45
- package/dist/types/src/solid/form-fields/index.d.ts +0 -3
- package/dist/types/src/solid/form-fields/submit.d.ts +0 -3
- package/dist/types/src/solid/forms/contexts.d.ts +0 -1
- package/dist/types/src/solid/forms/form-alert.d.ts +0 -6
- package/dist/types/src/solid/forms/index.d.ts +0 -43
- package/dist/types/src/solid/mutation/index.d.ts +0 -1
- package/dist/types/src/solid/mutation/use-app-mutation.d.ts +0 -22
- package/dist/types/src/solid/route-boundary/boundaries.d.ts +0 -8
- package/dist/types/src/solid/route-boundary/index.d.ts +0 -1
- package/dist/types/src/solid/settings/setting-list.d.ts +0 -37
- package/dist/types/src/solid/tables/data-table.d.ts +0 -58
- package/dist/types/src/solid/tables/filter-row.d.ts +0 -9
- package/dist/types/src/solid/tables/pagination.d.ts +0 -7
- package/src/solid/auth-shell/auth-shell.tsx +0 -16
- package/src/solid/auth-shell/index.ts +0 -1
- package/src/solid/document/compose-viewport.tsx +0 -69
- package/src/solid/document/index.ts +0 -1
- package/src/solid/form-fields/avatar.tsx +0 -370
- package/src/solid/form-fields/fields.tsx +0 -336
- package/src/solid/form-fields/index.ts +0 -3
- package/src/solid/form-fields/submit.tsx +0 -31
- package/src/solid/forms/contexts.ts +0 -7
- package/src/solid/forms/form-alert.tsx +0 -19
- package/src/solid/forms/index.ts +0 -32
- package/src/solid/mutation/index.ts +0 -5
- package/src/solid/mutation/use-app-mutation.ts +0 -171
- package/src/solid/route-boundary/boundaries.tsx +0 -104
- package/src/solid/route-boundary/index.ts +0 -1
- package/src/solid/settings/index.ts +0 -1
- package/src/solid/settings/setting-list.tsx +0 -185
- package/src/solid/styles.css +0 -2
- package/src/solid/tables/columns.tsx +0 -40
- package/src/solid/tables/data-table.tsx +0 -448
- package/src/solid/tables/filter-row.tsx +0 -161
- package/src/solid/tables/index.ts +0 -4
- package/src/solid/tables/pagination.tsx +0 -78
- /package/dist/types/src/{solid/auth-shell → auth-shell}/index.d.ts +0 -0
- /package/dist/types/src/{solid/document → document}/index.d.ts +0 -0
- /package/dist/types/src/{solid/settings → settings}/index.d.ts +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./boundaries";
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource solid-js */
|
|
2
|
-
import { type JSX } from "solid-js";
|
|
3
|
-
import { type LinkProps } from "@tanstack/solid-router";
|
|
4
|
-
import { type IconButtonSize } from "@passui/solid/icon-button";
|
|
5
|
-
declare function Row(props: {
|
|
6
|
-
icon?: JSX.Element;
|
|
7
|
-
title: JSX.Element;
|
|
8
|
-
description?: JSX.Element;
|
|
9
|
-
value?: JSX.Element;
|
|
10
|
-
trailing?: JSX.Element;
|
|
11
|
-
to?: LinkProps["to"];
|
|
12
|
-
params?: LinkProps["params"];
|
|
13
|
-
hash?: string;
|
|
14
|
-
onClick?: () => void;
|
|
15
|
-
chevron?: boolean;
|
|
16
|
-
tone?: "default" | "destructive";
|
|
17
|
-
}): JSX.Element;
|
|
18
|
-
declare function Copy(props: {
|
|
19
|
-
value: string;
|
|
20
|
-
label?: string;
|
|
21
|
-
size?: IconButtonSize;
|
|
22
|
-
}): JSX.Element;
|
|
23
|
-
export declare const SettingList: ((props: {
|
|
24
|
-
id?: string;
|
|
25
|
-
as?: "h2" | "h3";
|
|
26
|
-
icon?: JSX.Element;
|
|
27
|
-
title?: string;
|
|
28
|
-
description?: string;
|
|
29
|
-
action?: JSX.Element;
|
|
30
|
-
variant?: "inset" | "tile";
|
|
31
|
-
children: JSX.Element;
|
|
32
|
-
className?: string;
|
|
33
|
-
}) => JSX.Element) & {
|
|
34
|
-
Row: typeof Row;
|
|
35
|
-
Copy: typeof Copy;
|
|
36
|
-
};
|
|
37
|
-
export {};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource solid-js */
|
|
2
|
-
import { type ColumnDef, type RowData, type ColumnVisibilityState } from "@tanstack/solid-table";
|
|
3
|
-
import { type JSX } from "solid-js";
|
|
4
|
-
export declare const baseTableFeatures: {
|
|
5
|
-
globalFilteringFeature: import("@tanstack/solid-table").TableFeature;
|
|
6
|
-
columnFilteringFeature: import("@tanstack/solid-table").TableFeature;
|
|
7
|
-
rowSortingFeature: import("@tanstack/solid-table").TableFeature;
|
|
8
|
-
rowPaginationFeature: import("@tanstack/solid-table").TableFeature;
|
|
9
|
-
columnVisibilityFeature: import("@tanstack/solid-table").TableFeature;
|
|
10
|
-
rowSelectionFeature: import("@tanstack/solid-table").TableFeature;
|
|
11
|
-
filteredRowModel: (table: import("@tanstack/solid-table").Table<any, any>) => () => import("@tanstack/solid-table").RowModel<any, any>;
|
|
12
|
-
sortedRowModel: (table: import("@tanstack/solid-table").Table<any, any>) => () => import("@tanstack/solid-table").RowModel<any, any>;
|
|
13
|
-
paginatedRowModel: (table: import("@tanstack/solid-table").Table<any, any>) => () => import("@tanstack/solid-table").RowModel<any, any>;
|
|
14
|
-
filterFns: {
|
|
15
|
-
includesString: import("@tanstack/solid-table").CreatedFilterFn<any, any>;
|
|
16
|
-
inNumberRange: import("@tanstack/solid-table").CreatedFilterFn<any, any>;
|
|
17
|
-
equals: import("@tanstack/solid-table").CreatedFilterFn<any, any>;
|
|
18
|
-
arrIncludes: import("@tanstack/solid-table").CreatedFilterFn<any, any>;
|
|
19
|
-
arrIncludesSome: import("@tanstack/solid-table").CreatedFilterFn<any, any>;
|
|
20
|
-
inDateRange: import("@tanstack/solid-table").CreatedFilterFn<any, any>;
|
|
21
|
-
};
|
|
22
|
-
sortFns: {
|
|
23
|
-
text: import("@tanstack/solid-table").CreatedSortFn<any, any>;
|
|
24
|
-
alphanumeric: import("@tanstack/solid-table").CreatedSortFn<any, any>;
|
|
25
|
-
datetime: import("@tanstack/solid-table").CreatedSortFn<any, any>;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
export type DataTableFeatures = typeof baseTableFeatures;
|
|
29
|
-
/**
|
|
30
|
-
* `filterVariant: 'date'` is the one thing a caller has to opt into
|
|
31
|
-
* explicitly (`updatedAt`/`createdAt`, or a custom `type: 'date'` column):
|
|
32
|
-
* unlike an array-valued column (detected automatically below, from the
|
|
33
|
-
* actual data), a date is just a string or number at runtime, nothing to
|
|
34
|
-
* sniff it from safely.
|
|
35
|
-
*/
|
|
36
|
-
export type DataTableColumnMeta = {
|
|
37
|
-
filterVariant?: "date";
|
|
38
|
-
};
|
|
39
|
-
export type DataTableColumnDef<TData extends RowData, TValue = unknown> = ColumnDef<DataTableFeatures, TData, TValue> & {
|
|
40
|
-
meta?: DataTableColumnMeta;
|
|
41
|
-
};
|
|
42
|
-
export type DataTableProps<TData extends RowData> = {
|
|
43
|
-
data: TData[];
|
|
44
|
-
columns: DataTableColumnDef<TData, any>[];
|
|
45
|
-
getRowId?: (row: TData, index: number) => string;
|
|
46
|
-
emptyMessage?: string;
|
|
47
|
-
searchPlaceholder?: string;
|
|
48
|
-
bulkActions?: (selected: TData[], clear: () => void) => JSX.Element;
|
|
49
|
-
pagination?: boolean;
|
|
50
|
-
pageSizeOptions?: number[];
|
|
51
|
-
onSelectedRowsChange?: (rows: TData[]) => void;
|
|
52
|
-
onRowClick?: (row: TData) => void;
|
|
53
|
-
footer?: (columns: number) => JSX.Element;
|
|
54
|
-
isLoading?: boolean;
|
|
55
|
-
initialColumnVisibility?: ColumnVisibilityState;
|
|
56
|
-
"aria-label"?: string;
|
|
57
|
-
};
|
|
58
|
-
export declare function DataTable<TData extends RowData>(props: DataTableProps<TData>): JSX.Element;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Column, RowData } from "@tanstack/solid-table";
|
|
2
|
-
import type { DataTableFeatures } from "./data-table";
|
|
3
|
-
export declare function FilterRow<TData extends RowData>(props: {
|
|
4
|
-
column: Column<DataTableFeatures, TData, unknown>;
|
|
5
|
-
data: TData[];
|
|
6
|
-
skip: string[];
|
|
7
|
-
isArrayColumn: boolean;
|
|
8
|
-
isDateColumn?: boolean;
|
|
9
|
-
}): import("solid-js").JSX.Element;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource solid-js */
|
|
2
|
-
import type { RowData, SolidTable } from "@tanstack/solid-table";
|
|
3
|
-
import type { DataTableFeatures } from "./data-table";
|
|
4
|
-
export declare function DataTablePagination<TData extends RowData>(props: {
|
|
5
|
-
table: SolidTable<DataTableFeatures, TData>;
|
|
6
|
-
pageSizeOptions?: number[];
|
|
7
|
-
}): import("solid-js").JSX.Element;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource solid-js */
|
|
2
|
-
import { Outlet } from "@tanstack/solid-router"
|
|
3
|
-
import type { JSX } from "solid-js"
|
|
4
|
-
|
|
5
|
-
export function AuthShell(props: { brand: JSX.Element }) {
|
|
6
|
-
return (
|
|
7
|
-
<section class="relative isolate flex min-h-dvh flex-col items-center justify-center-safe px-4 py-12">
|
|
8
|
-
<div class="flex w-full max-w-[26rem] flex-col items-start gap-6">
|
|
9
|
-
{props.brand}
|
|
10
|
-
<div class="w-full">
|
|
11
|
-
<Outlet />
|
|
12
|
-
</div>
|
|
13
|
-
</div>
|
|
14
|
-
</section>
|
|
15
|
-
)
|
|
16
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./auth-shell"
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource solid-js */
|
|
2
|
-
import { splitProps, type JSX } from "solid-js"
|
|
3
|
-
import { HydrationScript } from "solid-js/web"
|
|
4
|
-
import { cn } from "@passui/solid/cn"
|
|
5
|
-
function Window(
|
|
6
|
-
props: JSX.HTMLAttributes<HTMLBodyElement> & {
|
|
7
|
-
after?: JSX.Element
|
|
8
|
-
before?: JSX.Element
|
|
9
|
-
className?: string
|
|
10
|
-
}
|
|
11
|
-
) {
|
|
12
|
-
const [local, rest] = splitProps(props, [
|
|
13
|
-
"children",
|
|
14
|
-
"after",
|
|
15
|
-
"before",
|
|
16
|
-
"class",
|
|
17
|
-
"className",
|
|
18
|
-
])
|
|
19
|
-
return (
|
|
20
|
-
<body
|
|
21
|
-
{...rest}
|
|
22
|
-
class={cn(
|
|
23
|
-
"fixed h-svh w-full min-w-full bg-background overflow-x-hidden typeset wrap-anywhere flex flex-col",
|
|
24
|
-
local.class,
|
|
25
|
-
local.className
|
|
26
|
-
)}
|
|
27
|
-
>
|
|
28
|
-
{local.before}
|
|
29
|
-
<main class="flex flex-1 flex-col min-h-svh overflow-auto no-scrollbar">
|
|
30
|
-
{local.children}
|
|
31
|
-
</main>
|
|
32
|
-
{local.after}
|
|
33
|
-
</body>
|
|
34
|
-
)
|
|
35
|
-
}
|
|
36
|
-
export const ComposeViewport = Object.assign(
|
|
37
|
-
function ComposeViewport(
|
|
38
|
-
props: JSX.IntrinsicElements["html"] & {
|
|
39
|
-
className?: string
|
|
40
|
-
head?: JSX.Element
|
|
41
|
-
}
|
|
42
|
-
) {
|
|
43
|
-
const [local, rest] = splitProps(props, [
|
|
44
|
-
"class",
|
|
45
|
-
"className",
|
|
46
|
-
"lang",
|
|
47
|
-
"head",
|
|
48
|
-
"children",
|
|
49
|
-
])
|
|
50
|
-
return (
|
|
51
|
-
<html
|
|
52
|
-
{...rest}
|
|
53
|
-
lang={local.lang ?? "en"}
|
|
54
|
-
class={cn(
|
|
55
|
-
"antialiased blur-none",
|
|
56
|
-
local.class,
|
|
57
|
-
local.className
|
|
58
|
-
)}
|
|
59
|
-
>
|
|
60
|
-
<head>
|
|
61
|
-
<HydrationScript />
|
|
62
|
-
{local.head}
|
|
63
|
-
</head>
|
|
64
|
-
{local.children}
|
|
65
|
-
</html>
|
|
66
|
-
)
|
|
67
|
-
},
|
|
68
|
-
{ Window }
|
|
69
|
-
)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./compose-viewport"
|
|
@@ -1,370 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource solid-js */
|
|
2
|
-
import {
|
|
3
|
-
createEffect,
|
|
4
|
-
createSignal,
|
|
5
|
-
onCleanup,
|
|
6
|
-
Show,
|
|
7
|
-
type JSX,
|
|
8
|
-
} from "solid-js"
|
|
9
|
-
import {
|
|
10
|
-
Ambient,
|
|
11
|
-
Button,
|
|
12
|
-
ProfileImage,
|
|
13
|
-
ProfileImageContent,
|
|
14
|
-
ProfileImageFallback,
|
|
15
|
-
Sheet,
|
|
16
|
-
} from "@passui/solid"
|
|
17
|
-
import { useFieldContext } from "../forms/contexts"
|
|
18
|
-
export type FieldAvatarValue = File | null | false
|
|
19
|
-
export type FieldAvatarLabels = {
|
|
20
|
-
edit: string
|
|
21
|
-
remove: string
|
|
22
|
-
confirmHint: string
|
|
23
|
-
save: string
|
|
24
|
-
cancel: string
|
|
25
|
-
photo: string
|
|
26
|
-
photoDescription: string
|
|
27
|
-
choosePhoto: string
|
|
28
|
-
takePhoto: string
|
|
29
|
-
capture: string
|
|
30
|
-
monogram: string
|
|
31
|
-
removePhoto: string
|
|
32
|
-
}
|
|
33
|
-
export function FieldAvatar(props: {
|
|
34
|
-
compact?: boolean
|
|
35
|
-
existingImage?: string | null
|
|
36
|
-
label: string
|
|
37
|
-
accept?: string
|
|
38
|
-
clearable?: boolean
|
|
39
|
-
caption?: JSX.Element
|
|
40
|
-
labels?: Partial<FieldAvatarLabels>
|
|
41
|
-
}) {
|
|
42
|
-
const field = useFieldContext<FieldAvatarValue>()
|
|
43
|
-
const [pending, setPending] = createSignal<File | null>(
|
|
44
|
-
null
|
|
45
|
-
),
|
|
46
|
-
[open, setOpen] = createSignal(false),
|
|
47
|
-
[camera, setCamera] = createSignal(false),
|
|
48
|
-
[preview, setPreview] = createSignal<string>(),
|
|
49
|
-
[error, setError] = createSignal("")
|
|
50
|
-
let input!: HTMLInputElement
|
|
51
|
-
const labels = () => ({
|
|
52
|
-
edit: "Edit",
|
|
53
|
-
remove: "Remove",
|
|
54
|
-
confirmHint:
|
|
55
|
-
"Press Enter to use this photo, Esc to cancel",
|
|
56
|
-
save: "Use photo",
|
|
57
|
-
cancel: "Cancel",
|
|
58
|
-
photo: "Photo",
|
|
59
|
-
photoDescription: "Choose how you appear.",
|
|
60
|
-
choosePhoto: "Choose Photo…",
|
|
61
|
-
takePhoto: "Take Photo",
|
|
62
|
-
capture: "Take photo",
|
|
63
|
-
monogram: "Monogram",
|
|
64
|
-
removePhoto: "Remove Photo",
|
|
65
|
-
...props.labels,
|
|
66
|
-
})
|
|
67
|
-
createEffect(() => {
|
|
68
|
-
const shown = pending() ?? field().state.value
|
|
69
|
-
if (!(shown instanceof File)) {
|
|
70
|
-
setPreview(undefined)
|
|
71
|
-
return
|
|
72
|
-
}
|
|
73
|
-
const url = URL.createObjectURL(shown)
|
|
74
|
-
setPreview(url)
|
|
75
|
-
onCleanup(() => URL.revokeObjectURL(url))
|
|
76
|
-
})
|
|
77
|
-
const image = () =>
|
|
78
|
-
field().state.value === false && !pending()
|
|
79
|
-
? undefined
|
|
80
|
-
: (preview() ?? props.existingImage ?? undefined)
|
|
81
|
-
function keep() {
|
|
82
|
-
const file = pending()
|
|
83
|
-
if (file) {
|
|
84
|
-
field().handleChange(file)
|
|
85
|
-
field().handleBlur()
|
|
86
|
-
setPending(null)
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
createEffect(() => {
|
|
90
|
-
if (!pending()) return
|
|
91
|
-
const key = (event: KeyboardEvent) => {
|
|
92
|
-
if (event.key === "Enter") {
|
|
93
|
-
event.preventDefault()
|
|
94
|
-
keep()
|
|
95
|
-
}
|
|
96
|
-
if (event.key === "Escape") setPending(null)
|
|
97
|
-
}
|
|
98
|
-
window.addEventListener("keydown", key)
|
|
99
|
-
onCleanup(() =>
|
|
100
|
-
window.removeEventListener("keydown", key)
|
|
101
|
-
)
|
|
102
|
-
})
|
|
103
|
-
function pick(files: FileList | null) {
|
|
104
|
-
const file = Array.from(files ?? []).find((file) =>
|
|
105
|
-
file.type.startsWith("image/")
|
|
106
|
-
)
|
|
107
|
-
if (file) setPending(file)
|
|
108
|
-
}
|
|
109
|
-
async function monogram() {
|
|
110
|
-
const canvas = document.createElement("canvas")
|
|
111
|
-
canvas.width = canvas.height = 512
|
|
112
|
-
const context = canvas.getContext("2d")
|
|
113
|
-
if (!context) return
|
|
114
|
-
const style = getComputedStyle(input.parentElement!)
|
|
115
|
-
context.fillStyle =
|
|
116
|
-
style.getPropertyValue("--color-accent").trim() ||
|
|
117
|
-
style.color
|
|
118
|
-
context.fillRect(0, 0, 512, 512)
|
|
119
|
-
context.fillStyle = "white"
|
|
120
|
-
context.font = "240px system-ui"
|
|
121
|
-
context.textAlign = "center"
|
|
122
|
-
context.textBaseline = "middle"
|
|
123
|
-
context.fillText(
|
|
124
|
-
props.label
|
|
125
|
-
.trim()
|
|
126
|
-
.split(/\s+/)
|
|
127
|
-
.map((word) => word[0])
|
|
128
|
-
.slice(0, 2)
|
|
129
|
-
.join("")
|
|
130
|
-
.toUpperCase(),
|
|
131
|
-
256,
|
|
132
|
-
270
|
|
133
|
-
)
|
|
134
|
-
const blob = await new Promise<Blob | null>(
|
|
135
|
-
(resolve) => canvas.toBlob(resolve, "image/png")
|
|
136
|
-
)
|
|
137
|
-
if (blob) {
|
|
138
|
-
field().handleChange(
|
|
139
|
-
new File([blob], "monogram.png", {
|
|
140
|
-
type: "image/png",
|
|
141
|
-
})
|
|
142
|
-
)
|
|
143
|
-
field().handleBlur()
|
|
144
|
-
setOpen(false)
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return (
|
|
148
|
-
<Ambient
|
|
149
|
-
src={
|
|
150
|
-
props.caption && !props.compact
|
|
151
|
-
? image()
|
|
152
|
-
: undefined
|
|
153
|
-
}
|
|
154
|
-
class={
|
|
155
|
-
props.compact
|
|
156
|
-
? "flex flex-wrap items-center gap-4"
|
|
157
|
-
: "flex flex-col items-center gap-4"
|
|
158
|
-
}
|
|
159
|
-
>
|
|
160
|
-
<div class="flex flex-col items-center gap-3">
|
|
161
|
-
<button
|
|
162
|
-
type="button"
|
|
163
|
-
aria-label={`${labels().edit} ${props.label}`}
|
|
164
|
-
onClick={() => setOpen(true)}
|
|
165
|
-
onDragOver={(event) =>
|
|
166
|
-
event.preventDefault()
|
|
167
|
-
}
|
|
168
|
-
onDrop={(event) => {
|
|
169
|
-
event.preventDefault()
|
|
170
|
-
pick(
|
|
171
|
-
event.dataTransfer?.files ?? null
|
|
172
|
-
)
|
|
173
|
-
}}
|
|
174
|
-
onPaste={(event) =>
|
|
175
|
-
pick(
|
|
176
|
-
event.clipboardData?.files ?? null
|
|
177
|
-
)
|
|
178
|
-
}
|
|
179
|
-
class="rounded-full focus-visible:ring-2 focus-visible:ring-accent"
|
|
180
|
-
>
|
|
181
|
-
<ProfileImage
|
|
182
|
-
class={
|
|
183
|
-
props.compact
|
|
184
|
-
? "size-16"
|
|
185
|
-
: "size-43"
|
|
186
|
-
}
|
|
187
|
-
>
|
|
188
|
-
<ProfileImageContent
|
|
189
|
-
src={image()}
|
|
190
|
-
alt={props.label}
|
|
191
|
-
/>
|
|
192
|
-
<ProfileImageFallback>
|
|
193
|
-
{props.label
|
|
194
|
-
.slice(0, 1)
|
|
195
|
-
.toUpperCase()}
|
|
196
|
-
</ProfileImageFallback>
|
|
197
|
-
</ProfileImage>
|
|
198
|
-
</button>
|
|
199
|
-
<Show when={pending()}>
|
|
200
|
-
<p class="text-footnote text-label-secondary">
|
|
201
|
-
{labels().confirmHint}
|
|
202
|
-
</p>
|
|
203
|
-
<div class="flex gap-2">
|
|
204
|
-
<Button
|
|
205
|
-
variant="secondary"
|
|
206
|
-
onClick={() => setPending(null)}
|
|
207
|
-
>
|
|
208
|
-
{labels().cancel}
|
|
209
|
-
</Button>
|
|
210
|
-
<Button onClick={keep}>
|
|
211
|
-
{labels().save}
|
|
212
|
-
</Button>
|
|
213
|
-
</div>
|
|
214
|
-
</Show>
|
|
215
|
-
</div>
|
|
216
|
-
<Show when={!pending()}>{props.caption}</Show>
|
|
217
|
-
<input
|
|
218
|
-
ref={input}
|
|
219
|
-
hidden
|
|
220
|
-
type="file"
|
|
221
|
-
accept={
|
|
222
|
-
props.accept ??
|
|
223
|
-
"image/png,image/webp,image/jpeg,image/svg+xml"
|
|
224
|
-
}
|
|
225
|
-
onChange={(event) => {
|
|
226
|
-
pick(event.currentTarget.files)
|
|
227
|
-
event.currentTarget.value = ""
|
|
228
|
-
}}
|
|
229
|
-
/>
|
|
230
|
-
<Sheet
|
|
231
|
-
open={open()}
|
|
232
|
-
label={labels().photo}
|
|
233
|
-
onClose={() => {
|
|
234
|
-
setOpen(false)
|
|
235
|
-
setCamera(false)
|
|
236
|
-
}}
|
|
237
|
-
>
|
|
238
|
-
<div class="flex flex-col gap-3 p-5">
|
|
239
|
-
<p>{labels().photoDescription}</p>
|
|
240
|
-
<Button
|
|
241
|
-
variant="secondary"
|
|
242
|
-
onClick={() => {
|
|
243
|
-
setOpen(false)
|
|
244
|
-
input.click()
|
|
245
|
-
}}
|
|
246
|
-
>
|
|
247
|
-
{labels().choosePhoto}
|
|
248
|
-
</Button>
|
|
249
|
-
<Button
|
|
250
|
-
variant="secondary"
|
|
251
|
-
onClick={() => {
|
|
252
|
-
setError("")
|
|
253
|
-
setCamera(true)
|
|
254
|
-
}}
|
|
255
|
-
>
|
|
256
|
-
{labels().takePhoto}
|
|
257
|
-
</Button>
|
|
258
|
-
<Button
|
|
259
|
-
variant="secondary"
|
|
260
|
-
onClick={() =>
|
|
261
|
-
void monogram().catch((error) =>
|
|
262
|
-
setError(String(error))
|
|
263
|
-
)
|
|
264
|
-
}
|
|
265
|
-
>
|
|
266
|
-
{labels().monogram}
|
|
267
|
-
</Button>
|
|
268
|
-
<Show when={props.clearable && image()}>
|
|
269
|
-
<Button
|
|
270
|
-
variant="destructive"
|
|
271
|
-
onClick={() => {
|
|
272
|
-
field().handleChange(false)
|
|
273
|
-
field().handleBlur()
|
|
274
|
-
setOpen(false)
|
|
275
|
-
}}
|
|
276
|
-
>
|
|
277
|
-
{labels().removePhoto}
|
|
278
|
-
</Button>
|
|
279
|
-
</Show>
|
|
280
|
-
<Show when={camera()}>
|
|
281
|
-
<Camera
|
|
282
|
-
captureLabel={labels().capture}
|
|
283
|
-
onError={setError}
|
|
284
|
-
onCapture={(file) => {
|
|
285
|
-
setPending(file)
|
|
286
|
-
setCamera(false)
|
|
287
|
-
setOpen(false)
|
|
288
|
-
}}
|
|
289
|
-
/>
|
|
290
|
-
</Show>
|
|
291
|
-
<Show when={error()}>
|
|
292
|
-
<p role="alert">{error()}</p>
|
|
293
|
-
</Show>
|
|
294
|
-
<Button
|
|
295
|
-
variant="ghost"
|
|
296
|
-
onClick={() => {
|
|
297
|
-
setOpen(false)
|
|
298
|
-
setCamera(false)
|
|
299
|
-
}}
|
|
300
|
-
>
|
|
301
|
-
{labels().cancel}
|
|
302
|
-
</Button>
|
|
303
|
-
</div>
|
|
304
|
-
</Sheet>
|
|
305
|
-
</Ambient>
|
|
306
|
-
)
|
|
307
|
-
}
|
|
308
|
-
function Camera(props: {
|
|
309
|
-
captureLabel: string
|
|
310
|
-
onCapture: (file: File) => void
|
|
311
|
-
onError: (message: string) => void
|
|
312
|
-
}) {
|
|
313
|
-
let video!: HTMLVideoElement,
|
|
314
|
-
stream: MediaStream | undefined,
|
|
315
|
-
disposed = false
|
|
316
|
-
createEffect(() => {
|
|
317
|
-
void navigator.mediaDevices
|
|
318
|
-
.getUserMedia({ video: { facingMode: "user" } })
|
|
319
|
-
.then((value) => {
|
|
320
|
-
if (disposed) {
|
|
321
|
-
value.getTracks().forEach((track) => {
|
|
322
|
-
track.stop()
|
|
323
|
-
})
|
|
324
|
-
return
|
|
325
|
-
}
|
|
326
|
-
stream = value
|
|
327
|
-
video.srcObject = value
|
|
328
|
-
void video.play()
|
|
329
|
-
})
|
|
330
|
-
.catch((error) => props.onError(String(error)))
|
|
331
|
-
onCleanup(() => {
|
|
332
|
-
disposed = true
|
|
333
|
-
stream?.getTracks().forEach((track) => {
|
|
334
|
-
track.stop()
|
|
335
|
-
})
|
|
336
|
-
})
|
|
337
|
-
})
|
|
338
|
-
function capture() {
|
|
339
|
-
if (!video.videoWidth) return
|
|
340
|
-
const canvas = document.createElement("canvas")
|
|
341
|
-
canvas.width = video.videoWidth
|
|
342
|
-
canvas.height = video.videoHeight
|
|
343
|
-
canvas.getContext("2d")?.drawImage(video, 0, 0)
|
|
344
|
-
canvas.toBlob(
|
|
345
|
-
(blob) => {
|
|
346
|
-
if (blob && !disposed)
|
|
347
|
-
props.onCapture(
|
|
348
|
-
new File([blob], "photo.jpg", {
|
|
349
|
-
type: "image/jpeg",
|
|
350
|
-
})
|
|
351
|
-
)
|
|
352
|
-
},
|
|
353
|
-
"image/jpeg",
|
|
354
|
-
0.92
|
|
355
|
-
)
|
|
356
|
-
}
|
|
357
|
-
return (
|
|
358
|
-
<div class="flex flex-col gap-3">
|
|
359
|
-
<video
|
|
360
|
-
ref={video}
|
|
361
|
-
muted
|
|
362
|
-
playsinline
|
|
363
|
-
class="max-h-64 rounded-xl"
|
|
364
|
-
/>
|
|
365
|
-
<Button onClick={capture}>
|
|
366
|
-
{props.captureLabel}
|
|
367
|
-
</Button>
|
|
368
|
-
</div>
|
|
369
|
-
)
|
|
370
|
-
}
|