@yimingliao/cms 0.0.146 → 0.0.148
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/export/client/components/editor/index.js +2 -0
- package/dist/export/client/components/index.js +67 -0
- package/dist/src/client/applications/ui/use-parent-pathname.js +10 -0
- package/dist/src/client/interfaces/components/admin-initializer.js +29 -0
- package/dist/src/client/interfaces/components/resources/file/file-card.js +84 -0
- package/dist/src/client/interfaces/components/resources/file/file-list.js +156 -0
- package/dist/src/client/interfaces/components/resources/file/is-locked-buttons.js +68 -0
- package/dist/src/client/interfaces/components/resources/file/type-buttons.js +59 -0
- package/dist/src/client/interfaces/components/shadcn/sidebar.js +1 -1
- package/dist/src/client/interfaces/components/ui/blocks/list-cards-container/list-cards-container.js +84 -0
- package/dist/src/client/interfaces/components/ui/blocks/list-cards-container/page-size-selector.js +51 -0
- package/dist/src/client/interfaces/components/ui/blocks/list-cards-container/pagination.js +94 -0
- package/dist/src/client/interfaces/components/ui/blocks/page-header/page-header-title.js +26 -0
- package/dist/src/client/interfaces/components/ui/blocks/page-header/page-header.js +74 -0
- package/dist/src/client/interfaces/components/ui/blocks/page-header/presets/batch-create.js +33 -0
- package/dist/src/client/interfaces/components/ui/blocks/page-header/presets/batch.js +39 -0
- package/dist/src/client/interfaces/components/ui/blocks/page-header/presets/create.js +33 -0
- package/dist/src/client/interfaces/components/ui/blocks/page-header/presets/edit.js +33 -0
- package/dist/src/client/interfaces/components/ui/blocks/page-header/presets/index.js +48 -0
- package/dist/src/client/interfaces/components/ui/blocks/page-header/presets/show.js +61 -0
- package/dist/src/client/interfaces/components/ui/blocks/page-header/presets/trash.js +39 -0
- package/dist/src/client/interfaces/components/ui/buttons/return-button.js +61 -0
- package/dist/src/client/interfaces/components/ui/cards/action-buttons-card.js +82 -0
- package/dist/src/client/interfaces/components/ui/cards/resource-card/card-status-bar.js +51 -0
- package/dist/src/client/interfaces/components/ui/cards/resource-card/card-text-content.js +38 -0
- package/dist/src/client/interfaces/components/ui/cards/resource-card/resource-card.js +77 -0
- package/dist/src/client/interfaces/components/ui/display/array-list.js +69 -0
- package/dist/src/client/interfaces/components/ui/display/badge.js +41 -0
- package/dist/src/client/interfaces/components/ui/display/html-display.js +32 -0
- package/dist/src/client/interfaces/components/ui/display/object-array-list.js +75 -0
- package/dist/src/client/interfaces/components/ui/features/accordion/accordion-container.js +31 -0
- package/dist/src/client/interfaces/components/ui/features/accordion/accordion-header.js +34 -0
- package/dist/src/client/interfaces/components/ui/features/accordion/accordion.js +81 -0
- package/dist/src/client/interfaces/components/ui/features/expandable-list/expand-bar.js +39 -0
- package/dist/src/client/interfaces/components/ui/features/expandable-list/expandable-list-content.js +49 -0
- package/dist/src/client/interfaces/components/ui/features/expandable-list/expandable-list.js +53 -0
- package/dist/src/client/interfaces/components/ui/features/external-link.js +15 -0
- package/dist/src/client/interfaces/components/ui/features/file/file-info/file-info.js +118 -0
- package/dist/src/client/interfaces/components/ui/features/file/file-info/file-name.js +48 -0
- package/dist/src/client/interfaces/components/ui/features/file/file-picker/file-picker-container.js +74 -0
- package/dist/src/client/interfaces/components/ui/features/file/file-picker/file-picker-placeholder.js +48 -0
- package/dist/src/client/interfaces/components/ui/features/file/file-picker/file-picker.js +109 -0
- package/dist/src/client/interfaces/components/ui/features/file/file-preview/file-preview-list.js +85 -0
- package/dist/src/client/interfaces/components/ui/features/file/file-preview/file-preview-meta.js +40 -0
- package/dist/src/client/interfaces/components/ui/features/file/file-preview/file-preview.js +113 -0
- package/dist/src/client/interfaces/components/ui/features/file/uploader.js +101 -0
- package/dist/src/client/interfaces/components/ui/features/pick-modal/pick-modal-body.js +112 -0
- package/dist/src/client/interfaces/components/ui/features/pick-modal/pick-modal-trigger.js +97 -0
- package/dist/src/client/interfaces/components/ui/features/pick-modal/pick-modal.js +77 -0
- package/dist/src/client/interfaces/components/ui/features/smart-image.js +57 -0
- package/dist/src/client/interfaces/components/ui/features/tick.js +27 -0
- package/dist/src/client/interfaces/components/ui/form/containers/fields-container.js +24 -0
- package/dist/src/client/interfaces/components/ui/form/containers/main-fields.js +25 -0
- package/dist/src/client/interfaces/components/ui/form/containers/side-fields.js +24 -0
- package/dist/src/client/interfaces/components/ui/form/control-fields/built-in-fields.js +9 -0
- package/dist/src/client/interfaces/components/ui/form/control-fields/control-fields-display.js +112 -0
- package/dist/src/client/interfaces/components/ui/form/control-fields/control-fields-input.js +158 -0
- package/dist/src/client/interfaces/components/ui/form/control-fields/control-fields.js +59 -0
- package/dist/src/client/interfaces/components/ui/form/field-body.js +79 -0
- package/dist/src/client/interfaces/components/ui/form/index-field.js +87 -0
- package/dist/src/client/interfaces/components/ui/form/slug-field.js +82 -0
- package/dist/src/client/interfaces/components/ui/inputs/array-input.js +110 -0
- package/dist/src/client/interfaces/components/ui/inputs/checkbox.js +93 -0
- package/dist/src/client/interfaces/components/ui/inputs/editor/base/base-editor.js +144 -0
- package/dist/src/client/interfaces/components/ui/inputs/editor/base/built-in-plugins.js +71 -0
- package/dist/src/client/interfaces/components/ui/inputs/editor/base/configs/heading.config.js +41 -0
- package/dist/src/client/interfaces/components/ui/inputs/editor/base/configs/image.config.js +32 -0
- package/dist/src/client/interfaces/components/ui/inputs/editor/base/configs/table.config.js +15 -0
- package/dist/src/client/interfaces/components/ui/inputs/editor/editor.js +112 -0
- package/dist/src/client/interfaces/components/ui/inputs/editor/plugins/asset-manager/asset-manager.js +24 -0
- package/dist/src/client/interfaces/components/ui/inputs/editor/plugins/asset-manager/use-control-asset-mamager.js +26 -0
- package/dist/src/client/interfaces/components/ui/inputs/editor/plugins/file-repository/upload-adapter.js +84 -0
- package/dist/src/client/interfaces/components/ui/inputs/editor/plugins/word-count-display/icons.js +17 -0
- package/dist/src/client/interfaces/components/ui/inputs/editor/plugins/word-count-display/word-count-display.js +81 -0
- package/dist/src/client/interfaces/components/ui/inputs/editor/use-init-editor/use-init-editor.js +51 -0
- package/dist/src/client/interfaces/components/ui/inputs/search-input.js +61 -0
- package/dist/src/client/interfaces/components/ui/inputs/select.js +69 -0
- package/dist/src/client/interfaces/components/ui/inputs/textarea.js +62 -0
- package/dist/src/client/interfaces/components/ui/layouts/content-container.js +38 -0
- package/dist/src/client/interfaces/components/ui/layouts/navbar/i18n-selector.js +42 -0
- package/dist/src/client/interfaces/components/ui/layouts/navbar/nav-user.js +106 -0
- package/dist/src/client/interfaces/components/ui/layouts/navbar/navbar.js +84 -0
- package/dist/src/client/interfaces/components/ui/layouts/navbar/sign-out-button.js +58 -0
- package/dist/src/client/interfaces/components/ui/layouts/navbar/theme-selector.js +51 -0
- package/dist/src/client/interfaces/components/ui/layouts/sidebar/nav-main.js +99 -0
- package/dist/src/client/interfaces/pages/auth/change-password/page.js +3 -6
- package/dist/src/client/interfaces/pages/auth/email-unverified/page.js +0 -3
- package/dist/src/client/interfaces/pages/auth/forgot-password/page.js +3 -6
- package/dist/src/client/interfaces/pages/auth/layout.js +0 -3
- package/dist/src/client/interfaces/pages/auth/reset-password/page.js +3 -6
- package/dist/src/client/interfaces/pages/auth/sign-in/page.js +2 -5
- package/dist/src/client/interfaces/pages/dashboard/layout.js +0 -3
- package/dist/src/client/interfaces/styles/constants.js +3 -1
- package/dist/src/constants/file.js +27 -0
- package/dist/src/shared/list-items.js +3 -0
- package/dist/src/shared/utils/debounce.js +14 -0
- package/dist/types/export/client/components/editor/index.d.ts +2 -0
- package/dist/types/export/client/components/editor/index.d.ts.map +1 -0
- package/dist/types/export/client/components/index.d.ts +1 -1
- package/dist/types/export/client/components/index.d.ts.map +1 -1
- package/dist/types/src/client/interfaces/components/index.d.ts +1 -1
- package/dist/types/src/client/interfaces/components/index.d.ts.map +1 -1
- package/dist/types/src/client/interfaces/components/ui/index.d.ts +1 -1
- package/dist/types/src/client/interfaces/components/ui/index.d.ts.map +1 -1
- package/dist/types/src/client/interfaces/components/ui/inputs/editor/base/base-editor.d.ts.map +1 -1
- package/dist/types/src/client/interfaces/components/ui/inputs/editor/use-init-editor/use-init-editor.d.ts.map +1 -1
- package/dist/types/src/client/interfaces/components/ui/inputs/index.d.ts +0 -1
- package/dist/types/src/client/interfaces/components/ui/inputs/index.d.ts.map +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { Archive } from 'lucide-react';
|
|
4
|
+
import { useState } from 'react';
|
|
5
|
+
import 'ua-parser-js';
|
|
6
|
+
import { cn } from '../../../../../applications/shadcn/utils.js';
|
|
7
|
+
import 'next/navigation';
|
|
8
|
+
import { ExpandBar } from './expand-bar.js';
|
|
9
|
+
import { ExpandableListContent } from './expandable-list-content.js';
|
|
10
|
+
|
|
11
|
+
function ExpandableList({
|
|
12
|
+
item,
|
|
13
|
+
items = [],
|
|
14
|
+
isDisabled,
|
|
15
|
+
isUnique
|
|
16
|
+
}) {
|
|
17
|
+
const [isExpand, setIsExpand] = useState(false);
|
|
18
|
+
const [isListOverFlow, setIsListOverFlow] = useState(false);
|
|
19
|
+
return /* @__PURE__ */ jsxs(
|
|
20
|
+
"button",
|
|
21
|
+
{
|
|
22
|
+
type: "button",
|
|
23
|
+
onClick: () => {
|
|
24
|
+
if (!isListOverFlow) return;
|
|
25
|
+
setIsExpand((prev) => !prev);
|
|
26
|
+
},
|
|
27
|
+
className: cn(
|
|
28
|
+
"group flex w-full flex-col gap-1 text-xs text-gray-400",
|
|
29
|
+
!isListOverFlow && "pointer-events-none"
|
|
30
|
+
),
|
|
31
|
+
children: [
|
|
32
|
+
/* @__PURE__ */ jsxs(
|
|
33
|
+
ExpandableListContent,
|
|
34
|
+
{
|
|
35
|
+
item,
|
|
36
|
+
items,
|
|
37
|
+
isExpand,
|
|
38
|
+
isDisabled,
|
|
39
|
+
isUnique,
|
|
40
|
+
onOverflowChange: setIsListOverFlow,
|
|
41
|
+
children: [
|
|
42
|
+
/* @__PURE__ */ jsx(Archive, { className: "size-4" }),
|
|
43
|
+
/* @__PURE__ */ jsx("span", { children: ":" })
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
),
|
|
47
|
+
isListOverFlow && /* @__PURE__ */ jsx(ExpandBar, { isExpand })
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { ExpandableList };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { SquareArrowOutUpRight } from 'lucide-react';
|
|
3
|
+
import { Button } from '../buttons/button.js';
|
|
4
|
+
import 'intor/react';
|
|
5
|
+
import 'next/navigation';
|
|
6
|
+
import 'react';
|
|
7
|
+
import 'ua-parser-js';
|
|
8
|
+
import 'clsx';
|
|
9
|
+
import 'tailwind-merge';
|
|
10
|
+
|
|
11
|
+
function ExternalLink({ href = "" }) {
|
|
12
|
+
return /* @__PURE__ */ jsx(Button, { variant: "outline", size: "icon", href, openNewTab: true, children: /* @__PURE__ */ jsx(SquareArrowOutUpRight, {}) });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { ExternalLink };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useTranslator } from 'intor/react';
|
|
4
|
+
import { SquareArrowOutUpRight } from 'lucide-react';
|
|
5
|
+
import Link from 'next/link';
|
|
6
|
+
import '../../../../../../../constants/paths/auth.js';
|
|
7
|
+
import '../../../../../../../constants/paths/main.js';
|
|
8
|
+
import '../../../../../../../constants/paths/resources.js';
|
|
9
|
+
import { NEW_TAB_REL, NEW_TAB_TARGET } from '../../../../../../../constants/anchor.js';
|
|
10
|
+
import '../../../../../../../constants/redirect-paths.js';
|
|
11
|
+
import { mimeToExtension } from '../../../../../../../shared/blob-file/mime-to-extension.js';
|
|
12
|
+
import { classifyFileType } from '../../../../../../../shared/blob-file/classify-file-type.js';
|
|
13
|
+
import { formatFileSize } from '../../../../../../../shared/blob-file/format-file-size.js';
|
|
14
|
+
import 'mime-types';
|
|
15
|
+
import { joinUrl } from '../../../../../../../shared/utils/join-url.js';
|
|
16
|
+
import 'react';
|
|
17
|
+
import 'ua-parser-js';
|
|
18
|
+
import { cn } from '../../../../../../applications/shadcn/utils.js';
|
|
19
|
+
import 'next/navigation';
|
|
20
|
+
import { Button } from '../../../buttons/button.js';
|
|
21
|
+
import { Field } from '../../../form/field.js';
|
|
22
|
+
import { FieldBody } from '../../../form/field-body.js';
|
|
23
|
+
import '@radix-ui/react-avatar';
|
|
24
|
+
import '../../../../shadcn/badge.js';
|
|
25
|
+
import '../../../../shadcn/button.js';
|
|
26
|
+
import '@radix-ui/react-collapsible';
|
|
27
|
+
import '@radix-ui/react-dialog';
|
|
28
|
+
import '@radix-ui/react-dropdown-menu';
|
|
29
|
+
import '../../../../shadcn/input-group.js';
|
|
30
|
+
import '@radix-ui/react-label';
|
|
31
|
+
import '@radix-ui/react-select';
|
|
32
|
+
import '@radix-ui/react-separator';
|
|
33
|
+
import '../../../../shadcn/sidebar.js';
|
|
34
|
+
import '@radix-ui/react-tooltip';
|
|
35
|
+
import { FileName } from './file-name.js';
|
|
36
|
+
|
|
37
|
+
function createFileInfo({
|
|
38
|
+
maxSize,
|
|
39
|
+
storageUrl
|
|
40
|
+
}) {
|
|
41
|
+
return function FileInfo({
|
|
42
|
+
file,
|
|
43
|
+
isExpand = true
|
|
44
|
+
// Use in [File] Batch Create
|
|
45
|
+
}) {
|
|
46
|
+
const { t } = useTranslator();
|
|
47
|
+
const isBlobFile = file instanceof Blob;
|
|
48
|
+
const isOversize = Number(file.size) > maxSize;
|
|
49
|
+
const fileType = isBlobFile ? classifyFileType(file.type, mimeToExtension(file.type)).toLowerCase() : file.type.toLowerCase();
|
|
50
|
+
return /* @__PURE__ */ jsxs(
|
|
51
|
+
"div",
|
|
52
|
+
{
|
|
53
|
+
className: cn(
|
|
54
|
+
"flex flex-col gap-4",
|
|
55
|
+
"overflow-hidden",
|
|
56
|
+
isExpand ? "w-28" : "w-0",
|
|
57
|
+
isExpand ? "ml-4" : "ml-0",
|
|
58
|
+
"transition-[width,margin]"
|
|
59
|
+
),
|
|
60
|
+
children: [
|
|
61
|
+
!isBlobFile && file && /* @__PURE__ */ jsx(Field, { label: t("ui.blob-file.file-info.file-link.text"), children: /* @__PURE__ */ jsx(Button, { variant: "outline", className: "group p-0", children: /* @__PURE__ */ jsx(
|
|
62
|
+
Link,
|
|
63
|
+
{
|
|
64
|
+
href: joinUrl(storageUrl, file.key),
|
|
65
|
+
target: NEW_TAB_TARGET,
|
|
66
|
+
rel: NEW_TAB_REL,
|
|
67
|
+
className: "group flex-center size-full",
|
|
68
|
+
children: /* @__PURE__ */ jsx(SquareArrowOutUpRight, { className: "transition group-hover:scale-110" })
|
|
69
|
+
}
|
|
70
|
+
) }) }),
|
|
71
|
+
/* @__PURE__ */ jsx(FileName, { fileName: isBlobFile ? file.name : file.originalName }),
|
|
72
|
+
/* @__PURE__ */ jsx(Field, { label: t("ui.blob-file.file-info.file-type.text"), children: /* @__PURE__ */ jsx(FieldBody, { children: /* @__PURE__ */ jsx("p", { className: "mx-auto truncate", children: t(`resources.file.file-type.${fileType}.text`) }) }) }),
|
|
73
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
74
|
+
/* @__PURE__ */ jsx(Field, { label: t("ui.blob-file.file-info.file-size.text"), children: /* @__PURE__ */ jsx(FieldBody, { children: /* @__PURE__ */ jsx(
|
|
75
|
+
"p",
|
|
76
|
+
{
|
|
77
|
+
className: cn(
|
|
78
|
+
"mx-auto truncate",
|
|
79
|
+
isOversize && "text-destructive"
|
|
80
|
+
),
|
|
81
|
+
children: formatFileSize(file.size)
|
|
82
|
+
}
|
|
83
|
+
) }) }),
|
|
84
|
+
/* @__PURE__ */ jsx(
|
|
85
|
+
"div",
|
|
86
|
+
{
|
|
87
|
+
className: cn(
|
|
88
|
+
"h-1 w-28",
|
|
89
|
+
"rounded-full",
|
|
90
|
+
"bg-white dark:bg-gray-200",
|
|
91
|
+
"transition"
|
|
92
|
+
),
|
|
93
|
+
children: /* @__PURE__ */ jsx(
|
|
94
|
+
"div",
|
|
95
|
+
{
|
|
96
|
+
className: cn(
|
|
97
|
+
"h-full rounded-full",
|
|
98
|
+
"overflow-hidden",
|
|
99
|
+
"transition"
|
|
100
|
+
),
|
|
101
|
+
style: {
|
|
102
|
+
width: `${Math.min(file.size / maxSize * 100, 100).toFixed(
|
|
103
|
+
2
|
|
104
|
+
)}%`
|
|
105
|
+
},
|
|
106
|
+
children: /* @__PURE__ */ jsx("div", { className: "h-full w-28 bg-linear-to-r from-green-300 via-yellow-400 to-red-500" })
|
|
107
|
+
}
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
)
|
|
111
|
+
] })
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export { createFileInfo };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { useTranslator } from 'intor/react';
|
|
3
|
+
import '@radix-ui/react-avatar';
|
|
4
|
+
import 'react';
|
|
5
|
+
import 'ua-parser-js';
|
|
6
|
+
import 'clsx';
|
|
7
|
+
import 'tailwind-merge';
|
|
8
|
+
import 'next/navigation';
|
|
9
|
+
import '../../../../shadcn/badge.js';
|
|
10
|
+
import '../../../../shadcn/button.js';
|
|
11
|
+
import '@radix-ui/react-collapsible';
|
|
12
|
+
import '@radix-ui/react-dialog';
|
|
13
|
+
import 'lucide-react';
|
|
14
|
+
import '@radix-ui/react-dropdown-menu';
|
|
15
|
+
import '../../../../shadcn/input-group.js';
|
|
16
|
+
import '@radix-ui/react-label';
|
|
17
|
+
import '@radix-ui/react-select';
|
|
18
|
+
import '@radix-ui/react-separator';
|
|
19
|
+
import '../../../../shadcn/sidebar.js';
|
|
20
|
+
import { Tooltip, TooltipTrigger, TooltipContent } from '../../../../shadcn/tooltip.js';
|
|
21
|
+
import { Field } from '../../../form/field.js';
|
|
22
|
+
import { FieldBody } from '../../../form/field-body.js';
|
|
23
|
+
import 'mime-types';
|
|
24
|
+
|
|
25
|
+
const splitFileName = (fileName) => {
|
|
26
|
+
const lastDotIndex = fileName.lastIndexOf(".");
|
|
27
|
+
if (lastDotIndex <= 0) return { name: fileName, ext: "" };
|
|
28
|
+
return {
|
|
29
|
+
name: fileName.slice(0, lastDotIndex),
|
|
30
|
+
ext: fileName.slice(lastDotIndex + 1)
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
function FileName({ fileName }) {
|
|
34
|
+
const { t } = useTranslator();
|
|
35
|
+
const { name, ext } = splitFileName(fileName);
|
|
36
|
+
return /* @__PURE__ */ jsx(Field, { label: t("ui.blob-file.file-info.file-name.text"), children: /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
37
|
+
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(FieldBody, { children: /* @__PURE__ */ jsxs("p", { className: "mx-auto flex truncate", children: [
|
|
38
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: name }),
|
|
39
|
+
ext && /* @__PURE__ */ jsxs("span", { children: [
|
|
40
|
+
".",
|
|
41
|
+
ext
|
|
42
|
+
] })
|
|
43
|
+
] }) }) }),
|
|
44
|
+
/* @__PURE__ */ jsx(TooltipContent, { children: /* @__PURE__ */ jsx("p", { children: fileName }) })
|
|
45
|
+
] }) });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { FileName };
|
package/dist/src/client/interfaces/components/ui/features/file/file-picker/file-picker-container.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
import 'react';
|
|
4
|
+
import 'ua-parser-js';
|
|
5
|
+
import { cn } from '../../../../../../applications/shadcn/utils.js';
|
|
6
|
+
import 'next/navigation';
|
|
7
|
+
import '@radix-ui/react-avatar';
|
|
8
|
+
import '../../../../shadcn/badge.js';
|
|
9
|
+
import '../../../../shadcn/button.js';
|
|
10
|
+
import '@radix-ui/react-collapsible';
|
|
11
|
+
import '@radix-ui/react-dialog';
|
|
12
|
+
import 'lucide-react';
|
|
13
|
+
import '@radix-ui/react-dropdown-menu';
|
|
14
|
+
import '../../../../shadcn/input-group.js';
|
|
15
|
+
import '@radix-ui/react-label';
|
|
16
|
+
import '@radix-ui/react-select';
|
|
17
|
+
import '@radix-ui/react-separator';
|
|
18
|
+
import '../../../../shadcn/sidebar.js';
|
|
19
|
+
import { Spinner } from '../../../../shadcn/spinner.js';
|
|
20
|
+
import '@radix-ui/react-tooltip';
|
|
21
|
+
import { FilePickerPlaceholder } from './file-picker-placeholder.js';
|
|
22
|
+
|
|
23
|
+
function FilePickerContainer({
|
|
24
|
+
inputRef,
|
|
25
|
+
hasSingleFile = false,
|
|
26
|
+
isDragOver,
|
|
27
|
+
setIsDragOver,
|
|
28
|
+
processFiles,
|
|
29
|
+
// ui states
|
|
30
|
+
isLoading = false,
|
|
31
|
+
isDisabled = false,
|
|
32
|
+
isDisplay = false,
|
|
33
|
+
// base
|
|
34
|
+
className = "",
|
|
35
|
+
children
|
|
36
|
+
}) {
|
|
37
|
+
const handleDrop = (e) => {
|
|
38
|
+
e.preventDefault();
|
|
39
|
+
setIsDragOver(false);
|
|
40
|
+
if (e.dataTransfer.files) void processFiles(e.dataTransfer.files);
|
|
41
|
+
};
|
|
42
|
+
return /* @__PURE__ */ jsx(
|
|
43
|
+
"div",
|
|
44
|
+
{
|
|
45
|
+
className: cn(
|
|
46
|
+
className,
|
|
47
|
+
"relative",
|
|
48
|
+
"flex-center",
|
|
49
|
+
"overflow-hidden",
|
|
50
|
+
"rounded-xl",
|
|
51
|
+
"bg-secondary",
|
|
52
|
+
"border-dashed",
|
|
53
|
+
!isDisplay && "cursor-pointer",
|
|
54
|
+
"transition",
|
|
55
|
+
isDragOver && "opacity-50",
|
|
56
|
+
hasSingleFile || isLoading ? "border-0" : "border-4 hover:opacity-50",
|
|
57
|
+
(isDisabled || isLoading) && "pointer-events-none"
|
|
58
|
+
),
|
|
59
|
+
onClick: () => inputRef.current && inputRef.current.click(),
|
|
60
|
+
onDrop: handleDrop,
|
|
61
|
+
onDragOver: (e) => {
|
|
62
|
+
e.preventDefault();
|
|
63
|
+
setIsDragOver(true);
|
|
64
|
+
},
|
|
65
|
+
onDragLeave: () => setIsDragOver(false),
|
|
66
|
+
children: isLoading ? /* @__PURE__ */ jsx(Spinner, { className: "size-16" }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
67
|
+
!hasSingleFile && /* @__PURE__ */ jsx("div", { className: "absolute size-full", children: /* @__PURE__ */ jsx(FilePickerPlaceholder, {}) }),
|
|
68
|
+
children
|
|
69
|
+
] })
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { FilePickerContainer };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useTranslator } from 'intor/react';
|
|
3
|
+
import { Upload } from 'lucide-react';
|
|
4
|
+
import 'react';
|
|
5
|
+
import 'ua-parser-js';
|
|
6
|
+
import { cn } from '../../../../../../applications/shadcn/utils.js';
|
|
7
|
+
import 'next/navigation';
|
|
8
|
+
import 'next/link';
|
|
9
|
+
import '../../../../../../../constants/paths/auth.js';
|
|
10
|
+
import '../../../../../../../constants/paths/main.js';
|
|
11
|
+
import '../../../../../../../constants/paths/resources.js';
|
|
12
|
+
import '../../../../../../../constants/redirect-paths.js';
|
|
13
|
+
import '@radix-ui/react-avatar';
|
|
14
|
+
import '../../../../shadcn/badge.js';
|
|
15
|
+
import '../../../../shadcn/button.js';
|
|
16
|
+
import '@radix-ui/react-collapsible';
|
|
17
|
+
import '@radix-ui/react-dialog';
|
|
18
|
+
import '@radix-ui/react-dropdown-menu';
|
|
19
|
+
import '../../../../shadcn/input-group.js';
|
|
20
|
+
import '@radix-ui/react-label';
|
|
21
|
+
import '@radix-ui/react-select';
|
|
22
|
+
import '@radix-ui/react-separator';
|
|
23
|
+
import '../../../../shadcn/sidebar.js';
|
|
24
|
+
import '@radix-ui/react-tooltip';
|
|
25
|
+
import 'mime-types';
|
|
26
|
+
import { Badge } from '../../../display/badge.js';
|
|
27
|
+
|
|
28
|
+
function FilePickerPlaceholder() {
|
|
29
|
+
const { t } = useTranslator();
|
|
30
|
+
return /* @__PURE__ */ jsxs(
|
|
31
|
+
"div",
|
|
32
|
+
{
|
|
33
|
+
className: cn(
|
|
34
|
+
"relative",
|
|
35
|
+
"size-full",
|
|
36
|
+
"flex-center flex-col gap-4",
|
|
37
|
+
"text-sm"
|
|
38
|
+
),
|
|
39
|
+
children: [
|
|
40
|
+
/* @__PURE__ */ jsx(Upload, {}),
|
|
41
|
+
/* @__PURE__ */ jsx(Badge, { children: t("ui.blob-file.file-picker.select-file.text") }),
|
|
42
|
+
/* @__PURE__ */ jsx("p", { className: "opacity-50", children: t("ui.blob-file.file-picker.drag-hint.text") })
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { FilePickerPlaceholder };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useRef, useState } from 'react';
|
|
4
|
+
import 'mime-types';
|
|
5
|
+
import { getMediaInfo } from '../../../../../../../shared/blob-file/get-media-info/get-media-info.js';
|
|
6
|
+
import 'ua-parser-js';
|
|
7
|
+
import { cn } from '../../../../../../applications/shadcn/utils.js';
|
|
8
|
+
import 'next/navigation';
|
|
9
|
+
import { FilePickerContainer } from './file-picker-container.js';
|
|
10
|
+
|
|
11
|
+
function createFilePicker({
|
|
12
|
+
FileInfo,
|
|
13
|
+
FilePreview
|
|
14
|
+
}) {
|
|
15
|
+
return function FilePicker({
|
|
16
|
+
// [File] (Prisma Model)
|
|
17
|
+
file,
|
|
18
|
+
// form context
|
|
19
|
+
fieldName,
|
|
20
|
+
formData,
|
|
21
|
+
setFormData,
|
|
22
|
+
// ui states
|
|
23
|
+
isLoading = false,
|
|
24
|
+
isDisabled = false,
|
|
25
|
+
isDisplay = false,
|
|
26
|
+
// base
|
|
27
|
+
className = "",
|
|
28
|
+
...props
|
|
29
|
+
}) {
|
|
30
|
+
const inputRef = useRef(null);
|
|
31
|
+
const [isDragOver, setIsDragOver] = useState(false);
|
|
32
|
+
const [resetKey, setResetKey] = useState(0);
|
|
33
|
+
const fieldValue = formData?.[fieldName ?? ""];
|
|
34
|
+
const isMultiple = Array.isArray(fieldValue);
|
|
35
|
+
const hasSingleBlobFile = !isMultiple && fieldValue;
|
|
36
|
+
const hasSingleFile = Boolean(hasSingleBlobFile || file);
|
|
37
|
+
const processFiles = async (files) => {
|
|
38
|
+
if (!files || files.length === 0 || !setFormData || !fieldName) return;
|
|
39
|
+
const filesWithInfo = await Promise.all(
|
|
40
|
+
[...files].map(async (file2) => {
|
|
41
|
+
const mediaInfo = await getMediaInfo(file2).catch(() => ({
|
|
42
|
+
width: null,
|
|
43
|
+
height: null,
|
|
44
|
+
duration: null
|
|
45
|
+
}));
|
|
46
|
+
return Object.assign(file2, {
|
|
47
|
+
id: crypto.randomUUID(),
|
|
48
|
+
width: mediaInfo.width,
|
|
49
|
+
height: mediaInfo.height,
|
|
50
|
+
duration: mediaInfo.duration
|
|
51
|
+
});
|
|
52
|
+
})
|
|
53
|
+
);
|
|
54
|
+
if (isMultiple) {
|
|
55
|
+
setFormData((p) => ({ ...p, [fieldName]: [...filesWithInfo] }));
|
|
56
|
+
} else {
|
|
57
|
+
setFormData((p) => ({ ...p, [fieldName]: filesWithInfo[0] }));
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
return /* @__PURE__ */ jsxs("div", { className: cn(className, "flex w-fit"), children: [
|
|
61
|
+
/* @__PURE__ */ jsxs(
|
|
62
|
+
FilePickerContainer,
|
|
63
|
+
{
|
|
64
|
+
inputRef,
|
|
65
|
+
hasSingleFile,
|
|
66
|
+
isDragOver,
|
|
67
|
+
setIsDragOver,
|
|
68
|
+
processFiles,
|
|
69
|
+
isLoading,
|
|
70
|
+
isDisabled,
|
|
71
|
+
isDisplay,
|
|
72
|
+
className: cn(
|
|
73
|
+
className,
|
|
74
|
+
"max-h-[600px] min-h-[300px] max-w-[600px] min-w-[300px]"
|
|
75
|
+
),
|
|
76
|
+
children: [
|
|
77
|
+
hasSingleFile && /* @__PURE__ */ jsx(
|
|
78
|
+
FilePreview,
|
|
79
|
+
{
|
|
80
|
+
blobFile: fieldValue,
|
|
81
|
+
fileKey: file?.key ?? ""
|
|
82
|
+
}
|
|
83
|
+
),
|
|
84
|
+
/* @__PURE__ */ jsx(
|
|
85
|
+
"input",
|
|
86
|
+
{
|
|
87
|
+
ref: inputRef,
|
|
88
|
+
type: "file",
|
|
89
|
+
multiple: isMultiple,
|
|
90
|
+
hidden: true,
|
|
91
|
+
disabled: isDisabled || isLoading || isDisplay,
|
|
92
|
+
onChange: (e) => {
|
|
93
|
+
if (!e.target.files) return;
|
|
94
|
+
void processFiles(e.target.files);
|
|
95
|
+
setResetKey((p) => p + 1);
|
|
96
|
+
},
|
|
97
|
+
...props
|
|
98
|
+
},
|
|
99
|
+
resetKey
|
|
100
|
+
)
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
),
|
|
104
|
+
hasSingleFile && /* @__PURE__ */ jsx(FileInfo, { file: fieldValue || file })
|
|
105
|
+
] });
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { createFilePicker };
|
package/dist/src/client/interfaces/components/ui/features/file/file-preview/file-preview-list.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useTranslator } from 'intor/react';
|
|
3
|
+
import { PanelLeftClose, PanelLeftOpen, CircleX } from 'lucide-react';
|
|
4
|
+
import { useState } from 'react';
|
|
5
|
+
import 'ua-parser-js';
|
|
6
|
+
import { cn } from '../../../../../../applications/shadcn/utils.js';
|
|
7
|
+
import 'next/navigation';
|
|
8
|
+
import { Button } from '../../../buttons/button.js';
|
|
9
|
+
|
|
10
|
+
function createFilePreviewList({
|
|
11
|
+
FileInfo,
|
|
12
|
+
FilePreview,
|
|
13
|
+
maxSize
|
|
14
|
+
}) {
|
|
15
|
+
return function FilePreviewList({
|
|
16
|
+
// Form Data
|
|
17
|
+
fieldName,
|
|
18
|
+
formData,
|
|
19
|
+
setFormData,
|
|
20
|
+
// Processing States
|
|
21
|
+
isDisabled = false,
|
|
22
|
+
// Base
|
|
23
|
+
className
|
|
24
|
+
}) {
|
|
25
|
+
const { t } = useTranslator();
|
|
26
|
+
const [isExpand, setIsExpand] = useState(false);
|
|
27
|
+
const raw = formData?.[fieldName ?? ""];
|
|
28
|
+
const blobFiles = Array.isArray(raw) ? raw : [];
|
|
29
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col gap-6", className), children: [
|
|
30
|
+
blobFiles.length > 0 ? /* @__PURE__ */ jsx(
|
|
31
|
+
Button,
|
|
32
|
+
{
|
|
33
|
+
variant: "outline",
|
|
34
|
+
icon: isExpand ? PanelLeftClose : PanelLeftOpen,
|
|
35
|
+
onClick: () => setIsExpand((prev) => !prev),
|
|
36
|
+
className: "w-fit text-sm",
|
|
37
|
+
children: t("ui.blob-file.file-preview-list.file-details.text")
|
|
38
|
+
}
|
|
39
|
+
) : /* @__PURE__ */ jsx("p", { className: "text-xs opacity-50", children: t("ui.blob-file.file-preview-list.no-file-selected.text") }),
|
|
40
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-6", children: blobFiles.map((blobFile) => {
|
|
41
|
+
const isOversize = blobFile.size > maxSize;
|
|
42
|
+
return /* @__PURE__ */ jsxs("div", { className: "relative flex", children: [
|
|
43
|
+
/* @__PURE__ */ jsx(
|
|
44
|
+
FilePreview,
|
|
45
|
+
{
|
|
46
|
+
blobFile,
|
|
47
|
+
className: cn(
|
|
48
|
+
"size-60!",
|
|
49
|
+
isOversize && "border-destructive border-4"
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
),
|
|
53
|
+
/* @__PURE__ */ jsx(FileInfo, { file: blobFile, isExpand }),
|
|
54
|
+
/* @__PURE__ */ jsx(
|
|
55
|
+
"button",
|
|
56
|
+
{
|
|
57
|
+
onClick: () => {
|
|
58
|
+
if (!setFormData || !fieldName) return;
|
|
59
|
+
setFormData((p) => ({
|
|
60
|
+
...p,
|
|
61
|
+
[fieldName]: blobFiles.filter(
|
|
62
|
+
(f) => f.id !== blobFile.id
|
|
63
|
+
)
|
|
64
|
+
}));
|
|
65
|
+
},
|
|
66
|
+
className: cn(
|
|
67
|
+
"absolute! top-2 left-2",
|
|
68
|
+
"z-20",
|
|
69
|
+
"bg-background text-destructive",
|
|
70
|
+
"rounded-full",
|
|
71
|
+
"shadow-xs",
|
|
72
|
+
"hover:scale-110 active:scale-95",
|
|
73
|
+
"duration-200",
|
|
74
|
+
isDisabled && "pointer-events-none"
|
|
75
|
+
),
|
|
76
|
+
children: /* @__PURE__ */ jsx(CircleX, { className: "stroke-2" })
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
] }, blobFile.id);
|
|
80
|
+
}) })
|
|
81
|
+
] });
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { createFilePreviewList };
|
package/dist/src/client/interfaces/components/ui/features/file/file-preview/file-preview-meta.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import 'react';
|
|
3
|
+
import 'ua-parser-js';
|
|
4
|
+
import { cn } from '../../../../../../applications/shadcn/utils.js';
|
|
5
|
+
import 'next/navigation';
|
|
6
|
+
|
|
7
|
+
function FilePreviewMeta({
|
|
8
|
+
width,
|
|
9
|
+
height,
|
|
10
|
+
duration
|
|
11
|
+
}) {
|
|
12
|
+
if (!(width || height) && !duration) return;
|
|
13
|
+
return /* @__PURE__ */ jsxs(
|
|
14
|
+
"span",
|
|
15
|
+
{
|
|
16
|
+
className: cn(
|
|
17
|
+
"flex gap-2",
|
|
18
|
+
"rounded",
|
|
19
|
+
"px-2 py-1",
|
|
20
|
+
"text-xs font-[500] text-gray-100",
|
|
21
|
+
"bg-gray-500/50 backdrop-blur-md",
|
|
22
|
+
"truncate"
|
|
23
|
+
),
|
|
24
|
+
children: [
|
|
25
|
+
width ?? "",
|
|
26
|
+
" x ",
|
|
27
|
+
height ?? "",
|
|
28
|
+
duration ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
29
|
+
/* @__PURE__ */ jsx("span", { className: "my-auto h-4 w-px bg-gray-300" }),
|
|
30
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
31
|
+
duration.toFixed(2),
|
|
32
|
+
" ms"
|
|
33
|
+
] })
|
|
34
|
+
] }) : null
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { FilePreviewMeta };
|