@vendure/dashboard 3.2.3 → 3.3.0

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.
Files changed (123) hide show
  1. package/dist/plugin/utils/ast-utils.d.ts +10 -0
  2. package/dist/plugin/utils/ast-utils.js +96 -0
  3. package/dist/plugin/utils/ast-utils.spec.d.ts +1 -0
  4. package/dist/plugin/utils/ast-utils.spec.js +120 -0
  5. package/dist/plugin/{config-loader.d.ts → utils/config-loader.d.ts} +22 -8
  6. package/dist/plugin/utils/config-loader.js +325 -0
  7. package/dist/plugin/{schema-generator.d.ts → utils/schema-generator.d.ts} +5 -0
  8. package/dist/plugin/{schema-generator.js → utils/schema-generator.js} +7 -1
  9. package/dist/plugin/{ui-config.js → utils/ui-config.js} +2 -3
  10. package/dist/plugin/vite-plugin-admin-api-schema.js +2 -2
  11. package/dist/plugin/vite-plugin-config-loader.d.ts +2 -3
  12. package/dist/plugin/vite-plugin-config-loader.js +18 -9
  13. package/dist/plugin/vite-plugin-config.js +4 -6
  14. package/dist/plugin/vite-plugin-dashboard-metadata.js +12 -14
  15. package/dist/plugin/vite-plugin-gql-tada.js +2 -2
  16. package/dist/plugin/vite-plugin-ui-config.js +3 -2
  17. package/package.json +16 -11
  18. package/src/app/app-providers.tsx +9 -9
  19. package/src/app/main.tsx +1 -1
  20. package/src/app/routes/_authenticated/_assets/assets.graphql.ts +26 -0
  21. package/src/app/routes/_authenticated/_assets/assets.tsx +2 -2
  22. package/src/app/routes/_authenticated/_assets/assets_.$id.tsx +156 -0
  23. package/src/app/routes/_authenticated/_orders/components/customer-address-selector.tsx +104 -0
  24. package/src/app/routes/_authenticated/_orders/components/edit-order-table.tsx +228 -0
  25. package/src/app/routes/_authenticated/_orders/components/money-gross-net.tsx +18 -0
  26. package/src/app/routes/_authenticated/_orders/components/order-address.tsx +2 -1
  27. package/src/app/routes/_authenticated/_orders/components/order-line-custom-fields-form.tsx +38 -0
  28. package/src/app/routes/_authenticated/_orders/components/order-table-totals.tsx +53 -0
  29. package/src/app/routes/_authenticated/_orders/components/order-table.tsx +8 -49
  30. package/src/app/routes/_authenticated/_orders/components/shipping-method-selector.tsx +65 -0
  31. package/src/app/routes/_authenticated/_orders/orders.graphql.ts +187 -2
  32. package/src/app/routes/_authenticated/_orders/orders.tsx +39 -18
  33. package/src/app/routes/_authenticated/_orders/orders_.$id.tsx +31 -9
  34. package/src/app/routes/_authenticated/_orders/orders_.draft.$id.tsx +418 -0
  35. package/src/app/routes/_authenticated/_product-variants/product-variants_.$id.tsx +8 -2
  36. package/src/app/routes/_authenticated/_products/products.tsx +1 -1
  37. package/src/app/routes/_authenticated/_promotions/promotions_.$id.tsx +6 -0
  38. package/src/app/routes/_authenticated/_system/job-queue.tsx +7 -8
  39. package/src/app/routes/_authenticated/_system/scheduled-tasks.tsx +241 -0
  40. package/src/app/routes/_authenticated.tsx +12 -1
  41. package/src/app/styles.css +15 -0
  42. package/src/lib/components/data-table/add-filter-menu.tsx +61 -0
  43. package/src/lib/components/data-table/data-table-column-header.tsx +0 -13
  44. package/src/lib/components/data-table/data-table-filter-badge.tsx +75 -0
  45. package/src/lib/components/data-table/data-table-filter-dialog.tsx +27 -28
  46. package/src/lib/components/data-table/data-table-types.ts +1 -0
  47. package/src/lib/components/data-table/data-table-view-options.tsx +73 -24
  48. package/src/lib/components/data-table/data-table.tsx +49 -44
  49. package/src/lib/components/data-table/filters/data-table-boolean-filter.tsx +57 -0
  50. package/src/lib/components/data-table/filters/data-table-datetime-filter.tsx +93 -0
  51. package/src/lib/components/data-table/filters/data-table-id-filter.tsx +58 -0
  52. package/src/lib/components/data-table/filters/data-table-number-filter.tsx +119 -0
  53. package/src/lib/components/data-table/filters/data-table-string-filter.tsx +62 -0
  54. package/src/lib/components/data-table/human-readable-operator.tsx +65 -0
  55. package/src/lib/components/data-table/refresh-button.tsx +25 -0
  56. package/src/lib/components/layout/nav-user.tsx +20 -15
  57. package/src/lib/components/layout/prerelease-popup.tsx +1 -5
  58. package/src/lib/components/shared/alerts.tsx +19 -1
  59. package/src/lib/components/shared/asset/asset-focal-point-editor.tsx +93 -0
  60. package/src/lib/components/shared/{asset-gallery.tsx → asset/asset-gallery.tsx} +51 -20
  61. package/src/lib/components/shared/{asset-picker-dialog.tsx → asset/asset-picker-dialog.tsx} +1 -1
  62. package/src/lib/components/shared/{asset-preview-dialog.tsx → asset/asset-preview-dialog.tsx} +1 -7
  63. package/src/lib/components/shared/asset/asset-preview-selector.tsx +34 -0
  64. package/src/lib/components/shared/asset/asset-preview.tsx +128 -0
  65. package/src/lib/components/shared/asset/asset-properties.tsx +46 -0
  66. package/src/lib/components/shared/{focal-point-control.tsx → asset/focal-point-control.tsx} +1 -1
  67. package/src/lib/components/shared/custom-fields-form.tsx +4 -3
  68. package/src/lib/components/shared/customer-selector.tsx +13 -14
  69. package/src/lib/components/shared/detail-page-button.tsx +2 -2
  70. package/src/lib/components/shared/entity-assets.tsx +3 -3
  71. package/src/lib/components/shared/error-page.tsx +2 -2
  72. package/src/lib/components/shared/navigation-confirmation.tsx +49 -0
  73. package/src/lib/components/shared/paginated-list-data-table.tsx +10 -1
  74. package/src/lib/components/shared/product-variant-selector.tsx +111 -0
  75. package/src/lib/components/shared/vendure-image.tsx +1 -1
  76. package/src/lib/components/ui/calendar.tsx +508 -63
  77. package/src/lib/framework/alert/alert-extensions.tsx +31 -0
  78. package/src/lib/framework/alert/alert-item.tsx +47 -0
  79. package/src/lib/framework/alert/alerts-indicator.tsx +23 -0
  80. package/src/lib/framework/alert/types.ts +13 -0
  81. package/src/lib/framework/dashboard-widget/base-widget.tsx +1 -0
  82. package/src/lib/framework/defaults.ts +34 -0
  83. package/src/lib/framework/document-introspection/get-document-structure.spec.ts +113 -3
  84. package/src/lib/framework/document-introspection/get-document-structure.ts +71 -13
  85. package/src/lib/framework/extension-api/define-dashboard-extension.ts +15 -5
  86. package/src/lib/framework/extension-api/extension-api-types.ts +81 -12
  87. package/src/lib/framework/form-engine/use-generated-form.tsx +8 -7
  88. package/src/lib/framework/layout-engine/layout-extensions.ts +3 -3
  89. package/src/lib/framework/layout-engine/page-layout.tsx +196 -35
  90. package/src/lib/framework/layout-engine/page-provider.tsx +10 -0
  91. package/src/lib/framework/page/detail-page.tsx +62 -9
  92. package/src/lib/framework/page/list-page.tsx +42 -4
  93. package/src/lib/framework/page/page-api.ts +1 -1
  94. package/src/lib/framework/page/use-detail-page.ts +82 -0
  95. package/src/lib/framework/registry/registry-types.ts +6 -2
  96. package/src/lib/graphql/fragments.tsx +8 -0
  97. package/src/lib/graphql/graphql-env.d.ts +25 -9
  98. package/src/lib/hooks/use-auth.tsx +13 -1
  99. package/src/lib/hooks/use-channel.ts +13 -0
  100. package/src/lib/hooks/use-local-format.ts +28 -1
  101. package/src/lib/hooks/use-page.tsx +2 -3
  102. package/src/lib/hooks/use-permissions.ts +13 -0
  103. package/src/lib/index.ts +7 -8
  104. package/src/lib/providers/auth.tsx +22 -9
  105. package/src/lib/providers/channel-provider.tsx +9 -1
  106. package/src/lib/providers/server-config.tsx +7 -1
  107. package/src/lib/providers/user-settings.tsx +24 -0
  108. package/vite/utils/ast-utils.spec.ts +128 -0
  109. package/vite/utils/ast-utils.ts +119 -0
  110. package/vite/utils/config-loader.ts +410 -0
  111. package/vite/{schema-generator.ts → utils/schema-generator.ts} +11 -6
  112. package/vite/{ui-config.ts → utils/ui-config.ts} +7 -3
  113. package/vite/vite-plugin-admin-api-schema.ts +2 -12
  114. package/vite/vite-plugin-config-loader.ts +25 -13
  115. package/vite/vite-plugin-config.ts +1 -0
  116. package/vite/vite-plugin-dashboard-metadata.ts +19 -15
  117. package/vite/vite-plugin-gql-tada.ts +2 -2
  118. package/vite/vite-plugin-ui-config.ts +3 -2
  119. package/dist/plugin/config-loader.js +0 -141
  120. package/src/lib/components/shared/asset-preview.tsx +0 -345
  121. package/src/lib/components/ui/avatar.tsx +0 -38
  122. package/vite/config-loader.ts +0 -181
  123. /package/dist/plugin/{ui-config.d.ts → utils/ui-config.d.ts} +0 -0
@@ -2,7 +2,7 @@ import { AdminUiConfig, VendureConfig } from '@vendure/core';
2
2
  import path from 'path';
3
3
  import { Plugin } from 'vite';
4
4
 
5
- import { getAdminUiConfig } from './ui-config.js';
5
+ import { getAdminUiConfig } from './utils/ui-config.js';
6
6
  import { ConfigLoaderApi, getConfigLoaderApi } from './vite-plugin-config-loader.js';
7
7
 
8
8
  const virtualModuleId = 'virtual:vendure-ui-config';
@@ -38,7 +38,8 @@ export function uiConfigPlugin({ adminUiConfig }: UiConfigPluginOptions): Plugin
38
38
  async load(id) {
39
39
  if (id === resolvedVirtualModuleId) {
40
40
  if (!vendureConfig) {
41
- vendureConfig = await configLoaderApi.getVendureConfig();
41
+ const result = await configLoaderApi.getVendureConfig();
42
+ vendureConfig = result.vendureConfig;
42
43
  }
43
44
 
44
45
  const config = getAdminUiConfig(vendureConfig, adminUiConfig);
@@ -1,141 +0,0 @@
1
- import { parse, transform } from '@swc/core';
2
- import fs from 'fs-extra';
3
- import path from 'path';
4
- import { pathToFileURL } from 'url';
5
- /**
6
- * @description
7
- * This function compiles the given Vendure config file and any imported relative files (i.e.
8
- * project files, not npm packages) into a temporary directory, and returns the compiled config.
9
- *
10
- * The reason we need to do this is that Vendure code makes use of TypeScript experimental decorators
11
- * (e.g. for NestJS decorators and TypeORM column decorators) which are not supported by esbuild.
12
- *
13
- * In Vite, when we load some TypeScript into the top-level Vite config file (in the end-user project), Vite
14
- * internally uses esbuild to temporarily compile that TypeScript code. Unfortunately, esbuild does not support
15
- * these experimental decorators, errors will be thrown as soon as e.g. a TypeORM column decorator is encountered.
16
- *
17
- * To work around this, we compile the Vendure config file and all its imports using SWC, which does support
18
- * these experimental decorators. The compiled files are then loaded by Vite, which is able to handle the compiled
19
- * JavaScript output.
20
- */
21
- export async function loadVendureConfig(options) {
22
- const { vendureConfigPath, vendureConfigExport, tempDir } = options;
23
- const outputPath = tempDir;
24
- const configFileName = path.basename(vendureConfigPath);
25
- const inputRootDir = path.dirname(vendureConfigPath);
26
- await fs.remove(outputPath);
27
- await compileFile(inputRootDir, vendureConfigPath, outputPath);
28
- const compiledConfigFilePath = pathToFileURL(path.join(outputPath, configFileName)).href.replace(/.ts$/, '.js');
29
- // create package.json with type commonjs and save it to the output dir
30
- await fs.writeFile(path.join(outputPath, 'package.json'), JSON.stringify({ type: 'commonjs' }, null, 2));
31
- // We need to figure out the symbol exported by the config file by
32
- // analyzing the AST and finding an export with the type "VendureConfig"
33
- const ast = await parse(await fs.readFile(vendureConfigPath, 'utf-8'), {
34
- syntax: 'typescript',
35
- decorators: true,
36
- });
37
- const detectedExportedSymbolName = findConfigExport(ast.body);
38
- const configExportedSymbolName = detectedExportedSymbolName || vendureConfigExport;
39
- if (!configExportedSymbolName) {
40
- throw new Error(`Could not find a variable exported as VendureConfig. Please specify the name of the exported variable using the "vendureConfigExport" option.`);
41
- }
42
- const config = await import(compiledConfigFilePath).then(m => m[configExportedSymbolName]);
43
- if (!config) {
44
- throw new Error(`Could not find a variable exported as VendureConfig with the name "${configExportedSymbolName}".`);
45
- }
46
- return { vendureConfig: config, exportedSymbolName: configExportedSymbolName };
47
- }
48
- /**
49
- * Given the AST of a TypeScript file, finds the name of the variable exported as VendureConfig.
50
- */
51
- function findConfigExport(statements) {
52
- var _a;
53
- for (const statement of statements) {
54
- if (statement.type === 'ExportDeclaration') {
55
- if (statement.declaration.type === 'VariableDeclaration') {
56
- for (const declaration of statement.declaration.declarations) {
57
- if (isBindingIdentifier(declaration.id)) {
58
- const typeRef = (_a = declaration.id.typeAnnotation) === null || _a === void 0 ? void 0 : _a.typeAnnotation;
59
- if ((typeRef === null || typeRef === void 0 ? void 0 : typeRef.type) === 'TsTypeReference') {
60
- if (typeRef.typeName.type === 'Identifier' &&
61
- typeRef.typeName.value === 'VendureConfig') {
62
- return declaration.id.value;
63
- }
64
- }
65
- }
66
- }
67
- }
68
- }
69
- }
70
- return undefined;
71
- }
72
- function isBindingIdentifier(id) {
73
- return id.type === 'Identifier' && !!id.typeAnnotation;
74
- }
75
- export async function compileFile(inputRootDir, inputPath, outputDir, compiledFiles = new Set()) {
76
- if (compiledFiles.has(inputPath)) {
77
- return;
78
- }
79
- compiledFiles.add(inputPath);
80
- // Ensure output directory exists
81
- await fs.ensureDir(outputDir);
82
- // Read the source file
83
- const source = await fs.readFile(inputPath, 'utf-8');
84
- // Transform config
85
- const config = {
86
- filename: inputPath,
87
- sourceMaps: true,
88
- jsc: {
89
- parser: {
90
- syntax: 'typescript',
91
- tsx: false,
92
- decorators: true,
93
- },
94
- target: 'es2020',
95
- loose: false,
96
- transform: {
97
- legacyDecorator: true,
98
- decoratorMetadata: true,
99
- },
100
- },
101
- module: {
102
- type: 'commonjs',
103
- strict: true,
104
- strictMode: true,
105
- lazy: false,
106
- noInterop: false,
107
- },
108
- };
109
- // Transform the code using SWC
110
- const result = await transform(source, config);
111
- // Generate output file path
112
- const relativePath = path.relative(inputRootDir, inputPath);
113
- const outputPath = path.join(outputDir, relativePath).replace(/\.ts$/, '.js');
114
- // Ensure the subdirectory for the output file exists
115
- await fs.ensureDir(path.dirname(outputPath));
116
- // Write the transformed code
117
- await fs.writeFile(outputPath, result.code);
118
- // Write source map if available
119
- if (result.map) {
120
- await fs.writeFile(`${outputPath}.map`, JSON.stringify(result.map));
121
- }
122
- // Parse the source to find relative imports
123
- const ast = await parse(source, { syntax: 'typescript', decorators: true });
124
- const importPaths = new Set();
125
- function collectImports(node) {
126
- if (node.type === 'ImportDeclaration' && node.source.value.startsWith('.')) {
127
- const importPath = path.resolve(path.dirname(inputPath), node.source.value);
128
- importPaths.add(importPath + '.ts');
129
- }
130
- for (const key in node) {
131
- if (node[key] && typeof node[key] === 'object') {
132
- collectImports(node[key]);
133
- }
134
- }
135
- }
136
- collectImports(ast);
137
- // Recursively compile all relative imports
138
- for (const importPath of importPaths) {
139
- await compileFile(inputRootDir, importPath, outputDir, compiledFiles);
140
- }
141
- }
@@ -1,345 +0,0 @@
1
- import { Button } from '@/components/ui/button.js';
2
- import { Card, CardContent, CardHeader } from '@/components/ui/card.js';
3
- import { FormControl, FormField, FormItem, FormLabel } from '@/components/ui/form.js';
4
- import { Input } from '@/components/ui/input.js';
5
- import { Label } from '@/components/ui/label.js';
6
- import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select.js';
7
- import { VendureImage } from '@/components/shared/vendure-image.js';
8
- import { AssetFragment } from '@/graphql/fragments.js';
9
- import { cn, formatFileSize } from '@/lib/utils.js';
10
- import { ChevronLeft, ChevronRight, Crosshair, Edit, ExternalLink, X } from 'lucide-react';
11
- import { useEffect, useRef, useState } from 'react';
12
- import { useForm } from 'react-hook-form';
13
- import { FocalPointControl } from './focal-point-control.js';
14
-
15
- export type PreviewPreset = 'tiny' | 'thumb' | 'small' | 'medium' | 'large' | '';
16
-
17
- interface Point {
18
- x: number;
19
- y: number;
20
- }
21
-
22
- export type AssetWithTags = AssetFragment & { tags?: { value: string }[] };
23
-
24
- interface AssetPreviewProps {
25
- asset: AssetWithTags;
26
- assets?: AssetWithTags[];
27
- editable?: boolean;
28
- customFields?: any[];
29
- onAssetChange?: (asset: Partial<AssetWithTags>) => void;
30
- onEditClick?: () => void;
31
- }
32
-
33
- export function AssetPreview({
34
- asset,
35
- assets,
36
- editable = false,
37
- customFields = [],
38
- onAssetChange,
39
- onEditClick,
40
- }: AssetPreviewProps) {
41
- const [size, setSize] = useState<PreviewPreset>('medium');
42
- const [width, setWidth] = useState(0);
43
- const [height, setHeight] = useState(0);
44
- const [centered, setCentered] = useState(true);
45
- const [settingFocalPoint, setSettingFocalPoint] = useState(false);
46
- const [lastFocalPoint, setLastFocalPoint] = useState<Point>();
47
- const [assetIndex, setAssetIndex] = useState(assets?.indexOf(asset) || 0);
48
-
49
- const imageRef = useRef<HTMLImageElement>(null);
50
- const containerRef = useRef<HTMLDivElement>(null);
51
- const sizePriorToFocalPoint = useRef<PreviewPreset>('medium');
52
-
53
- const form = useForm({
54
- defaultValues: {
55
- name: asset.name,
56
- tags: asset.tags?.map(t => t.value) || [],
57
- },
58
- });
59
- const activeAsset = assets?.[assetIndex] ?? asset;
60
-
61
- useEffect(() => {
62
- if (assets?.length) {
63
- const index = assets.findIndex(a => a.id === asset.id);
64
- setAssetIndex(index === -1 ? 0 : index);
65
- }
66
- }, [assets, asset.id]);
67
-
68
- useEffect(() => {
69
- const handleResize = () => {
70
- updateDimensions();
71
- };
72
-
73
- window.addEventListener('resize', handleResize);
74
- return () => window.removeEventListener('resize', handleResize);
75
- }, []);
76
-
77
- const updateDimensions = () => {
78
- if (!imageRef.current || !containerRef.current) return;
79
-
80
- const img = imageRef.current;
81
- const container = containerRef.current;
82
- const imgWidth = img.naturalWidth;
83
- const imgHeight = img.naturalHeight;
84
- const containerWidth = container.offsetWidth;
85
- const containerHeight = container.offsetHeight;
86
-
87
- if (settingFocalPoint) {
88
- const controlsMarginPx = 48 * 2;
89
- const availableHeight = containerHeight - controlsMarginPx;
90
- const availableWidth = containerWidth;
91
- const hRatio = imgHeight / availableHeight;
92
- const wRatio = imgWidth / availableWidth;
93
-
94
- if (1 < hRatio || 1 < wRatio) {
95
- const factor = hRatio < wRatio ? wRatio : hRatio;
96
- setWidth(Math.round(imgWidth / factor));
97
- setHeight(Math.round(imgHeight / factor));
98
- setCentered(true);
99
- return;
100
- }
101
- }
102
-
103
- setWidth(imgWidth);
104
- setHeight(imgHeight);
105
- setCentered(imgWidth <= containerWidth && imgHeight <= containerHeight);
106
- };
107
-
108
- const handleFocalPointStart = () => {
109
- sizePriorToFocalPoint.current = size;
110
- setSize('medium');
111
- setSettingFocalPoint(true);
112
- setLastFocalPoint(asset.focalPoint || { x: 0.5, y: 0.5 });
113
- updateDimensions();
114
- };
115
-
116
- const handleFocalPointChange = (point: Point) => {
117
- setLastFocalPoint(point);
118
- };
119
-
120
- const handleFocalPointCancel = () => {
121
- setSettingFocalPoint(false);
122
- setLastFocalPoint(undefined);
123
- setSize(sizePriorToFocalPoint.current);
124
- };
125
-
126
- const handleFocalPointSet = async () => {
127
- if (!lastFocalPoint) return;
128
-
129
- try {
130
- // TODO: Implement API call to update focal point
131
- await onAssetChange?.({
132
- id: asset.id,
133
- focalPoint: lastFocalPoint,
134
- });
135
- setSettingFocalPoint(false);
136
- setSize(sizePriorToFocalPoint.current);
137
- // Show success toast
138
- } catch (err) {
139
- // Show error toast
140
- }
141
- };
142
-
143
- const handleRemoveFocalPoint = async () => {
144
- try {
145
- // TODO: Implement API call to remove focal point
146
- await onAssetChange?.({
147
- id: asset.id,
148
- focalPoint: null,
149
- });
150
- // Show success toast
151
- } catch (err) {
152
- // Show error toast
153
- }
154
- };
155
-
156
- return (
157
- <div className="grid grid-cols-1 md:grid-cols-[300px_1fr] gap-4 h-full">
158
- <div className="space-y-4">
159
- <Card>
160
- <CardContent className="space-y-4 pt-6">
161
- {!editable && onEditClick && (
162
- <Button variant="ghost" className="w-full justify-start" onClick={onEditClick}>
163
- <Edit className="mr-2 h-4 w-4" />
164
- Edit
165
- <ChevronRight className="ml-auto h-4 w-4" />
166
- </Button>
167
- )}
168
-
169
- {editable ? (
170
- <FormField
171
- control={form.control}
172
- name="name"
173
- render={({ field }) => (
174
- <FormItem>
175
- <FormLabel>Name</FormLabel>
176
- <FormControl>
177
- <Input {...field} />
178
- </FormControl>
179
- </FormItem>
180
- )}
181
- />
182
- ) : (
183
- <div>
184
- <Label>Name</Label>
185
- <p className="truncate text-sm text-muted-foreground">{activeAsset.name}</p>
186
- </div>
187
- )}
188
-
189
- <div>
190
- <Label>Source File</Label>
191
- <a
192
- href={activeAsset.source}
193
- target="_blank"
194
- rel="noopener noreferrer"
195
- className="text-sm text-primary hover:underline flex items-center"
196
- >
197
- {activeAsset.source.split('/').pop()}
198
- <ExternalLink className="ml-1 h-3 w-3" />
199
- </a>
200
- </div>
201
-
202
- <div>
203
- <Label>File Size</Label>
204
- <p className="text-sm text-muted-foreground">
205
- {formatFileSize(activeAsset.fileSize)}
206
- </p>
207
- </div>
208
-
209
- <div>
210
- <Label>Dimensions</Label>
211
- <p className="text-sm text-muted-foreground">
212
- {activeAsset.width} x {activeAsset.height}
213
- </p>
214
- </div>
215
-
216
- <div>
217
- <Label>Focal Point</Label>
218
- <div className="space-y-2">
219
- <p className="text-sm text-muted-foreground">
220
- {activeAsset.focalPoint ? (
221
- <span className="flex items-center">
222
- <Crosshair className="mr-1 h-4 w-4" />
223
- x: {activeAsset.focalPoint.x.toFixed(2)}, y:{' '}
224
- {activeAsset.focalPoint.y.toFixed(2)}
225
- </span>
226
- ) : (
227
- 'Not set'
228
- )}
229
- </p>
230
- <div className="flex gap-2">
231
- <Button
232
- variant="secondary"
233
- size="sm"
234
- disabled={settingFocalPoint}
235
- onClick={handleFocalPointStart}
236
- >
237
- {activeAsset.focalPoint ? 'Update' : 'Set'} Focal Point
238
- </Button>
239
- {activeAsset.focalPoint && (
240
- <Button
241
- variant="secondary"
242
- size="sm"
243
- disabled={settingFocalPoint}
244
- onClick={handleRemoveFocalPoint}
245
- >
246
- Remove
247
- </Button>
248
- )}
249
- </div>
250
- </div>
251
- </div>
252
- </CardContent>
253
- </Card>
254
-
255
- <Card>
256
- <CardHeader>Preview Options</CardHeader>
257
- <CardContent className="space-y-4">
258
- <Select value={size} onValueChange={value => setSize(value as PreviewPreset)}>
259
- <SelectTrigger>
260
- <SelectValue placeholder="Select size" />
261
- </SelectTrigger>
262
- <SelectContent>
263
- <SelectItem value="tiny">Tiny</SelectItem>
264
- <SelectItem value="thumb">Thumb</SelectItem>
265
- <SelectItem value="small">Small</SelectItem>
266
- <SelectItem value="medium">Medium</SelectItem>
267
- <SelectItem value="large">Large</SelectItem>
268
- <SelectItem value="full">Full Size</SelectItem>
269
- </SelectContent>
270
- </Select>
271
- <p className="text-sm text-muted-foreground">
272
- {width} x {height}
273
- </p>
274
- </CardContent>
275
- </Card>
276
- </div>
277
-
278
- <div className="relative flex items-center justify-center bg-muted/30 rounded-lg">
279
- {assets && assets.length > 1 && (
280
- <>
281
- <Button
282
- variant="ghost"
283
- size="icon"
284
- className="absolute left-4 z-10"
285
- onClick={() => setAssetIndex(i => i - 1)}
286
- disabled={assetIndex === 0}
287
- >
288
- <ChevronLeft className="h-4 w-4" />
289
- </Button>
290
- <Button
291
- variant="ghost"
292
- size="icon"
293
- className="absolute right-4 z-10"
294
- onClick={() => setAssetIndex(i => i + 1)}
295
- disabled={assetIndex === assets.length - 1}
296
- >
297
- <ChevronRight className="h-4 w-4" />
298
- </Button>
299
- </>
300
- )}
301
-
302
- <div
303
- ref={containerRef}
304
- className={cn(
305
- 'relative',
306
- centered && 'flex items-center justify-center',
307
- settingFocalPoint && 'cursor-crosshair',
308
- )}
309
- >
310
- <div className="relative" style={{ width: `${width}px`, height: `${height}px` }}>
311
- <VendureImage
312
- ref={imageRef}
313
- asset={activeAsset}
314
- preset={size || undefined}
315
- mode="resize"
316
- onLoad={updateDimensions}
317
- className="max-w-full max-h-full object-contain"
318
- />
319
- {settingFocalPoint && lastFocalPoint && (
320
- <FocalPointControl
321
- width={width}
322
- height={height}
323
- point={lastFocalPoint}
324
- onChange={handleFocalPointChange}
325
- />
326
- )}
327
- </div>
328
-
329
- {settingFocalPoint && (
330
- <div className="absolute bottom-4 left-1/2 -translate-x-1/2 flex gap-2">
331
- <Button variant="secondary" onClick={handleFocalPointCancel}>
332
- <X className="mr-2 h-4 w-4" />
333
- Cancel
334
- </Button>
335
- <Button onClick={handleFocalPointSet}>
336
- <Crosshair className="mr-2 h-4 w-4" />
337
- Set Focal Point
338
- </Button>
339
- </div>
340
- )}
341
- </div>
342
- </div>
343
- </div>
344
- );
345
- }
@@ -1,38 +0,0 @@
1
- 'use client';
2
-
3
- import * as React from 'react';
4
- import * as AvatarPrimitive from '@radix-ui/react-avatar';
5
-
6
- import { cn } from '@/lib/utils.js';
7
-
8
- function Avatar({ className, ...props }: React.ComponentProps<typeof AvatarPrimitive.Root>) {
9
- return (
10
- <AvatarPrimitive.Root
11
- data-slot="avatar"
12
- className={cn('relative flex size-8 shrink-0 overflow-hidden rounded-full', className)}
13
- {...props}
14
- />
15
- );
16
- }
17
-
18
- function AvatarImage({ className, ...props }: React.ComponentProps<typeof AvatarPrimitive.Image>) {
19
- return (
20
- <AvatarPrimitive.Image
21
- data-slot="avatar-image"
22
- className={cn('aspect-square size-full', className)}
23
- {...props}
24
- />
25
- );
26
- }
27
-
28
- function AvatarFallback({ className, ...props }: React.ComponentProps<typeof AvatarPrimitive.Fallback>) {
29
- return (
30
- <AvatarPrimitive.Fallback
31
- data-slot="avatar-fallback"
32
- className={cn('bg-muted flex size-full items-center justify-center rounded-full', className)}
33
- {...props}
34
- />
35
- );
36
- }
37
-
38
- export { Avatar, AvatarImage, AvatarFallback };