@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
@@ -1,181 +0,0 @@
1
- import { Options, parse, transform } from '@swc/core';
2
- import { BindingIdentifier, ModuleItem, Pattern, Statement } from '@swc/types';
3
- import { VendureConfig } from '@vendure/core';
4
- import fs from 'fs-extra';
5
- import path from 'path';
6
- import { pathToFileURL } from 'url';
7
-
8
- export interface ConfigLoaderOptions {
9
- vendureConfigPath: string;
10
- tempDir: string;
11
- vendureConfigExport?: string;
12
- }
13
-
14
- /**
15
- * @description
16
- * This function compiles the given Vendure config file and any imported relative files (i.e.
17
- * project files, not npm packages) into a temporary directory, and returns the compiled config.
18
- *
19
- * The reason we need to do this is that Vendure code makes use of TypeScript experimental decorators
20
- * (e.g. for NestJS decorators and TypeORM column decorators) which are not supported by esbuild.
21
- *
22
- * In Vite, when we load some TypeScript into the top-level Vite config file (in the end-user project), Vite
23
- * internally uses esbuild to temporarily compile that TypeScript code. Unfortunately, esbuild does not support
24
- * these experimental decorators, errors will be thrown as soon as e.g. a TypeORM column decorator is encountered.
25
- *
26
- * To work around this, we compile the Vendure config file and all its imports using SWC, which does support
27
- * these experimental decorators. The compiled files are then loaded by Vite, which is able to handle the compiled
28
- * JavaScript output.
29
- */
30
- export async function loadVendureConfig(
31
- options: ConfigLoaderOptions,
32
- ): Promise<{ vendureConfig: VendureConfig; exportedSymbolName: string }> {
33
- const { vendureConfigPath, vendureConfigExport, tempDir } = options;
34
- const outputPath = tempDir;
35
- const configFileName = path.basename(vendureConfigPath);
36
- const inputRootDir = path.dirname(vendureConfigPath);
37
- await fs.remove(outputPath);
38
- await compileFile(inputRootDir, vendureConfigPath, outputPath);
39
- const compiledConfigFilePath = pathToFileURL(path.join(outputPath, configFileName)).href.replace(
40
- /.ts$/,
41
- '.js',
42
- );
43
- // create package.json with type commonjs and save it to the output dir
44
- await fs.writeFile(path.join(outputPath, 'package.json'), JSON.stringify({ type: 'commonjs' }, null, 2));
45
-
46
- // We need to figure out the symbol exported by the config file by
47
- // analyzing the AST and finding an export with the type "VendureConfig"
48
- const ast = await parse(await fs.readFile(vendureConfigPath, 'utf-8'), {
49
- syntax: 'typescript',
50
- decorators: true,
51
- });
52
- const detectedExportedSymbolName = findConfigExport(ast.body);
53
- const configExportedSymbolName = detectedExportedSymbolName || vendureConfigExport;
54
- if (!configExportedSymbolName) {
55
- throw new Error(
56
- `Could not find a variable exported as VendureConfig. Please specify the name of the exported variable using the "vendureConfigExport" option.`,
57
- );
58
- }
59
- const config = await import(compiledConfigFilePath).then(m => m[configExportedSymbolName]);
60
- if (!config) {
61
- throw new Error(
62
- `Could not find a variable exported as VendureConfig with the name "${configExportedSymbolName}".`,
63
- );
64
- }
65
- return { vendureConfig: config, exportedSymbolName: configExportedSymbolName };
66
- }
67
-
68
- /**
69
- * Given the AST of a TypeScript file, finds the name of the variable exported as VendureConfig.
70
- */
71
- function findConfigExport(statements: ModuleItem[]): string | undefined {
72
- for (const statement of statements) {
73
- if (statement.type === 'ExportDeclaration') {
74
- if (statement.declaration.type === 'VariableDeclaration') {
75
- for (const declaration of statement.declaration.declarations) {
76
- if (isBindingIdentifier(declaration.id)) {
77
- const typeRef = declaration.id.typeAnnotation?.typeAnnotation;
78
- if (typeRef?.type === 'TsTypeReference') {
79
- if (
80
- typeRef.typeName.type === 'Identifier' &&
81
- typeRef.typeName.value === 'VendureConfig'
82
- ) {
83
- return declaration.id.value;
84
- }
85
- }
86
- }
87
- }
88
- }
89
- }
90
- }
91
- return undefined;
92
- }
93
-
94
- function isBindingIdentifier(id: Pattern): id is BindingIdentifier {
95
- return id.type === 'Identifier' && !!(id as BindingIdentifier).typeAnnotation;
96
- }
97
-
98
- export async function compileFile(
99
- inputRootDir: string,
100
- inputPath: string,
101
- outputDir: string,
102
- compiledFiles = new Set<string>(),
103
- ): Promise<void> {
104
- if (compiledFiles.has(inputPath)) {
105
- return;
106
- }
107
- compiledFiles.add(inputPath);
108
-
109
- // Ensure output directory exists
110
- await fs.ensureDir(outputDir);
111
-
112
- // Read the source file
113
- const source = await fs.readFile(inputPath, 'utf-8');
114
-
115
- // Transform config
116
- const config: Options = {
117
- filename: inputPath,
118
- sourceMaps: true,
119
- jsc: {
120
- parser: {
121
- syntax: 'typescript',
122
- tsx: false,
123
- decorators: true,
124
- },
125
- target: 'es2020',
126
- loose: false,
127
- transform: {
128
- legacyDecorator: true,
129
- decoratorMetadata: true,
130
- },
131
- },
132
- module: {
133
- type: 'commonjs',
134
- strict: true,
135
- strictMode: true,
136
- lazy: false,
137
- noInterop: false,
138
- },
139
- };
140
-
141
- // Transform the code using SWC
142
- const result = await transform(source, config);
143
-
144
- // Generate output file path
145
- const relativePath = path.relative(inputRootDir, inputPath);
146
- const outputPath = path.join(outputDir, relativePath).replace(/\.ts$/, '.js');
147
-
148
- // Ensure the subdirectory for the output file exists
149
- await fs.ensureDir(path.dirname(outputPath));
150
-
151
- // Write the transformed code
152
- await fs.writeFile(outputPath, result.code);
153
-
154
- // Write source map if available
155
- if (result.map) {
156
- await fs.writeFile(`${outputPath}.map`, JSON.stringify(result.map));
157
- }
158
-
159
- // Parse the source to find relative imports
160
- const ast = await parse(source, { syntax: 'typescript', decorators: true });
161
- const importPaths = new Set<string>();
162
-
163
- function collectImports(node: any) {
164
- if (node.type === 'ImportDeclaration' && node.source.value.startsWith('.')) {
165
- const importPath = path.resolve(path.dirname(inputPath), node.source.value);
166
- importPaths.add(importPath + '.ts');
167
- }
168
- for (const key in node) {
169
- if (node[key] && typeof node[key] === 'object') {
170
- collectImports(node[key]);
171
- }
172
- }
173
- }
174
-
175
- collectImports(ast);
176
-
177
- // Recursively compile all relative imports
178
- for (const importPath of importPaths) {
179
- await compileFile(inputRootDir, importPath, outputDir, compiledFiles);
180
- }
181
- }