UNPKG

1.2 kBPlain TextView Raw
1/*eslint padded-blocks:0*/
2import {useView, customElement, bindable, useShadowDOM} from 'aurelia-templating';
3import { getLogger } from 'aurelia-logging';
4
5export function _createDynamicElement({ name, viewUrl, bindableNames, useShadowDOMmode }: {
6 name: string,
7 viewUrl: string,
8 bindableNames: string[],
9 useShadowDOMmode: null | '' | 'open' | 'closed'
10}): Function {
11 @customElement(name)
12 @useView(viewUrl)
13 class DynamicElement {
14 $parent: any;
15 bind(bindingContext) {
16 this.$parent = bindingContext;
17 }
18 }
19
20 for (let i = 0, ii = bindableNames.length; i < ii; ++i) {
21 bindable(bindableNames[i])(DynamicElement);
22 }
23
24 switch (useShadowDOMmode) {
25 case 'open':
26 useShadowDOM({ mode: 'open' })(DynamicElement);
27 break;
28
29 case 'closed':
30 useShadowDOM({ mode: 'closed' })(DynamicElement);
31 break;
32
33 case '':
34 useShadowDOM(DynamicElement);
35 break;
36
37 case null:
38 // Do not use shadow dom
39 break;
40
41 default:
42 getLogger('aurelia-html-only-element')
43 .warn(`Expected 'use-shadow-dom' value to be "close", "open" or "", received ${useShadowDOMmode}`);
44 break;
45 }
46
47 return DynamicElement;
48}