occulite-ui 0.0.0-stage → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +290 -2
- package/THIRD_PARTY_NOTICES.md +36 -0
- package/dist/clipboard.d.ts +26 -0
- package/dist/clipboard.js +70 -0
- package/dist/components/ContextMenu.svelte +158 -0
- package/dist/components/ContextMenu.svelte.d.ts +14 -0
- package/dist/components/DataTable.svelte +1990 -0
- package/dist/components/DataTable.svelte.d.ts +154 -0
- package/dist/components/Dialog.svelte +420 -0
- package/dist/components/Dialog.svelte.d.ts +55 -0
- package/dist/components/GithubLink.svelte +74 -0
- package/dist/components/GithubLink.svelte.d.ts +16 -0
- package/dist/components/Header.svelte +196 -0
- package/dist/components/Header.svelte.d.ts +42 -0
- package/dist/components/Icon.svelte +51 -0
- package/dist/components/Icon.svelte.d.ts +12 -0
- package/dist/components/LanguageSwitch.svelte +63 -0
- package/dist/components/LanguageSwitch.svelte.d.ts +17 -0
- package/dist/components/Loader.svelte +65 -0
- package/dist/components/Loader.svelte.d.ts +9 -0
- package/dist/components/MultiSelect.svelte +467 -0
- package/dist/components/MultiSelect.svelte.d.ts +28 -0
- package/dist/components/Notices.svelte +146 -0
- package/dist/components/Notices.svelte.d.ts +16 -0
- package/dist/components/PrimaryToolbarButton.svelte +189 -0
- package/dist/components/PrimaryToolbarButton.svelte.d.ts +34 -0
- package/dist/components/Tabs.svelte +118 -0
- package/dist/components/Tabs.svelte.d.ts +16 -0
- package/dist/components/ThemeSwitch.svelte +46 -0
- package/dist/components/ThemeSwitch.svelte.d.ts +11 -0
- package/dist/components/Toolbar.svelte +57 -0
- package/dist/components/Toolbar.svelte.d.ts +11 -0
- package/dist/components/ToolbarButton.svelte +126 -0
- package/dist/components/ToolbarButton.svelte.d.ts +22 -0
- package/dist/components/Tooltip.svelte +106 -0
- package/dist/components/Tooltip.svelte.d.ts +31 -0
- package/dist/components/TooltipBubble.svelte +65 -0
- package/dist/components/TooltipBubble.svelte.d.ts +18 -0
- package/dist/components/contextMenu.d.ts +19 -0
- package/dist/components/contextMenu.js +6 -0
- package/dist/components/dialogGeometry.d.ts +91 -0
- package/dist/components/dialogGeometry.js +140 -0
- package/dist/components/index.d.ts +22 -0
- package/dist/components/index.js +22 -0
- package/dist/components/multiSelect.d.ts +27 -0
- package/dist/components/multiSelect.js +26 -0
- package/dist/components/navigation.d.ts +34 -0
- package/dist/components/navigation.js +19 -0
- package/dist/components/tooltip.d.ts +29 -0
- package/dist/components/tooltip.js +27 -0
- package/dist/css/app.css +3 -0
- package/dist/css/base.css +84 -0
- package/dist/css/tokens.css +170 -0
- package/dist/dialog/index.d.ts +6 -0
- package/dist/dialog/index.js +6 -0
- package/dist/embedding/ShellEmbedding.svelte.d.ts +27 -0
- package/dist/embedding/ShellEmbedding.svelte.js +79 -0
- package/dist/embedding/constants.d.ts +23 -0
- package/dist/embedding/constants.js +54 -0
- package/dist/embedding/index.d.ts +2 -0
- package/dist/embedding/index.js +2 -0
- package/dist/externalLink.d.ts +15 -0
- package/dist/externalLink.js +20 -0
- package/dist/format.d.ts +6 -0
- package/dist/format.js +16 -0
- package/dist/i18n/i18n.svelte.d.ts +112 -0
- package/dist/i18n/i18n.svelte.js +211 -0
- package/dist/i18n/index.d.ts +3 -0
- package/dist/i18n/index.js +3 -0
- package/dist/i18n/messages.d.ts +9 -0
- package/dist/i18n/messages.js +58 -0
- package/dist/i18n/translator.d.ts +65 -0
- package/dist/i18n/translator.js +99 -0
- package/dist/icons/index.d.ts +17 -0
- package/dist/icons/index.js +11 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +16 -0
- package/dist/notices/NoticesStore.svelte.d.ts +64 -0
- package/dist/notices/NoticesStore.svelte.js +127 -0
- package/dist/notices/index.d.ts +1 -0
- package/dist/notices/index.js +1 -0
- package/dist/storage.d.ts +11 -0
- package/dist/storage.js +27 -0
- package/dist/table/LocalColumnWidths.svelte.d.ts +32 -0
- package/dist/table/LocalColumnWidths.svelte.js +91 -0
- package/dist/table/columnMeasure.d.ts +24 -0
- package/dist/table/columnMeasure.js +82 -0
- package/dist/table/columnWidths.d.ts +60 -0
- package/dist/table/columnWidths.js +86 -0
- package/dist/table/dataTableContext.d.ts +26 -0
- package/dist/table/dataTableContext.js +16 -0
- package/dist/table/index.d.ts +6 -0
- package/dist/table/index.js +6 -0
- package/dist/table/metrics.d.ts +10 -0
- package/dist/table/metrics.js +10 -0
- package/dist/table/tableModel.d.ts +306 -0
- package/dist/table/tableModel.js +437 -0
- package/dist/theme/choices.d.ts +8 -0
- package/dist/theme/choices.js +6 -0
- package/dist/theme/index.d.ts +2 -0
- package/dist/theme/index.js +2 -0
- package/dist/theme/theme.svelte.d.ts +60 -0
- package/dist/theme/theme.svelte.js +108 -0
- package/package.json +137 -4
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { type ShellEmbedding } from '../embedding/ShellEmbedding.svelte.js';
|
|
2
|
+
import { type StorageLike } from '../storage.js';
|
|
3
|
+
import { type Catalogue, type Language, type LanguageChoice, type LanguageCode, type MessageParams } from './translator.js';
|
|
4
|
+
/** The languages the kit offers in its language switch. */
|
|
5
|
+
export declare const UI_LANGUAGES: readonly Language[];
|
|
6
|
+
/** English is what a browser that asks for nothing the UI has gets. */
|
|
7
|
+
export declare const FALLBACK_LANGUAGE: Language;
|
|
8
|
+
/** The name of each language in itself. An app with an extra fallback locale adds its own entry. */
|
|
9
|
+
export declare const LANGUAGE_LABELS: Readonly<Record<string, string>>;
|
|
10
|
+
/** `de-AT` -> `de`; `undefined` for anything that is not one of {@link UI_LANGUAGES}. */
|
|
11
|
+
export declare function supportedLanguage(code: string | null | undefined): Language | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* The language the browser asks for: the first entry of `navigator.languages` the UI has, English
|
|
14
|
+
* behind it.
|
|
15
|
+
*
|
|
16
|
+
* Region subtags are dropped, so `de-DE`, `de-AT` and `de-CH` are all German and `en-GB` is
|
|
17
|
+
* English; a browser that asks for French first and German second gets German, because the *order*
|
|
18
|
+
* is what the user expressed.
|
|
19
|
+
*/
|
|
20
|
+
export declare function browserLanguage(languages?: readonly string[]): Language;
|
|
21
|
+
/**
|
|
22
|
+
* The language a UI starts in: a choice the user made and stored wins, and everything else -
|
|
23
|
+
* `auto`, an absent value, a language the UI does not have - means the browser decides.
|
|
24
|
+
*/
|
|
25
|
+
export declare function resolveLanguage(stored: string | undefined, languages?: readonly string[]): Language;
|
|
26
|
+
export interface I18nOptions {
|
|
27
|
+
/**
|
|
28
|
+
* The catalogue, or a function returning it. A function is read reactively, so a catalogue
|
|
29
|
+
* that grows later (`addMessages`) re-renders what was translated with it.
|
|
30
|
+
*/
|
|
31
|
+
readonly catalogue?: Catalogue | (() => Catalogue);
|
|
32
|
+
/** Languages to try after the current one; English, then German by default. */
|
|
33
|
+
readonly fallbacks?: readonly LanguageCode[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A language that can change at runtime, and the translation in it. Everything that called `t()`
|
|
37
|
+
* in a template re-renders when the language changes.
|
|
38
|
+
*/
|
|
39
|
+
export declare class I18n {
|
|
40
|
+
#private;
|
|
41
|
+
constructor(language?: LanguageCode, options?: I18nOptions);
|
|
42
|
+
get language(): LanguageCode;
|
|
43
|
+
set language(language: LanguageCode);
|
|
44
|
+
/** `t('Close')`, `t('{count} more', {}, 7)`. Bound, so it can be passed around. */
|
|
45
|
+
readonly t: (key: string, params?: MessageParams, count?: number) => string;
|
|
46
|
+
/** Is there a text for this key at all? */
|
|
47
|
+
readonly has: (key: string) => boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Every text of a key, in every language of the catalogue - for a filter that should match
|
|
50
|
+
* what the reader may have read, whatever language it was in. The key comes first.
|
|
51
|
+
*/
|
|
52
|
+
readonly translations: (key: string) => string[];
|
|
53
|
+
}
|
|
54
|
+
export declare function createI18n(language?: LanguageCode, options?: I18nOptions): I18n;
|
|
55
|
+
/**
|
|
56
|
+
* Adds an app's (or an addon's) strings to the page's catalogue. May be called more than once;
|
|
57
|
+
* later catalogues win over earlier ones and every app catalogue wins over the kit's, per key and
|
|
58
|
+
* per language.
|
|
59
|
+
*/
|
|
60
|
+
export declare function addMessages(...catalogues: readonly Catalogue[]): void;
|
|
61
|
+
/** The page's catalogue as it is now: the kit's strings with every `addMessages()` on top. */
|
|
62
|
+
export declare function catalogue(): Catalogue;
|
|
63
|
+
/** Back to the kit's own strings only - for tests. */
|
|
64
|
+
export declare function resetMessages(): void;
|
|
65
|
+
/** The page's translation: the kit's components and every app that does not bring its own. */
|
|
66
|
+
export declare const i18n: I18n;
|
|
67
|
+
/** `t('Close')` in the page's language; reactive in a template. */
|
|
68
|
+
export declare const t: (key: string, params?: MessageParams, count?: number) => string;
|
|
69
|
+
/** Is there a text for this key in the page's catalogue? */
|
|
70
|
+
export declare const has: (key: string) => boolean;
|
|
71
|
+
/** Every text of a key, in every language. */
|
|
72
|
+
export declare const translations: (key: string) => string[];
|
|
73
|
+
export interface InitI18nOptions {
|
|
74
|
+
/** The `localStorage` key the app keeps its choice in (`myapp.language`); none stores nothing. */
|
|
75
|
+
readonly storageKey?: string | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* `shell` (the default): inside openccu-lite's shell the page speaks the shell's language and
|
|
78
|
+
* follows it when it changes. `none`: the page's own choice and the browser only.
|
|
79
|
+
*/
|
|
80
|
+
readonly follow?: 'shell' | 'none';
|
|
81
|
+
/** Read the shell's `ol-lang` cookie when nothing is stored (default `true`). */
|
|
82
|
+
readonly cookie?: boolean;
|
|
83
|
+
/** The storage to use; `localStorage` where the browser allows it. */
|
|
84
|
+
readonly storage?: StorageLike | undefined;
|
|
85
|
+
/** The browser's languages; `navigator.languages` by default. */
|
|
86
|
+
readonly languages?: readonly string[] | undefined;
|
|
87
|
+
/** The embedding to follow; the page's shared one by default. */
|
|
88
|
+
readonly shell?: ShellEmbedding | undefined;
|
|
89
|
+
/** The document whose `lang` is set and whose cookie is read; `document` by default. */
|
|
90
|
+
readonly document?: Document | undefined;
|
|
91
|
+
}
|
|
92
|
+
/** What the user chose: a language, or `auto`. Reactive; a language switch binds to it. */
|
|
93
|
+
export declare const languageChoice: {
|
|
94
|
+
value: LanguageChoice;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Picks the page's language, in this order:
|
|
98
|
+
*
|
|
99
|
+
* 1. the shell's, when embedded in openccu-lite's shell and `follow` is `shell`;
|
|
100
|
+
* 2. the app's own stored choice (`storageKey`);
|
|
101
|
+
* 3. the shell's `ol-lang` cookie of this origin, when nothing is stored;
|
|
102
|
+
* 4. the browser's languages, English behind them.
|
|
103
|
+
*
|
|
104
|
+
* Returns a function that stops following the shell.
|
|
105
|
+
*/
|
|
106
|
+
export declare function initI18n(options?: InitI18nOptions): () => void;
|
|
107
|
+
/**
|
|
108
|
+
* Sets the page's language: a language, or `auto` for the browser's. Stored under the app's key
|
|
109
|
+
* (when `initI18n` was given one) and written to `<html lang>`; nothing else, the shell's cookie
|
|
110
|
+
* least of all - that is the shell's to write.
|
|
111
|
+
*/
|
|
112
|
+
export declare function setLanguage(choice: LanguageChoice): void;
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { LANG_COOKIE, readCookie } from '../embedding/constants.js';
|
|
2
|
+
import { shellEmbedding } from '../embedding/ShellEmbedding.svelte.js';
|
|
3
|
+
import { defaultStorage, readStored, writeStored } from '../storage.js';
|
|
4
|
+
import { KIT_MESSAGES } from './messages.js';
|
|
5
|
+
import { createTranslator, mergeCatalogues, } from './translator.js';
|
|
6
|
+
/** The languages the kit offers in its language switch. */
|
|
7
|
+
export const UI_LANGUAGES = ['de', 'en'];
|
|
8
|
+
/** English is what a browser that asks for nothing the UI has gets. */
|
|
9
|
+
export const FALLBACK_LANGUAGE = 'en';
|
|
10
|
+
/** The name of each language in itself. An app with an extra fallback locale adds its own entry. */
|
|
11
|
+
export const LANGUAGE_LABELS = {
|
|
12
|
+
de: 'Deutsch',
|
|
13
|
+
en: 'English',
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* What the browser prefers, in its own order; empty outside a browser.
|
|
17
|
+
*
|
|
18
|
+
* `navigator.languages` is typed as always there but is not on every engine, so the single
|
|
19
|
+
* `navigator.language` is the fallback behind it.
|
|
20
|
+
*/
|
|
21
|
+
function navigatorLanguages() {
|
|
22
|
+
if (typeof navigator === 'undefined') {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
const list = navigator.languages;
|
|
26
|
+
if (list !== undefined && list.length > 0) {
|
|
27
|
+
return list;
|
|
28
|
+
}
|
|
29
|
+
return navigator.language === '' ? [] : [navigator.language];
|
|
30
|
+
}
|
|
31
|
+
/** `de-AT` -> `de`; `undefined` for anything that is not one of {@link UI_LANGUAGES}. */
|
|
32
|
+
export function supportedLanguage(code) {
|
|
33
|
+
if (code === undefined || code === null) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
const base = code.toLowerCase().split('-')[0];
|
|
37
|
+
return UI_LANGUAGES.find((candidate) => candidate === base);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The language the browser asks for: the first entry of `navigator.languages` the UI has, English
|
|
41
|
+
* behind it.
|
|
42
|
+
*
|
|
43
|
+
* Region subtags are dropped, so `de-DE`, `de-AT` and `de-CH` are all German and `en-GB` is
|
|
44
|
+
* English; a browser that asks for French first and German second gets German, because the *order*
|
|
45
|
+
* is what the user expressed.
|
|
46
|
+
*/
|
|
47
|
+
export function browserLanguage(languages = navigatorLanguages()) {
|
|
48
|
+
for (const entry of languages) {
|
|
49
|
+
const supported = supportedLanguage(entry);
|
|
50
|
+
if (supported !== undefined) {
|
|
51
|
+
return supported;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return FALLBACK_LANGUAGE;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The language a UI starts in: a choice the user made and stored wins, and everything else -
|
|
58
|
+
* `auto`, an absent value, a language the UI does not have - means the browser decides.
|
|
59
|
+
*/
|
|
60
|
+
export function resolveLanguage(stored, languages = navigatorLanguages()) {
|
|
61
|
+
const chosen = stored === undefined || stored === 'auto' ? undefined : UI_LANGUAGES.find((c) => c === stored);
|
|
62
|
+
return chosen ?? browserLanguage(languages);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A language that can change at runtime, and the translation in it. Everything that called `t()`
|
|
66
|
+
* in a template re-renders when the language changes.
|
|
67
|
+
*/
|
|
68
|
+
export class I18n {
|
|
69
|
+
#language = $state(FALLBACK_LANGUAGE);
|
|
70
|
+
#catalogue;
|
|
71
|
+
#fallbacks;
|
|
72
|
+
#translator = $derived.by(() => {
|
|
73
|
+
const catalogue = this.#catalogue();
|
|
74
|
+
const fallbacks = this.#fallbacks;
|
|
75
|
+
return createTranslator(this.#language, fallbacks === undefined ? { catalogue } : { catalogue, fallbacks });
|
|
76
|
+
});
|
|
77
|
+
constructor(language = FALLBACK_LANGUAGE, options = {}) {
|
|
78
|
+
this.#language = language;
|
|
79
|
+
const catalogue = options.catalogue ?? {};
|
|
80
|
+
this.#catalogue = typeof catalogue === 'function' ? catalogue : () => catalogue;
|
|
81
|
+
this.#fallbacks = options.fallbacks;
|
|
82
|
+
}
|
|
83
|
+
get language() {
|
|
84
|
+
return this.#language;
|
|
85
|
+
}
|
|
86
|
+
set language(language) {
|
|
87
|
+
this.#language = language;
|
|
88
|
+
}
|
|
89
|
+
/** `t('Close')`, `t('{count} more', {}, 7)`. Bound, so it can be passed around. */
|
|
90
|
+
t = (key, params = {}, count) => this.#translator.t(key, params, count);
|
|
91
|
+
/** Is there a text for this key at all? */
|
|
92
|
+
has = (key) => this.#translator.has(key);
|
|
93
|
+
/**
|
|
94
|
+
* Every text of a key, in every language of the catalogue - for a filter that should match
|
|
95
|
+
* what the reader may have read, whatever language it was in. The key comes first.
|
|
96
|
+
*/
|
|
97
|
+
translations = (key) => {
|
|
98
|
+
const catalogue = this.#catalogue();
|
|
99
|
+
const entry = Object.prototype.hasOwnProperty.call(catalogue, key) ? catalogue[key] : undefined;
|
|
100
|
+
// a plain Set: a local value that is returned as an array, never rendered from
|
|
101
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity -- see above
|
|
102
|
+
const texts = new Set([key]);
|
|
103
|
+
for (const text of Object.values(entry ?? {})) {
|
|
104
|
+
if (typeof text === 'string') {
|
|
105
|
+
texts.add(text);
|
|
106
|
+
}
|
|
107
|
+
else if (text !== undefined) {
|
|
108
|
+
texts.add(text.one);
|
|
109
|
+
texts.add(text.other);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return [...texts];
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export function createI18n(language = FALLBACK_LANGUAGE, options = {}) {
|
|
116
|
+
return new I18n(language, options);
|
|
117
|
+
}
|
|
118
|
+
// ------------------------------------------------------------------ the page's catalogue and language
|
|
119
|
+
let registry = $state.raw(KIT_MESSAGES);
|
|
120
|
+
/**
|
|
121
|
+
* Adds an app's (or an addon's) strings to the page's catalogue. May be called more than once;
|
|
122
|
+
* later catalogues win over earlier ones and every app catalogue wins over the kit's, per key and
|
|
123
|
+
* per language.
|
|
124
|
+
*/
|
|
125
|
+
export function addMessages(...catalogues) {
|
|
126
|
+
registry = mergeCatalogues(registry, ...catalogues);
|
|
127
|
+
}
|
|
128
|
+
/** The page's catalogue as it is now: the kit's strings with every `addMessages()` on top. */
|
|
129
|
+
export function catalogue() {
|
|
130
|
+
return registry;
|
|
131
|
+
}
|
|
132
|
+
/** Back to the kit's own strings only - for tests. */
|
|
133
|
+
export function resetMessages() {
|
|
134
|
+
registry = KIT_MESSAGES;
|
|
135
|
+
}
|
|
136
|
+
/** The page's translation: the kit's components and every app that does not bring its own. */
|
|
137
|
+
export const i18n = new I18n(FALLBACK_LANGUAGE, { catalogue: () => registry });
|
|
138
|
+
/** `t('Close')` in the page's language; reactive in a template. */
|
|
139
|
+
export const t = i18n.t;
|
|
140
|
+
/** Is there a text for this key in the page's catalogue? */
|
|
141
|
+
export const has = i18n.has;
|
|
142
|
+
/** Every text of a key, in every language. */
|
|
143
|
+
export const translations = i18n.translations;
|
|
144
|
+
let setup = {
|
|
145
|
+
storageKey: undefined,
|
|
146
|
+
storage: undefined,
|
|
147
|
+
languages: undefined,
|
|
148
|
+
document: typeof document === 'undefined' ? undefined : document,
|
|
149
|
+
};
|
|
150
|
+
/** What the user chose: a language, or `auto`. Reactive; a language switch binds to it. */
|
|
151
|
+
export const languageChoice = $state({ value: 'auto' });
|
|
152
|
+
/**
|
|
153
|
+
* Picks the page's language, in this order:
|
|
154
|
+
*
|
|
155
|
+
* 1. the shell's, when embedded in openccu-lite's shell and `follow` is `shell`;
|
|
156
|
+
* 2. the app's own stored choice (`storageKey`);
|
|
157
|
+
* 3. the shell's `ol-lang` cookie of this origin, when nothing is stored;
|
|
158
|
+
* 4. the browser's languages, English behind them.
|
|
159
|
+
*
|
|
160
|
+
* Returns a function that stops following the shell.
|
|
161
|
+
*/
|
|
162
|
+
export function initI18n(options = {}) {
|
|
163
|
+
setup = {
|
|
164
|
+
storageKey: options.storageKey,
|
|
165
|
+
storage: options.storage ?? defaultStorage(),
|
|
166
|
+
languages: options.languages,
|
|
167
|
+
document: options.document ?? (typeof document === 'undefined' ? undefined : document),
|
|
168
|
+
};
|
|
169
|
+
const stored = setup.storageKey === undefined ? undefined : readStored(setup.storage, setup.storageKey);
|
|
170
|
+
const storedChoice = stored === 'auto' ? 'auto' : supportedLanguage(stored);
|
|
171
|
+
languageChoice.value = storedChoice ?? 'auto';
|
|
172
|
+
if (storedChoice !== undefined && storedChoice !== 'auto') {
|
|
173
|
+
apply(storedChoice);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
const fromCookie = storedChoice === undefined && options.cookie !== false
|
|
177
|
+
? supportedLanguage(readCookie(LANG_COOKIE, setup.document))
|
|
178
|
+
: undefined;
|
|
179
|
+
apply(fromCookie ?? browserLanguage(setup.languages ?? navigatorLanguages()));
|
|
180
|
+
}
|
|
181
|
+
if (options.follow === 'none') {
|
|
182
|
+
return () => { };
|
|
183
|
+
}
|
|
184
|
+
const shell = options.shell ?? shellEmbedding();
|
|
185
|
+
return $effect.root(() => {
|
|
186
|
+
$effect(() => {
|
|
187
|
+
const fromShell = shell.embedded ? supportedLanguage(shell.lang) : undefined;
|
|
188
|
+
if (fromShell !== undefined) {
|
|
189
|
+
apply(fromShell);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Sets the page's language: a language, or `auto` for the browser's. Stored under the app's key
|
|
196
|
+
* (when `initI18n` was given one) and written to `<html lang>`; nothing else, the shell's cookie
|
|
197
|
+
* least of all - that is the shell's to write.
|
|
198
|
+
*/
|
|
199
|
+
export function setLanguage(choice) {
|
|
200
|
+
languageChoice.value = choice;
|
|
201
|
+
if (setup.storageKey !== undefined) {
|
|
202
|
+
writeStored(setup.storage, setup.storageKey, choice);
|
|
203
|
+
}
|
|
204
|
+
apply(resolveLanguage(choice, setup.languages ?? navigatorLanguages()));
|
|
205
|
+
}
|
|
206
|
+
function apply(language) {
|
|
207
|
+
i18n.language = language;
|
|
208
|
+
if (setup.document?.documentElement) {
|
|
209
|
+
setup.document.documentElement.lang = language;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Catalogue } from './translator.js';
|
|
2
|
+
/**
|
|
3
|
+
* The kit's own strings: the chrome of its components (close, filter, the table's column menu,
|
|
4
|
+
* the toast stack, the theme and language switches) and the handful of words every dialog needs.
|
|
5
|
+
*
|
|
6
|
+
* An app adds its own catalogue with `addMessages()`; on a collision the app wins, per language.
|
|
7
|
+
* Every key has a German and an English text (`i18n.test.ts` checks it).
|
|
8
|
+
*/
|
|
9
|
+
export declare const KIT_MESSAGES: Catalogue;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The kit's own strings: the chrome of its components (close, filter, the table's column menu,
|
|
3
|
+
* the toast stack, the theme and language switches) and the handful of words every dialog needs.
|
|
4
|
+
*
|
|
5
|
+
* An app adds its own catalogue with `addMessages()`; on a collision the app wins, per language.
|
|
6
|
+
* Every key has a German and an English text (`i18n.test.ts` checks it).
|
|
7
|
+
*/
|
|
8
|
+
export const KIT_MESSAGES = {
|
|
9
|
+
// dialogs and buttons
|
|
10
|
+
Close: { de: 'Schließen', en: 'Close' },
|
|
11
|
+
Apply: { de: 'Übernehmen', en: 'Apply' },
|
|
12
|
+
Cancel: { de: 'Abbrechen', en: 'Cancel' },
|
|
13
|
+
OK: { de: 'OK', en: 'OK' },
|
|
14
|
+
Save: { de: 'Speichern', en: 'Save' },
|
|
15
|
+
Delete: { de: 'Löschen', en: 'Delete' },
|
|
16
|
+
Copy: { de: 'Kopieren', en: 'Copy' },
|
|
17
|
+
Error: { de: 'Fehler', en: 'Error' },
|
|
18
|
+
Loading: { de: 'Wird geladen', en: 'Loading' },
|
|
19
|
+
Menu: { de: 'Menü', en: 'Menu' },
|
|
20
|
+
Tabs: { de: 'Reiter', en: 'Tabs' },
|
|
21
|
+
Toolbar: { de: 'Werkzeugleiste', en: 'Toolbar' },
|
|
22
|
+
// filters and selections
|
|
23
|
+
Filter: { de: 'Filter', en: 'Filter' },
|
|
24
|
+
'Filter all columns': { de: 'Alle Spalten filtern', en: 'Filter all columns' },
|
|
25
|
+
All: { de: 'Alle', en: 'All' },
|
|
26
|
+
'Clear filter': { de: 'Filter löschen', en: 'Clear filter' },
|
|
27
|
+
'No row matches the filter': { de: 'Keine Zeile passt zum Filter', en: 'No row matches the filter' },
|
|
28
|
+
'Check all': { de: 'Alle auswählen', en: 'Check all' },
|
|
29
|
+
'Uncheck all': { de: 'Auswahl entfernen', en: 'Uncheck all' },
|
|
30
|
+
// the table's column handles, its header menu and the copy button of a cell
|
|
31
|
+
'Resize column {column}': { de: 'Breite der Spalte {column} ändern', en: 'Resize column {column}' },
|
|
32
|
+
'Fit column to content': { de: 'Spaltenbreite an den Inhalt anpassen', en: 'Fit column to content' },
|
|
33
|
+
'Reset column widths': { de: 'Spaltenbreiten zurücksetzen', en: 'Reset column widths' },
|
|
34
|
+
'Column widths': { de: 'Spaltenbreiten', en: 'Column widths' },
|
|
35
|
+
'Expand row': { de: 'Zeile aufklappen', en: 'Expand row' },
|
|
36
|
+
'Collapse row': { de: 'Zeile zuklappen', en: 'Collapse row' },
|
|
37
|
+
'Copy name': { de: 'Namen kopieren', en: 'Copy name' },
|
|
38
|
+
'Copy address': { de: 'Adresse kopieren', en: 'Copy address' },
|
|
39
|
+
Copied: { de: 'Kopiert', en: 'Copied' },
|
|
40
|
+
'Could not copy - the text is selected': {
|
|
41
|
+
de: 'Kopieren nicht möglich - der Text ist markiert',
|
|
42
|
+
en: 'Could not copy - the text is selected',
|
|
43
|
+
},
|
|
44
|
+
// the toast stack
|
|
45
|
+
Dismiss: { de: 'Ausblenden', en: 'Dismiss' },
|
|
46
|
+
'{count} more': {
|
|
47
|
+
de: { one: '{count} weitere', other: '{count} weitere' },
|
|
48
|
+
en: { one: '{count} more', other: '{count} more' },
|
|
49
|
+
},
|
|
50
|
+
'Show fewer': { de: 'Weniger anzeigen', en: 'Show fewer' },
|
|
51
|
+
// theme and language
|
|
52
|
+
Theme: { de: 'Design', en: 'Theme' },
|
|
53
|
+
'Theme: light': { de: 'Design: hell', en: 'Theme: light' },
|
|
54
|
+
'Theme: dark': { de: 'Design: dunkel', en: 'Theme: dark' },
|
|
55
|
+
'Theme: system': { de: 'Design: System', en: 'Theme: system' },
|
|
56
|
+
Language: { de: 'Sprache', en: 'Language' },
|
|
57
|
+
'Browser language': { de: 'Sprache des Browsers', en: 'Browser language' },
|
|
58
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message translation: `t(key, params, count)`.
|
|
3
|
+
*
|
|
4
|
+
* A missing translation is never an error: the chain is the requested language, then English,
|
|
5
|
+
* then German, then the key itself, and interpolation happens either way. A half-translated UI is
|
|
6
|
+
* usable, a UI that throws on a missing string is not. The key is the English text, so a
|
|
7
|
+
* catalogue entry without `en` still reads correctly in English.
|
|
8
|
+
*/
|
|
9
|
+
/** The languages the kit has its own strings in. */
|
|
10
|
+
export type Language = 'de' | 'en';
|
|
11
|
+
/**
|
|
12
|
+
* A language code a catalogue may carry beyond `de`/`en` (an app's own fallback locale, say).
|
|
13
|
+
* `Language` is what the kit offers in its switches; `LanguageCode` is what it can look up.
|
|
14
|
+
*/
|
|
15
|
+
export type LanguageCode = Language | (string & {});
|
|
16
|
+
/** What a language switch stores: a language, or `auto` for "the browser decides". */
|
|
17
|
+
export type LanguageChoice = Language | 'auto';
|
|
18
|
+
/** The plural categories German and English need. */
|
|
19
|
+
export type PluralCategory = 'one' | 'other';
|
|
20
|
+
/** Values for the `{placeholders}` of a message. */
|
|
21
|
+
export type MessageParams = Readonly<Record<string, string | number>>;
|
|
22
|
+
/** A message: one string, or the two plural forms German and English need. */
|
|
23
|
+
export type MessageEntry = string | {
|
|
24
|
+
readonly one: string;
|
|
25
|
+
readonly other: string;
|
|
26
|
+
};
|
|
27
|
+
/** Message key -> language -> text. */
|
|
28
|
+
export type Catalogue = Readonly<Record<string, Readonly<Partial<Record<LanguageCode, MessageEntry>>>>>;
|
|
29
|
+
/** The default fallback chain: English is the key language, German the most complete one. */
|
|
30
|
+
export declare const DEFAULT_FALLBACKS: readonly LanguageCode[];
|
|
31
|
+
/**
|
|
32
|
+
* The plural category of a count. German and English agree: exactly one is `one`, everything else
|
|
33
|
+
* (zero included) is `other`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function pluralCategory(language: LanguageCode, count: number): PluralCategory;
|
|
36
|
+
/** Replaces `{name}` with the value; a placeholder without a value is left as it is. */
|
|
37
|
+
export declare function interpolate(template: string, params: MessageParams): string;
|
|
38
|
+
export interface TranslatorOptions {
|
|
39
|
+
/** The catalogue to look keys up in; empty by default. */
|
|
40
|
+
readonly catalogue?: Catalogue;
|
|
41
|
+
/** Languages to try after the requested one; {@link DEFAULT_FALLBACKS} by default. */
|
|
42
|
+
readonly fallbacks?: readonly LanguageCode[];
|
|
43
|
+
}
|
|
44
|
+
/** Translates message keys into one language. Immutable; make a new one to switch languages. */
|
|
45
|
+
export declare class Translator {
|
|
46
|
+
#private;
|
|
47
|
+
readonly language: LanguageCode;
|
|
48
|
+
constructor(language: LanguageCode, options?: TranslatorOptions);
|
|
49
|
+
/** Is there a text for this key in any language of the chain? */
|
|
50
|
+
has(key: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* The translated text.
|
|
53
|
+
*
|
|
54
|
+
* @param params values for the `{placeholders}`; `{count}` is filled from `count`.
|
|
55
|
+
* @param count selects the plural form and becomes the `{count}` placeholder.
|
|
56
|
+
*/
|
|
57
|
+
t(key: string, params?: MessageParams, count?: number): string;
|
|
58
|
+
}
|
|
59
|
+
/** Shorthand for `new Translator(...)`. */
|
|
60
|
+
export declare function createTranslator(language: LanguageCode, options?: TranslatorOptions): Translator;
|
|
61
|
+
/**
|
|
62
|
+
* Merges catalogues: later ones win, per key and per language, so a catalogue that only brings a
|
|
63
|
+
* German text for a key keeps the English one of the catalogue before it.
|
|
64
|
+
*/
|
|
65
|
+
export declare function mergeCatalogues(...catalogues: readonly Catalogue[]): Catalogue;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message translation: `t(key, params, count)`.
|
|
3
|
+
*
|
|
4
|
+
* A missing translation is never an error: the chain is the requested language, then English,
|
|
5
|
+
* then German, then the key itself, and interpolation happens either way. A half-translated UI is
|
|
6
|
+
* usable, a UI that throws on a missing string is not. The key is the English text, so a
|
|
7
|
+
* catalogue entry without `en` still reads correctly in English.
|
|
8
|
+
*/
|
|
9
|
+
/** The default fallback chain: English is the key language, German the most complete one. */
|
|
10
|
+
export const DEFAULT_FALLBACKS = ['en', 'de'];
|
|
11
|
+
/**
|
|
12
|
+
* Languages without plural agreement with a number: their `other` form is used for every count.
|
|
13
|
+
* Turkish is the one an app of this family carries as a fallback locale.
|
|
14
|
+
*/
|
|
15
|
+
const NO_PLURAL_AGREEMENT = new Set(['tr']);
|
|
16
|
+
/**
|
|
17
|
+
* The plural category of a count. German and English agree: exactly one is `one`, everything else
|
|
18
|
+
* (zero included) is `other`.
|
|
19
|
+
*/
|
|
20
|
+
export function pluralCategory(language, count) {
|
|
21
|
+
if (NO_PLURAL_AGREEMENT.has(language)) {
|
|
22
|
+
return 'other';
|
|
23
|
+
}
|
|
24
|
+
return count === 1 ? 'one' : 'other';
|
|
25
|
+
}
|
|
26
|
+
/** Replaces `{name}` with the value; a placeholder without a value is left as it is. */
|
|
27
|
+
export function interpolate(template, params) {
|
|
28
|
+
return template.replace(/\{(\w+)\}/g, (placeholder, name) => {
|
|
29
|
+
const value = params[name];
|
|
30
|
+
return value === undefined ? placeholder : String(value);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/** Translates message keys into one language. Immutable; make a new one to switch languages. */
|
|
34
|
+
export class Translator {
|
|
35
|
+
language;
|
|
36
|
+
#catalogue;
|
|
37
|
+
#chain;
|
|
38
|
+
constructor(language, options = {}) {
|
|
39
|
+
this.language = language;
|
|
40
|
+
this.#catalogue = options.catalogue ?? {};
|
|
41
|
+
const fallbacks = options.fallbacks ?? DEFAULT_FALLBACKS;
|
|
42
|
+
this.#chain = [language, ...fallbacks.filter((candidate) => candidate !== language)];
|
|
43
|
+
}
|
|
44
|
+
/** Is there a text for this key in any language of the chain? */
|
|
45
|
+
has(key) {
|
|
46
|
+
return this.#entry(key) !== undefined;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The translated text.
|
|
50
|
+
*
|
|
51
|
+
* @param params values for the `{placeholders}`; `{count}` is filled from `count`.
|
|
52
|
+
* @param count selects the plural form and becomes the `{count}` placeholder.
|
|
53
|
+
*/
|
|
54
|
+
t(key, params = {}, count) {
|
|
55
|
+
const entry = this.#entry(key);
|
|
56
|
+
const values = count === undefined ? params : { count, ...params };
|
|
57
|
+
if (entry === undefined) {
|
|
58
|
+
return interpolate(key, values);
|
|
59
|
+
}
|
|
60
|
+
const [text, language] = entry;
|
|
61
|
+
if (typeof text === 'string') {
|
|
62
|
+
return interpolate(text, values);
|
|
63
|
+
}
|
|
64
|
+
const category = pluralCategory(language, count ?? 0);
|
|
65
|
+
return interpolate(text[category], values);
|
|
66
|
+
}
|
|
67
|
+
/** The first text for the key in the fallback chain, with the language it came from. */
|
|
68
|
+
#entry(key) {
|
|
69
|
+
const message = Object.prototype.hasOwnProperty.call(this.#catalogue, key) ? this.#catalogue[key] : undefined;
|
|
70
|
+
if (!message) {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
for (const language of this.#chain) {
|
|
74
|
+
const text = message[language];
|
|
75
|
+
if (text !== undefined) {
|
|
76
|
+
return [text, language];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** Shorthand for `new Translator(...)`. */
|
|
83
|
+
export function createTranslator(language, options = {}) {
|
|
84
|
+
return new Translator(language, options);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Merges catalogues: later ones win, per key and per language, so a catalogue that only brings a
|
|
88
|
+
* German text for a key keeps the English one of the catalogue before it.
|
|
89
|
+
*/
|
|
90
|
+
export function mergeCatalogues(...catalogues) {
|
|
91
|
+
const merged = {};
|
|
92
|
+
for (const catalogue of catalogues) {
|
|
93
|
+
for (const [key, entry] of Object.entries(catalogue)) {
|
|
94
|
+
const before = Object.prototype.hasOwnProperty.call(merged, key) ? merged[key] : undefined;
|
|
95
|
+
merged[key] = before === undefined ? { ...entry } : { ...before, ...entry };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return merged;
|
|
99
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Icons as data: each icon is one export, so an app that draws five icons ships five. `<Icon
|
|
3
|
+
* icon={iconGithub} />` draws one; a toolbar button's `icon` takes either a character or icon data.
|
|
4
|
+
*/
|
|
5
|
+
export interface IconData {
|
|
6
|
+
/** The `viewBox` of the drawing, `0 0 24 24` when absent. */
|
|
7
|
+
readonly viewBox?: string;
|
|
8
|
+
/** The path data, drawn in `currentColor`. */
|
|
9
|
+
readonly paths: readonly string[];
|
|
10
|
+
/** `fill` (the default) or `stroke`: a line drawing is stroked with `strokeWidth`. */
|
|
11
|
+
readonly mode?: 'fill' | 'stroke';
|
|
12
|
+
readonly strokeWidth?: number;
|
|
13
|
+
}
|
|
14
|
+
/** Is this icon data rather than a character? */
|
|
15
|
+
export declare function isIconData(icon: unknown): icon is IconData;
|
|
16
|
+
/** The GitHub mark, monochrome. */
|
|
17
|
+
export declare const iconGithub: IconData;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Is this icon data rather than a character? */
|
|
2
|
+
export function isIconData(icon) {
|
|
3
|
+
return typeof icon === 'object' && icon !== null && Array.isArray(icon.paths);
|
|
4
|
+
}
|
|
5
|
+
/** The GitHub mark, monochrome. */
|
|
6
|
+
export const iconGithub = {
|
|
7
|
+
viewBox: '0 0 16 16',
|
|
8
|
+
paths: [
|
|
9
|
+
'M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27s1.36.09 2 .27c1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8Z',
|
|
10
|
+
],
|
|
11
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* occulite-ui: the barrel. Every subpath (`occulite-ui/table`, `/i18n`, `/theme`, `/embedding`,
|
|
3
|
+
* `/dialog`, `/notices`, `/icons`, `/format`, `/clipboard`) is re-exported here, so an app may
|
|
4
|
+
* import from the package root or narrowly; both tree-shake.
|
|
5
|
+
*/
|
|
6
|
+
export * from './components/index.js';
|
|
7
|
+
export * from './table/index.js';
|
|
8
|
+
export * from './i18n/index.js';
|
|
9
|
+
export * from './theme/index.js';
|
|
10
|
+
export * from './embedding/index.js';
|
|
11
|
+
export * from './notices/index.js';
|
|
12
|
+
export * from './icons/index.js';
|
|
13
|
+
export * from './format.js';
|
|
14
|
+
export * from './clipboard.js';
|
|
15
|
+
export * from './externalLink.js';
|
|
16
|
+
export * from './storage.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* occulite-ui: the barrel. Every subpath (`occulite-ui/table`, `/i18n`, `/theme`, `/embedding`,
|
|
3
|
+
* `/dialog`, `/notices`, `/icons`, `/format`, `/clipboard`) is re-exported here, so an app may
|
|
4
|
+
* import from the package root or narrowly; both tree-shake.
|
|
5
|
+
*/
|
|
6
|
+
export * from './components/index.js';
|
|
7
|
+
export * from './table/index.js';
|
|
8
|
+
export * from './i18n/index.js';
|
|
9
|
+
export * from './theme/index.js';
|
|
10
|
+
export * from './embedding/index.js';
|
|
11
|
+
export * from './notices/index.js';
|
|
12
|
+
export * from './icons/index.js';
|
|
13
|
+
export * from './format.js';
|
|
14
|
+
export * from './clipboard.js';
|
|
15
|
+
export * from './externalLink.js';
|
|
16
|
+
export * from './storage.js';
|