@ganpatiinfo/gids-web-dom-reference 0.0.1

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.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # DOM ref implementation
2
+
3
+ This package contains the reference to dom implementation
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Referenced to DOM components
3
+ */
4
+ /**
5
+ * Utilities
6
+ */
7
+ export * from './utils/domUtils';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,cAAc,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Referenced to DOM components
3
+ */
4
+ /**
5
+ * Utilities
6
+ */
7
+ export * from './utils/domUtils';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,12 @@
1
+ export type DomNodeOrString = Node | string;
2
+ export type DomChildren = DomNodeOrString | DomNodeOrString[];
3
+ export declare const toElementArray: <E extends DomNodeOrString = DomNodeOrString>(singleOrArr: E | E[] | undefined) => E[];
4
+ export declare const appendAsChildren: (parent: Element, children: DomChildren | undefined) => void;
5
+ export declare const toggleAttribute: (element: Element, attributeName: string, force?: boolean) => boolean;
6
+ export declare const applyStatefulInputProps: (inputElement: HTMLInputElement, { value, defaultValue, checked, defaultChecked, }: {
7
+ value?: string;
8
+ defaultValue?: string;
9
+ checked?: boolean;
10
+ defaultChecked?: boolean;
11
+ }) => void;
12
+ //# sourceMappingURL=domUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domUtils.d.ts","sourceRoot":"","sources":["../../src/utils/domUtils.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG,IAAI,GAAG,MAAM,CAAC;AAE5C,MAAM,MAAM,WAAW,GAAG,eAAe,GAAG,eAAe,EAAE,CAAC;AAE9D,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,eAAe,GAAG,eAAe,EACzE,aAAa,CAAC,GAAG,CAAC,EAAE,GAAG,SAAS,KAC9B,CAAC,EAKH,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAC5B,QAAQ,OAAO,EACf,UAAU,WAAW,GAAG,SAAS,KAC/B,IAIF,CAAC;AAEF,eAAO,MAAM,eAAe,GAC3B,SAAS,OAAO,EAChB,eAAe,MAAM,EACrB,QAAQ,OAAO,KACb,OAYF,CAAC;AAEF,eAAO,MAAM,uBAAuB,GACnC,cAAc,gBAAgB,EAC9B,mDAKG;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB,KACC,IAaF,CAAC"}
@@ -0,0 +1,41 @@
1
+ export const toElementArray = (singleOrArr) => {
2
+ if (singleOrArr === undefined) {
3
+ return [];
4
+ }
5
+ return Array.isArray(singleOrArr) ? singleOrArr : [singleOrArr];
6
+ };
7
+ export const appendAsChildren = (parent, children) => {
8
+ toElementArray(children).forEach((child) => {
9
+ parent.append(child);
10
+ });
11
+ };
12
+ export const toggleAttribute = (element, attributeName, force) => {
13
+ if (typeof element.toggleAttribute === 'function') {
14
+ return element.toggleAttribute(attributeName, force);
15
+ }
16
+ else {
17
+ if (element.hasAttribute(attributeName) || !force) {
18
+ element.removeAttribute(attributeName);
19
+ return false;
20
+ }
21
+ else {
22
+ element.setAttribute(attributeName, '');
23
+ return true;
24
+ }
25
+ }
26
+ };
27
+ export const applyStatefulInputProps = (inputElement, { value, defaultValue, checked, defaultChecked, }) => {
28
+ if (value !== undefined) {
29
+ inputElement.value = value;
30
+ }
31
+ if (defaultValue !== undefined) {
32
+ inputElement.defaultValue = defaultValue;
33
+ }
34
+ if (checked !== undefined) {
35
+ inputElement.checked = checked;
36
+ }
37
+ if (defaultChecked !== undefined) {
38
+ inputElement.defaultChecked = defaultChecked;
39
+ }
40
+ };
41
+ //# sourceMappingURL=domUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domUtils.js","sourceRoot":"","sources":["../../src/utils/domUtils.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,cAAc,GAAG,CAC7B,WAAgC,EAC1B,EAAE;IACR,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO,EAAE,CAAC;IACX,CAAC;IACD,OAAO,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;AACjE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC/B,MAAe,EACf,QAAiC,EAC1B,EAAE;IACT,cAAc,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QAC1C,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAC9B,OAAgB,EAChB,aAAqB,EACrB,KAAe,EACL,EAAE;IACZ,IAAI,OAAO,OAAO,CAAC,eAAe,KAAK,UAAU,EAAE,CAAC;QACnD,OAAO,OAAO,CAAC,eAAe,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;SAAM,CAAC;QACP,IAAI,OAAO,CAAC,YAAY,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YACnD,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;YACvC,OAAO,KAAK,CAAC;QACd,CAAC;aAAM,CAAC;YACP,OAAO,CAAC,YAAY,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;YACxC,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;AACF,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACtC,YAA8B,EAC9B,EACC,KAAK,EACL,YAAY,EACZ,OAAO,EACP,cAAc,GAMd,EACM,EAAE;IACT,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,YAAY,CAAC,KAAK,GAAG,KAAK,CAAC;IAC5B,CAAC;IACD,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAChC,YAAY,CAAC,YAAY,GAAG,YAAY,CAAC;IAC1C,CAAC;IACD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC3B,YAAY,CAAC,OAAO,GAAG,OAAO,CAAC;IAChC,CAAC;IACD,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;QAClC,YAAY,CAAC,cAAc,GAAG,cAAc,CAAC;IAC9C,CAAC;AACF,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@ganpatiinfo/gids-web-dom-reference",
3
+ "version": "0.0.1",
4
+ "private": false,
5
+ "description": "DOM for components reference implementations",
6
+ "homepage": "https://ganpatiinfosystem.vercel.app/",
7
+ "type": "module",
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "scripts": {
11
+ "clean": "del-cli dist/*",
12
+ "build": "tsc",
13
+ "release:manually": "npm run build && npm publish --access public"
14
+ },
15
+ "author": {
16
+ "name": "Ganpatiinfo Design System",
17
+ "email": "ganpatiinfosysystem0@gmail.com",
18
+ "url": "https://ganpatiinfosystem.vercel.app/"
19
+ },
20
+ "license": "MIT",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/ganpatiinfosystem/ganpatiinfo-design-system",
24
+ "directory": "packages/private/web-dom-reference"
25
+ },
26
+ "dependencies": {
27
+ "@ganpatiinfo/gids-core-shared": "0.0.1",
28
+ "@ganpatiinfo/gids-web-shared": "0.0.1"
29
+ },
30
+ "peerDependencies": {
31
+ "@jest/globals": "29.7.0",
32
+ "@types/jasmine": "5.1.7",
33
+ "expect": "29.7.0"
34
+ },
35
+ "peerDependenciesMeta": {
36
+ "@jest/globals": {
37
+ "optional": true
38
+ },
39
+ "expect": {
40
+ "optional": true
41
+ },
42
+ "@types/jasmine": {
43
+ "optional": true
44
+ }
45
+ }
46
+ }
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Referenced to DOM components
3
+ */
4
+
5
+ /**
6
+ * Utilities
7
+ */
8
+ export * from './utils/domUtils';
@@ -0,0 +1,67 @@
1
+ export type DomNodeOrString = Node | string;
2
+
3
+ export type DomChildren = DomNodeOrString | DomNodeOrString[];
4
+
5
+ export const toElementArray = <E extends DomNodeOrString = DomNodeOrString>(
6
+ singleOrArr: E | E[] | undefined,
7
+ ): E[] => {
8
+ if (singleOrArr === undefined) {
9
+ return [];
10
+ }
11
+ return Array.isArray(singleOrArr) ? singleOrArr : [singleOrArr];
12
+ };
13
+
14
+ export const appendAsChildren = (
15
+ parent: Element,
16
+ children: DomChildren | undefined,
17
+ ): void => {
18
+ toElementArray(children).forEach((child) => {
19
+ parent.append(child);
20
+ });
21
+ };
22
+
23
+ export const toggleAttribute = (
24
+ element: Element,
25
+ attributeName: string,
26
+ force?: boolean,
27
+ ): boolean => {
28
+ if (typeof element.toggleAttribute === 'function') {
29
+ return element.toggleAttribute(attributeName, force);
30
+ } else {
31
+ if (element.hasAttribute(attributeName) || !force) {
32
+ element.removeAttribute(attributeName);
33
+ return false;
34
+ } else {
35
+ element.setAttribute(attributeName, '');
36
+ return true;
37
+ }
38
+ }
39
+ };
40
+
41
+ export const applyStatefulInputProps = (
42
+ inputElement: HTMLInputElement,
43
+ {
44
+ value,
45
+ defaultValue,
46
+ checked,
47
+ defaultChecked,
48
+ }: {
49
+ value?: string;
50
+ defaultValue?: string;
51
+ checked?: boolean;
52
+ defaultChecked?: boolean;
53
+ },
54
+ ): void => {
55
+ if (value !== undefined) {
56
+ inputElement.value = value;
57
+ }
58
+ if (defaultValue !== undefined) {
59
+ inputElement.defaultValue = defaultValue;
60
+ }
61
+ if (checked !== undefined) {
62
+ inputElement.checked = checked;
63
+ }
64
+ if (defaultChecked !== undefined) {
65
+ inputElement.defaultChecked = defaultChecked;
66
+ }
67
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../../tsconfig.web-lib.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist"
5
+ },
6
+ "include": ["src"]
7
+ }