qcobjects 2.5.109-beta → 2.5.110-beta

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.
@@ -42,7 +42,8 @@ declare module "Cast" {
42
42
  }
43
43
  declare module "DOMCreateElement" {
44
44
  import { IQCObjectsElement } from "types";
45
- export const _DOMCreateElement: (elementName: string) => IQCObjectsElement;
45
+ export const _DOMCreateElement: (elementName: string, props?: any[], children?: any) => IQCObjectsElement;
46
+ export const _DOMCreateComplexElement: (_type: string | Function, props?: any[], children?: any) => HTMLElement;
46
47
  }
47
48
  declare module "ObjectName" {
48
49
  /**
@@ -1,12 +1,46 @@
1
1
  import { IQCObjectsElement } from "types";
2
2
  import { isBrowser } from "./platform";
3
3
 
4
- export const _DOMCreateElement = function (elementName:string):IQCObjectsElement {
4
+ export const _DOMCreateElement = function (elementName:string, props?:any[], children?:any):IQCObjectsElement {
5
5
  let _ret_;
6
6
  if (isBrowser) {
7
- _ret_ = document.createElement(elementName) as unknown as IQCObjectsElement;
7
+ _ret_ = _DOMCreateComplexElement(elementName, props, children) as unknown as IQCObjectsElement;
8
8
  } else {
9
9
  _ret_ = {} as IQCObjectsElement;
10
10
  }
11
11
  return _ret_;
12
12
  };
13
+
14
+
15
+ const ComplexTypeCall = (_type:Function, {props, children}:{props?:any[], children?:any}):IQCObjectsElement => {
16
+ return _type({props, children}) as IQCObjectsElement;
17
+ };
18
+ export const _DOMCreateComplexElement = (_type:string|Function, props?:any[], children?:any) => {
19
+
20
+ if (typeof _type !== "string") {
21
+ return ComplexTypeCall(_type, {props,children});
22
+ }
23
+ const element = document.createElement(_type);
24
+
25
+ if (props) {
26
+ Object.entries(props).forEach(([key, value]) => {
27
+ if (typeof value === "string" || typeof value === "number") {
28
+ element.setAttribute(key, value.toString());
29
+ } else if (typeof value === "function" && key.toLowerCase().startsWith("on")) {
30
+ element.addEventListener(key.slice(2).toLowerCase(), value.bind(element));
31
+ }
32
+ });
33
+ }
34
+
35
+ if (Array.isArray(children)) {
36
+ children.filter((child => child instanceof Node)).forEach(child => {
37
+ element.appendChild(child);
38
+ });
39
+ } else if (children instanceof Node) {
40
+ element.appendChild(children);
41
+ } else if (typeof children === "string") {
42
+ element.innerHTML = children;
43
+ }
44
+
45
+ return element;
46
+ };