@vendure-io/ui 2.0.0-beta.9 → 2.0.0-rc.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 (75) hide show
  1. package/LICENSE.md +34 -0
  2. package/package.json +8 -6
  3. package/src/components/atoms/alert-dialog.tsx +1 -1
  4. package/src/components/atoms/alert.tsx +1 -1
  5. package/src/components/atoms/badge.tsx +1 -1
  6. package/src/components/atoms/button.tsx +2 -2
  7. package/src/components/atoms/card.tsx +39 -4
  8. package/src/components/atoms/checkbox.tsx +1 -1
  9. package/src/components/atoms/combobox.tsx +24 -5
  10. package/src/components/atoms/command.tsx +16 -5
  11. package/src/components/atoms/context-menu.tsx +1 -1
  12. package/src/components/atoms/dialog.tsx +1 -1
  13. package/src/components/atoms/drawer.tsx +134 -35
  14. package/src/components/atoms/dropdown-menu.tsx +1 -1
  15. package/src/components/atoms/field.tsx +2 -2
  16. package/src/components/atoms/input.tsx +1 -1
  17. package/src/components/atoms/item.tsx +4 -1
  18. package/src/components/atoms/menubar.tsx +1 -1
  19. package/src/components/atoms/native-select.tsx +1 -1
  20. package/src/components/atoms/navigation-menu.tsx +8 -2
  21. package/src/components/atoms/progress.tsx +1 -1
  22. package/src/components/atoms/radio-group.tsx +1 -1
  23. package/src/components/atoms/scroll-area.tsx +1 -2
  24. package/src/components/atoms/select.tsx +1 -1
  25. package/src/components/atoms/sheet.tsx +1 -1
  26. package/src/components/atoms/sidebar.tsx +6 -4
  27. package/src/components/atoms/slider.tsx +2 -2
  28. package/src/components/atoms/switch.tsx +1 -1
  29. package/src/components/atoms/table.tsx +34 -2
  30. package/src/components/atoms/tabs.tsx +64 -1
  31. package/src/components/atoms/textarea.tsx +1 -1
  32. package/src/components/atoms/toggle-group.tsx +1 -1
  33. package/src/components/atoms/toggle.tsx +5 -2
  34. package/src/components/molecules/chip.tsx +7 -2
  35. package/src/components/molecules/code-block/file-type-icons.tsx +123 -0
  36. package/src/components/molecules/code-block/process-code.ts +60 -0
  37. package/src/components/molecules/code-block/transform-command.tsx +177 -0
  38. package/src/components/molecules/code-block.tsx +25 -443
  39. package/src/components/molecules/combobox-free-text.tsx +23 -2
  40. package/src/components/molecules/copyable-text.tsx +14 -1
  41. package/src/components/molecules/data-table/data-table-bulk-actions.tsx +12 -13
  42. package/src/components/molecules/data-table/data-table-types.tsx +50 -2
  43. package/src/components/molecules/data-table/data-table-view-options.tsx +2 -1
  44. package/src/components/molecules/data-table/data-table.tsx +188 -96
  45. package/src/components/molecules/date-picker.tsx +3 -1
  46. package/src/components/molecules/date-range-picker.tsx +3 -1
  47. package/src/components/molecules/date-time-picker.tsx +3 -1
  48. package/src/components/molecules/file-dropzone.tsx +15 -5
  49. package/src/components/molecules/illustrations/empty-database.tsx +8 -5
  50. package/src/components/molecules/illustrations/error.tsx +19 -17
  51. package/src/components/molecules/illustrations/expired.tsx +55 -0
  52. package/src/components/molecules/illustrations/first-run.tsx +3 -1
  53. package/src/components/molecules/illustrations/no-activity.tsx +35 -14
  54. package/src/components/molecules/illustrations/no-customers.tsx +66 -0
  55. package/src/components/molecules/illustrations/no-documents.tsx +4 -3
  56. package/src/components/molecules/illustrations/no-invoices.tsx +45 -0
  57. package/src/components/molecules/illustrations/no-notifications.tsx +7 -8
  58. package/src/components/molecules/illustrations/no-orders.tsx +25 -17
  59. package/src/components/molecules/illustrations/no-plugins.tsx +21 -31
  60. package/src/components/molecules/illustrations/no-products.tsx +53 -0
  61. package/src/components/molecules/illustrations/no-projects.tsx +54 -0
  62. package/src/components/molecules/illustrations/no-promotions.tsx +49 -0
  63. package/src/components/molecules/illustrations/no-subscription.tsx +72 -0
  64. package/src/components/molecules/illustrations/not-found.tsx +17 -15
  65. package/src/components/molecules/illustrations/offline.tsx +12 -10
  66. package/src/components/molecules/illustrations/payment-failed.tsx +53 -0
  67. package/src/components/molecules/illustrations/success.tsx +43 -0
  68. package/src/components/molecules/inline-code.tsx +26 -0
  69. package/src/components/molecules/page-header.tsx +7 -3
  70. package/src/components/molecules/stat-card.tsx +13 -12
  71. package/src/components/molecules/state-views/empty-state.tsx +12 -1
  72. package/src/components/molecules/state-views/loading-state.tsx +7 -3
  73. package/src/lib/highlight.ts +37 -1
  74. package/src/lib/state-dictionary.ts +18 -5
  75. package/src/lib/utils.ts +0 -19
@@ -0,0 +1,60 @@
1
+ import { supportsNotationComments } from '@vendure-io/ui/lib/highlight';
2
+
3
+ /**
4
+ * Process code to extract filename directive and strip Shiki notations for unsupported languages.
5
+ * Supports: // filename: path/to/file.ts (must be first line)
6
+ *
7
+ * Note: Line highlighting uses Shiki's native notation:
8
+ * - // [!code highlight] for JS/TS (at end of line)
9
+ * - # [!code highlight] for bash/shell (at end of line)
10
+ * - // [!code ++] and // [!code --] for diff
11
+ * - // [!code focus] for focus mode
12
+ *
13
+ * For languages where the notation would not survive highlighting (see
14
+ * `supportsNotationComments`), these notations are stripped.
15
+ */
16
+ function processCode(
17
+ code: string,
18
+ language?: string,
19
+ ): {
20
+ cleanCode: string;
21
+ extractedFilename?: string;
22
+ } {
23
+ const lines = code.split('\n');
24
+ const cleanLines: string[] = [];
25
+ let extractedFilename: string | undefined;
26
+
27
+ const shouldStripNotations = !supportsNotationComments(language);
28
+
29
+ for (let i = 0; i < lines.length; i++) {
30
+ let line = lines[i] ?? '';
31
+ const trimmedLine = line.trim();
32
+
33
+ // Check for filename directive (must be first non-empty line)
34
+ if (i === 0 || (cleanLines.length === 0 && !extractedFilename)) {
35
+ const filenameMatch = trimmedLine.match(/^\/\/\s*filename:\s*(.+)$/);
36
+ if (filenameMatch) {
37
+ extractedFilename = filenameMatch[1]?.trim();
38
+ continue; // Don't include this directive line
39
+ }
40
+ }
41
+
42
+ if (shouldStripNotations) {
43
+ line = line.replace(/\s*\/\/\s*\[!code\s+[^\]]+\]\s*$/, '');
44
+ line = line.replace(/\s*#\s*\[!code\s+[^\]]+\]\s*$/, '');
45
+ // Skip lines that are only the notation (e.g., standalone "// [!code highlight]")
46
+ if (trimmedLine.match(/^(\/\/|#)\s*\[!code\s+[^\]]+\]\s*$/)) {
47
+ continue;
48
+ }
49
+ }
50
+
51
+ cleanLines.push(line);
52
+ }
53
+
54
+ return {
55
+ cleanCode: cleanLines.join('\n'),
56
+ extractedFilename,
57
+ };
58
+ }
59
+
60
+ export { processCode };
@@ -0,0 +1,177 @@
1
+ type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun';
2
+
3
+ const PACKAGE_MANAGERS: PackageManager[] = ['npm', 'pnpm', 'yarn', 'bun'];
4
+
5
+ /**
6
+ * Detects if a single line is an npm/npx command that can be transformed
7
+ */
8
+ function isNpmLine(line: string): boolean {
9
+ const trimmed = line.trim();
10
+ return /^(npm\s+(install|i|add|run|exec|create|init|ci|remove|uninstall|rm)|npx\s+)/.test(
11
+ trimmed,
12
+ );
13
+ }
14
+
15
+ /**
16
+ * Detects if the code contains any package manager commands that can be transformed
17
+ */
18
+ function isPackageManagerCommand(code: string): boolean {
19
+ const lines = code.split('\n');
20
+ return lines.some((line) => isNpmLine(line));
21
+ }
22
+
23
+ /**
24
+ * Transforms a single npm/npx command line to the equivalent for other package
25
+ * managers, preserving the line's leading whitespace. Returns the line unchanged
26
+ * when no rewrite applies.
27
+ */
28
+ function transformSingleLine(line: string, targetPm: PackageManager): string {
29
+ if (targetPm === 'npm') return line;
30
+
31
+ const transformed = transformTrimmedCommand(line.trim(), targetPm);
32
+ if (transformed === null) return line;
33
+
34
+ const indent = line.slice(0, line.length - line.trimStart().length);
35
+ return indent + transformed;
36
+ }
37
+
38
+ function transformTrimmedCommand(
39
+ trimmed: string,
40
+ targetPm: Exclude<PackageManager, 'npm'>,
41
+ ): string | null {
42
+ // Handle npx commands
43
+ if (trimmed.startsWith('npx ')) {
44
+ const rest = trimmed.slice(4);
45
+ switch (targetPm) {
46
+ case 'pnpm':
47
+ return `pnpm dlx ${rest}`;
48
+ case 'yarn':
49
+ return `yarn dlx ${rest}`;
50
+ case 'bun':
51
+ return `bunx ${rest}`;
52
+ }
53
+ }
54
+
55
+ // Handle npm create / npm init
56
+ if (/^npm\s+(create|init)\s+/.test(trimmed)) {
57
+ const match = trimmed.match(/^npm\s+(create|init)\s+(.+)$/);
58
+ if (match) {
59
+ const args = match[2];
60
+ switch (targetPm) {
61
+ case 'pnpm':
62
+ return `pnpm create ${args}`;
63
+ case 'yarn':
64
+ return `yarn create ${args}`;
65
+ case 'bun':
66
+ return `bun create ${args}`;
67
+ }
68
+ }
69
+ }
70
+
71
+ // Handle npm install / npm i / npm add (with packages)
72
+ if (/^npm\s+(install|i|add)\s+/.test(trimmed)) {
73
+ const match = trimmed.match(/^npm\s+(install|i|add)\s+(.+)$/);
74
+ if (match) {
75
+ const packages = match[2] ?? '';
76
+ // Match dev flags as whole tokens so package names containing "-D"
77
+ // don't false-positive.
78
+ const tokens = packages.split(/\s+/);
79
+ const devFlag = tokens.includes('-D') || tokens.includes('--save-dev');
80
+ const cleanPackages = tokens
81
+ .filter((token) => token !== '-D' && token !== '--save-dev')
82
+ .join(' ');
83
+
84
+ switch (targetPm) {
85
+ case 'pnpm':
86
+ return devFlag ? `pnpm add -D ${cleanPackages}` : `pnpm add ${cleanPackages}`;
87
+ case 'yarn':
88
+ return devFlag ? `yarn add -D ${cleanPackages}` : `yarn add ${cleanPackages}`;
89
+ case 'bun':
90
+ return devFlag ? `bun add -d ${cleanPackages}` : `bun add ${cleanPackages}`;
91
+ }
92
+ }
93
+ }
94
+
95
+ // Handle npm install (without packages - install from package.json)
96
+ if (/^npm\s+(install|i|ci)$/.test(trimmed)) {
97
+ switch (targetPm) {
98
+ case 'pnpm':
99
+ return 'pnpm install';
100
+ case 'yarn':
101
+ return 'yarn';
102
+ case 'bun':
103
+ return 'bun install';
104
+ }
105
+ }
106
+
107
+ // Handle npm run <script>
108
+ if (/^npm\s+run\s+/.test(trimmed)) {
109
+ const match = trimmed.match(/^npm\s+run\s+(.+)$/);
110
+ if (match) {
111
+ const script = match[1];
112
+ switch (targetPm) {
113
+ case 'pnpm':
114
+ return `pnpm run ${script}`;
115
+ case 'yarn':
116
+ return `yarn ${script}`;
117
+ case 'bun':
118
+ return `bun run ${script}`;
119
+ }
120
+ }
121
+ }
122
+
123
+ // Handle npm remove / npm uninstall / npm rm
124
+ if (/^npm\s+(remove|uninstall|rm)\s+/.test(trimmed)) {
125
+ const match = trimmed.match(/^npm\s+(remove|uninstall|rm)\s+(.+)$/);
126
+ if (match) {
127
+ const packages = match[2];
128
+ switch (targetPm) {
129
+ case 'pnpm':
130
+ return `pnpm remove ${packages}`;
131
+ case 'yarn':
132
+ return `yarn remove ${packages}`;
133
+ case 'bun':
134
+ return `bun remove ${packages}`;
135
+ }
136
+ }
137
+ }
138
+
139
+ // Handle npm exec
140
+ if (/^npm\s+exec\s+/.test(trimmed)) {
141
+ const match = trimmed.match(/^npm\s+exec\s+(.+)$/);
142
+ if (match) {
143
+ const rest = match[1];
144
+ switch (targetPm) {
145
+ case 'pnpm':
146
+ return `pnpm exec ${rest}`;
147
+ case 'yarn':
148
+ return `yarn exec ${rest}`;
149
+ case 'bun':
150
+ return `bun x ${rest}`;
151
+ }
152
+ }
153
+ }
154
+
155
+ return null;
156
+ }
157
+
158
+ /**
159
+ * Transforms all npm/npx commands in a code block to the target package manager.
160
+ * Leaves non-npm lines unchanged.
161
+ */
162
+ function transformCommand(code: string, targetPm: PackageManager): string {
163
+ if (targetPm === 'npm') return code;
164
+
165
+ const lines = code.split('\n');
166
+ const transformedLines = lines.map((line) => {
167
+ if (isNpmLine(line)) {
168
+ return transformSingleLine(line, targetPm);
169
+ }
170
+ return line;
171
+ });
172
+
173
+ return transformedLines.join('\n');
174
+ }
175
+
176
+ export { PACKAGE_MANAGERS, isPackageManagerCommand, transformCommand };
177
+ export type { PackageManager };