| @@ -9,8 +9,14 function when<T, T2>(value: PromiseOrVal | |||||
| 9 | cb(value); | 
             | 
        9 | cb(value); | |
| 10 | } | 
             | 
        10 | } | |
| 11 | 
             | 
        11 | |||
| 12 | const chainObjects = <T extends object, T2 extends object>(o1: T, o2: T2) => | 
             | 
        12 | const loadPackage = <T extends object>(localeData: LocaleProvider<Partial<T>> | undefined) => | |
| 13 | mixin(Object.create(o1) as T, o2); | 
             | 
        13 | localeData ? | |
| 
             | 
        14 | when(localeData(), data => data && "default" in data ? data.default : data) : | |||
| 
             | 
        15 | undefined; | |||
| 
             | 
        16 | ||||
| 
             | 
        17 | const chainObjects = <T extends object>(o1: T, o2: Partial<T> | undefined): T => | |||
| 
             | 
        18 | o2 ? mixin(Object.create(o1) as T, o2) : o1; | |||
| 
             | 
        19 | ||||
| 14 | export class NlsBundle<T extends object> { | 
             | 
        20 | export class NlsBundle<T extends object> { | |
| 15 | private readonly _locales: MapOf<LocaleProvider<Partial<T>>>; | 
             | 
        21 | private readonly _locales: MapOf<LocaleProvider<Partial<T>>>; | |
| 16 | 
             | 
        22 | |||
| @@ -44,15 +50,11 export class NlsBundle<T extends object> | |||||
| 44 | if (this._cache[locale]) | 
             | 
        50 | if (this._cache[locale]) | |
| 45 | return this._cache[locale]; | 
             | 
        51 | return this._cache[locale]; | |
| 46 | 
             | 
        52 | |||
| 47 | 
            
                    const data =  | 
        
             | 
        53 | const data = loadPackage(this._locales[locale]); | |
| 48 | const parent = this._resolveLocale(locales); | 
             | 
        54 | const parent = this._resolveLocale(locales); | |
| 49 | 
             | 
        55 | |||
| 50 | return this._cache[locale] = when(data, x => { | 
             | 
        56 | return this._cache[locale] = when(data, x => { | |
| 51 | return when(parent, y => this._cache[locale] = chainObjects(y, x)); | 
             | 
        57 | return when(parent, y => this._cache[locale] = chainObjects(y, x)); | |
| 52 | }); | 
             | 
        58 | }); | |
| 53 | } | 
             | 
        59 | } | |
| 54 | 
             | 
        ||||
| 55 | _loadPackage(localeData: LocaleProvider<Partial<T>>) { | 
             | 
        |||
| 56 | return when(localeData(), data => data && "default" in data ? data.default : data); | 
             | 
        |||
| 57 | } | 
             | 
        60 | } | |
| 58 | } | 
             | 
        |||
| @@ -1,7 +1,11 | |||||
| 
             | 
        1 | import { FunctionRendition } from "./FunctionRendition"; | |||
| 
             | 
        2 | import { getItemDom } from "./render"; | |||
| 
             | 
        3 | ||||
| 1 | /** Special functional component used to create a document fragment */ | 
             | 
        4 | /** Special functional component used to create a document fragment */ | |
| 2 | 
            
            export  | 
        
             | 
        5 | export const DjxFragment = ({ children }: { children?: unknown | unknown[] }) => | |
| 
             | 
        6 | new FunctionRendition(() => { | |||
| 3 | const fragment = document.createDocumentFragment(); | 
             | 
        7 | const fragment = document.createDocumentFragment(); | |
| 4 | if (children) | 
             | 
        8 | if (children) | |
| 5 | (children instanceof Array ? children : [children]).forEach(child => fragment.appendChild(child)); | 
             | 
        9 | (children instanceof Array ? children : [children]).map(getItemDom).forEach(child => fragment.appendChild(child)); | |
| 6 | return fragment; | 
             | 
        10 | return fragment; | |
| 7 | } No newline at end of file | 
             | 
        11 | }); No newline at end of file | |
| @@ -1,11 +1,12 | |||||
| 1 | import { djbase, djclass } from "../declare"; | 
             | 
        1 | import { djbase, djclass } from "../declare"; | |
| 2 | import _WidgetBase = require("dijit/_WidgetBase"); | 
             | 
        2 | import _WidgetBase = require("dijit/_WidgetBase"); | |
| 3 | import _AttachMixin = require("dijit/_AttachMixin"); | 
             | 
        3 | import _AttachMixin = require("dijit/_AttachMixin"); | |
| 4 | 
            
            import { | 
        
             | 
        4 | import { isNode, isElementNode } from "./traits"; | |
| 5 | import registry = require("dijit/registry"); | 
             | 
        5 | import registry = require("dijit/registry"); | |
| 6 | import on = require("dojo/on"); | 
             | 
        6 | import on = require("dojo/on"); | |
| 7 | import { Scope } from "./Scope"; | 
             | 
        7 | import { Scope } from "./Scope"; | |
| 8 | import { render } from "./render"; | 
             | 
        8 | import { render } from "./render"; | |
| 
             | 
        9 | import { isNull } from "@implab/core-amd/safe"; | |||
| 9 | 
             | 
        10 | |||
| 10 | // type Handle = dojo.Handle; | 
             | 
        11 | // type Handle = dojo.Handle; | |
| 11 | 
             | 
        12 | |||
| @@ -70,7 +71,7 export abstract class DjxWidgetBase<Attr | |||||
| 70 | } | 
             | 
        71 | } | |
| 71 | } | 
             | 
        72 | } | |
| 72 | 
             | 
        73 | |||
| 73 | 
            
                abstract render():  | 
        
             | 
        74 | abstract render(): JSX.Element; | |
| 74 | 
             | 
        75 | |||
| 75 | private _connectEventHandlers() { | 
             | 
        76 | private _connectEventHandlers() { | |
| 76 | if (this._eventHandlers) | 
             | 
        77 | if (this._eventHandlers) | |
| @@ -83,7 +84,7 export abstract class DjxWidgetBase<Attr | |||||
| 83 | 
             | 
        84 | |||
| 84 | _processTemplateNode<T extends (Element | Node | _WidgetBase)>( | 
             | 
        85 | _processTemplateNode<T extends (Element | Node | _WidgetBase)>( | |
| 85 | baseNode: T, | 
             | 
        86 | baseNode: T, | |
| 86 | getAttrFunc: (baseNode: T, attr: string) => string, | 
             | 
        87 | getAttrFunc: (baseNode: T, attr: string) => string | undefined, | |
| 87 | // tslint:disable-next-line: ban-types | 
             | 
        88 | // tslint:disable-next-line: ban-types | |
| 88 | attachFunc: (node: T, type: string, func?: (...args: unknown[]) => unknown) => dojo.Handle | 
             | 
        89 | attachFunc: (node: T, type: string, func?: (...args: unknown[]) => unknown) => dojo.Handle | |
| 89 | ): boolean { | 
             | 
        90 | ): boolean { | |
| @@ -92,7 +93,10 export abstract class DjxWidgetBase<Attr | |||||
| 92 | if (w) { | 
             | 
        93 | if (w) { | |
| 93 | // from dijit/_WidgetsInTemplateMixin | 
             | 
        94 | // from dijit/_WidgetsInTemplateMixin | |
| 94 | this._processTemplateNode(w, | 
             | 
        95 | this._processTemplateNode(w, | |
| 95 | (n, p) => String(n.get(p as keyof typeof n)), // callback to get a property of a widget | 
             | 
        96 | (n, p) => { | |
| 
             | 
        97 | const v = n.get(p as keyof typeof n); | |||
| 
             | 
        98 | return isNull(v) ? undefined : String(v); | |||
| 
             | 
        99 | }, // callback to get a property of a widget | |||
| 96 | (widget, type, callback) => { | 
             | 
        100 | (widget, type, callback) => { | |
| 97 | if (!callback) | 
             | 
        101 | if (!callback) | |
| 98 | throw new Error("The callback must be specified"); | 
             | 
        102 | throw new Error("The callback must be specified"); | |
| @@ -112,7 +116,7 export abstract class DjxWidgetBase<Attr | |||||
| 112 | } | 
             | 
        116 | } | |
| 113 | } | 
             | 
        117 | } | |
| 114 | // eslint-disable-next-line @typescript-eslint/ban-types | 
             | 
        118 | // eslint-disable-next-line @typescript-eslint/ban-types | |
| 115 | return super._processTemplateNode(baseNode, getAttrFunc, attachFunc as (node: T, type: string, func?: Function) => dojo.Handle); | 
             | 
        119 | return super._processTemplateNode(baseNode, getAttrFunc as (baseNode: T, attr: string) => string, attachFunc as (node: T, type: string, func?: Function) => dojo.Handle); | |
| 116 | } | 
             | 
        120 | } | |
| 117 | 
             | 
        121 | |||
| 118 | /** Starts current widget and all its supporting widgets (placed outside | 
             | 
        122 | /** Starts current widget and all its supporting widgets (placed outside | |
| @@ -59,7 +59,7 export abstract class RenditionBase<TNod | |||||
| 59 | 
             | 
        59 | |||
| 60 | placeAt(domNode, refNode, position); | 
             | 
        60 | placeAt(domNode, refNode, position); | |
| 61 | 
             | 
        61 | |||
| 62 | if (isMounted(startupPending[0])) | 
             | 
        62 | if (startupPending.length && isMounted(startupPending[0])) | |
| 63 | startupPending.forEach(n => startupWidgets(n)); | 
             | 
        63 | startupPending.forEach(n => startupWidgets(n)); | |
| 64 | 
             | 
        64 | |||
| 65 | } | 
             | 
        65 | } | |
| @@ -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.4.4", | |||
| 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
                    
                