@vokality/design-system 2.0.0 → 3.0.1
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/CHANGELOG.md +35 -0
- package/README.md +63 -3
- package/bin/vokality-skill.mjs +68 -0
- package/dist/browser.d.ts +13 -0
- package/dist/browser.js +7 -0
- package/dist/charts/chart.d.ts +6 -5
- package/dist/charts/chart.js +44 -25
- package/dist/chat.d.ts +54 -0
- package/dist/chat.js +1 -0
- package/dist/components/Accordion/Accordion.js +1 -1
- package/dist/components/Alert/Alert.js +5 -2
- package/dist/components/AppShell/AppShell.js +10 -14
- package/dist/components/Avatar/Avatar.js +2 -2
- package/dist/components/AvatarGroup/AvatarGroup.js +2 -2
- package/dist/components/BarChart/BarChart.js +17 -15
- package/dist/components/Breadcrumbs/Breadcrumbs.js +6 -3
- package/dist/components/Calendar/Calendar.js +6 -5
- package/dist/components/Card/Card.js +2 -3
- package/dist/components/ChatInbox/ChatInbox.d.ts +11 -0
- package/dist/components/ChatInbox/ChatInbox.js +49 -0
- package/dist/components/ChatPanel/ChatPanel.d.ts +3 -0
- package/dist/components/ChatPanel/ChatPanel.js +13 -0
- package/dist/components/ChatPanel/composer.d.ts +5 -0
- package/dist/components/ChatPanel/composer.js +32 -0
- package/dist/components/ChatPanel/transcript.d.ts +13 -0
- package/dist/components/ChatPanel/transcript.js +39 -0
- package/dist/components/ChatWidget/ChatWidget.d.ts +12 -0
- package/dist/components/ChatWidget/ChatWidget.js +42 -0
- package/dist/components/Checkbox/Checkbox.d.ts +5 -10
- package/dist/components/Checkbox/Checkbox.js +5 -19
- package/dist/components/CodeBlock/CodeBlock.js +19 -5
- package/dist/components/Combobox/Combobox.js +22 -15
- package/dist/components/Combobox/ListPanel.js +20 -9
- package/dist/components/CommandPalette/CommandPalette.js +33 -14
- package/dist/components/ContextMenu/ContextMenu.d.ts +2 -2
- package/dist/components/ContextMenu/ContextMenu.js +5 -50
- package/dist/components/DatePicker/DatePicker.js +35 -29
- package/dist/components/DescriptionList/DescriptionList.js +1 -1
- package/dist/components/Dialog/Dialog.d.ts +24 -7
- package/dist/components/Dialog/Dialog.js +30 -41
- package/dist/components/Drawer/Drawer.d.ts +4 -2
- package/dist/components/EmptyState/EmptyState.js +2 -2
- package/dist/components/ErrorSummary/ErrorSummary.js +5 -3
- package/dist/components/FaqList/FaqList.js +1 -1
- package/dist/components/Field/Field.js +2 -2
- package/dist/components/FileUpload/FileUpload.js +17 -9
- package/dist/components/Grid/Grid.d.ts +5 -5
- package/dist/components/Grid/Grid.js +1 -1
- package/dist/components/Heading/Heading.js +2 -1
- package/dist/components/Icon/Icon.js +4 -2
- package/dist/components/Inline/Inline.d.ts +7 -7
- package/dist/components/LineChart/LineChart.js +17 -15
- package/dist/components/LinkProvider/LinkProvider.d.ts +1 -1
- package/dist/components/LinkProvider/LinkProvider.js +6 -2
- package/dist/components/List/List.js +1 -1
- package/dist/components/MediaCard/MediaCard.js +2 -2
- package/dist/components/Menu/Menu.js +6 -43
- package/dist/components/Menu/entries.d.ts +1 -30
- package/dist/components/Menu/entries.js +16 -100
- package/dist/components/MultiSelect/MultiSelect.js +43 -34
- package/dist/components/NumberInput/NumberInput.js +17 -18
- package/dist/components/OtpInput/OtpInput.d.ts +1 -1
- package/dist/components/OtpInput/OtpInput.js +10 -67
- package/dist/components/PageHeader/PageHeader.js +2 -2
- package/dist/components/Pagination/Pagination.js +3 -1
- package/dist/components/PasswordInput/PasswordInput.d.ts +1 -1
- package/dist/components/PasswordInput/PasswordInput.js +9 -4
- package/dist/components/Popover/Popover.d.ts +6 -7
- package/dist/components/Popover/Popover.js +2 -19
- package/dist/components/Progress/Progress.d.ts +1 -1
- package/dist/components/Progress/Progress.js +7 -11
- package/dist/components/Radio/Radio.d.ts +4 -2
- package/dist/components/RadioGroup/RadioGroup.d.ts +5 -12
- package/dist/components/RadioGroup/RadioGroup.js +6 -33
- package/dist/components/RichTextEditor/RichTextEditor.d.ts +63 -0
- package/dist/components/RichTextEditor/RichTextEditor.js +175 -0
- package/dist/components/RichTextEditor/toolbar.d.ts +15 -0
- package/dist/components/RichTextEditor/toolbar.js +142 -0
- package/dist/components/RichTextEditor/uploads.d.ts +41 -0
- package/dist/components/RichTextEditor/uploads.js +124 -0
- package/dist/components/SearchInput/SearchInput.js +4 -2
- package/dist/components/SectionHeader/SectionHeader.js +1 -3
- package/dist/components/SegmentedControl/SegmentedControl.js +2 -12
- package/dist/components/Select/Select.d.ts +15 -16
- package/dist/components/Select/Select.js +11 -252
- package/dist/components/Slider/Slider.js +11 -21
- package/dist/components/Sparkline/Sparkline.js +8 -3
- package/dist/components/Spinner/Spinner.js +5 -2
- package/dist/components/Stack/Stack.d.ts +5 -5
- package/dist/components/Stat/Stat.js +6 -3
- package/dist/components/Steps/Steps.js +6 -3
- package/dist/components/Switch/Switch.d.ts +7 -7
- package/dist/components/Switch/Switch.js +4 -10
- package/dist/components/Table/Table.js +38 -19
- package/dist/components/Tabs/Tabs.js +2 -22
- package/dist/components/Tag/Tag.js +3 -1
- package/dist/components/Text/Text.d.ts +1 -1
- package/dist/components/TileGrid/TileGrid.js +1 -1
- package/dist/components/TimePicker/TimePicker.js +35 -33
- package/dist/components/Timeline/Timeline.js +5 -4
- package/dist/components/Toaster/Toaster.js +21 -17
- package/dist/components/Tooltip/Tooltip.d.ts +6 -6
- package/dist/components/Tooltip/Tooltip.js +3 -17
- package/dist/components/TreeView/TreeView.js +15 -12
- package/dist/components.css +179 -8
- package/dist/hooks/useTheme.js +6 -6
- package/dist/icons/message-circle.svg +1 -0
- package/dist/internal/CharCount.js +3 -1
- package/dist/internal/choice.d.ts +10 -48
- package/dist/internal/choice.js +8 -96
- package/dist/internal/options.d.ts +10 -5
- package/dist/internal/options.js +25 -11
- package/dist/internal/status.d.ts +3 -2
- package/dist/internal/status.js +10 -2
- package/dist/internal/useScrollActive.js +2 -2
- package/dist/internal/useToday.d.ts +3 -0
- package/dist/internal/useToday.js +42 -0
- package/dist/lib/dates.js +25 -15
- package/dist/lib/format.js +11 -8
- package/dist/lib/icons.d.ts +5 -0
- package/dist/lib/icons.js +2 -0
- package/dist/lib/math.js +17 -5
- package/dist/lib/rich-text.d.ts +13 -0
- package/dist/lib/rich-text.js +62 -0
- package/dist/lib/space.d.ts +1 -2
- package/dist/lib/space.js +4 -1
- package/dist/lib/text.js +1 -1
- package/dist/lib/theme.js +1 -1
- package/dist/localization.d.ts +166 -0
- package/dist/localization.js +142 -0
- package/dist/vokality.css +179 -8
- package/dist/vokality.iife.js +35986 -9685
- package/docs/brand.md +6 -3
- package/docs/components/AppShell/README.md +1 -1
- package/docs/components/BarChart/README.md +1 -0
- package/docs/components/ChatInbox/README.md +41 -0
- package/docs/components/ChatWidget/README.md +47 -0
- package/docs/components/Checkbox/README.md +7 -3
- package/docs/components/ContextMenu/README.md +7 -3
- package/docs/components/Dialog/README.md +9 -4
- package/docs/components/Drawer/README.md +1 -1
- package/docs/components/Field/README.md +1 -1
- package/docs/components/Fieldset/README.md +2 -2
- package/docs/components/LineChart/README.md +1 -0
- package/docs/components/LocaleProvider/README.md +48 -0
- package/docs/components/Menu/README.md +13 -8
- package/docs/components/OtpInput/README.md +9 -5
- package/docs/components/PasswordInput/README.md +11 -2
- package/docs/components/Popover/README.md +6 -3
- package/docs/components/Progress/README.md +3 -1
- package/docs/components/RadioGroup/README.md +5 -2
- package/docs/components/RichTextEditor/README.md +84 -0
- package/docs/components/SegmentedControl/README.md +2 -0
- package/docs/components/Select/README.md +13 -17
- package/docs/components/Skeleton/README.md +1 -1
- package/docs/components/Slider/README.md +4 -2
- package/docs/components/Steps/README.md +1 -1
- package/docs/components/Switch/README.md +5 -2
- package/docs/components/Tabs/README.md +4 -2
- package/docs/components/Toaster/README.md +3 -1
- package/docs/components/Tooltip/README.md +5 -3
- package/package.json +55 -6
- package/skills/vokality-design-system/SKILL.md +55 -0
- package/skills/vokality-design-system/references/examples.tsx +103 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { defaultMarkdownParser, defaultMarkdownSerializer } from "prosemirror-markdown";
|
|
2
|
+
/** Control characters are never valid in persisted attachment names or document URLs. */
|
|
3
|
+
export function hasRichTextControlCharacters(value) {
|
|
4
|
+
return Array.from(value).some((character) => {
|
|
5
|
+
const code = character.charCodeAt(0);
|
|
6
|
+
return code < 32 || code === 127;
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
/** URLs accepted by the editor, its clipboard boundary and attachment uploads. */
|
|
10
|
+
export function isRichTextUrl(value) {
|
|
11
|
+
if (typeof value !== "string" || !value || value !== value.trim() || (hasRichTextControlCharacters(value) || value.includes(" ") || value.includes("\\")))
|
|
12
|
+
return false;
|
|
13
|
+
if (value.startsWith("//"))
|
|
14
|
+
return false;
|
|
15
|
+
const scheme = /^([A-Za-z][A-Za-z0-9+.-]*):/.exec(value);
|
|
16
|
+
const schemeName = scheme?.[1];
|
|
17
|
+
if (schemeName) {
|
|
18
|
+
if (!["https", "http", "mailto", "tel"].includes(schemeName.toLowerCase()))
|
|
19
|
+
return false;
|
|
20
|
+
try {
|
|
21
|
+
const url = new URL(value);
|
|
22
|
+
return url.protocol === "http:" || url.protocol === "https:" ? !!url.hostname : url.pathname.length > 0;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// A colon in the first path segment is never a relative URL.
|
|
29
|
+
const firstPathSegment = value.split(/[/?#]/, 1)[0];
|
|
30
|
+
return firstPathSegment !== undefined && !firstPathSegment.includes(":");
|
|
31
|
+
}
|
|
32
|
+
/** Images may load only HTTP(S) or relative URLs; email and telephone links are links only. */
|
|
33
|
+
export function isRichTextImageUrl(value) {
|
|
34
|
+
return isRichTextUrl(value) && !/^(mailto|tel):/i.test(value);
|
|
35
|
+
}
|
|
36
|
+
/** Validate all URL-bearing nodes before a parsed or pasted document enters the view. */
|
|
37
|
+
export function hasSafeRichTextUrls(doc) {
|
|
38
|
+
let valid = true;
|
|
39
|
+
doc.descendants((node) => {
|
|
40
|
+
if (node.type.name === "image" && !isRichTextImageUrl(node.attrs.src))
|
|
41
|
+
valid = false;
|
|
42
|
+
if (node.marks.some((mark) => mark.type.name === "link" && !isRichTextUrl(mark.attrs.href)))
|
|
43
|
+
valid = false;
|
|
44
|
+
return valid;
|
|
45
|
+
});
|
|
46
|
+
return valid;
|
|
47
|
+
}
|
|
48
|
+
/** Parse CommonMark without interpreting raw HTML. Unknown values fail at this boundary. */
|
|
49
|
+
export function parseRichTextMarkdown(value) {
|
|
50
|
+
if (typeof value !== "string")
|
|
51
|
+
throw new TypeError("Rich-text content must be a Markdown string.");
|
|
52
|
+
const doc = defaultMarkdownParser.parse(value);
|
|
53
|
+
if (!hasSafeRichTextUrls(doc))
|
|
54
|
+
throw new TypeError("Rich-text content contains an unsafe URL.");
|
|
55
|
+
return doc;
|
|
56
|
+
}
|
|
57
|
+
/** CommonMark serialization preserves document structure and escapes link labels. */
|
|
58
|
+
export function serializeRichTextMarkdown(doc) {
|
|
59
|
+
if (!hasSafeRichTextUrls(doc))
|
|
60
|
+
throw new TypeError("Rich-text content contains an unsafe URL.");
|
|
61
|
+
return defaultMarkdownSerializer.serialize(doc);
|
|
62
|
+
}
|
package/dist/lib/space.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { SpaceStep } from "../types.js";
|
|
2
2
|
export declare const SPACE: Record<SpaceStep, string>;
|
|
3
|
-
|
|
4
|
-
export declare function space(value: SpaceStep | string | undefined, fallback: SpaceStep): string;
|
|
3
|
+
export declare function space(value: string | undefined, fallback: SpaceStep): string;
|
package/dist/lib/space.js
CHANGED
|
@@ -3,7 +3,10 @@ export const SPACE = {
|
|
|
3
3
|
xl: "var(--space-xl)", "2xl": "var(--space-2xl)", "3xl": "var(--space-3xl)",
|
|
4
4
|
};
|
|
5
5
|
/** A spacing step ("md") as its token, or any other CSS length as given; `fallback` when unset. */
|
|
6
|
+
function isSpaceStep(value) {
|
|
7
|
+
return Object.hasOwn(SPACE, value);
|
|
8
|
+
}
|
|
6
9
|
export function space(value, fallback) {
|
|
7
10
|
const v = value == null ? fallback : value;
|
|
8
|
-
return SPACE[v]
|
|
11
|
+
return isSpaceStep(v) ? SPACE[v] : v;
|
|
9
12
|
}
|
package/dist/lib/text.js
CHANGED
package/dist/lib/theme.js
CHANGED
|
@@ -6,7 +6,7 @@ export const THEMES = ["dark", "light", "contrast"];
|
|
|
6
6
|
*/
|
|
7
7
|
export function themeScript(options = {}) {
|
|
8
8
|
// JSON-quoted, with "<" escaped so the value can never close the inline <script>.
|
|
9
|
-
const key = JSON.stringify(
|
|
9
|
+
const key = JSON.stringify(options.storageKey || "vk-theme").replace(/</g, "\\u003c");
|
|
10
10
|
const fallback = JSON.stringify(options.defaultTheme && THEMES.includes(options.defaultTheme) ? options.defaultTheme : "dark");
|
|
11
11
|
const system = options.followSystem === false ? "" :
|
|
12
12
|
'if(matchMedia("(prefers-contrast: more)").matches)t="contrast";else if(matchMedia("(prefers-color-scheme: light)").matches)t="light";else if(matchMedia("(prefers-color-scheme: dark)").matches)t="dark";';
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
/** Accessible labels and feedback for RichTextEditor. */
|
|
3
|
+
export interface RichTextMessages {
|
|
4
|
+
toolbar: string;
|
|
5
|
+
formatting: string;
|
|
6
|
+
paragraph: string;
|
|
7
|
+
heading: (level: number) => string;
|
|
8
|
+
bold: string;
|
|
9
|
+
italic: string;
|
|
10
|
+
bulletList: string;
|
|
11
|
+
orderedList: string;
|
|
12
|
+
quote: string;
|
|
13
|
+
inlineCode: string;
|
|
14
|
+
codeBlock: string;
|
|
15
|
+
undo: string;
|
|
16
|
+
redo: string;
|
|
17
|
+
addLink: string;
|
|
18
|
+
removeLink: string;
|
|
19
|
+
linkUrl: string;
|
|
20
|
+
linkText: string;
|
|
21
|
+
applyLink: string;
|
|
22
|
+
cancel: string;
|
|
23
|
+
invalidUrl: string;
|
|
24
|
+
emoji: string;
|
|
25
|
+
emojiSearch: string;
|
|
26
|
+
noEmoji: string;
|
|
27
|
+
emojiName: (value: string) => string;
|
|
28
|
+
attachFiles: string;
|
|
29
|
+
uploading: (name: string) => string;
|
|
30
|
+
uploadFailed: (name: string) => string;
|
|
31
|
+
retryUpload: (name: string) => string;
|
|
32
|
+
cancelUpload: (name: string) => string;
|
|
33
|
+
removeAttachment: (name: string) => string;
|
|
34
|
+
attachmentUploaded: (name: string) => string;
|
|
35
|
+
maxFileSize: (size: string) => string;
|
|
36
|
+
editorLoading: string;
|
|
37
|
+
}
|
|
38
|
+
/** Conversation chrome, delivery feedback and composer labels. */
|
|
39
|
+
export interface ChatMessages {
|
|
40
|
+
open: string;
|
|
41
|
+
close: string;
|
|
42
|
+
messages: string;
|
|
43
|
+
message: string;
|
|
44
|
+
placeholder: string;
|
|
45
|
+
send: string;
|
|
46
|
+
sending: string;
|
|
47
|
+
failed: string;
|
|
48
|
+
retry: string;
|
|
49
|
+
retryMessage: (author: string) => string;
|
|
50
|
+
tryAgain: string;
|
|
51
|
+
back: string;
|
|
52
|
+
empty: string;
|
|
53
|
+
chooseThread: string;
|
|
54
|
+
noThreads: string;
|
|
55
|
+
conversations: string;
|
|
56
|
+
unread: (count: number) => string;
|
|
57
|
+
}
|
|
58
|
+
/** Built-in interface copy. Functions keep interpolation and plurals typed. */
|
|
59
|
+
export interface LocaleMessages {
|
|
60
|
+
richText: RichTextMessages;
|
|
61
|
+
chat: ChatMessages;
|
|
62
|
+
dismiss: string;
|
|
63
|
+
close: string;
|
|
64
|
+
clear: string;
|
|
65
|
+
today: string;
|
|
66
|
+
showPassword: string;
|
|
67
|
+
hidePassword: string;
|
|
68
|
+
decrease: string;
|
|
69
|
+
increase: string;
|
|
70
|
+
loading: string;
|
|
71
|
+
progress: string;
|
|
72
|
+
breadcrumb: string;
|
|
73
|
+
pagination: string;
|
|
74
|
+
previous: string;
|
|
75
|
+
next: string;
|
|
76
|
+
page: (page: number) => string;
|
|
77
|
+
previousMonth: string;
|
|
78
|
+
nextMonth: string;
|
|
79
|
+
chooseDate: string;
|
|
80
|
+
chooseDates: string;
|
|
81
|
+
selectDate: string;
|
|
82
|
+
selectDates: string;
|
|
83
|
+
invalidDate: (example: string) => string;
|
|
84
|
+
invalidTime: (example: string) => string;
|
|
85
|
+
times: string;
|
|
86
|
+
selectOne: string;
|
|
87
|
+
noMatches: (query: string) => string;
|
|
88
|
+
remove: (name: string) => string;
|
|
89
|
+
clearSearch: string;
|
|
90
|
+
moreActions: string;
|
|
91
|
+
actions: string;
|
|
92
|
+
skipToContent: string;
|
|
93
|
+
sidebar: string;
|
|
94
|
+
showSidebar: string;
|
|
95
|
+
hideSidebar: string;
|
|
96
|
+
menu: string;
|
|
97
|
+
statusInfo: string;
|
|
98
|
+
statusSuccess: string;
|
|
99
|
+
statusWarning: string;
|
|
100
|
+
statusDanger: string;
|
|
101
|
+
notifications: string;
|
|
102
|
+
dismissNotification: string;
|
|
103
|
+
notificationAnnouncement: string;
|
|
104
|
+
dropFile: string;
|
|
105
|
+
dropFiles: string;
|
|
106
|
+
or: string;
|
|
107
|
+
browse: string;
|
|
108
|
+
fileTooLarge: (size: string) => string;
|
|
109
|
+
fixProblems: (count: number) => string;
|
|
110
|
+
charactersLeft: (count: number) => string;
|
|
111
|
+
charactersOver: (count: number) => string;
|
|
112
|
+
oneTimeCode: string;
|
|
113
|
+
digit: string;
|
|
114
|
+
digitPosition: (label: string, position: number, total: number) => string;
|
|
115
|
+
details: string;
|
|
116
|
+
selectAllRows: string;
|
|
117
|
+
row: (position: number) => string;
|
|
118
|
+
selectRow: (position: number) => string;
|
|
119
|
+
showDetails: (name: string) => string;
|
|
120
|
+
hideDetails: (name: string) => string;
|
|
121
|
+
nothingToShow: string;
|
|
122
|
+
pageSummary: (from: number, to: number, total: number) => string;
|
|
123
|
+
completedStep: string;
|
|
124
|
+
currentStep: string;
|
|
125
|
+
up: string;
|
|
126
|
+
down: string;
|
|
127
|
+
copy: string;
|
|
128
|
+
copied: string;
|
|
129
|
+
code: string;
|
|
130
|
+
languageCode: (language: string) => string;
|
|
131
|
+
commandPalette: string;
|
|
132
|
+
commandSearch: string;
|
|
133
|
+
commands: string;
|
|
134
|
+
noCommands: (query: string) => string;
|
|
135
|
+
commandMove: string;
|
|
136
|
+
commandRun: string;
|
|
137
|
+
commandClose: string;
|
|
138
|
+
category: string;
|
|
139
|
+
value: string;
|
|
140
|
+
showChart: string;
|
|
141
|
+
showTable: string;
|
|
142
|
+
barChart: string;
|
|
143
|
+
lineChart: string;
|
|
144
|
+
chartInstructions: (title: string) => string;
|
|
145
|
+
trend: (values: string) => string;
|
|
146
|
+
}
|
|
147
|
+
/** Partial dictionaries inherit omitted keys within each interface domain. */
|
|
148
|
+
export type LocaleMessageOverrides = Partial<Omit<LocaleMessages, "richText" | "chat">> & {
|
|
149
|
+
richText?: Partial<RichTextMessages>;
|
|
150
|
+
chat?: Partial<ChatMessages>;
|
|
151
|
+
};
|
|
152
|
+
export interface LocaleProviderProps {
|
|
153
|
+
/** Explicit locale for both built-in messages and date/number formatting. Inherits when omitted. */
|
|
154
|
+
locale?: string;
|
|
155
|
+
/** App-specific translations; nested providers inherit these and replace only the keys supplied. */
|
|
156
|
+
messages?: LocaleMessageOverrides;
|
|
157
|
+
children?: ReactNode;
|
|
158
|
+
}
|
|
159
|
+
/** Scoped locale and translations. Does not read browser language or mutate the document. */
|
|
160
|
+
export declare function LocaleProvider({ locale, messages, children }: LocaleProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
161
|
+
export interface LocaleValue {
|
|
162
|
+
locale: string;
|
|
163
|
+
messages: LocaleMessages;
|
|
164
|
+
}
|
|
165
|
+
/** Read the nearest provider; an explicit control locale selects its formatting and default dictionary. */
|
|
166
|
+
export declare function useLocale(localeOverride?: string): LocaleValue;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext, useMemo } from "react";
|
|
4
|
+
import { resolveLocale } from "./lib/format.js";
|
|
5
|
+
const englishEmojiNames = {
|
|
6
|
+
"😀": "Grinning face", "🙂": "Smile", "❤️": "Heart", "👍": "Thumbs up", "👎": "Thumbs down", "🎉": "Celebration",
|
|
7
|
+
"✅": "Check", "⚠️": "Warning", "💡": "Idea", "🚀": "Rocket", "👀": "Eyes", "🙏": "Thank you",
|
|
8
|
+
};
|
|
9
|
+
const dutchEmojiNames = {
|
|
10
|
+
"😀": "Grijnzend gezicht", "🙂": "Glimlach", "❤️": "Hart", "👍": "Duim omhoog", "👎": "Duim omlaag", "🎉": "Feest",
|
|
11
|
+
"✅": "Vinkje", "⚠️": "Waarschuwing", "💡": "Idee", "🚀": "Raket", "👀": "Ogen", "🙏": "Bedankt",
|
|
12
|
+
};
|
|
13
|
+
const english = {
|
|
14
|
+
chat: {
|
|
15
|
+
open: "Open chat", close: "Close chat", messages: "Messages", message: "Message", placeholder: "Write a message…",
|
|
16
|
+
send: "Send message", sending: "Sending message", failed: "Message not sent", retry: "Retry", retryMessage: (author) => "Retry message from " + author,
|
|
17
|
+
tryAgain: "Try again", back: "Back to conversations", empty: "No messages yet. Start the conversation.", chooseThread: "Choose a conversation to read and reply.", noThreads: "No conversations yet.",
|
|
18
|
+
conversations: "Conversations", unread: (count) => String(count) + (count === 1 ? " unread message" : " unread messages"),
|
|
19
|
+
},
|
|
20
|
+
richText: {
|
|
21
|
+
formatting: "Formatting options",
|
|
22
|
+
toolbar: "Formatting", paragraph: "Paragraph", heading: (level) => "Heading " + String(level),
|
|
23
|
+
bold: "Bold", italic: "Italic", bulletList: "Bullet list", orderedList: "Numbered list", quote: "Quote",
|
|
24
|
+
inlineCode: "Inline code", codeBlock: "Code block", undo: "Undo", redo: "Redo",
|
|
25
|
+
addLink: "Add link", removeLink: "Remove link", linkUrl: "Link URL", linkText: "Link text", applyLink: "Apply link", cancel: "Cancel",
|
|
26
|
+
invalidUrl: "Enter a valid URL or relative link.", emojiName: (value) => englishEmojiNames[value] || value, emoji: "Insert emoji", emojiSearch: "Search emoji", noEmoji: "No emoji found", attachFiles: "Attach files",
|
|
27
|
+
uploading: (name) => "Uploading " + name, uploadFailed: (name) => "Could not upload " + name,
|
|
28
|
+
retryUpload: (name) => "Retry upload for " + name, cancelUpload: (name) => "Cancel upload for " + name,
|
|
29
|
+
removeAttachment: (name) => "Remove attachment " + name, attachmentUploaded: (name) => "Uploaded " + name,
|
|
30
|
+
maxFileSize: (size) => "Choose a file smaller than " + size + ".", editorLoading: "Loading editor",
|
|
31
|
+
},
|
|
32
|
+
dismiss: "Dismiss", close: "Close", clear: "Clear", today: "Today",
|
|
33
|
+
showPassword: "Show", hidePassword: "Hide", decrease: "Decrease", increase: "Increase",
|
|
34
|
+
loading: "Loading", progress: "Progress", breadcrumb: "Breadcrumb", pagination: "Pagination",
|
|
35
|
+
previous: "Previous", next: "Next", page: (page) => "Page " + String(page),
|
|
36
|
+
previousMonth: "Previous month", nextMonth: "Next month",
|
|
37
|
+
chooseDate: "Choose a date", chooseDates: "Choose dates", selectDate: "Select a date", selectDates: "Select dates",
|
|
38
|
+
invalidDate: (example) => "Enter a date like " + example + ".",
|
|
39
|
+
invalidTime: (example) => "Enter a time like " + example + ".",
|
|
40
|
+
times: "Times", selectOne: "Select one", noMatches: (query) => "No matches for “" + query + "”",
|
|
41
|
+
remove: (name) => "Remove " + name, clearSearch: "Clear search", moreActions: "More actions", actions: "Actions",
|
|
42
|
+
skipToContent: "Skip to content", sidebar: "Sidebar", showSidebar: "Show sidebar", hideSidebar: "Hide sidebar", menu: "Menu",
|
|
43
|
+
statusInfo: "Info", statusSuccess: "Success", statusWarning: "Warning", statusDanger: "Error",
|
|
44
|
+
notifications: "Notifications", dismissNotification: "Dismiss notification", notificationAnnouncement: "Notification",
|
|
45
|
+
dropFile: "Drop a file here", dropFiles: "Drop files here", or: " or ", browse: "browse",
|
|
46
|
+
fileTooLarge: (size) => "Larger than " + size + ".",
|
|
47
|
+
fixProblems: (count) => "Fix " + String(count) + (count === 1 ? " problem" : " problems") + " to continue",
|
|
48
|
+
charactersLeft: (count) => String(count) + (count === 1 ? " character left" : " characters left"),
|
|
49
|
+
charactersOver: (count) => String(count) + (count === 1 ? " character over" : " characters over"),
|
|
50
|
+
oneTimeCode: "One-time code", digit: "Digit", digitPosition: (label, position, total) => label + " " + String(position) + " of " + String(total),
|
|
51
|
+
details: "Details", selectAllRows: "Select all rows", row: (position) => "row " + String(position),
|
|
52
|
+
selectRow: (position) => "Select row " + String(position), showDetails: (name) => "Show details for " + name,
|
|
53
|
+
hideDetails: (name) => "Hide details for " + name, nothingToShow: "Nothing to show yet.",
|
|
54
|
+
pageSummary: (from, to, total) => String(from) + "–" + String(to) + " of " + String(total),
|
|
55
|
+
completedStep: " (completed)", currentStep: " (current step)", up: "Up ", down: "Down ",
|
|
56
|
+
copy: "Copy", copied: "Copied", code: "Code", languageCode: (language) => language + " code",
|
|
57
|
+
commandPalette: "Command palette", commandSearch: "Type a command or search", commands: "Commands",
|
|
58
|
+
noCommands: (query) => "No commands match “" + query + "”", commandMove: " to move ", commandRun: " to run ", commandClose: " to close",
|
|
59
|
+
category: "Category", value: "Value", showChart: "Show chart", showTable: "Show table",
|
|
60
|
+
barChart: "Bar chart", lineChart: "Line chart", chartInstructions: (title) => title + ". Use the arrow keys to read each value.",
|
|
61
|
+
trend: (values) => "Trend: " + values,
|
|
62
|
+
};
|
|
63
|
+
const dutch = {
|
|
64
|
+
chat: {
|
|
65
|
+
open: "Chat openen", close: "Chat sluiten", messages: "Berichten", message: "Bericht", placeholder: "Schrijf een bericht…",
|
|
66
|
+
send: "Bericht verzenden", sending: "Bericht wordt verzonden", failed: "Bericht niet verzonden", retry: "Opnieuw proberen", retryMessage: (author) => "Bericht van " + author + " opnieuw proberen",
|
|
67
|
+
tryAgain: "Opnieuw proberen", back: "Terug naar gesprekken", empty: "Nog geen berichten. Begin het gesprek.", chooseThread: "Kies een gesprek om te lezen en te antwoorden.", noThreads: "Nog geen gesprekken.",
|
|
68
|
+
conversations: "Gesprekken", unread: (count) => String(count) + (count === 1 ? " ongelezen bericht" : " ongelezen berichten"),
|
|
69
|
+
},
|
|
70
|
+
richText: {
|
|
71
|
+
formatting: "Opmaakopties",
|
|
72
|
+
toolbar: "Opmaak", paragraph: "Alinea", heading: (level) => "Kop " + String(level),
|
|
73
|
+
bold: "Vet", italic: "Cursief", bulletList: "Opsomming", orderedList: "Genummerde lijst", quote: "Citaat",
|
|
74
|
+
inlineCode: "Inline code", codeBlock: "Codeblok", undo: "Ongedaan maken", redo: "Opnieuw uitvoeren",
|
|
75
|
+
addLink: "Link toevoegen", removeLink: "Link verwijderen", linkUrl: "Link-URL", linkText: "Linktekst", applyLink: "Link toepassen", cancel: "Annuleren",
|
|
76
|
+
invalidUrl: "Voer een geldige URL of relatieve link in.", emojiName: (value) => dutchEmojiNames[value] || value, emoji: "Emoji invoegen", emojiSearch: "Emoji zoeken", noEmoji: "Geen emoji gevonden", attachFiles: "Bestanden bijvoegen",
|
|
77
|
+
uploading: (name) => name + " uploaden", uploadFailed: (name) => name + " kon niet worden geüpload",
|
|
78
|
+
retryUpload: (name) => "Upload van " + name + " opnieuw proberen", cancelUpload: (name) => "Upload van " + name + " annuleren",
|
|
79
|
+
removeAttachment: (name) => "Bijlage " + name + " verwijderen", attachmentUploaded: (name) => name + " geüpload",
|
|
80
|
+
maxFileSize: (size) => "Kies een bestand kleiner dan " + size + ".", editorLoading: "Editor laden",
|
|
81
|
+
},
|
|
82
|
+
dismiss: "Sluiten", close: "Sluiten", clear: "Wissen", today: "Vandaag",
|
|
83
|
+
showPassword: "Tonen", hidePassword: "Verbergen", decrease: "Verlagen", increase: "Verhogen",
|
|
84
|
+
loading: "Laden", progress: "Voortgang", breadcrumb: "Kruimelpad", pagination: "Paginering",
|
|
85
|
+
previous: "Vorige", next: "Volgende", page: (page) => "Pagina " + String(page),
|
|
86
|
+
previousMonth: "Vorige maand", nextMonth: "Volgende maand",
|
|
87
|
+
chooseDate: "Kies een datum", chooseDates: "Kies datums", selectDate: "Selecteer een datum", selectDates: "Selecteer datums",
|
|
88
|
+
invalidDate: (example) => "Voer een datum in zoals " + example + ".",
|
|
89
|
+
invalidTime: (example) => "Voer een tijd in zoals " + example + ".",
|
|
90
|
+
times: "Tijden", selectOne: "Selecteer een optie", noMatches: (query) => "Geen resultaten voor “" + query + "”",
|
|
91
|
+
remove: (name) => name ? "Verwijder " + name : "Verwijderen", clearSearch: "Zoekopdracht wissen", moreActions: "Meer acties", actions: "Acties",
|
|
92
|
+
skipToContent: "Ga naar inhoud", sidebar: "Zijbalk", showSidebar: "Zijbalk tonen", hideSidebar: "Zijbalk verbergen", menu: "Menu",
|
|
93
|
+
statusInfo: "Informatie", statusSuccess: "Geslaagd", statusWarning: "Waarschuwing", statusDanger: "Fout",
|
|
94
|
+
notifications: "Meldingen", dismissNotification: "Melding sluiten", notificationAnnouncement: "Melding",
|
|
95
|
+
dropFile: "Sleep een bestand hierheen", dropFiles: "Sleep bestanden hierheen", or: " of ", browse: "bladeren",
|
|
96
|
+
fileTooLarge: (size) => "Groter dan " + size + ".",
|
|
97
|
+
fixProblems: (count) => "Los " + String(count) + (count === 1 ? " probleem" : " problemen") + " op om door te gaan",
|
|
98
|
+
charactersLeft: (count) => "Nog " + String(count) + (count === 1 ? " teken" : " tekens"),
|
|
99
|
+
charactersOver: (count) => String(count) + (count === 1 ? " teken te veel" : " tekens te veel"),
|
|
100
|
+
oneTimeCode: "Eenmalige code", digit: "Cijfer", digitPosition: (label, position, total) => label + " " + String(position) + " van " + String(total),
|
|
101
|
+
details: "Details", selectAllRows: "Alle rijen selecteren", row: (position) => "rij " + String(position),
|
|
102
|
+
selectRow: (position) => "Selecteer rij " + String(position), showDetails: (name) => "Details tonen voor " + name,
|
|
103
|
+
hideDetails: (name) => "Details verbergen voor " + name, nothingToShow: "Er is nog niets om weer te geven.",
|
|
104
|
+
pageSummary: (from, to, total) => String(from) + "–" + String(to) + " van " + String(total),
|
|
105
|
+
completedStep: " (voltooid)", currentStep: " (huidige stap)", up: "Omhoog ", down: "Omlaag ",
|
|
106
|
+
copy: "Kopiëren", copied: "Gekopieerd", code: "Code", languageCode: (language) => language + "-code",
|
|
107
|
+
commandPalette: "Opdrachtenpalet", commandSearch: "Typ een opdracht of zoek", commands: "Opdrachten",
|
|
108
|
+
noCommands: (query) => "Geen opdrachten voor “" + query + "”", commandMove: " om te navigeren ", commandRun: " om uit te voeren ", commandClose: " om te sluiten",
|
|
109
|
+
category: "Categorie", value: "Waarde", showChart: "Grafiek tonen", showTable: "Tabel tonen",
|
|
110
|
+
barChart: "Staafdiagram", lineChart: "Lijndiagram", chartInstructions: (title) => title + ". Gebruik de pijltjestoetsen om elke waarde te lezen.",
|
|
111
|
+
trend: (values) => "Trend: " + values,
|
|
112
|
+
};
|
|
113
|
+
/** Optional translation fields inherit when omitted or explicitly undefined. */
|
|
114
|
+
function mergeDefined(base, overrides) {
|
|
115
|
+
const merged = { ...base };
|
|
116
|
+
if (overrides)
|
|
117
|
+
for (const key in overrides) {
|
|
118
|
+
const value = overrides[key];
|
|
119
|
+
if (value !== undefined)
|
|
120
|
+
merged[key] = value;
|
|
121
|
+
}
|
|
122
|
+
return merged;
|
|
123
|
+
}
|
|
124
|
+
const LocaleContext = createContext({ locale: "en-US", overrides: {} });
|
|
125
|
+
/** Scoped locale and translations. Does not read browser language or mutate the document. */
|
|
126
|
+
export function LocaleProvider({ locale, messages, children }) {
|
|
127
|
+
const parent = useContext(LocaleContext);
|
|
128
|
+
const value = useMemo(() => ({
|
|
129
|
+
locale: locale === undefined ? parent.locale : resolveLocale(locale),
|
|
130
|
+
overrides: mergeDefined(parent.overrides, { ...messages, richText: mergeDefined(parent.overrides.richText || {}, messages?.richText), chat: mergeDefined(parent.overrides.chat || {}, messages?.chat) }),
|
|
131
|
+
}), [locale, messages, parent]);
|
|
132
|
+
return _jsx(LocaleContext.Provider, { value: value, children: children });
|
|
133
|
+
}
|
|
134
|
+
/** Read the nearest provider; an explicit control locale selects its formatting and default dictionary. */
|
|
135
|
+
export function useLocale(localeOverride) {
|
|
136
|
+
const context = useContext(LocaleContext);
|
|
137
|
+
const locale = localeOverride === undefined ? context.locale : resolveLocale(localeOverride);
|
|
138
|
+
return useMemo(() => {
|
|
139
|
+
const defaults = /^nl(?:-|$)/i.test(locale) ? dutch : english;
|
|
140
|
+
return { locale, messages: mergeDefined(defaults, { ...context.overrides, richText: mergeDefined(defaults.richText, context.overrides.richText), chat: mergeDefined(defaults.chat, context.overrides.chat) }) };
|
|
141
|
+
}, [locale, context.overrides]);
|
|
142
|
+
}
|