@hashicorp/mds-react 0.9.4 → 0.9.6
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/components/badge/style.module.scss +8 -6
- package/components/badge-count/style.module.scss +7 -6
- package/components/breadcrumbs/truncation-button/index.js +6 -6
- package/components/breadcrumbs/truncation-button/index.js.map +1 -1
- package/components/button/button-primitive.d.ts +5 -0
- package/components/button/button-primitive.js +59 -0
- package/components/button/button-primitive.js.map +1 -0
- package/components/button/index.d.ts +2 -4
- package/components/button/index.js +21 -71
- package/components/button/index.js.map +1 -1
- package/components/card/index.js +9 -9
- package/components/card/index.js.map +1 -1
- package/components/code-block/code-block.module.scss +3 -3
- package/components/form/error/index.js +7 -7
- package/components/form/error/index.js.map +1 -1
- package/components/form/fieldset/index.d.ts +1 -2
- package/components/form/fieldset/index.js.map +1 -1
- package/components/form/file-input/form-file-input.module.scss +2 -2
- package/components/form/indicator/index.js +3 -4
- package/components/form/indicator/index.js.map +1 -1
- package/components/form/radio/index.d.ts +3 -5
- package/components/form/radio/index.js.map +1 -1
- package/components/form/radio-card/RadioCardStory.css +21 -0
- package/components/form/select/index.d.ts +1 -0
- package/components/form/select/index.js.map +1 -1
- package/components/icon-tile/style.module.scss +12 -10
- package/components/inline-link/index.js +12 -11
- package/components/inline-link/index.js.map +1 -1
- package/components/modal/modal.module.css +5 -0
- package/components/tabs/index.js +63 -65
- package/components/tabs/index.js.map +1 -1
- package/index.js +26 -22
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/patterns/card/person-card/index.js +37 -35
- package/patterns/card/person-card/index.js.map +1 -1
- package/patterns/card/primitives.js +16 -16
- package/patterns/card/primitives.js.map +1 -1
- package/style.css +1 -1
- package/utils/i18n/constants/index.js +16 -3
- package/utils/i18n/constants/index.js.map +1 -1
- package/utils/i18n/helpers/index.d.ts +4 -0
- package/utils/i18n/helpers/index.js +8 -0
- package/utils/i18n/helpers/index.js.map +1 -0
- package/utils/i18n/helpers/locale-provider.d.ts +14 -0
- package/utils/i18n/helpers/locale-provider.js +14 -4
- package/utils/i18n/helpers/locale-provider.js.map +1 -1
- package/utils/i18n/helpers/to-smart-sentence-case.d.ts +2 -0
- package/utils/i18n/helpers/to-smart-sentence-case.js.map +1 -1
- package/utils/i18n/helpers/to-smart-title-case.d.ts +2 -0
- package/utils/i18n/helpers/to-smart-title-case.js.map +1 -1
- package/utils/i18n/helpers/use-locale.d.ts +2 -0
- package/utils/i18n/helpers/use-locale.js +1 -1
- package/utils/i18n/helpers/use-locale.js.map +1 -1
- package/utils/i18n/index.d.ts +11 -1
- package/utils/i18n/index.js +29 -3
- package/utils/i18n/index.js.map +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +10 -6
- package/utils/index.js.map +1 -1
- package/utils/i18n/index2.js +0 -33
- package/utils/i18n/index2.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../utils/i18n/constants/index.ts"],"sourcesContent":["import type { SupportedLocale } from '../types'\n\nexport const DEFAULT_LOCALE = 'en'\n\nexport const LOCALE_LANGUAGE_MAP = {\n\ten: 'English',\n\tfr: 'Français',\n\tde: 'Deutsch',\n\tja: '日本語',\n\tko: '한국어',\n\tpt: 'Português',\n\tes: 'Español',\n\tid: 'Bahasa Indonesia',\n}\n\nexport const SUPPORTED_LOCALES = Object.keys(\n\tLOCALE_LANGUAGE_MAP\n) as SupportedLocale[]\n\nexport const smallWordsByLocale: Record<SupportedLocale, Set<string>> = {\n\ten: new Set([\n\t\t'a',\n\t\t'an',\n\t\t'and',\n\t\t'as',\n\t\t'at',\n\t\t'but',\n\t\t'by',\n\t\t'for',\n\t\t'in',\n\t\t'nor',\n\t\t'of',\n\t\t'on',\n\t\t'or',\n\t\t'so',\n\t\t'the',\n\t\t'to',\n\t\t'up',\n\t\t'yet',\n\t]),\n\tde: new Set(), // Capitalization rules in German don't suppress small words.\n\tes: new Set([\n\t\t'el',\n\t\t'la',\n\t\t'los',\n\t\t'las',\n\t\t'un',\n\t\t'una',\n\t\t'unos',\n\t\t'unas',\n\t\t'y',\n\t\t'o',\n\t\t'pero',\n\t\t'de',\n\t\t'del',\n\t\t'al',\n\t\t'en',\n\t\t'por',\n\t\t'para',\n\t\t'con',\n\t]),\n\tfr: new Set([\n\t\t'le',\n\t\t'la',\n\t\t'les',\n\t\t'un',\n\t\t'une',\n\t\t'et',\n\t\t'de',\n\t\t'du',\n\t\t'des',\n\t\t'en',\n\t\t'à',\n\t\t'au',\n\t\t'aux',\n\t\t'pour',\n\t\t'avec',\n\t]),\n\tja: new Set(), // Japanese doesn't use title casing; characters are not case-sensitive\n\tko: new Set(), // Korean doesn't use casing\n\tpt: new Set([\n\t\t'o',\n\t\t'a',\n\t\t'os',\n\t\t'as',\n\t\t'um',\n\t\t'uma',\n\t\t'uns',\n\t\t'umas',\n\t\t'e',\n\t\t'ou',\n\t\t'mas',\n\t\t'de',\n\t\t'do',\n\t\t'da',\n\t\t'dos',\n\t\t'das',\n\t\t'em',\n\t\t'no',\n\t\t'na',\n\t\t'nos',\n\t\t'nas',\n\t\t'por',\n\t\t'para',\n\t\t'com',\n\t]),\n\tid: new Set(), // ! TODO Determine Indonesian's small word rules, and apply them here\n}\n"],"names":["DEFAULT_LOCALE","smallWordsByLocale"],"mappings":"AAEO,MAAMA,IAAiB,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../utils/i18n/constants/index.ts"],"sourcesContent":["import type { SupportedLocale } from '../types'\n\nexport const DEFAULT_LOCALE = 'en'\n\nexport const LOCALE_LANGUAGE_MAP = {\n\ten: 'English',\n\tfr: 'Français',\n\tde: 'Deutsch',\n\tja: '日本語',\n\tko: '한국어',\n\tpt: 'Português',\n\tes: 'Español',\n\tid: 'Bahasa Indonesia',\n}\n\nexport const SUPPORTED_LOCALES = Object.keys(\n\tLOCALE_LANGUAGE_MAP\n) as SupportedLocale[]\n\nexport const smallWordsByLocale: Record<SupportedLocale, Set<string>> = {\n\ten: new Set([\n\t\t'a',\n\t\t'an',\n\t\t'and',\n\t\t'as',\n\t\t'at',\n\t\t'but',\n\t\t'by',\n\t\t'for',\n\t\t'in',\n\t\t'nor',\n\t\t'of',\n\t\t'on',\n\t\t'or',\n\t\t'so',\n\t\t'the',\n\t\t'to',\n\t\t'up',\n\t\t'yet',\n\t]),\n\tde: new Set(), // Capitalization rules in German don't suppress small words.\n\tes: new Set([\n\t\t'el',\n\t\t'la',\n\t\t'los',\n\t\t'las',\n\t\t'un',\n\t\t'una',\n\t\t'unos',\n\t\t'unas',\n\t\t'y',\n\t\t'o',\n\t\t'pero',\n\t\t'de',\n\t\t'del',\n\t\t'al',\n\t\t'en',\n\t\t'por',\n\t\t'para',\n\t\t'con',\n\t]),\n\tfr: new Set([\n\t\t'le',\n\t\t'la',\n\t\t'les',\n\t\t'un',\n\t\t'une',\n\t\t'et',\n\t\t'de',\n\t\t'du',\n\t\t'des',\n\t\t'en',\n\t\t'à',\n\t\t'au',\n\t\t'aux',\n\t\t'pour',\n\t\t'avec',\n\t]),\n\tja: new Set(), // Japanese doesn't use title casing; characters are not case-sensitive\n\tko: new Set(), // Korean doesn't use casing\n\tpt: new Set([\n\t\t'o',\n\t\t'a',\n\t\t'os',\n\t\t'as',\n\t\t'um',\n\t\t'uma',\n\t\t'uns',\n\t\t'umas',\n\t\t'e',\n\t\t'ou',\n\t\t'mas',\n\t\t'de',\n\t\t'do',\n\t\t'da',\n\t\t'dos',\n\t\t'das',\n\t\t'em',\n\t\t'no',\n\t\t'na',\n\t\t'nos',\n\t\t'nas',\n\t\t'por',\n\t\t'para',\n\t\t'com',\n\t]),\n\tid: new Set(), // ! TODO Determine Indonesian's small word rules, and apply them here\n}\n"],"names":["DEFAULT_LOCALE","LOCALE_LANGUAGE_MAP","SUPPORTED_LOCALES","smallWordsByLocale"],"mappings":"AAEO,MAAMA,IAAiB,MAEjBC,IAAsB;AAAA,EAClC,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACL,GAEaC,IAAoB,OAAO;AAAA,EACvCD;AACD,GAEaE,IAA2D;AAAA,EACvE,wBAAQ,IAAI;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACA;AAAA,EACD,wBAAQ,IAAA;AAAA;AAAA,EACR,wBAAQ,IAAI;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACA;AAAA,EACD,wBAAQ,IAAI;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACA;AAAA,EACD,wBAAQ,IAAA;AAAA;AAAA,EACR,wBAAQ,IAAA;AAAA;AAAA,EACR,wBAAQ,IAAI;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACA;AAAA,EACD,wBAAQ,IAAA;AAAA;AACT;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../utils/i18n/helpers/index.ts"],"sourcesContent":["import { SUPPORTED_LOCALES } from '../constants'\nimport type { SupportedLocale } from '../types'\n\nexport function isSupportedLocale(locale: string): locale is SupportedLocale {\n\treturn SUPPORTED_LOCALES.includes(locale as SupportedLocale)\n}\n"],"names":["isSupportedLocale","locale","SUPPORTED_LOCALES"],"mappings":";AAGO,SAASA,EAAkBC,GAA2C;AAC5E,SAAOC,EAAkB,SAASD,CAAyB;AAC5D;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
import { SupportedLocale } from '@web/utils/i18n/types';
|
|
3
|
+
type LocaleContextValue = {
|
|
4
|
+
locale: SupportedLocale;
|
|
5
|
+
};
|
|
6
|
+
interface LocaleProviderProps extends PropsWithChildren {
|
|
7
|
+
/**
|
|
8
|
+
* Supported locales can be found in `SUPPORTED_LOCALES`.
|
|
9
|
+
*/
|
|
10
|
+
locale: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const LocaleContext: import('react').Context<LocaleContextValue | undefined>;
|
|
13
|
+
export declare const LocaleProvider: ({ locale, children }: LocaleProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export {};
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { jsx as t } from "react/jsx-runtime";
|
|
3
|
+
import { createContext as c } from "react";
|
|
4
|
+
import { DEFAULT_LOCALE as l } from "../constants/index.js";
|
|
5
|
+
import { isSupportedLocale as i } from "./index.js";
|
|
6
|
+
function n(o) {
|
|
7
|
+
return i(o) ? o : l;
|
|
8
|
+
}
|
|
9
|
+
const a = c(
|
|
4
10
|
void 0
|
|
5
|
-
)
|
|
11
|
+
), v = ({ locale: o, children: e }) => {
|
|
12
|
+
const r = n(o);
|
|
13
|
+
return /* @__PURE__ */ t(a.Provider, { value: { locale: r }, children: e });
|
|
14
|
+
};
|
|
6
15
|
export {
|
|
7
|
-
|
|
16
|
+
a as LocaleContext,
|
|
17
|
+
v as LocaleProvider
|
|
8
18
|
};
|
|
9
19
|
//# sourceMappingURL=locale-provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locale-provider.js","sources":["
|
|
1
|
+
{"version":3,"file":"locale-provider.js","sources":["../../../../src/utils/i18n/helpers/locale-provider.tsx"],"sourcesContent":["'use client'\n\nimport { createContext, type PropsWithChildren } from 'react'\nimport type { SupportedLocale } from '@web/utils/i18n/types'\nimport { DEFAULT_LOCALE } from '@web/utils/i18n/constants'\nimport { isSupportedLocale } from '@web/utils/i18n/helpers'\n\nfunction resolveLocale(input: string): SupportedLocale {\n\treturn isSupportedLocale(input) ? input : DEFAULT_LOCALE\n}\n\ntype LocaleContextValue = {\n\tlocale: SupportedLocale\n}\n\ninterface LocaleProviderProps extends PropsWithChildren {\n\t/**\n\t * Supported locales can be found in `SUPPORTED_LOCALES`.\n\t */\n\tlocale: string\n}\n\nexport const LocaleContext = createContext<LocaleContextValue | undefined>(\n\tundefined\n)\n\nexport const LocaleProvider = ({ locale, children }: LocaleProviderProps) => {\n\tconst resolvedLocale = resolveLocale(locale)\n\n\treturn (\n\t\t<LocaleContext.Provider value={{ locale: resolvedLocale }}>\n\t\t\t{children}\n\t\t</LocaleContext.Provider>\n\t)\n}\n"],"names":["resolveLocale","isSupportedLocale","input","DEFAULT_LOCALE","LocaleContext","createContext","locale","children","jsx","resolvedLocale"],"mappings":";;;;;AAQC,SAAOA,KAAkB;AAC1B,SAAAC,EAAAC,CAAA,IAAAA,IAAAC;AAaO;AAAsB,MAC5BC,IAAAC;AAAA,EACD;AAEO,OACA,CAAA,EAAiB,QAAAC,GAAA,UAAAC,QAAoB;AAE3C,YACCP,GAAe;AAIjB,SAAA,gBAAAQ,EAAAJ,EAAA,UAAA,EAAA,OAAA,EAAA,QAAAK,EAAA,GAAA,UAAAF,EAAA,CAAA;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-smart-sentence-case.js","sources":["
|
|
1
|
+
{"version":3,"file":"to-smart-sentence-case.js","sources":["../../../../src/utils/i18n/helpers/to-smart-sentence-case.ts"],"sourcesContent":["import type { SupportedLocale } from '@web/utils/i18n/types'\n\nexport function toSmartSentenceCase(\n\ttext: string,\n\tlocale: SupportedLocale\n): string {\n\t// Skip transformation for non-cased languages\n\tif (locale === 'ja' || locale === 'ko') {\n\t\treturn text\n\t}\n\n\tconst match = text.match(/^(\\s*[\\p{P}\\p{Zs}]*)?(\\p{L})(.*)$/u)\n\n\tif (!match) return text // fallback if no match\n\n\tconst [, leading, firstChar, rest] = match\n\n\treturn (\n\t\t(leading ?? '') +\n\t\tfirstChar.toLocaleUpperCase(locale) +\n\t\trest.toLocaleLowerCase(locale)\n\t)\n}\n"],"names":["toSmartSentenceCase","text","locale","match","leading","firstChar","rest"],"mappings":"AAEO,SAASA,EACfC,GACAC,GACS;AAET,MAAIA,MAAW,QAAQA,MAAW;AACjC,WAAOD;AAGR,QAAME,IAAQF,EAAK,MAAM,oCAAoC;AAE7D,MAAI,CAACE,EAAO,QAAOF;AAEnB,QAAM,GAAGG,GAASC,GAAWC,CAAI,IAAIH;AAErC,UACEC,KAAW,MACZC,EAAU,kBAAkBH,CAAM,IAClCI,EAAK,kBAAkBJ,CAAM;AAE/B;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-smart-title-case.js","sources":["
|
|
1
|
+
{"version":3,"file":"to-smart-title-case.js","sources":["../../../../src/utils/i18n/helpers/to-smart-title-case.ts"],"sourcesContent":["import { smallWordsByLocale } from '@web/utils/i18n/constants'\nimport type { SupportedLocale } from '@web/utils/i18n/types'\n\nexport function toSmartTitleCase(\n\ttext: string,\n\tlocale: SupportedLocale\n): string {\n\tconst smallWords = smallWordsByLocale[locale]\n\tconst segments = text.toLocaleLowerCase(locale).split(/([\\s\\-:,.]+)/)\n\n\tlet capitalizeNext = true\n\n\treturn segments\n\t\t.map((segment) => {\n\t\t\tif (/^[\\s\\-:,.]+$/.test(segment)) {\n\t\t\t\t// If punctuation ends a sentence-like clause, capitalize the next word\n\t\t\t\tif (/[:.!?]\\s*$/.test(segment)) {\n\t\t\t\t\tcapitalizeNext = true\n\t\t\t\t}\n\t\t\t\treturn segment\n\t\t\t}\n\n\t\t\t// For non-cased languages (ja, ko), return as-is\n\t\t\tif (!segment.charAt(0).toLocaleUpperCase) return segment\n\n\t\t\tif (capitalizeNext || !smallWords.has(segment)) {\n\t\t\t\tcapitalizeNext = false\n\t\t\t\treturn segment.charAt(0).toLocaleUpperCase(locale) + segment.slice(1)\n\t\t\t} else {\n\t\t\t\treturn segment\n\t\t\t}\n\t\t})\n\t\t.join('')\n}\n"],"names":["toSmartTitleCase","text","locale","smallWords","smallWordsByLocale","segments","capitalizeNext","segment"],"mappings":";AAGO,SAASA,EACfC,GACAC,GACS;AACT,QAAMC,IAAaC,EAAmBF,CAAM,GACtCG,IAAWJ,EAAK,kBAAkBC,CAAM,EAAE,MAAM,cAAc;AAEpE,MAAII,IAAiB;AAErB,SAAOD,EACL,IAAI,CAACE,MACD,eAAe,KAAKA,CAAO,KAE1B,aAAa,KAAKA,CAAO,MAC5BD,IAAiB,KAEXC,KAIHA,EAAQ,OAAO,CAAC,EAAE,sBAEnBD,KAAkB,CAACH,EAAW,IAAII,CAAO,MAC5CD,IAAiB,IACVC,EAAQ,OAAO,CAAC,EAAE,kBAAkBL,CAAM,IAAIK,EAAQ,MAAM,CAAC,KAJpBA,CAQjD,EACA,KAAK,EAAE;AACV;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useContext as n } from "react";
|
|
2
|
-
import { DEFAULT_LOCALE as e } from "../constants/index.js";
|
|
3
2
|
import { LocaleContext as r } from "./locale-provider.js";
|
|
3
|
+
import { DEFAULT_LOCALE as e } from "../constants/index.js";
|
|
4
4
|
let t = !1;
|
|
5
5
|
function i() {
|
|
6
6
|
const o = n(r)?.locale;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-locale.js","sources":["
|
|
1
|
+
{"version":3,"file":"use-locale.js","sources":["../../../../src/utils/i18n/helpers/use-locale.ts"],"sourcesContent":["import { useContext } from 'react'\nimport { LocaleContext } from './locale-provider'\nimport type { SupportedLocale } from '@web/utils/i18n/types'\nimport { DEFAULT_LOCALE } from '@web/utils/i18n/constants'\n\nlet hasWarned = false\n\nexport function useLocale(): SupportedLocale {\n\tconst locale = useContext(LocaleContext)?.locale\n\n\tif (!locale && typeof window !== 'undefined' && !hasWarned) {\n\t\thasWarned = true\n\t\tconsole.warn(\n\t\t\t`[@web/utils] No <LocaleProvider> found. Defaulting to \"${DEFAULT_LOCALE}\".`\n\t\t)\n\t}\n\n\treturn locale || DEFAULT_LOCALE\n}\n"],"names":["hasWarned","useLocale","locale","useContext","LocaleContext","DEFAULT_LOCALE"],"mappings":";;;AAKA,IAAIA,IAAY;AAET,SAASC,IAA6B;AAC5C,QAAMC,IAASC,EAAWC,CAAa,GAAG;AAE1C,SAAI,CAACF,KAAU,OAAO,SAAW,OAAe,CAACF,MAChDA,IAAY,IACZ,QAAQ;AAAA,IACP,0DAA0DK,CAAc;AAAA,EAAA,IAInEH,KAAUG;AAClB;"}
|
package/utils/i18n/index.d.ts
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { SupportedLocale } from '@web/utils/i18n/types';
|
|
2
|
+
type Capitalization = 'none' | 'lower' | 'sentence' | 'title' | 'upper';
|
|
3
|
+
type DotPrefix<T extends string, U extends string> = `${T}.${U}`;
|
|
4
|
+
type NestedKeyOf<ObjectType extends object> = {
|
|
5
|
+
[K in keyof ObjectType & string]: ObjectType[K] extends object ? DotPrefix<K, NestedKeyOf<ObjectType[K]>> : K;
|
|
6
|
+
}[keyof ObjectType & string];
|
|
7
|
+
export declare const localize: (key: NestedKeyOf<{
|
|
8
|
+
optional: string;
|
|
9
|
+
required: string;
|
|
10
|
+
}>, locale: SupportedLocale, capitalization?: Capitalization) => string;
|
|
11
|
+
export {};
|
package/utils/i18n/index.js
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { toSmartSentenceCase as p } from "./helpers/to-smart-sentence-case.js";
|
|
2
|
+
import { toSmartTitleCase as l } from "./helpers/to-smart-title-case.js";
|
|
3
|
+
function a(i, n) {
|
|
4
|
+
return n.split(".").reduce((r, t) => {
|
|
5
|
+
if (typeof r == "object" && r !== null && t in r)
|
|
6
|
+
return r[t];
|
|
7
|
+
}, i);
|
|
8
|
+
}
|
|
9
|
+
function d(i, n = "en") {
|
|
10
|
+
return function(t, o, u) {
|
|
11
|
+
const e = a(i[o], t) ?? a(i[n], t);
|
|
12
|
+
if (typeof e != "string") return "";
|
|
13
|
+
switch (u) {
|
|
14
|
+
case "title":
|
|
15
|
+
return l(e, o);
|
|
16
|
+
case "sentence":
|
|
17
|
+
return p(e, o);
|
|
18
|
+
case "upper":
|
|
19
|
+
return e.toLocaleUpperCase(o);
|
|
20
|
+
case "lower":
|
|
21
|
+
return e.toLocaleLowerCase(o);
|
|
22
|
+
case "none":
|
|
23
|
+
default:
|
|
24
|
+
return e;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const c = d({
|
|
3
29
|
de: {
|
|
4
30
|
optional: "optional",
|
|
5
31
|
// "optional" is the same in German
|
|
@@ -36,6 +62,6 @@ const r = o({
|
|
|
36
62
|
}
|
|
37
63
|
});
|
|
38
64
|
export {
|
|
39
|
-
|
|
65
|
+
c as localize
|
|
40
66
|
};
|
|
41
67
|
//# sourceMappingURL=index.js.map
|
package/utils/i18n/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/utils/i18n/index.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/utils/i18n/index.ts"],"sourcesContent":["import type { SupportedLocale } from '@web/utils/i18n/types'\nimport { toSmartSentenceCase, toSmartTitleCase } from './helpers'\n\ntype Capitalization = 'none' | 'lower' | 'sentence' | 'title' | 'upper'\n\ntype DotPrefix<T extends string, U extends string> = `${T}.${U}`\n\ntype NestedKeyOf<ObjectType extends object> = {\n\t[K in keyof ObjectType & string]: ObjectType[K] extends object\n\t\t? DotPrefix<K, NestedKeyOf<ObjectType[K]>>\n\t\t: K\n}[keyof ObjectType & string]\n\nfunction getByDotPath<T extends object, P extends string>(\n\tobj: T,\n\tpath: P\n): unknown {\n\treturn path.split('.').reduce((acc: unknown, part) => {\n\t\tif (typeof acc === 'object' && acc !== null && part in acc) {\n\t\t\treturn (acc as Record<string, unknown>)[part]\n\t\t}\n\t\treturn undefined\n\t}, obj)\n}\n\nfunction createLocalize<Messages extends Record<string, unknown>>(\n\tlocalizations: Record<SupportedLocale, Messages>,\n\tfallbackLocale: SupportedLocale = 'en'\n) {\n\ttype Key = NestedKeyOf<Messages>\n\n\treturn function translate(\n\t\tkey: Key,\n\t\tlocale: SupportedLocale,\n\t\tcapitalization?: Capitalization\n\t): string {\n\t\tconst word =\n\t\t\tgetByDotPath(localizations[locale], key) ??\n\t\t\tgetByDotPath(localizations[fallbackLocale], key)\n\n\t\tif (typeof word !== 'string') return ''\n\n\t\tswitch (capitalization) {\n\t\t\tcase 'title':\n\t\t\t\treturn toSmartTitleCase(word, locale)\n\t\t\tcase 'sentence':\n\t\t\t\treturn toSmartSentenceCase(word, locale)\n\t\t\tcase 'upper':\n\t\t\t\treturn word.toLocaleUpperCase(locale)\n\t\t\tcase 'lower':\n\t\t\t\treturn word.toLocaleLowerCase(locale)\n\t\t\tcase 'none':\n\t\t\tdefault:\n\t\t\t\treturn word\n\t\t}\n\t}\n}\n\nexport const localize = createLocalize({\n\tde: {\n\t\toptional: 'optional', // \"optional\" is the same in German\n\t\trequired: 'erforderlich',\n\t},\n\ten: {\n\t\toptional: 'optional',\n\t\trequired: 'required',\n\t},\n\tes: {\n\t\toptional: 'opcional',\n\t\trequired: 'obligatorio',\n\t},\n\tfr: {\n\t\toptional: 'facultatif',\n\t\trequired: 'obligatoire',\n\t},\n\tid: {\n\t\t// ! TODO Translate text to Indonesian\n\t\toptional: 'optional',\n\t\trequired: 'required',\n\t},\n\tja: {\n\t\toptional: '任意',\n\t\trequired: '必須',\n\t},\n\tko: {\n\t\toptional: '선택 사항',\n\t\trequired: '필수',\n\t},\n\tpt: {\n\t\toptional: 'opcional',\n\t\trequired: 'obrigatório',\n\t},\n})\n"],"names":["getByDotPath","obj","path","acc","part","createLocalize","localizations","fallbackLocale","key","locale","capitalization","word","toSmartTitleCase","toSmartSentenceCase","localize"],"mappings":";;AAaA,SAASA,EACRC,GACAC,GACU;AACV,SAAOA,EAAK,MAAM,GAAG,EAAE,OAAO,CAACC,GAAcC,MAAS;AACrD,QAAI,OAAOD,KAAQ,YAAYA,MAAQ,QAAQC,KAAQD;AACtD,aAAQA,EAAgCC,CAAI;AAAA,EAG9C,GAAGH,CAAG;AACP;AAEA,SAASI,EACRC,GACAC,IAAkC,MACjC;AAGD,SAAO,SACNC,GACAC,GACAC,GACS;AACT,UAAMC,IACLX,EAAaM,EAAcG,CAAM,GAAGD,CAAG,KACvCR,EAAaM,EAAcC,CAAc,GAAGC,CAAG;AAEhD,QAAI,OAAOG,KAAS,SAAU,QAAO;AAErC,YAAQD,GAAA;AAAA,MACP,KAAK;AACJ,eAAOE,EAAiBD,GAAMF,CAAM;AAAA,MACrC,KAAK;AACJ,eAAOI,EAAoBF,GAAMF,CAAM;AAAA,MACxC,KAAK;AACJ,eAAOE,EAAK,kBAAkBF,CAAM;AAAA,MACrC,KAAK;AACJ,eAAOE,EAAK,kBAAkBF,CAAM;AAAA,MACrC,KAAK;AAAA,MACL;AACC,eAAOE;AAAA,IAAA;AAAA,EAEV;AACD;AAEO,MAAMG,IAAWT,EAAe;AAAA,EACtC,IAAI;AAAA,IACH,UAAU;AAAA;AAAA,IACV,UAAU;AAAA,EAAA;AAAA,EAEX,IAAI;AAAA,IACH,UAAU;AAAA,IACV,UAAU;AAAA,EAAA;AAAA,EAEX,IAAI;AAAA,IACH,UAAU;AAAA,IACV,UAAU;AAAA,EAAA;AAAA,EAEX,IAAI;AAAA,IACH,UAAU;AAAA,IACV,UAAU;AAAA,EAAA;AAAA,EAEX,IAAI;AAAA;AAAA,IAEH,UAAU;AAAA,IACV,UAAU;AAAA,EAAA;AAAA,EAEX,IAAI;AAAA,IACH,UAAU;AAAA,IACV,UAAU;AAAA,EAAA;AAAA,EAEX,IAAI;AAAA,IACH,UAAU;AAAA,IACV,UAAU;AAAA,EAAA;AAAA,EAEX,IAAI;AAAA,IACH,UAAU;AAAA,IACV,UAAU;AAAA,EAAA;AAEZ,CAAC;"}
|
package/utils/index.d.ts
CHANGED
package/utils/index.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { useLarge as
|
|
2
|
-
import { MDSProvider as
|
|
1
|
+
import { useLarge as o, useMedium as m, useMediumUp as u, useSmall as p } from "./hooks/use-screen-size.js";
|
|
2
|
+
import { MDSProvider as a } from "./mds-context/index.js";
|
|
3
|
+
import { LocaleProvider as f } from "./i18n/helpers/locale-provider.js";
|
|
4
|
+
import { useLocale as l } from "./i18n/helpers/use-locale.js";
|
|
3
5
|
export {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
f as LocaleProvider,
|
|
7
|
+
a as MDSProvider,
|
|
8
|
+
o as useLarge,
|
|
9
|
+
l as useLocale,
|
|
6
10
|
m as useMedium,
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
u as useMediumUp,
|
|
12
|
+
p as useSmall
|
|
9
13
|
};
|
|
10
14
|
//# sourceMappingURL=index.js.map
|
package/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
package/utils/i18n/index2.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import "./helpers/locale-provider.js";
|
|
2
|
-
import { toSmartSentenceCase as p } from "./helpers/to-smart-sentence-case.js";
|
|
3
|
-
import { toSmartTitleCase as f } from "./helpers/to-smart-title-case.js";
|
|
4
|
-
import "react";
|
|
5
|
-
function i(o, u) {
|
|
6
|
-
return u.split(".").reduce((t, r) => {
|
|
7
|
-
if (typeof t == "object" && t !== null && r in t)
|
|
8
|
-
return t[r];
|
|
9
|
-
}, o);
|
|
10
|
-
}
|
|
11
|
-
function w(o, u = "en") {
|
|
12
|
-
return function(r, n, s) {
|
|
13
|
-
const e = i(o[n], r) ?? i(o[u], r);
|
|
14
|
-
if (typeof e != "string") return "";
|
|
15
|
-
switch (s) {
|
|
16
|
-
case "title":
|
|
17
|
-
return f(e, n);
|
|
18
|
-
case "sentence":
|
|
19
|
-
return p(e, n);
|
|
20
|
-
case "upper":
|
|
21
|
-
return e.toLocaleUpperCase(n);
|
|
22
|
-
case "lower":
|
|
23
|
-
return e.toLocaleLowerCase(n);
|
|
24
|
-
case "none":
|
|
25
|
-
default:
|
|
26
|
-
return e;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
export {
|
|
31
|
-
w as createLocalize
|
|
32
|
-
};
|
|
33
|
-
//# sourceMappingURL=index2.js.map
|
package/utils/i18n/index2.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index2.js","sources":["../../../../utils/i18n/index.ts"],"sourcesContent":["import { toSmartSentenceCase, toSmartTitleCase } from './helpers'\nimport type { SupportedLocale } from './types'\n\ntype Capitalization = 'none' | 'lower' | 'sentence' | 'title' | 'upper'\n\ntype DotPrefix<T extends string, U extends string> = `${T}.${U}`\n\ntype NestedKeyOf<ObjectType extends object> = {\n\t[K in keyof ObjectType & string]: ObjectType[K] extends object\n\t\t? DotPrefix<K, NestedKeyOf<ObjectType[K]>>\n\t\t: K\n}[keyof ObjectType & string]\n\nfunction getByDotPath<T extends object, P extends string>(\n\tobj: T,\n\tpath: P\n): unknown {\n\treturn path.split('.').reduce((acc: unknown, part) => {\n\t\tif (typeof acc === 'object' && acc !== null && part in acc) {\n\t\t\treturn (acc as Record<string, unknown>)[part]\n\t\t}\n\t\treturn undefined\n\t}, obj)\n}\n\nexport function createLocalize<Messages extends Record<string, unknown>>(\n\tlocalizations: Record<SupportedLocale, Messages>,\n\tfallbackLocale: SupportedLocale = 'en'\n) {\n\ttype Key = NestedKeyOf<Messages>\n\n\treturn function translate(\n\t\tkey: Key,\n\t\tlocale: SupportedLocale,\n\t\tcapitalization?: Capitalization\n\t): string {\n\t\tconst word =\n\t\t\tgetByDotPath(localizations[locale], key) ??\n\t\t\tgetByDotPath(localizations[fallbackLocale], key)\n\n\t\tif (typeof word !== 'string') return ''\n\n\t\tswitch (capitalization) {\n\t\t\tcase 'title':\n\t\t\t\treturn toSmartTitleCase(word, locale)\n\t\t\tcase 'sentence':\n\t\t\t\treturn toSmartSentenceCase(word, locale)\n\t\t\tcase 'upper':\n\t\t\t\treturn word.toLocaleUpperCase(locale)\n\t\t\tcase 'lower':\n\t\t\t\treturn word.toLocaleLowerCase(locale)\n\t\t\tcase 'none':\n\t\t\tdefault:\n\t\t\t\treturn word\n\t\t}\n\t}\n}\n"],"names":["getByDotPath","obj","path","acc","part","createLocalize","localizations","fallbackLocale","key","locale","capitalization","word","toSmartTitleCase","toSmartSentenceCase"],"mappings":";;;;AAaA,SAASA,EACRC,GACAC,GACU;AACV,SAAOA,EAAK,MAAM,GAAG,EAAE,OAAO,CAACC,GAAcC,MAAS;AACrD,QAAI,OAAOD,KAAQ,YAAYA,MAAQ,QAAQC,KAAQD;AACtD,aAAQA,EAAgCC,CAAI;AAAA,EAG9C,GAAGH,CAAG;AACP;AAEO,SAASI,EACfC,GACAC,IAAkC,MACjC;AAGD,SAAO,SACNC,GACAC,GACAC,GACS;AACT,UAAMC,IACLX,EAAaM,EAAcG,CAAM,GAAGD,CAAG,KACvCR,EAAaM,EAAcC,CAAc,GAAGC,CAAG;AAEhD,QAAI,OAAOG,KAAS,SAAU,QAAO;AAErC,YAAQD,GAAA;AAAA,MACP,KAAK;AACJ,eAAOE,EAAiBD,GAAMF,CAAM;AAAA,MACrC,KAAK;AACJ,eAAOI,EAAoBF,GAAMF,CAAM;AAAA,MACxC,KAAK;AACJ,eAAOE,EAAK,kBAAkBF,CAAM;AAAA,MACrC,KAAK;AACJ,eAAOE,EAAK,kBAAkBF,CAAM;AAAA,MACrC,KAAK;AAAA,MACL;AACC,eAAOE;AAAA,IAAA;AAAA,EAEV;AACD;"}
|