tool-shack 0.0.2 → 0.0.3
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { IExtendingElementProps } from './interfaces/createElement';
|
|
2
|
-
export declare const createElement: <T = HTMLElement>(tagName: string, props?: (Partial<T
|
|
2
|
+
export declare const createElement: <T = HTMLElement>(tagName: string, props?: (Partial<Omit<T, "children">> & IExtendingElementProps) | undefined) => T;
|
|
@@ -2,7 +2,11 @@ export const createElement = (tagName, props) => {
|
|
|
2
2
|
const element = document.createElement(tagName);
|
|
3
3
|
if (props) {
|
|
4
4
|
for (let key in props) {
|
|
5
|
-
|
|
5
|
+
const value = props[key];
|
|
6
|
+
if (key === 'role') {
|
|
7
|
+
element.setAttribute('key', value);
|
|
8
|
+
}
|
|
9
|
+
else if (key === 'children') {
|
|
6
10
|
props.children.forEach((child) => element.appendChild(child));
|
|
7
11
|
}
|
|
8
12
|
else if (key === 'listeners') {
|
|
@@ -12,7 +16,7 @@ export const createElement = (tagName, props) => {
|
|
|
12
16
|
}
|
|
13
17
|
}
|
|
14
18
|
else {
|
|
15
|
-
element[key] =
|
|
19
|
+
element[key] = value;
|
|
16
20
|
}
|
|
17
21
|
}
|
|
18
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createElement.js","sourceRoot":"","sources":["../../src/dom/createElement.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAmB,OAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"createElement.js","sourceRoot":"","sources":["../../src/dom/createElement.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAmB,OAAe,EAAE,KAA6D,EAAK,EAAE;IACnI,MAAM,OAAO,GAAgB,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAE7D,IAAI,KAAK,EAAE;QACT,KAAK,IAAI,GAAG,IAAI,KAAK,EAAE;YACrB,MAAM,KAAK,GAAI,KAAa,CAAC,GAAG,CAAC,CAAC;YAElC,IAAI,GAAG,KAAK,MAAM,EAAE;gBAClB,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;aACpC;iBACI,IAAI,GAAG,KAAK,UAAU,EAAE;gBAC3B,KAAK,CAAC,QAAS,CAAC,OAAO,CAAC,CAAC,KAAkB,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;aAC7E;iBAAM,IAAI,GAAG,KAAK,WAAW,EAAE;gBAC9B,KAAK,IAAI,SAAS,IAAI,KAAK,CAAC,SAAU,EAAE;oBACtC,MAAM,YAAY,GAAG,CACnB,KAAK,CAAC,SAAU,CAAC,SAAS,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,SAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAU,CAAC,SAAS,CAAC,CAAC,CACnE,CAAC;oBAE1C,YAAY,CAAC,OAAO,CAAC,CAAC,EAAsC,EAAE,EAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC;iBAC3G;aACF;iBAAM;gBACJ,OAAe,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;aAC/B;SACF;KACF;IAED,OAAO,OAAuB,CAAC;AACjC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tool-shack",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Collection of usefull functions to ease work",
|
|
5
5
|
"main": "src",
|
|
6
6
|
"author": "David Myška",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"bugs": {
|
|
9
|
-
"url": "https://
|
|
9
|
+
"url": "https://github.com/miskith/tool-shack/issues"
|
|
10
10
|
},
|
|
11
|
-
"homepage": "https://
|
|
11
|
+
"homepage": "https://github.com/miskith/tool-shack#readme",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
|
-
"url": "git+https://
|
|
14
|
+
"url": "git+https://github.com/miskith/tool-shack.git"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "tsc -p ."
|
package/src/dom/createElement.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { IExtendingElementProps } from './interfaces/createElement';
|
|
2
2
|
|
|
3
|
-
export const createElement = <T = HTMLElement> (tagName: string, props?: Partial<T
|
|
3
|
+
export const createElement = <T = HTMLElement> (tagName: string, props?: Partial<Omit<T, 'children'>> & IExtendingElementProps): T => {
|
|
4
4
|
const element: HTMLElement = document.createElement(tagName);
|
|
5
5
|
|
|
6
6
|
if (props) {
|
|
7
7
|
for (let key in props) {
|
|
8
|
-
|
|
8
|
+
const value = (props as any)[key];
|
|
9
|
+
|
|
10
|
+
if (key === 'role') {
|
|
11
|
+
element.setAttribute('key', value);
|
|
12
|
+
}
|
|
13
|
+
else if (key === 'children') {
|
|
9
14
|
props.children!.forEach((child: HTMLElement) => element.appendChild(child));
|
|
10
|
-
} else if (key==='listeners') {
|
|
15
|
+
} else if (key === 'listeners') {
|
|
11
16
|
for (let eventName in props.listeners!) {
|
|
12
17
|
const functionList = (
|
|
13
18
|
props.listeners![eventName] instanceof Array ? props.listeners![eventName] : [props.listeners![eventName]]
|
|
@@ -16,7 +21,7 @@ export const createElement = <T = HTMLElement> (tagName: string, props?: Partial
|
|
|
16
21
|
functionList.forEach((fn: EventListenerOrEventListenerObject) => element.addEventListener(eventName, fn));
|
|
17
22
|
}
|
|
18
23
|
} else {
|
|
19
|
-
(element as any)[key] =
|
|
24
|
+
(element as any)[key] = value;
|
|
20
25
|
}
|
|
21
26
|
}
|
|
22
27
|
}
|