qcobjects 2.5.108-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.
@@ -12,6 +12,10 @@ declare module "ClassFactory" {
12
12
  import { TClassFactory } from "types";
13
13
  export const ClassFactory: TClassFactory;
14
14
  }
15
+ declare module "_import_" {
16
+ function _import_(name: string): Promise<any>;
17
+ export { _import_ };
18
+ }
15
19
  declare module "platform" {
16
20
  export const isDeno: boolean;
17
21
  export const isBrowser: boolean;
@@ -38,7 +42,8 @@ declare module "Cast" {
38
42
  }
39
43
  declare module "DOMCreateElement" {
40
44
  import { IQCObjectsElement } from "types";
41
- 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;
42
47
  }
43
48
  declare module "ObjectName" {
44
49
  /**
@@ -1050,3 +1055,5 @@ declare module "localStorage" {
1050
1055
  declare module "uniqueID" {
1051
1056
  export const uniqueId: () => string;
1052
1057
  }
1058
+
1059
+ export {};
@@ -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
+ };
@@ -0,0 +1,27 @@
1
+ import { logger } from "./Logger";
2
+
3
+ async function _import_(name:string):Promise<any> {
4
+ logger.debug(`Importing ${name}...`);
5
+ function isPackage(name:string) {
6
+ logger.debug(`Validating if ${name} is a package name...`);
7
+ // Simple check to determine if the name is a package
8
+ // This can be enhanced based on your specific needs
9
+ return !name.startsWith(".") && !name.startsWith("/") && !name.includes("/");
10
+ }
11
+
12
+ try {
13
+ // Ensure the name has a .js extension if it's not a package
14
+ const hasExtension = /\.[^/\\]+$/.test(name);
15
+ if (!hasExtension && !isPackage(name)) {
16
+ logger.debug(`${name} does not have an extension and is not a package. Adding js extension.`);
17
+ name += ".js";
18
+ }
19
+
20
+ const m:any = await import(name);
21
+ return m;
22
+ } catch (error:any) {
23
+ logger.warn(`Failed to load module: ${error}`);
24
+ }
25
+ }
26
+
27
+ export {_import_};
@@ -1,12 +1,12 @@
1
1
  import { CONFIG } from "./CONFIG";
2
2
  import { Export } from "./Export";
3
3
  import { logger } from "./Logger";
4
- import { _require_, isBrowser } from "./platform";
4
+ import { isBrowser } from "./platform";
5
+ import fs from "node:fs";
5
6
 
6
7
  export const findPackageNodePath = function (packagename:string):string|null {
7
8
  let sdkPath = null;
8
9
  if (!isBrowser) {
9
- const fs = _require_("fs");
10
10
  try {
11
11
  let sdkPaths = [
12
12
  `${CONFIG.get("projectPath")}${CONFIG.get("relativeImportPath")}`,
package/src/platform.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { _import_ } from "./_import_";
1
2
  import { logger } from "./Logger";
2
3
 
3
4
  export const isDeno:boolean = (typeof window !== "undefined" && "Deno" in window);
@@ -11,8 +12,14 @@ export const _require_ = (name:string):any => {
11
12
  ( (name):any => {
12
13
  let r;
13
14
  try {
14
- // eslint-disable-next-line @typescript-eslint/no-require-imports
15
- r = require(name);
15
+ _import_ (name)
16
+ .then ((m) => {
17
+ r = (m && m.default) || m;
18
+ })
19
+ .catch ((e:any) => {
20
+ logger.warn(`An error ocurred: ${e}`);
21
+ });
22
+
16
23
  } catch (e:any) {
17
24
  logger.debug(`An error ocurred importing module. ${e}`);
18
25
  r = {export:{}};
package/src/index.cts DELETED
@@ -1,2 +0,0 @@
1
- const QCObjects = require("./QCObjects.js");
2
- module.exports = QCObjects;
package/src/index.mts DELETED
@@ -1,2 +0,0 @@
1
- import * as QCObjects from "./QCObjects.js";
2
- export default QCObjects;