@hyvor/design 0.0.59 → 0.0.61-alpha

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.
@@ -1,4 +1,10 @@
1
- <script>import { getContext, onMount, tick, afterUpdate } from "svelte";
1
+ <script generics="StringsT extends I18nStrings">import {} from "./types.js";
2
+ import {
3
+ getContext,
4
+ onMount,
5
+ tick,
6
+ afterUpdate
7
+ } from "svelte";
2
8
  import { getStringByKey, InternationalizationService } from "./i18n.js";
3
9
  import { IntlMessageFormat } from "intl-messageformat";
4
10
  import { browser } from "$app/environment";
@@ -68,12 +74,7 @@ const locale = i18n.locale;
68
74
  const strings = i18n.strings;
69
75
  let message = getMessage(getParamsForBackend());
70
76
  function getMessage(processedParams) {
71
- return getMessageBase(
72
- key,
73
- processedParams,
74
- $strings,
75
- $locale
76
- );
77
+ return getMessageBase(key, processedParams, $strings, $locale);
77
78
  }
78
79
  function bindComponents() {
79
80
  for (let [id, binding] of componentBindings) {
@@ -110,4 +111,4 @@ onMount(async () => {
110
111
  });
111
112
  </script>
112
113
 
113
- {@html message}
114
+ {@html message}
@@ -1,23 +1,24 @@
1
1
  import { SvelteComponent } from "svelte";
2
+ import { type ToDotPaths, type I18nStrings } from "./types.js";
2
3
  import { type ComponentType } from "svelte";
3
- import { type PrimitiveType } from 'intl-messageformat';
4
- declare const __propDef: {
5
- props: {
6
- key: string;
4
+ import { type PrimitiveType } from "intl-messageformat";
5
+ declare class __sveltets_Render<StringsT extends I18nStrings> {
6
+ props(): {
7
+ key: ToDotPaths<StringsT>;
7
8
  params?: Record<string, PrimitiveType | {
8
9
  element?: string | undefined;
9
10
  component?: ComponentType | undefined;
10
11
  props?: Record<string, any> | undefined;
11
12
  }> | undefined;
12
13
  };
13
- events: {
14
+ events(): {} & {
14
15
  [evt: string]: CustomEvent<any>;
15
16
  };
16
- slots: {};
17
- };
18
- export type TProps = typeof __propDef.props;
19
- export type TEvents = typeof __propDef.events;
20
- export type TSlots = typeof __propDef.slots;
21
- export default class T extends SvelteComponent<TProps, TEvents, TSlots> {
17
+ slots(): {};
18
+ }
19
+ export type TProps<StringsT extends I18nStrings> = ReturnType<__sveltets_Render<StringsT>['props']>;
20
+ export type TEvents<StringsT extends I18nStrings> = ReturnType<__sveltets_Render<StringsT>['events']>;
21
+ export type TSlots<StringsT extends I18nStrings> = ReturnType<__sveltets_Render<StringsT>['slots']>;
22
+ export default class T<StringsT extends I18nStrings> extends SvelteComponent<TProps<StringsT>, TEvents<StringsT>, TSlots<StringsT>> {
22
23
  }
23
24
  export {};
@@ -1,6 +1,8 @@
1
1
  /// <reference types="svelte" />
2
2
  import type { PrimitiveType } from "intl-messageformat";
3
3
  import { type Readable, type Writable } from "svelte/store";
4
+ import T from "./T.svelte";
5
+ import type { ToDotPaths, I18nStrings } from "./types.js";
4
6
  export type i18nLoaderType = () => Promise<any>;
5
7
  interface LanguageBase {
6
8
  name: string;
@@ -16,7 +18,7 @@ interface LanguageWithLoader extends LanguageBase {
16
18
  loader: i18nLoaderType;
17
19
  }
18
20
  export type Language = LanguageWithStrings | LanguageWithLoader;
19
- export declare class InternationalizationService {
21
+ export declare class InternationalizationService<StringsT extends I18nStrings = I18nStrings> {
20
22
  languages: LanguageWithLoader[];
21
23
  locale: Writable<string>;
22
24
  localeLanguage: Readable<LanguageWithLoader>;
@@ -29,7 +31,8 @@ export declare class InternationalizationService {
29
31
  register(language: Language): void;
30
32
  found(code: string): boolean;
31
33
  languageByCode(code: string): LanguageWithLoader | undefined;
32
- t(key: string, params?: Record<string, PrimitiveType>): string;
34
+ t(key: ToDotPaths<StringsT>, params?: Record<string, PrimitiveType>): string;
35
+ T: typeof T<StringsT>;
33
36
  }
34
37
  export declare function getStringByKey(messages: Record<string, any>, key: string): string | undefined;
35
38
  export {};
@@ -1,6 +1,7 @@
1
1
  import { deepmerge } from "deepmerge-ts";
2
2
  import { writable, derived } from "svelte/store";
3
3
  import { t } from "./t.js";
4
+ import T from "./T.svelte";
4
5
  export class InternationalizationService {
5
6
  languages = [];
6
7
  locale;
@@ -62,6 +63,7 @@ export class InternationalizationService {
62
63
  t(key, params = {}) {
63
64
  return t(key, params, this);
64
65
  }
66
+ T = T;
65
67
  }
66
68
  export function getStringByKey(messages, key) {
67
69
  const keys = key.split('.');
@@ -1,8 +1,9 @@
1
1
  import { type PrimitiveType } from "intl-messageformat";
2
2
  import { type InternationalizationService } from "./i18n.js";
3
+ import type { I18nStrings, ToDotPaths } from "./types.js";
3
4
  type ParamValue = PrimitiveType | ((chunks: string | string[]) => string);
4
5
  type ParamsType = Record<string, ParamValue>;
5
6
  export declare function getMessage(key: string, params: ParamsType, $strings: Record<string, any>, $locale: string): string;
6
7
  export type TParams = Record<string, PrimitiveType>;
7
- export declare function t(key: string, params?: Record<string, PrimitiveType>, i18n?: InternationalizationService | null): string;
8
+ export declare function t<T extends ToDotPaths<I18nStrings>>(key: T, params?: Record<string, PrimitiveType>, i18n?: InternationalizationService | null): string;
8
9
  export {};
@@ -0,0 +1,7 @@
1
+ export type I18nStrings = {
2
+ [key: string]: string | I18nStrings;
3
+ };
4
+ export type ToDotPaths<T> = T extends object ? {
5
+ [K in keyof T]: `${Exclude<K, symbol>}${"" | `.${ToDotPaths<T[K]>}`}`;
6
+ }[keyof T] : never;
7
+ export type FromDotPath<T, K extends string> = K extends keyof T ? T[K] : K extends `${infer K0}.${infer KR}` ? K0 extends keyof T ? FromDotPath<T[K0], KR> : never : never;
@@ -0,0 +1 @@
1
+ export {};
@@ -43,6 +43,13 @@ export { default as IconMessage } from './IconMessage/IconMessage.svelte';
43
43
  export { clickOutside } from './directives/clickOutside.js';
44
44
  export { default as InternationalizationProvider } from './Internationalization/InternationalizationProvider.svelte';
45
45
  export { default as LanguageToggle } from './Internationalization/LanguageToggle.svelte';
46
- export { default as T } from './Internationalization/T.svelte';
47
46
  export { type Language as InternationalizationLanguage, InternationalizationService } from './Internationalization/i18n.js';
47
+ export { type I18nStrings as i18nStrings } from './Internationalization/types.js';
48
+ /**
49
+ * @deprecated
50
+ */
48
51
  export { t } from './Internationalization/t.js';
52
+ /**
53
+ * @deprecated
54
+ */
55
+ export { default as T } from './Internationalization/T.svelte';
@@ -45,6 +45,13 @@ export { clickOutside } from './directives/clickOutside.js';
45
45
  // i18n
46
46
  export { default as InternationalizationProvider } from './Internationalization/InternationalizationProvider.svelte';
47
47
  export { default as LanguageToggle } from './Internationalization/LanguageToggle.svelte';
48
- export { default as T } from './Internationalization/T.svelte';
49
48
  export { InternationalizationService } from './Internationalization/i18n.js';
49
+ export {} from './Internationalization/types.js';
50
+ /**
51
+ * @deprecated
52
+ */
50
53
  export { t } from './Internationalization/t.js';
54
+ /**
55
+ * @deprecated
56
+ */
57
+ export { default as T } from './Internationalization/T.svelte';
@@ -1,21 +1,39 @@
1
1
  <script>export let name;
2
2
  </script>
3
+
3
4
  <div class="nav-category">
4
- <div class="name">{name}</div>
5
- <div class="nav-items">
6
- <slot />
7
- </div>
5
+ <div class="name">
6
+ <span class="button-content">
7
+ {#if $$slots.start}
8
+ <span class="slot start"><slot name="start" /></span>
9
+ {/if}
10
+
11
+ {#if $$slots.end}
12
+ <span class="slot end"><slot name="end" /></span>
13
+ {/if}
14
+ </span>
15
+ {name}
16
+ </div>
17
+ <div class="nav-items">
18
+ <slot />
19
+ </div>
8
20
  </div>
9
21
 
10
22
  <style>
23
+ .nav-category {
24
+ margin-bottom: 20px;
25
+ }
11
26
 
12
- .nav-category {
13
- margin-bottom: 20px;
14
- }
15
-
16
- .name {
17
- font-weight: 600;
18
- padding: 10px 25px;
19
- }
27
+ .name {
28
+ font-weight: 600;
29
+ padding: 10px 25px;
30
+ display: flex;
31
+ align-items: center;
32
+ }
20
33
 
21
- </style>
34
+ .slot.start {
35
+ margin-right: 5px;
36
+ margin-left: 0;
37
+ display: flex;
38
+ }
39
+ </style>
@@ -7,6 +7,8 @@ declare const __propDef: {
7
7
  [evt: string]: CustomEvent<any>;
8
8
  };
9
9
  slots: {
10
+ start: {};
11
+ end: {};
10
12
  default: {};
11
13
  };
12
14
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyvor/design",
3
- "version": "0.0.59",
3
+ "version": "0.0.61-alpha",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "scripts": {