@contember/create 1.4.0-rc.4 → 1.4.0-rc.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/dist/src/commands/WorkspaceCreateCommand.d.ts +4 -3
- package/dist/src/commands/WorkspaceCreateCommand.d.ts.map +1 -1
- package/dist/src/commands/WorkspaceCreateCommand.js +10 -4
- package/dist/src/commands/WorkspaceCreateCommand.js.map +1 -1
- package/dist/src/lib/FileSystem.d.ts +14 -0
- package/dist/src/lib/FileSystem.d.ts.map +1 -0
- package/dist/src/lib/FileSystem.js +54 -0
- package/dist/src/lib/FileSystem.js.map +1 -0
- package/dist/src/lib/PackageDownloader.d.ts +7 -0
- package/dist/src/lib/PackageDownloader.d.ts.map +1 -0
- package/dist/src/lib/PackageDownloader.js +32 -0
- package/dist/src/lib/PackageDownloader.js.map +1 -0
- package/dist/src/lib/TemplateInstaller.d.ts +13 -0
- package/dist/src/lib/TemplateInstaller.d.ts.map +1 -0
- package/dist/src/lib/TemplateInstaller.js +75 -0
- package/dist/src/lib/TemplateInstaller.js.map +1 -0
- package/dist/src/lib/pathUtils.d.ts +3 -0
- package/dist/src/lib/pathUtils.d.ts.map +1 -0
- package/dist/src/lib/pathUtils.js +7 -0
- package/dist/src/lib/pathUtils.js.map +1 -0
- package/dist/src/run.js +7 -3
- package/dist/src/run.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -3
- package/resources/templates/template-workspace/.gitignore.dist +3 -0
- package/resources/templates/template-workspace/admin/.env.development +3 -0
- package/resources/templates/template-workspace/admin/.env.production +3 -0
- package/resources/templates/template-workspace/admin/app/components/layout.tsx +32 -0
- package/resources/templates/template-workspace/admin/app/components/logo.tsx +16 -0
- package/resources/templates/template-workspace/admin/app/components/navigation.tsx +1 -0
- package/resources/templates/template-workspace/admin/app/config.ts +27 -0
- package/resources/templates/template-workspace/admin/app/index.html +15 -0
- package/resources/templates/template-workspace/admin/app/index.tsx +40 -0
- package/resources/templates/template-workspace/admin/app/pages/index.tsx +5 -0
- package/resources/templates/template-workspace/admin/index.css +53 -0
- package/resources/templates/template-workspace/admin/index.html +13 -0
- package/resources/templates/template-workspace/admin/index.tsx +268 -0
- package/resources/templates/template-workspace/admin/lib/binding/binding.tsx +45 -0
- package/resources/templates/template-workspace/admin/lib/binding/delete.tsx +43 -0
- package/resources/templates/template-workspace/admin/lib/binding/hooks.tsx +71 -0
- package/resources/templates/template-workspace/admin/lib/binding/identity.tsx +19 -0
- package/resources/templates/template-workspace/admin/lib/binding/index.ts +5 -0
- package/resources/templates/template-workspace/admin/lib/binding/persist.tsx +70 -0
- package/resources/templates/template-workspace/admin/lib/block-repeater/block-repeater.tsx +224 -0
- package/resources/templates/template-workspace/admin/lib/block-repeater/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/board/board.tsx +240 -0
- package/resources/templates/template-workspace/admin/lib/board/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/buttons/back-button.tsx +20 -0
- package/resources/templates/template-workspace/admin/lib/buttons/index.ts +2 -0
- package/resources/templates/template-workspace/admin/lib/buttons/link-back-button.tsx +21 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/cells.tsx +64 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/column-header.tsx +65 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/columns.tsx +166 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/elements.tsx +42 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/empty.tsx +8 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/export.tsx +17 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/boolean.tsx +76 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/common.tsx +29 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/date.tsx +153 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/enum.tsx +115 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/index.ts +7 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/mobile.tsx +19 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/number.tsx +100 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/relation.tsx +180 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/text.tsx +121 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/grid.tsx +61 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/index.ts +16 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/layout-switcher.tsx +32 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/loader.tsx +10 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/pagination.tsx +103 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/table.tsx +69 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/tiles.tsx +24 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/toolbar.tsx +66 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/ui.tsx +153 -0
- package/resources/templates/template-workspace/admin/lib/dev/index.ts +2 -0
- package/resources/templates/template-workspace/admin/lib/dev/login-panel.tsx +56 -0
- package/resources/templates/template-workspace/admin/lib/dev/todo.tsx +14 -0
- package/resources/templates/template-workspace/admin/lib/dict.ts +324 -0
- package/resources/templates/template-workspace/admin/lib/dimensions/dimensions.tsx +135 -0
- package/resources/templates/template-workspace/admin/lib/dimensions/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/editor/block-editor.tsx +111 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/baseEditorPlugins.tsx +66 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/buttons.tsx +83 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/editor-block-toolbar.tsx +17 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/editor-canvas.tsx +30 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/editor-editable-canvas.tsx +50 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/editor-inline-toolbar.tsx +63 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/AnchorRenderer.tsx +36 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/BlockElement.tsx +48 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/HeadingRenderer.tsx +48 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/HorizontalRuleRenderer.tsx +28 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/ListItemRenderer.tsx +13 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/OrderedListRenderer.tsx +13 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/ParagraphRenderer.tsx +15 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/ScrollTargetRenderer.tsx +30 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/TableCellElementRenderer.tsx +20 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/TableElementRenderer.tsx +96 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/TableRowElementRenderer.tsx +15 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/elements/UnorderedListRenderer.tsx +13 -0
- package/resources/templates/template-workspace/admin/lib/editor/common/index.ts +6 -0
- package/resources/templates/template-workspace/admin/lib/editor/editor-block.tsx +96 -0
- package/resources/templates/template-workspace/admin/lib/editor/index.ts +5 -0
- package/resources/templates/template-workspace/admin/lib/editor/plugins.tsx +36 -0
- package/resources/templates/template-workspace/admin/lib/editor/rich-text.tsx +54 -0
- package/resources/templates/template-workspace/admin/lib/editor/sortable-block.tsx +51 -0
- package/resources/templates/template-workspace/admin/lib/errors/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/errors/use-error-formatter.ts +26 -0
- package/resources/templates/template-workspace/admin/lib/form/container.tsx +63 -0
- package/resources/templates/template-workspace/admin/lib/form/index.ts +5 -0
- package/resources/templates/template-workspace/admin/lib/form/inputs.tsx +99 -0
- package/resources/templates/template-workspace/admin/lib/form/select.tsx +123 -0
- package/resources/templates/template-workspace/admin/lib/form/ui.tsx +29 -0
- package/resources/templates/template-workspace/admin/lib/form/upload.tsx +243 -0
- package/resources/templates/template-workspace/admin/lib/formatting/formatting.ts +62 -0
- package/resources/templates/template-workspace/admin/lib/formatting/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/images/formatImageResizeUrl.ts +23 -0
- package/resources/templates/template-workspace/admin/lib/images/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/layout/index.ts +2 -0
- package/resources/templates/template-workspace/admin/lib/layout/layout.tsx +167 -0
- package/resources/templates/template-workspace/admin/lib/layout/slots.tsx +24 -0
- package/resources/templates/template-workspace/admin/lib/outdated-application-dialog/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/outdated-application-dialog/outdated-application-dialog.tsx +41 -0
- package/resources/templates/template-workspace/admin/lib/repeater/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/repeater/repeater.tsx +142 -0
- package/resources/templates/template-workspace/admin/lib/select/create-new.tsx +34 -0
- package/resources/templates/template-workspace/admin/lib/select/filter.tsx +13 -0
- package/resources/templates/template-workspace/admin/lib/select/highlight.tsx +16 -0
- package/resources/templates/template-workspace/admin/lib/select/index.ts +7 -0
- package/resources/templates/template-workspace/admin/lib/select/list.tsx +49 -0
- package/resources/templates/template-workspace/admin/lib/select/multi-select.tsx +95 -0
- package/resources/templates/template-workspace/admin/lib/select/pagination.tsx +48 -0
- package/resources/templates/template-workspace/admin/lib/select/select.tsx +87 -0
- package/resources/templates/template-workspace/admin/lib/select/sortable-select.tsx +129 -0
- package/resources/templates/template-workspace/admin/lib/select/ui.tsx +80 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/change-my-password.tsx +40 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/common.tsx +94 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/create-api-key.tsx +39 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/index.ts +8 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/invite.tsx +46 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/login.tsx +52 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/memberships-control.tsx +128 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/password-reset-request.tsx +31 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/password-reset.tsx +44 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/update-project-member.tsx +32 -0
- package/resources/templates/template-workspace/admin/lib/tenant/hooks/useInvite.ts +28 -0
- package/resources/templates/template-workspace/admin/lib/tenant/hooks/useInviteUser.tsx +45 -0
- package/resources/templates/template-workspace/admin/lib/tenant/index.ts +3 -0
- package/resources/templates/template-workspace/admin/lib/tenant/listing/api-key-list.tsx +25 -0
- package/resources/templates/template-workspace/admin/lib/tenant/listing/index.ts +4 -0
- package/resources/templates/template-workspace/admin/lib/tenant/listing/member-delete-dialog.tsx +38 -0
- package/resources/templates/template-workspace/admin/lib/tenant/listing/member-list.tsx +147 -0
- package/resources/templates/template-workspace/admin/lib/tenant/listing/person-list.tsx +25 -0
- package/resources/templates/template-workspace/admin/lib/tenant/otp/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/tenant/otp/otp-setup.tsx +146 -0
- package/resources/templates/template-workspace/admin/lib/toast/index.ts +2 -0
- package/resources/templates/template-workspace/admin/lib/toast/toast.tsx +112 -0
- package/resources/templates/template-workspace/admin/lib/toast/toaster.tsx +104 -0
- package/resources/templates/template-workspace/admin/lib/ui/alert-dialog.tsx +59 -0
- package/resources/templates/template-workspace/admin/lib/ui/button.tsx +29 -0
- package/resources/templates/template-workspace/admin/lib/ui/card.tsx +25 -0
- package/resources/templates/template-workspace/admin/lib/ui/dialog.tsx +51 -0
- package/resources/templates/template-workspace/admin/lib/ui/divider.tsx +11 -0
- package/resources/templates/template-workspace/admin/lib/ui/dropdown.tsx +108 -0
- package/resources/templates/template-workspace/admin/lib/ui/input.tsx +62 -0
- package/resources/templates/template-workspace/admin/lib/ui/label.tsx +7 -0
- package/resources/templates/template-workspace/admin/lib/ui/loader.tsx +30 -0
- package/resources/templates/template-workspace/admin/lib/ui/menu.tsx +103 -0
- package/resources/templates/template-workspace/admin/lib/ui/overlay.tsx +33 -0
- package/resources/templates/template-workspace/admin/lib/ui/popover.tsx +31 -0
- package/resources/templates/template-workspace/admin/lib/ui/progress.tsx +25 -0
- package/resources/templates/template-workspace/admin/lib/ui/scroll-area.tsx +45 -0
- package/resources/templates/template-workspace/admin/lib/ui/sheet.tsx +67 -0
- package/resources/templates/template-workspace/admin/lib/ui/sortable.tsx +13 -0
- package/resources/templates/template-workspace/admin/lib/ui/switch.tsx +10 -0
- package/resources/templates/template-workspace/admin/lib/ui/table.tsx +46 -0
- package/resources/templates/template-workspace/admin/lib/ui/textarea.tsx +18 -0
- package/resources/templates/template-workspace/admin/lib/ui/toggle-group.tsx +44 -0
- package/resources/templates/template-workspace/admin/lib/ui/toggle.tsx +29 -0
- package/resources/templates/template-workspace/admin/lib/ui/tooltip.tsx +24 -0
- package/resources/templates/template-workspace/admin/lib/upload/dropzone.tsx +21 -0
- package/resources/templates/template-workspace/admin/lib/upload/index.ts +3 -0
- package/resources/templates/template-workspace/admin/lib/upload/repeater.tsx +12 -0
- package/resources/templates/template-workspace/admin/lib/upload/ui.tsx +57 -0
- package/resources/templates/template-workspace/admin/lib/upload/upload-progress.tsx +130 -0
- package/resources/templates/template-workspace/admin/lib/upload/view.tsx +219 -0
- package/resources/templates/template-workspace/admin/lib/utils/cn.ts +4 -0
- package/resources/templates/template-workspace/admin/lib/utils/dict-format.tsx +3 -0
- package/resources/templates/template-workspace/admin/lib/utils/format-image-resize-url.ts +17 -0
- package/resources/templates/template-workspace/admin/lib/utils/formatting.ts +60 -0
- package/resources/templates/template-workspace/admin/lib/utils/index.ts +2 -0
- package/resources/templates/template-workspace/admin/lib/utils/uic.tsx +79 -0
- package/resources/templates/template-workspace/admin/package.json +63 -0
- package/resources/templates/template-workspace/admin/postcss.config.js +6 -0
- package/resources/templates/template-workspace/admin/public/favicon.png +0 -0
- package/resources/templates/template-workspace/admin/tailwind.config.js +73 -0
- package/resources/templates/template-workspace/admin/tsconfig.json +23 -0
- package/resources/templates/template-workspace/admin/vite-env.d.ts +7 -0
- package/resources/templates/template-workspace/admin/vite.config.ts +39 -0
- package/resources/templates/template-workspace/api/index.ts +7 -0
- package/resources/templates/template-workspace/api/migrations/.gitkeep +1 -0
- package/resources/templates/template-workspace/api/model/index.ts +1 -0
- package/resources/templates/template-workspace/api/package.json +16 -0
- package/resources/templates/template-workspace/api/tsconfig.json +10 -0
- package/resources/templates/template-workspace/biome.json +45 -0
- package/resources/templates/template-workspace/client/package.json +16 -0
- package/resources/templates/template-workspace/client/src/index.ts +1 -0
- package/resources/templates/template-workspace/client/tsconfig.json +9 -0
- package/resources/templates/template-workspace/contember.template.yaml +7 -0
- package/resources/templates/template-workspace/docker-compose.yaml +124 -0
- package/resources/templates/template-workspace/package.json +32 -0
- package/resources/templates/template-workspace/scripts/generate-client.sh +8 -0
- package/resources/templates/template-workspace/tsconfig.json +9 -0
- package/resources/templates/template-workspace/tsconfig.settings.json +15 -0
- package/src/commands/WorkspaceCreateCommand.ts +15 -6
- package/src/lib/FileSystem.ts +24 -0
- package/src/lib/PackageDownloader.ts +33 -0
- package/src/lib/TemplateInstaller.ts +102 -0
- package/src/lib/pathUtils.ts +4 -0
- package/src/run.ts +14 -5
- package/tsconfig.settings.json +5 -1
- package/types/download-tarball/index.d.ts +7 -0
- package/types/get-package-json-from-registry/index.d.ts +3 -0
- package/types/registry-info/index.d.ts +7 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { uic } from '../utils'
|
|
2
|
+
|
|
3
|
+
export const TableWrapper = uic('div', {
|
|
4
|
+
baseClass: 'relative w-full overflow-auto',
|
|
5
|
+
displayName: 'TableWrapper',
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
export const Table = uic('table', {
|
|
9
|
+
baseClass: 'w-full caption-bottom text-sm',
|
|
10
|
+
displayName: 'Table',
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
export const TableHeader = uic('thead', {
|
|
14
|
+
baseClass: '[&_tr]:border-b',
|
|
15
|
+
displayName: 'TableHeader',
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
export const TableBody = uic('tbody', {
|
|
19
|
+
baseClass: '[&_tr:last-child]:border-0',
|
|
20
|
+
displayName: 'TableBody',
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
export const TableFooter = uic('tfoot', {
|
|
24
|
+
baseClass: 'border-t bg-muted/50 font-medium [&>tr]:last:border-b-0',
|
|
25
|
+
displayName: 'TableFooter',
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
export const TableRow = uic('tr', {
|
|
29
|
+
baseClass: 'border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted',
|
|
30
|
+
displayName: 'TableRow',
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
export const TableHead = uic('th', {
|
|
34
|
+
baseClass: 'px-4 py-3 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0',
|
|
35
|
+
displayName: 'TableHead',
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
export const TableCell = uic('td', {
|
|
39
|
+
baseClass: 'px-4 py-3 align-middle [&:has([role=checkbox])]:pr-0',
|
|
40
|
+
displayName: 'TableCell',
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
export const TableCaption = uic('caption', {
|
|
44
|
+
baseClass: 'mt-4 text-sm text-muted-foreground',
|
|
45
|
+
displayName: 'TableCaption',
|
|
46
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useAutoHeightTextArea, useComposeRef } from '@contember/react-utils'
|
|
2
|
+
import { uic } from '../utils'
|
|
3
|
+
import { ComponentProps, forwardRef, useRef } from 'react'
|
|
4
|
+
|
|
5
|
+
export const Textarea = uic('textarea', {
|
|
6
|
+
baseClass: 'w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50',
|
|
7
|
+
displayName: 'Textarea',
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
export const TextareaAutosize = forwardRef<HTMLTextAreaElement, ComponentProps<typeof Textarea> & {
|
|
11
|
+
minRows?: number
|
|
12
|
+
maxRows?: number
|
|
13
|
+
}>(({ minRows, maxRows, ...props }, ref) => {
|
|
14
|
+
const innerRef = useRef<HTMLTextAreaElement | null>(null)
|
|
15
|
+
useAutoHeightTextArea(innerRef, props.value?.toString() ?? '', minRows ?? 3, maxRows ?? 100)
|
|
16
|
+
|
|
17
|
+
return <Textarea ref={useComposeRef(innerRef, ref)} {...props} />
|
|
18
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import * as ToggleGroupPrimitive from '@radix-ui/react-toggle-group'
|
|
3
|
+
import { toggleConfig, ToggleProps } from './toggle'
|
|
4
|
+
import { cn } from '../utils/cn'
|
|
5
|
+
import { uic } from '../utils/uic'
|
|
6
|
+
|
|
7
|
+
const ToggleGroupContext = React.createContext<ToggleProps>({
|
|
8
|
+
size: 'default',
|
|
9
|
+
variant: 'default',
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
const ToggleGroup = React.forwardRef<
|
|
13
|
+
React.ElementRef<typeof ToggleGroupPrimitive.Root>,
|
|
14
|
+
React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Root> &
|
|
15
|
+
ToggleProps
|
|
16
|
+
>(({ className, variant, size, children, ...props }, ref) => (
|
|
17
|
+
<ToggleGroupPrimitive.Root
|
|
18
|
+
ref={ref}
|
|
19
|
+
className={cn('flex items-center justify-center gap-1', className)}
|
|
20
|
+
{...props}
|
|
21
|
+
>
|
|
22
|
+
<ToggleGroupContext.Provider value={{ variant, size }}>
|
|
23
|
+
{children}
|
|
24
|
+
</ToggleGroupContext.Provider>
|
|
25
|
+
</ToggleGroupPrimitive.Root>
|
|
26
|
+
))
|
|
27
|
+
|
|
28
|
+
ToggleGroup.displayName = ToggleGroupPrimitive.Root.displayName
|
|
29
|
+
|
|
30
|
+
const ToggleGroupItemInner = uic(ToggleGroupPrimitive.Item, toggleConfig)
|
|
31
|
+
|
|
32
|
+
const ToggleGroupItem = React.forwardRef<
|
|
33
|
+
React.ElementRef<typeof ToggleGroupPrimitive.Item>,
|
|
34
|
+
React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Item> &
|
|
35
|
+
ToggleProps
|
|
36
|
+
>(({ className, children, variant, size, ...props }, ref) => {
|
|
37
|
+
const context = React.useContext(ToggleGroupContext)
|
|
38
|
+
|
|
39
|
+
return <ToggleGroupItemInner ref={ref} className={className} variant={context.variant || variant} size={context.size || size} {...props}>{children}</ToggleGroupItemInner>
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
ToggleGroupItem.displayName = ToggleGroupPrimitive.Item.displayName
|
|
43
|
+
|
|
44
|
+
export { ToggleGroup, ToggleGroupItem }
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import * as TogglePrimitive from '@radix-ui/react-toggle'
|
|
3
|
+
import { ConfigVariants, uic, uiconfig } from '../utils/uic'
|
|
4
|
+
|
|
5
|
+
export const toggleConfig = uiconfig({
|
|
6
|
+
baseClass: 'inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 data-[active]:bg-accent data-[active]:shadow-inner data-[active]:text-accent-foreground',
|
|
7
|
+
variants: {
|
|
8
|
+
variant: {
|
|
9
|
+
default: 'bg-transparent',
|
|
10
|
+
outline:
|
|
11
|
+
'border border-input bg-transparent shadow-sm hover:bg-accent hover:text-accent-foreground',
|
|
12
|
+
},
|
|
13
|
+
size: {
|
|
14
|
+
default: 'h-8 px-3',
|
|
15
|
+
sm: 'h-8 px-2',
|
|
16
|
+
lg: 'h-10 px-3',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
defaultVariants: {
|
|
20
|
+
variant: 'default',
|
|
21
|
+
size: 'default',
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
export type ToggleProps = ConfigVariants<Exclude<typeof toggleConfig.variants, undefined>>
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
export const Toggle = uic(TogglePrimitive.Root, toggleConfig)
|
|
29
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as TooltipPrimitive from '@radix-ui/react-tooltip'
|
|
2
|
+
import { uic } from '../utils'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export const TooltipProvider = TooltipPrimitive.Provider
|
|
6
|
+
|
|
7
|
+
export const Tooltip = TooltipPrimitive.Root
|
|
8
|
+
|
|
9
|
+
export const TooltipTrigger = TooltipPrimitive.Trigger
|
|
10
|
+
|
|
11
|
+
export const TooltipContent = uic(TooltipPrimitive.Content, {
|
|
12
|
+
baseClass: 'z-50 overflow-hidden p-2 text-sm text-popover-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
|
|
13
|
+
variants: {
|
|
14
|
+
variant: {
|
|
15
|
+
default: 'rounded-md border bg-popover shadow-md',
|
|
16
|
+
blurred: 'rounded-md backdrop-blur shadow-md border',
|
|
17
|
+
seamless: '',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
defaultVariants: {
|
|
21
|
+
variant: 'default',
|
|
22
|
+
},
|
|
23
|
+
displayName: 'TooltipContent',
|
|
24
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { UploaderDropzoneArea, UploaderDropzoneRoot } from '@contember/react-uploader-dropzone'
|
|
3
|
+
import { useUploaderStateFiles } from '@contember/react-uploader'
|
|
4
|
+
import { UploaderDropzoneAreaUI, UploaderDropzoneWrapperUI, UploaderInactiveDropzoneUI } from './ui'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export const UploaderDropzone = ({ inactiveOnUpload }: { inactiveOnUpload?: boolean }) => {
|
|
8
|
+
const filesInProgress = useUploaderStateFiles({ state: ['uploading', 'initial', 'finalizing'] })
|
|
9
|
+
const showLoader = inactiveOnUpload && filesInProgress.length > 0
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<UploaderDropzoneRoot>
|
|
13
|
+
<UploaderDropzoneWrapperUI>
|
|
14
|
+
{showLoader
|
|
15
|
+
? <UploaderInactiveDropzoneUI />
|
|
16
|
+
: <UploaderDropzoneArea><UploaderDropzoneAreaUI /></UploaderDropzoneArea>
|
|
17
|
+
}
|
|
18
|
+
</UploaderDropzoneWrapperUI>
|
|
19
|
+
</UploaderDropzoneRoot>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DropIndicator } from '../ui/sortable'
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { RepeaterSortableDropIndicator } from '@contember/react-repeater-dnd-kit'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export const UploaderRepeaterDropIndicator = ({ position }: { position: 'before' | 'after' }) => (
|
|
7
|
+
<div className={'relative'}>
|
|
8
|
+
<RepeaterSortableDropIndicator position={position}>
|
|
9
|
+
<DropIndicator placement={position === 'before' ? 'left' : 'right'} />
|
|
10
|
+
</RepeaterSortableDropIndicator>
|
|
11
|
+
</div>
|
|
12
|
+
)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { Loader } from '../ui/loader'
|
|
3
|
+
import { GripIcon, GripVerticalIcon, UploadIcon } from 'lucide-react'
|
|
4
|
+
import { dict } from '../dict'
|
|
5
|
+
import { Button } from '../ui/button'
|
|
6
|
+
import { uic } from '../utils/uic'
|
|
7
|
+
|
|
8
|
+
export const UploaderDropzoneWrapperUI = uic('div', { baseClass: 'rounded border p-1 shadow' })
|
|
9
|
+
export const UploaderDropzoneAreaUI = uic('div', {
|
|
10
|
+
baseClass: `h-40 w-40 flex flex-col gap-1 justify-center items-center py-4 border-dashed border-2 border-gray-300 rounded relative
|
|
11
|
+
transition-colors
|
|
12
|
+
hover:border-gray-300 hover:bg-gray-50 hover:cursor-pointer
|
|
13
|
+
data-[dropzone-accept]:border-green-500 group-data-[dropzone-accept]:bg-green-100
|
|
14
|
+
data-[dropzone-reject]:border-red-500 group-data-[dropzone-reject]:bg-red-100
|
|
15
|
+
`,
|
|
16
|
+
variants: {
|
|
17
|
+
size: {
|
|
18
|
+
square: 'h-40 w-40',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
defaultVariants: {
|
|
22
|
+
size: 'square',
|
|
23
|
+
},
|
|
24
|
+
beforeChildren: <>
|
|
25
|
+
<UploadIcon className={'w-12 h-12 text-gray-400'} />
|
|
26
|
+
<div className={'font-semibold text-sm'}>{dict.uploader.dropFiles}</div>
|
|
27
|
+
<div className={'text-xs'}>{dict.uploader.or}</div>
|
|
28
|
+
<div className={'flex gap-2 items-center text-xs'}>
|
|
29
|
+
<Button size={'sm'} variant={'outline'}>{dict.uploader.browseFiles}</Button>
|
|
30
|
+
</div>
|
|
31
|
+
</>,
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
export const UploaderItemUI = uic('div', {
|
|
36
|
+
baseClass: 'rounded border p-1 shadow bg-gray-100 flex gap-2 relative',
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
export const UploaderInactiveDropzoneUI = uic('div', {
|
|
41
|
+
baseClass: 'h-40 w-40 flex flex-col pointer-events-none relative',
|
|
42
|
+
beforeChildren: <Loader position="absolute" />,
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
export const UploaderRepeaterItemsWrapperUI = uic('div', {
|
|
46
|
+
baseClass: 'flex flex-wrap gap-4',
|
|
47
|
+
})
|
|
48
|
+
export const UploaderRepeaterItemUI = UploaderItemUI
|
|
49
|
+
export const UploaderRepeaterDragOverlayUI = uic('div', {
|
|
50
|
+
baseClass: 'rounded border border-gray-300 p-4 relative bg-opacity-60 bg-gray-100 backdrop-blur-sm',
|
|
51
|
+
})
|
|
52
|
+
export const UploaderRepeaterHandleUI = uic('button', {
|
|
53
|
+
baseClass: 'absolute top-0 left-0 h-6 w-6 inline-flex justify-center align-center opacity-10 hover:opacity-100 transition-opacity z-10',
|
|
54
|
+
beforeChildren: <GripIcon size={16} />,
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { CheckIcon, FileIcon, Loader2Icon, StopCircleIcon, XIcon } from 'lucide-react'
|
|
2
|
+
import { Button } from '../ui/button'
|
|
3
|
+
import { Progress } from '../ui/progress'
|
|
4
|
+
import * as React from 'react'
|
|
5
|
+
import { ReactNode, useEffect } from 'react'
|
|
6
|
+
import { Toast } from '../toast'
|
|
7
|
+
import { dict } from '../dict'
|
|
8
|
+
import { UploaderEachFile, UploaderError, UploaderFileStateError, UploaderFileStateFinalizing, UploaderFileStateSuccess, UploaderFileStateSwitch, UploaderFileStateUploading } from '@contember/react-uploader'
|
|
9
|
+
import { formatBytes } from '../formatting/formatting'
|
|
10
|
+
import { Loader } from '../ui/loader'
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
const formatError = (error: unknown) => {
|
|
14
|
+
if (error instanceof UploaderError) {
|
|
15
|
+
return dict.uploader.uploadErrors[error.options.type]
|
|
16
|
+
}
|
|
17
|
+
return dict.uploader.uploaderUnknownError
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const AbortButton = ({ state: { file: { abortController } } }: { state: UploaderFileStateFinalizing | UploaderFileStateUploading }) => {
|
|
21
|
+
return <Button className="p-1 h-5 text-red-500" variant="ghost" size={'sm'} onClick={() => abortController.abort()}><StopCircleIcon className="h-3 w-3" /></Button>
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const DismissButton = ({ state }: { state: UploaderFileStateSuccess | UploaderFileStateError }) => {
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const timeout = setTimeout(() => {
|
|
27
|
+
state.dismiss()
|
|
28
|
+
}, 5000)
|
|
29
|
+
return () => clearTimeout(timeout)
|
|
30
|
+
}, [state])
|
|
31
|
+
|
|
32
|
+
return <Button className="p-1 h-5" variant="ghost" size={'sm'} onClick={() => state.dismiss()}><XIcon className="h-3 w-3" /></Button>
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const UploadError = ({ state: { error } }: { state: UploaderFileStateError }) => {
|
|
36
|
+
const formattedError = error ? formatError(error) : undefined
|
|
37
|
+
if (!formattedError) {
|
|
38
|
+
return null
|
|
39
|
+
}
|
|
40
|
+
return <div className="text-red-700 text-xs font-semibold">{formattedError}</div>
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const UploaderFileProgressUI = ({ file, progress, info, actions }: { file: File, progress?: number, actions?: ReactNode, info?: ReactNode }) => {
|
|
44
|
+
const fileName = file.name
|
|
45
|
+
const extension = file.name.split('.').pop()?.toUpperCase()
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<div className="border-t p-2 flex-1">
|
|
49
|
+
<div className="flex items-center gap-2">
|
|
50
|
+
<div className="relative">
|
|
51
|
+
<FileIcon className="w-10 h-10 text-gray-400" />
|
|
52
|
+
<div className="absolute bottom-2 right-0 left-0 text-[0.5rem] text-gray-600 font-semibold inline-flex justify-center">{extension}</div>
|
|
53
|
+
</div>
|
|
54
|
+
<div className="flex-1 gap-1 flex flex-col">
|
|
55
|
+
<div className="flex justify-between">
|
|
56
|
+
<div>{fileName}</div>
|
|
57
|
+
<div>
|
|
58
|
+
{actions}
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
<Progress value={progress ?? 0} />
|
|
62
|
+
{info}
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
export const UploaderProgress = () => {
|
|
71
|
+
const [open, setOpen] = React.useState(true)
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<Toast open={open} onOpenChange={setOpen}>
|
|
75
|
+
<div className="flex flex-col flex-1 max-h-80 overflow-y-auto">
|
|
76
|
+
<UploaderEachFile>
|
|
77
|
+
<UploaderFileStateSwitch
|
|
78
|
+
uploading={it => (
|
|
79
|
+
<UploaderFileProgressUI
|
|
80
|
+
file={it.file.file}
|
|
81
|
+
progress={(it.progress.progress ?? 0) * 100}
|
|
82
|
+
actions={<AbortButton state={it} />}
|
|
83
|
+
info={<div className="text-gray-400 text-xs">{formatBytes(it.progress.uploadedBytes)} / {formatBytes(it.progress.totalBytes)}</div>}
|
|
84
|
+
/>
|
|
85
|
+
)}
|
|
86
|
+
initial={it => (
|
|
87
|
+
<UploaderFileProgressUI
|
|
88
|
+
file={it.file.file}
|
|
89
|
+
progress={0}
|
|
90
|
+
/>
|
|
91
|
+
)}
|
|
92
|
+
finalizing={it => (
|
|
93
|
+
<UploaderFileProgressUI
|
|
94
|
+
file={it.file.file}
|
|
95
|
+
progress={100}
|
|
96
|
+
actions={<AbortButton state={it} />}
|
|
97
|
+
info={(
|
|
98
|
+
<div className="text-gray-400 text-xs inline-flex gap-1 items-center">
|
|
99
|
+
<Loader2Icon className="animate-spin h-3 w-3 inline-block" />
|
|
100
|
+
{formatBytes(it.file.file.size)}
|
|
101
|
+
</div>
|
|
102
|
+
)}
|
|
103
|
+
/>
|
|
104
|
+
)}
|
|
105
|
+
error={it => (
|
|
106
|
+
<UploaderFileProgressUI
|
|
107
|
+
file={it.file.file}
|
|
108
|
+
actions={<DismissButton state={it} />}
|
|
109
|
+
info={<UploadError state={it} />}
|
|
110
|
+
/>
|
|
111
|
+
)}
|
|
112
|
+
success={it => (
|
|
113
|
+
<UploaderFileProgressUI
|
|
114
|
+
file={it.file.file}
|
|
115
|
+
progress={100}
|
|
116
|
+
actions={<DismissButton state={it} />}
|
|
117
|
+
info={(
|
|
118
|
+
<div className="flex gap-1 items-center text-green-600 ">
|
|
119
|
+
<CheckIcon className="w-3 h-3" />
|
|
120
|
+
<div className="text-green-600 text-xs "> Done ({formatBytes(it.file.file.size)})</div>
|
|
121
|
+
</div>
|
|
122
|
+
)}
|
|
123
|
+
/>
|
|
124
|
+
)}
|
|
125
|
+
/>
|
|
126
|
+
</UploaderEachFile>
|
|
127
|
+
</div>
|
|
128
|
+
</Toast>
|
|
129
|
+
)
|
|
130
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { ComponentType, ReactNode } from 'react'
|
|
3
|
+
import { Component, Field, SugaredRelativeSingleField, useEntity, useField } from '@contember/interface'
|
|
4
|
+
import { AudioFileDataExtractorProps, FileUrlDataExtractorProps, GenericFileMetadataExtractorProps, ImageFileDataExtractorProps, VideoFileDataExtractorProps } from '@contember/react-uploader'
|
|
5
|
+
import { formatBytes, formatDate, formatDuration } from '../formatting/formatting'
|
|
6
|
+
import { Button } from '../ui/button'
|
|
7
|
+
import { FileIcon, InfoIcon, TrashIcon } from 'lucide-react'
|
|
8
|
+
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover'
|
|
9
|
+
import { formatImageResizeUrl } from '../images/formatImageResizeUrl'
|
|
10
|
+
|
|
11
|
+
export type UploadedImageViewProps =
|
|
12
|
+
& FileUrlDataExtractorProps
|
|
13
|
+
& GenericFileMetadataExtractorProps
|
|
14
|
+
& ImageFileDataExtractorProps
|
|
15
|
+
& {
|
|
16
|
+
DestroyAction?: ComponentType<{ children: ReactNode }>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const UploadedImageView = Component<UploadedImageViewProps>(({ DestroyAction, ...props }) => {
|
|
20
|
+
const url = useField<string>(props.urlField).value
|
|
21
|
+
return (
|
|
22
|
+
<div className="flex items-center justify-center h-40 w-40 rounded-md group relative">
|
|
23
|
+
{url && <img src={formatImageResizeUrl(url)} className="max-w-full max-h-full" />}
|
|
24
|
+
<FileActions DestroyAction={DestroyAction}>
|
|
25
|
+
<ImageMetadata {...props} />
|
|
26
|
+
</FileActions>
|
|
27
|
+
</div>
|
|
28
|
+
)
|
|
29
|
+
}, () => {
|
|
30
|
+
// todo
|
|
31
|
+
return null
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const ImageMetadata = ({ heightField, widthField, ...props }: UploadedImageViewProps) => {
|
|
35
|
+
return (
|
|
36
|
+
<Metadata {...props}>
|
|
37
|
+
<DimensionsMeta widthField={widthField} heightField={heightField} />
|
|
38
|
+
</Metadata>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
export type UploadedAudioViewProps =
|
|
44
|
+
& FileUrlDataExtractorProps
|
|
45
|
+
& GenericFileMetadataExtractorProps
|
|
46
|
+
& AudioFileDataExtractorProps
|
|
47
|
+
& {
|
|
48
|
+
DestroyAction?: ComponentType<{ children: ReactNode }>
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const UploadedAudioView = Component<UploadedAudioViewProps>(({ DestroyAction, ...props }) => {
|
|
52
|
+
const url = useField<string>(props.urlField).value
|
|
53
|
+
return (
|
|
54
|
+
<div className="flex items-end justify-center h-40 max-w-80 rounded-md group">
|
|
55
|
+
{url && <audio src={url} controls className="max-w-full max-h-full" controlsList="nodownload noremoteplayback noplaybackrate" />}
|
|
56
|
+
<FileActions DestroyAction={DestroyAction}>
|
|
57
|
+
<AudioMetadata {...props} />
|
|
58
|
+
</FileActions>
|
|
59
|
+
</div>
|
|
60
|
+
)
|
|
61
|
+
}, () => {
|
|
62
|
+
// todo
|
|
63
|
+
return null
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
const AudioMetadata = ({ durationField, ...props }: UploadedAudioViewProps) => {
|
|
67
|
+
return (
|
|
68
|
+
<Metadata {...props}>
|
|
69
|
+
<MetaField field={durationField} label="Duration:" format={formatDuration} />
|
|
70
|
+
</Metadata>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
export type UploadedVideoViewProps =
|
|
76
|
+
& FileUrlDataExtractorProps
|
|
77
|
+
& GenericFileMetadataExtractorProps
|
|
78
|
+
& VideoFileDataExtractorProps
|
|
79
|
+
& {
|
|
80
|
+
DestroyAction?: ComponentType<{ children: ReactNode }>
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export const UploadedVideoView = Component<UploadedVideoViewProps>(({ DestroyAction, ...props }) => {
|
|
84
|
+
const url = useField<string>(props.urlField).value
|
|
85
|
+
return (
|
|
86
|
+
<div className="flex items-center justify-center h-40 max-w-60 rounded-md group">
|
|
87
|
+
{url && <video src={url} controls className="max-w-full max-h-full" controlsList="nodownload noremoteplayback noplaybackrate" />}
|
|
88
|
+
<FileActions DestroyAction={DestroyAction}>
|
|
89
|
+
<VideoMetadata {...props} />
|
|
90
|
+
</FileActions>
|
|
91
|
+
</div>
|
|
92
|
+
)
|
|
93
|
+
}, () => {
|
|
94
|
+
// todo
|
|
95
|
+
return null
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
const VideoMetadata = ({ durationField, widthField, heightField, ...props }: UploadedVideoViewProps) => {
|
|
99
|
+
return (
|
|
100
|
+
<Metadata {...props}>
|
|
101
|
+
<MetaField field={durationField} label="Duration:" format={formatDuration} />
|
|
102
|
+
<DimensionsMeta widthField={widthField} heightField={heightField} />
|
|
103
|
+
</Metadata>
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export type UploadedAnyViewProps =
|
|
108
|
+
& FileUrlDataExtractorProps
|
|
109
|
+
& GenericFileMetadataExtractorProps
|
|
110
|
+
& {
|
|
111
|
+
DestroyAction?: ComponentType<{ children: ReactNode }>
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export const UploadedAnyView = Component<UploadedAnyViewProps>(({ DestroyAction, ...props }) => {
|
|
115
|
+
const url = useField<string>(props.urlField).value
|
|
116
|
+
return (
|
|
117
|
+
<div className="flex h-40 w-40 rounded-md group">
|
|
118
|
+
<a href={url ?? '#'} target="_blank" rel="noreferrer" className="text-blue-600 hover:text-blue-700 underline overflow-hidden whitespace-nowrap overflow-ellipsis flex flex-col group/anchor flex-1 items-center justify-center">
|
|
119
|
+
<FileIcon className="h-16 w-16 text-gray-400 group-hover/anchor:text-gray-500 transition-all" />
|
|
120
|
+
{props.fileNameField ? <span><Field field={props.fileNameField} /></span> : null}
|
|
121
|
+
</a>
|
|
122
|
+
<FileActions DestroyAction={DestroyAction}>
|
|
123
|
+
<Metadata {...props} />
|
|
124
|
+
</FileActions>
|
|
125
|
+
</div>
|
|
126
|
+
)
|
|
127
|
+
}, () => {
|
|
128
|
+
// todo
|
|
129
|
+
return null
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
type MetadataProps =
|
|
134
|
+
& FileUrlDataExtractorProps
|
|
135
|
+
& GenericFileMetadataExtractorProps
|
|
136
|
+
& {
|
|
137
|
+
children?: ReactNode
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const Metadata = ({ children, urlField, fileSizeField, fileNameField, lastModifiedField, fileTypeField }: MetadataProps) => {
|
|
141
|
+
return (
|
|
142
|
+
<div className="grid grid-cols-[6rem_1fr] gap-2">
|
|
143
|
+
<MetaField field={fileSizeField} label="Size:" format={formatBytes} />
|
|
144
|
+
<MetaField field={fileTypeField} label="Type:" />
|
|
145
|
+
<MetaField field={fileNameField} label="File name:" />
|
|
146
|
+
{children}
|
|
147
|
+
<MetaField field={lastModifiedField} label="Date:" format={formatDate} />
|
|
148
|
+
<MetaField field={urlField} label="URL:" format={url => (
|
|
149
|
+
<a href={url} target="_blank" rel="noreferrer" className="text-blue-600 underline overflow-hidden whitespace-nowrap overflow-ellipsis">
|
|
150
|
+
{url.replace(/^(.{15}).*(.{15})$/, '$1…$2')}
|
|
151
|
+
</a>
|
|
152
|
+
)} />
|
|
153
|
+
</div>
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const DimensionsMeta = ({ widthField, heightField }: {
|
|
158
|
+
widthField?: SugaredRelativeSingleField['field']
|
|
159
|
+
heightField?: SugaredRelativeSingleField['field']
|
|
160
|
+
}) => {
|
|
161
|
+
const entity = useEntity()
|
|
162
|
+
if (!widthField || !heightField) {
|
|
163
|
+
return null
|
|
164
|
+
}
|
|
165
|
+
const width = entity.getField<number>(widthField).value
|
|
166
|
+
const height = entity.getField<number>(heightField).value
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<>
|
|
170
|
+
<span className="font-semibold text-right">Dimensions:</span>
|
|
171
|
+
<span>{width} x {height} px</span>
|
|
172
|
+
</>
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const MetaField = ({ field, label, format = it => it }: {
|
|
178
|
+
field?: SugaredRelativeSingleField['field']
|
|
179
|
+
label: ReactNode
|
|
180
|
+
format?: (value: any) => ReactNode
|
|
181
|
+
}) => {
|
|
182
|
+
const entity = useEntity()
|
|
183
|
+
return field ? (
|
|
184
|
+
<>
|
|
185
|
+
<span className="font-semibold text-right">{label}</span>
|
|
186
|
+
<span>
|
|
187
|
+
{format(entity.getField(field).value)}
|
|
188
|
+
</span>
|
|
189
|
+
</>
|
|
190
|
+
) : null
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
const FileActions = ({ DestroyAction, children }: {
|
|
195
|
+
children: ReactNode
|
|
196
|
+
DestroyAction?: ComponentType<{ children: ReactNode }>
|
|
197
|
+
}) => {
|
|
198
|
+
return (
|
|
199
|
+
<div className="absolute -top-2 -right-1 p-0.5 bg-gray-200 border border-gray-300 rounded shadow flex gap-1 opacity-0 transition-opacity group-hover:opacity-100">
|
|
200
|
+
<Popover>
|
|
201
|
+
<PopoverTrigger asChild>
|
|
202
|
+
<Button variant={'ghost'} size={'sm'} className={'p-0.5 h-5 w-5'} onClick={e => e.stopPropagation()}>
|
|
203
|
+
<InfoIcon className="h-3 w-3" />
|
|
204
|
+
</Button>
|
|
205
|
+
</PopoverTrigger>
|
|
206
|
+
<PopoverContent>
|
|
207
|
+
<div className="text-sm">
|
|
208
|
+
{children}
|
|
209
|
+
</div>
|
|
210
|
+
</PopoverContent>
|
|
211
|
+
</Popover>
|
|
212
|
+
{DestroyAction && <DestroyAction>
|
|
213
|
+
<Button variant={'ghost'} size={'sm'} className={'p-0.5 h-5 w-5 text-red-500'}>
|
|
214
|
+
<TrashIcon className="h-3 w-3" />
|
|
215
|
+
</Button>
|
|
216
|
+
</DestroyAction>}
|
|
217
|
+
</div>
|
|
218
|
+
)
|
|
219
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type ImageResizeOptions = {
|
|
2
|
+
width?: number
|
|
3
|
+
height?: number
|
|
4
|
+
blur?: number
|
|
5
|
+
quality?: number
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function formatImageResizeUrl(src: string, resizeOptions: ImageResizeOptions, isDev = import.meta.env.DEV) {
|
|
9
|
+
if (isDev) return src
|
|
10
|
+
|
|
11
|
+
const url = new URL(src)
|
|
12
|
+
const urlOptions = Object.keys(resizeOptions)
|
|
13
|
+
.map(key => `${key}=${resizeOptions[key as keyof ImageResizeOptions]}`)
|
|
14
|
+
.join(',')
|
|
15
|
+
|
|
16
|
+
return `${url.protocol}//${url.hostname}/cdn-cgi/image/${urlOptions}${url.pathname}`
|
|
17
|
+
}
|