@vendure-io/ui 2.0.0-beta.2 → 2.0.0-beta.20
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/LICENSE.md +34 -0
- package/README.md +6 -3
- package/package.json +10 -9
- package/src/components/atoms/button.tsx +5 -1
- package/src/components/atoms/card.tsx +39 -4
- package/src/components/atoms/combobox.tsx +19 -4
- package/src/components/atoms/scroll-area.tsx +4 -2
- package/src/components/atoms/sidebar.tsx +27 -12
- package/src/components/atoms/table.tsx +1 -1
- package/src/components/atoms/tabs.tsx +64 -1
- package/src/components/atoms/toggle-group.tsx +1 -1
- package/src/components/atoms/toggle.tsx +5 -2
- package/src/components/molecules/anonymized-token.tsx +2 -2
- package/src/components/molecules/app-shell.tsx +110 -0
- package/src/components/molecules/code-block/file-type-icons.tsx +123 -0
- package/src/components/molecules/code-block/transform-command.tsx +177 -0
- package/src/components/molecules/code-block.tsx +634 -0
- package/src/components/molecules/combobox-free-text.tsx +18 -0
- package/src/components/molecules/copy-feedback-provider.tsx +33 -0
- package/src/components/molecules/copyable-text.tsx +30 -7
- package/src/components/molecules/data-table/data-table-bulk-actions.tsx +10 -9
- package/src/components/molecules/data-table/data-table-types.tsx +50 -2
- package/src/components/molecules/data-table/data-table.tsx +184 -91
- package/src/components/molecules/date-picker.tsx +119 -0
- package/src/components/molecules/date-range-picker.tsx +153 -0
- package/src/components/molecules/date-time-picker.tsx +133 -0
- package/src/components/molecules/file-dropzone.tsx +271 -0
- package/src/components/molecules/id-chip.tsx +1 -1
- package/src/components/molecules/page-header.tsx +7 -3
- package/src/components/molecules/skip-link.tsx +36 -0
- package/src/components/molecules/state-views/empty-state.tsx +12 -1
- package/src/components/molecules/state-views/loading-state.tsx +7 -3
- package/src/lib/date-value.ts +48 -0
- package/src/lib/highlight.ts +174 -0
- package/src/lib/utils.ts +0 -19
|
@@ -24,13 +24,16 @@ export interface LoadingStateProps
|
|
|
24
24
|
rows?: number;
|
|
25
25
|
/** Classes applied to each skeleton row (e.g. `h-10` for tighter lists). */
|
|
26
26
|
rowClassName?: string;
|
|
27
|
-
/** Visible label. An sr-only
|
|
27
|
+
/** Visible label. An sr-only `srLabel` is always rendered for assistive tech. */
|
|
28
28
|
label?: React.ReactNode;
|
|
29
|
+
/** Sr-only label announced to assistive tech. Override for host i18n. @default "Loading…" */
|
|
30
|
+
srLabel?: string;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
/**
|
|
32
34
|
* Placeholder shell for in-flight list/detail queries. Renders as an
|
|
33
|
-
* `aria-live` `<output>` with an always-present sr-only
|
|
35
|
+
* `aria-live` `<output>` with an always-present sr-only `srLabel` (defaults to
|
|
36
|
+
* "Loading…", overridable for host i18n).
|
|
34
37
|
* `skeleton` (default) draws N shimmer rows; `spinner` centers the `Spinner`
|
|
35
38
|
* atom for compact or unknown-height regions.
|
|
36
39
|
*/
|
|
@@ -39,6 +42,7 @@ function LoadingState({
|
|
|
39
42
|
rows = 5,
|
|
40
43
|
rowClassName,
|
|
41
44
|
label,
|
|
45
|
+
srLabel = 'Loading…',
|
|
42
46
|
className,
|
|
43
47
|
...props
|
|
44
48
|
}: LoadingStateProps) {
|
|
@@ -49,7 +53,7 @@ function LoadingState({
|
|
|
49
53
|
className={cn(loadingStateVariants({ variant }), className)}
|
|
50
54
|
{...props}
|
|
51
55
|
>
|
|
52
|
-
<span className="sr-only">
|
|
56
|
+
<span className="sr-only">{srLabel}</span>
|
|
53
57
|
{variant === 'spinner' ? (
|
|
54
58
|
<>
|
|
55
59
|
{/* aria-hidden overrides the atom's role="status": the <output> is
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const CALENDAR_DATE_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
2
|
+
|
|
3
|
+
/** Parse `YYYY-MM-DD` into a local calendar date without a UTC shift. */
|
|
4
|
+
function parseCalendarDate(value: string | null | undefined): Date | undefined {
|
|
5
|
+
if (!value) return undefined;
|
|
6
|
+
const match = CALENDAR_DATE_PATTERN.exec(value);
|
|
7
|
+
if (!match) return undefined;
|
|
8
|
+
const year = Number(match[1]);
|
|
9
|
+
const month = Number(match[2]);
|
|
10
|
+
const day = Number(match[3]);
|
|
11
|
+
const date = new Date(year, month - 1, day);
|
|
12
|
+
if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
return date;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Serialize a local calendar date as `YYYY-MM-DD`. */
|
|
19
|
+
function formatCalendarDate(date: Date): string {
|
|
20
|
+
const year = date.getFullYear();
|
|
21
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
22
|
+
const day = String(date.getDate()).padStart(2, '0');
|
|
23
|
+
return `${year}-${month}-${day}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function parseInstant(value: string | null | undefined): Date | undefined {
|
|
27
|
+
if (!value) return undefined;
|
|
28
|
+
const date = new Date(value);
|
|
29
|
+
return Number.isNaN(date.getTime()) ? undefined : date;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function formatDateLabel(date: Date, locale?: string): string {
|
|
33
|
+
return new Intl.DateTimeFormat(locale, { dateStyle: 'medium' }).format(date);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function formatDateRangeLabel(from: Date, to: Date | undefined, locale?: string): string {
|
|
37
|
+
if (!to || from.getTime() === to.getTime()) return formatDateLabel(from, locale);
|
|
38
|
+
const formatter = new Intl.DateTimeFormat(locale, { dateStyle: 'medium' });
|
|
39
|
+
return formatter.formatRange(from, to);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
formatCalendarDate,
|
|
44
|
+
formatDateLabel,
|
|
45
|
+
formatDateRangeLabel,
|
|
46
|
+
parseCalendarDate,
|
|
47
|
+
parseInstant,
|
|
48
|
+
};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import {
|
|
2
|
+
transformerNotationDiff,
|
|
3
|
+
transformerNotationErrorLevel,
|
|
4
|
+
transformerNotationFocus,
|
|
5
|
+
transformerNotationHighlight,
|
|
6
|
+
transformerNotationWordHighlight,
|
|
7
|
+
} from '@shikijs/transformers';
|
|
8
|
+
import { createHighlighterCore } from 'shiki/core';
|
|
9
|
+
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The design system's Shiki setup: a lazy shared highlighter with the DS themes
|
|
13
|
+
* (github-light / github-dark-default), a fixed grammar set, and the `[!code ...]`
|
|
14
|
+
* notation transformers. Exported so consumers rendering highlighted HTML outside
|
|
15
|
+
* of `CodeBlock` (e.g. custom docs pipelines) reuse the exact same setup instead
|
|
16
|
+
* of duplicating it — and get the lazy per-language chunks instead of the full
|
|
17
|
+
* Shiki bundle.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const languageLoaders = {
|
|
21
|
+
bash: () => import('@shikijs/langs/bash').then((module) => module.default),
|
|
22
|
+
css: () => import('@shikijs/langs/css').then((module) => module.default),
|
|
23
|
+
dotenv: () => import('@shikijs/langs/dotenv').then((module) => module.default),
|
|
24
|
+
graphql: () => import('@shikijs/langs/graphql').then((module) => module.default),
|
|
25
|
+
html: () => import('@shikijs/langs/html').then((module) => module.default),
|
|
26
|
+
ini: () => import('@shikijs/langs/ini').then((module) => module.default),
|
|
27
|
+
javascript: () => import('@shikijs/langs/javascript').then((module) => module.default),
|
|
28
|
+
json: () => import('@shikijs/langs/json').then((module) => module.default),
|
|
29
|
+
jsonc: () => import('@shikijs/langs/jsonc').then((module) => module.default),
|
|
30
|
+
jsx: () => import('@shikijs/langs/jsx').then((module) => module.default),
|
|
31
|
+
markdown: () => import('@shikijs/langs/markdown').then((module) => module.default),
|
|
32
|
+
mdx: () => import('@shikijs/langs/mdx').then((module) => module.default),
|
|
33
|
+
python: () => import('@shikijs/langs/python').then((module) => module.default),
|
|
34
|
+
shellscript: () => import('@shikijs/langs/shellscript').then((module) => module.default),
|
|
35
|
+
sql: () => import('@shikijs/langs/sql').then((module) => module.default),
|
|
36
|
+
tsx: () => import('@shikijs/langs/tsx').then((module) => module.default),
|
|
37
|
+
typescript: () => import('@shikijs/langs/typescript').then((module) => module.default),
|
|
38
|
+
yaml: () => import('@shikijs/langs/yaml').then((module) => module.default),
|
|
39
|
+
} as const;
|
|
40
|
+
|
|
41
|
+
type SupportedLanguage = keyof typeof languageLoaders;
|
|
42
|
+
|
|
43
|
+
const themeLoaders = [
|
|
44
|
+
() => import('@shikijs/themes/github-light').then((module) => module.default),
|
|
45
|
+
() => import('@shikijs/themes/github-dark-default').then((module) => module.default),
|
|
46
|
+
] as const;
|
|
47
|
+
|
|
48
|
+
let highlighterPromise: ReturnType<typeof createHighlighterCore> | null = null;
|
|
49
|
+
|
|
50
|
+
function getHighlighter(): ReturnType<typeof createHighlighterCore> {
|
|
51
|
+
highlighterPromise ??= Promise.all([
|
|
52
|
+
Promise.all(themeLoaders.map((loadTheme) => loadTheme())),
|
|
53
|
+
Promise.all(Object.values(languageLoaders).map((loadLanguage) => loadLanguage())),
|
|
54
|
+
]).then(([themes, languages]) =>
|
|
55
|
+
createHighlighterCore({
|
|
56
|
+
themes,
|
|
57
|
+
langs: languages.flat(),
|
|
58
|
+
engine: createJavaScriptRegexEngine(),
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return highlighterPromise;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const highlightedCodeCache = new Map<string, Promise<string>>();
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Highlight code using Shiki with all transformers.
|
|
69
|
+
* Uses Shiki's native notation for highlighting:
|
|
70
|
+
* - // [!code highlight] - highlight a line (use language-appropriate comment)
|
|
71
|
+
* - // [!code ++] / // [!code --] - diff highlighting
|
|
72
|
+
* - // [!code focus] - focus mode (blur other lines)
|
|
73
|
+
* - // [!code word:myVar] - highlight specific word
|
|
74
|
+
* - // [!code error] / // [!code warning] - error levels
|
|
75
|
+
*/
|
|
76
|
+
async function highlightCode(code: string, language: SupportedLanguage): Promise<string> {
|
|
77
|
+
const cacheKey = `${language}:${code}`;
|
|
78
|
+
const cached = highlightedCodeCache.get(cacheKey);
|
|
79
|
+
if (cached) return cached;
|
|
80
|
+
|
|
81
|
+
const highlighted = getHighlighter().then((highlighter) =>
|
|
82
|
+
highlighter.codeToHtml(code, {
|
|
83
|
+
lang: language,
|
|
84
|
+
themes: {
|
|
85
|
+
light: 'github-light',
|
|
86
|
+
dark: 'github-dark-default',
|
|
87
|
+
},
|
|
88
|
+
transformers: [
|
|
89
|
+
transformerNotationDiff({ matchAlgorithm: 'v3' }),
|
|
90
|
+
transformerNotationHighlight({ matchAlgorithm: 'v3' }),
|
|
91
|
+
transformerNotationWordHighlight({ matchAlgorithm: 'v3' }),
|
|
92
|
+
transformerNotationFocus({ matchAlgorithm: 'v3' }),
|
|
93
|
+
transformerNotationErrorLevel({ matchAlgorithm: 'v3' }),
|
|
94
|
+
],
|
|
95
|
+
}),
|
|
96
|
+
);
|
|
97
|
+
highlightedCodeCache.set(cacheKey, highlighted);
|
|
98
|
+
return highlighted;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Language aliases that map to Shiki's bundled language names
|
|
103
|
+
*/
|
|
104
|
+
const LANGUAGE_ALIASES: Record<string, SupportedLanguage> = {
|
|
105
|
+
env: 'dotenv',
|
|
106
|
+
js: 'javascript',
|
|
107
|
+
ts: 'typescript',
|
|
108
|
+
sh: 'bash',
|
|
109
|
+
shell: 'bash',
|
|
110
|
+
yml: 'yaml',
|
|
111
|
+
py: 'python',
|
|
112
|
+
md: 'markdown',
|
|
113
|
+
plaintext: 'ini',
|
|
114
|
+
text: 'ini',
|
|
115
|
+
chroma: 'ini',
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Normalize language identifier for Shiki/BundledLanguage.
|
|
120
|
+
* Falls back to 'ini' for unsupported languages (minimal highlighting).
|
|
121
|
+
*/
|
|
122
|
+
function normalizeLanguage(lang?: string): SupportedLanguage {
|
|
123
|
+
const normalized = lang?.toLowerCase() || 'ini';
|
|
124
|
+
|
|
125
|
+
// Check for aliases first
|
|
126
|
+
const alias = LANGUAGE_ALIASES[normalized];
|
|
127
|
+
if (alias) {
|
|
128
|
+
return alias;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Check if the language is one of the explicitly bundled grammars.
|
|
132
|
+
if (normalized in languageLoaders) {
|
|
133
|
+
return normalized as SupportedLanguage;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Fallback to 'ini' for unsupported languages (has minimal highlighting)
|
|
137
|
+
return 'ini';
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Bundled grammars whose `//` / `#` comment syntax lets the `[!code ...]`
|
|
142
|
+
* notation transformers match. Only languages with a loader above can qualify:
|
|
143
|
+
* anything else falls back to the `ini` grammar, which renders the notation
|
|
144
|
+
* comment as literal text instead of consuming it.
|
|
145
|
+
*/
|
|
146
|
+
const NOTATION_TRANSFORMER_LANGUAGES = new Set<SupportedLanguage>([
|
|
147
|
+
'javascript',
|
|
148
|
+
'typescript',
|
|
149
|
+
'jsx',
|
|
150
|
+
'tsx',
|
|
151
|
+
'python',
|
|
152
|
+
'bash',
|
|
153
|
+
'shellscript',
|
|
154
|
+
'yaml',
|
|
155
|
+
]);
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Whether `[!code ...]` notations in `lang` survive highlighting. Alias-aware:
|
|
159
|
+
* the check runs on the normalized language, so `ts`, `py`, `sh`, … qualify
|
|
160
|
+
* through their canonical grammar. Callers should strip notations when this
|
|
161
|
+
* returns false, or they render as literal text.
|
|
162
|
+
*/
|
|
163
|
+
function supportsNotationComments(lang?: string): boolean {
|
|
164
|
+
return NOTATION_TRANSFORMER_LANGUAGES.has(normalizeLanguage(lang));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export {
|
|
168
|
+
NOTATION_TRANSFORMER_LANGUAGES,
|
|
169
|
+
getHighlighter,
|
|
170
|
+
highlightCode,
|
|
171
|
+
normalizeLanguage,
|
|
172
|
+
supportsNotationComments,
|
|
173
|
+
};
|
|
174
|
+
export type { SupportedLanguage };
|
package/src/lib/utils.ts
CHANGED
|
@@ -4,22 +4,3 @@ import { twMerge } from 'tailwind-merge';
|
|
|
4
4
|
export function cn(...inputs: ClassValue[]): string {
|
|
5
5
|
return twMerge(clsx(inputs));
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
export function slugify(str: string): string {
|
|
9
|
-
return str
|
|
10
|
-
.toLowerCase()
|
|
11
|
-
.trim()
|
|
12
|
-
.replace(/[^\w\s-]/g, '')
|
|
13
|
-
.replace(/[\s_-]+/g, '-')
|
|
14
|
-
.replace(/^-+|-+$/g, '');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function hashString(str: string): number {
|
|
18
|
-
let hash = 0;
|
|
19
|
-
for (let i = 0; i < str.length; i++) {
|
|
20
|
-
const char = str.charCodeAt(i);
|
|
21
|
-
hash = (hash << 5) - hash + char;
|
|
22
|
-
hash |= 0;
|
|
23
|
-
}
|
|
24
|
-
return Math.abs(hash);
|
|
25
|
-
}
|