@@ -0,0 +1,8 | |||||
|
1 | import { bundle } from "../i18n"; | |||
|
2 | ||||
|
3 | export const { i18n, load, define } = bundle({ | |||
|
4 | foo: "foo", | |||
|
5 | bar: "bar" | |||
|
6 | }, { | |||
|
7 | ru: () => import("./ru/nls-test") | |||
|
8 | }); No newline at end of file |
@@ -0,0 +1,5 | |||||
|
1 | import { define } from "../nls-test"; | |||
|
2 | ||||
|
3 | export default define({ | |||
|
4 | foo: "Фу" | |||
|
5 | }); No newline at end of file |
@@ -1,7 +1,7 | |||||
1 | import { MapOf, PromiseOrValue } from "@implab/core-amd/interfaces"; |
|
1 | import { MapOf, PromiseOrValue } from "@implab/core-amd/interfaces"; | |
2 | import { argumentNotEmptyString, isPromise, mixin } from "@implab/core-amd/safe"; |
|
2 | import { argumentNotEmptyString, isPromise, mixin } from "@implab/core-amd/safe"; | |
3 |
|
3 | |||
4 |
export type LocaleProvider<T> = () => PromiseOrValue<T | { |
|
4 | export type LocaleProvider<T> = () => PromiseOrValue<T | {default: T}>; | |
5 |
|
5 | |||
6 | function when<T, T2>(value: PromiseOrValue<T>, cb: (v: T) => PromiseOrValue<T2>): PromiseOrValue<T2> { |
|
6 | function when<T, T2>(value: PromiseOrValue<T>, cb: (v: T) => PromiseOrValue<T2>): PromiseOrValue<T2> { | |
7 | return isPromise(value) ? |
|
7 | return isPromise(value) ? |
@@ -1,6 +1,6 | |||||
1 | import { id as mid} from "module"; |
|
1 | import { id as mid} from "module"; | |
2 |
import { |
|
2 | import { PromiseOrValue } from "@implab/core-amd/interfaces"; | |
3 |
import { |
|
3 | import { NlsBundle } from "./NlsBundle"; | |
4 | import { isPromise } from "@implab/core-amd/safe"; |
|
4 | import { isPromise } from "@implab/core-amd/safe"; | |
5 | import { locale as sysLocale } from "dojo/_base/kernel"; |
|
5 | import { locale as sysLocale } from "dojo/_base/kernel"; | |
6 | import { TraceSource } from "@implab/core-amd/log/TraceSource"; |
|
6 | import { TraceSource } from "@implab/core-amd/log/TraceSource"; | |
@@ -14,7 +14,11 export interface OnLoad { | |||||
14 | error(err: unknown): void; |
|
14 | error(err: unknown): void; | |
15 | } |
|
15 | } | |
16 |
|
16 | |||
17 |
export |
|
17 | export const bundle = <T extends object>(nls: T, locales?: Record<string, () => PromiseOrValue<object>>) : { | |
|
18 | i18n: (locale?: string) => T; | |||
|
19 | define: (pack: Partial<T>) => object; | |||
|
20 | load: (id: string, require: Require, cb: OnLoad, config: {isBuild?: boolean}) => void; | |||
|
21 | } => { | |||
18 | const nlsBundle = new NlsBundle(nls, locales); |
|
22 | const nlsBundle = new NlsBundle(nls, locales); | |
19 |
|
23 | |||
20 | const fn = (_locale?: string) => { |
|
24 | const fn = (_locale?: string) => { | |
@@ -27,7 +31,8 export function bundle<T extends object> | |||||
27 | return result; |
|
31 | return result; | |
28 | }; |
|
32 | }; | |
29 |
|
33 | |||
30 | fn.define = (pack: Partial<T>) => pack; |
|
34 | fn.i18n = fn; | |
|
35 | fn.define = (pack: Partial<T>): object => pack; | |||
31 | fn.load = async (id: string, require: Require, cb: OnLoad, config: {isBuild?: boolean}) => { |
|
36 | fn.load = async (id: string, require: Require, cb: OnLoad, config: {isBuild?: boolean}) => { | |
32 | const locale = id || sysLocale; |
|
37 | const locale = id || sysLocale; | |
33 | if (config && config.isBuild) { |
|
38 | if (config && config.isBuild) { | |
@@ -48,4 +53,4 export function bundle<T extends object> | |||||
48 | }; |
|
53 | }; | |
49 |
|
54 | |||
50 | return fn; |
|
55 | return fn; | |
51 | } |
|
56 | }; |
@@ -33,7 +33,7 export const isDjObservableResults = <T> | |||||
33 | v && (typeof (v as { observe?: unknown; }).observe === "function"); |
|
33 | v && (typeof (v as { observe?: unknown; }).observe === "function"); | |
34 |
|
34 | |||
35 | export const query = <T, Q, O>(store: Queryable<T, Q, O>, includeUpdates = true) => |
|
35 | export const query = <T, Q, O>(store: Queryable<T, Q, O>, includeUpdates = true) => | |
36 | (query?: Q, options?: O & { observe: boolean }) => { |
|
36 | (query?: Q, options?: O & { observe?: boolean }) => { | |
37 | return observe<OrderedUpdate<T>>(({ next, complete, error, isClosed }) => { |
|
37 | return observe<OrderedUpdate<T>>(({ next, complete, error, isClosed }) => { | |
38 | try { |
|
38 | try { | |
39 | const results = store.query(query, options); |
|
39 | const results = store.query(query, options); |
@@ -147,13 +147,20 export const bind = <K extends string, T | |||||
147 | }; |
|
147 | }; | |
148 | }; |
|
148 | }; | |
149 |
|
149 | |||
|
150 | /** Creates refHook to toggle the specified css class on the target element | |||
|
151 | * | |||
|
152 | * @param className | |||
|
153 | * @param subj a boolean observable value. When the value is false the className | |||
|
154 | * is removed, when the value is true, the className is added to the target element | |||
|
155 | * @returns refHook | |||
|
156 | */ | |||
150 | export const toggleClass = (className: string, subj: Subscribable<boolean>) => { |
|
157 | export const toggleClass = (className: string, subj: Subscribable<boolean>) => { | |
151 | let h = { unsubscribe() { } }; |
|
158 | let h = { unsubscribe() { } }; | |
152 | return (elOrWidget: HTMLElement | _WidgetBase | undefined) => { |
|
159 | return (elOrWidget: HTMLElement | _WidgetBase | undefined) => { | |
153 | const el = isWidget(elOrWidget) ? elOrWidget.domNode : elOrWidget; |
|
160 | const el = isWidget(elOrWidget) ? elOrWidget.domNode : elOrWidget; | |
154 | if (el) { |
|
161 | if (el) { | |
155 | h = subj.subscribe({ |
|
162 | h = subj.subscribe({ | |
156 | next: v => djClass.toggle(el, className, v) |
|
163 | next: v => djClass.toggle(el, className, v || false) | |
157 | }); |
|
164 | }); | |
158 | } else { |
|
165 | } else { | |
159 | h.unsubscribe(); |
|
166 | h.unsubscribe(); | |
@@ -161,6 +168,7 export const toggleClass = (className: s | |||||
161 | }; |
|
168 | }; | |
162 | }; |
|
169 | }; | |
163 |
|
170 | |||
|
171 | /** Combines multiple hooks to the single one */ | |||
164 | export const all = <T, A extends JSX.Ref<T>[]>(...cbs: A): JSX.Ref<T> => (arg: T | undefined) => cbs.forEach(cb => cb(arg)); |
|
172 | export const all = <T, A extends JSX.Ref<T>[]>(...cbs: A): JSX.Ref<T> => (arg: T | undefined) => cbs.forEach(cb => cb(arg)); | |
165 |
|
173 | |||
166 | /** Decorates the method which will be registered as the handle for the specified event. |
|
174 | /** Decorates the method which will be registered as the handle for the specified event. |
@@ -165,6 +165,8 export const render = (rendition: unknow | |||||
165 | } |
|
165 | } | |
166 | }; |
|
166 | }; | |
167 |
|
167 | |||
|
168 | const emptyFragment = document.createDocumentFragment(); | |||
|
169 | ||||
168 | /** Renders DOM element for different types of the argument. */ |
|
170 | /** Renders DOM element for different types of the argument. */ | |
169 | export const getItemDom = (v: unknown) => { |
|
171 | export const getItemDom = (v: unknown) => { | |
170 | if (typeof v === "string" || typeof v === "number" || v instanceof RegExp || v instanceof Date) { |
|
172 | if (typeof v === "string" || typeof v === "number" || v instanceof RegExp || v instanceof Date) { | |
@@ -181,7 +183,7 export const getItemDom = (v: unknown) = | |||||
181 | return v.domNode; |
|
183 | return v.domNode; | |
182 | } else if (typeof v === "boolean" || v === null || v === undefined) { |
|
184 | } else if (typeof v === "boolean" || v === null || v === undefined) { | |
183 | // null | undefined | boolean are removed |
|
185 | // null | undefined | boolean are removed | |
184 |
return |
|
186 | return emptyFragment; | |
185 | } else if (v instanceof Array) { |
|
187 | } else if (v instanceof Array) { | |
186 | // arrays will be translated to document fragments |
|
188 | // arrays will be translated to document fragments | |
187 | const fragment = document.createDocumentFragment(); |
|
189 | const fragment = document.createDocumentFragment(); |
@@ -76,7 +76,7 export class MyWidget extends djbase(Djx | |||||
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | @on("count-inc") |
|
78 | @on("count-inc") | |
79 |
pr |
|
79 | protected _onCounterInc(evt: Event & { detail: number; x?: number; }) { | |
80 | argumentNotNull(evt, "evt"); |
|
80 | argumentNotNull(evt, "evt"); | |
81 | } |
|
81 | } | |
82 |
|
82 |
@@ -30,6 +30,7 | |||||
30 | }, |
|
30 | }, | |
31 | "../djx/build/npm/package": { |
|
31 | "../djx/build/npm/package": { | |
32 | "name": "@implab/djx", |
|
32 | "name": "@implab/djx", | |
|
33 | "version": "1.6.2", | |||
33 | "dev": true, |
|
34 | "dev": true, | |
34 | "license": "BSD-2-Clause", |
|
35 | "license": "BSD-2-Clause", | |
35 | "peerDependencies": { |
|
36 | "peerDependencies": { |
General Comments 0
You need to be logged in to leave comments.
Login now