landaxs 1.0.0
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 +0 -0
- package/dist/get.d.ts +0 -0
- package/dist/get.js +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +153 -0
- package/dist/index.js.map +1 -0
- package/package.json +27 -0
package/README.md
ADDED
|
File without changes
|
package/dist/get.d.ts
ADDED
|
File without changes
|
package/dist/get.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare class Landaxs {
|
|
2
|
+
private _data;
|
|
3
|
+
input: Record<string, any>;
|
|
4
|
+
input_details: Array<Record<string, any>>;
|
|
5
|
+
ref: Record<string, any>;
|
|
6
|
+
method: Record<string, (...args: any[]) => any>;
|
|
7
|
+
defineInput(data: Record<string, any>): this;
|
|
8
|
+
setRef(data: Array<string>): this;
|
|
9
|
+
triggerInput(name_input: string | Array<string>, callback: Function): this;
|
|
10
|
+
methods(function_parameter: Record<string, (...args: any[]) => any>): this;
|
|
11
|
+
}
|
|
12
|
+
export default Landaxs;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
class Landaxs {
|
|
2
|
+
constructor() {
|
|
3
|
+
this._data = {};
|
|
4
|
+
this.input = {};
|
|
5
|
+
this.input_details = [];
|
|
6
|
+
this.ref = {};
|
|
7
|
+
this.method = {};
|
|
8
|
+
}
|
|
9
|
+
defineInput(data) {
|
|
10
|
+
this._data = data;
|
|
11
|
+
this.input = new Proxy(this._data, {
|
|
12
|
+
set: (target, key, value) => {
|
|
13
|
+
target[key] = value;
|
|
14
|
+
document.querySelectorAll(`[x_input='${key}']`).forEach(ctx => {
|
|
15
|
+
ctx.value = value;
|
|
16
|
+
this._data[key] = value;
|
|
17
|
+
});
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
let input_details = [];
|
|
22
|
+
for (let [key, value] of Object.entries(this._data)) {
|
|
23
|
+
document.querySelectorAll(`[x_input='${key}']`).forEach((ctx) => {
|
|
24
|
+
if (ctx instanceof HTMLInputElement) {
|
|
25
|
+
input_details.push({
|
|
26
|
+
name_input: key,
|
|
27
|
+
type_input: ctx.type,
|
|
28
|
+
type_variable: typeof this._data[key],
|
|
29
|
+
});
|
|
30
|
+
if (ctx.type === "radio") {
|
|
31
|
+
ctx.setAttribute("name", key);
|
|
32
|
+
if (ctx.value === this._data[key]) {
|
|
33
|
+
ctx.checked = true;
|
|
34
|
+
}
|
|
35
|
+
ctx.addEventListener("change", (e) => {
|
|
36
|
+
let target = e.currentTarget;
|
|
37
|
+
this._data[key] = target.value;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
else if (ctx.type === "checkbox") {
|
|
41
|
+
ctx.setAttribute("name", `${key}[]`);
|
|
42
|
+
this._data[key].forEach((ctx2) => {
|
|
43
|
+
if (ctx.value === ctx2) {
|
|
44
|
+
ctx.checked = true;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
ctx.addEventListener("input", (e) => {
|
|
48
|
+
let target = e.currentTarget;
|
|
49
|
+
if (target.checked) {
|
|
50
|
+
this._data[key].push(target.value);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
this._data[key] = this._data[key].filter((item) => {
|
|
54
|
+
return item !== target.value;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else if (ctx.type === "file") {
|
|
60
|
+
ctx.setAttribute("name", key);
|
|
61
|
+
ctx.addEventListener("change", (e) => {
|
|
62
|
+
let target = e.target;
|
|
63
|
+
this._data[key] = target.files;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
ctx.setAttribute("name", key);
|
|
68
|
+
ctx.value = this._data[key];
|
|
69
|
+
ctx.addEventListener("input", (e) => {
|
|
70
|
+
let target = e.currentTarget;
|
|
71
|
+
this._data[key] = target.value;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else if (ctx instanceof HTMLSelectElement && ctx.hasAttribute("multiple")) {
|
|
76
|
+
ctx.setAttribute("name", key);
|
|
77
|
+
input_details.push({
|
|
78
|
+
name_input: key,
|
|
79
|
+
type_input: "select",
|
|
80
|
+
type_variable: typeof this._data[key],
|
|
81
|
+
});
|
|
82
|
+
let cx = [];
|
|
83
|
+
this._data[key].forEach((ctx2) => {
|
|
84
|
+
for (let i = 0; i < ctx.options.length; i++) {
|
|
85
|
+
if (ctx.options[i].value === ctx2) {
|
|
86
|
+
ctx.options[i].selected = true;
|
|
87
|
+
cx.push(ctx2);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
ctx.addEventListener("input", (e) => {
|
|
92
|
+
this._data[key] = [];
|
|
93
|
+
const target = e.currentTarget;
|
|
94
|
+
for (let i = 0; i < target.length; i++) {
|
|
95
|
+
if (target.options[i].selected === true) {
|
|
96
|
+
this._data[key].push(target.options[i].value);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function removeDuplicateByKey(arr, key) {
|
|
104
|
+
return [...new Map(arr.map(item => [item[key], item])).values()];
|
|
105
|
+
}
|
|
106
|
+
this.input_details = removeDuplicateByKey(input_details, "name_input");
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
setRef(data) {
|
|
110
|
+
data.forEach(ctx => {
|
|
111
|
+
this.ref[ctx] = document.querySelectorAll(`[x_ref='${ctx}']`)[0];
|
|
112
|
+
});
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
triggerInput(name_input, callback) {
|
|
116
|
+
if (typeof name_input === "string") {
|
|
117
|
+
document.querySelectorAll(`[x_input='${name_input}']`).forEach(ctx => {
|
|
118
|
+
if (ctx.type === "file") {
|
|
119
|
+
ctx.addEventListener("change", (e) => {
|
|
120
|
+
callback(this._data);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
ctx.addEventListener("input", (e) => {
|
|
125
|
+
callback(this._data);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
name_input.forEach(ctx => {
|
|
132
|
+
document.querySelectorAll(`[x_input='${ctx}']`).forEach(ctx => {
|
|
133
|
+
if (ctx.type === "file") {
|
|
134
|
+
ctx.addEventListener("change", (e) => {
|
|
135
|
+
callback(this._data);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
ctx.addEventListener("input", (e) => {
|
|
140
|
+
callback(this._data);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
148
|
+
methods(function_parameter) {
|
|
149
|
+
this.method = function_parameter;
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
export default Landaxs;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;AAAA,MAAM,OAAO;IAAb;QACY,UAAK,GAAwB,EAAE,CAAA;QAChC,UAAK,GAAsB,EAAE,CAAA;QAC7B,kBAAa,GAA8B,EAAE,CAAA;QAC7C,QAAG,GAAsB,EAAE,CAAA;QAC3B,WAAM,GAA2C,EAAE,CAAA;IA6K9D,CAAC;IA3KG,WAAW,CAAC,IAAuB;QAE/B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;QAEjB,IAAI,CAAC,KAAK,GAAG,IAA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;wBACzB,CAAC,CAAC,CAAA;oBACN,CAAC;gBACL,CAAC,CAAC,CAAA;YACN,CAAC,CAAC,CAAA;QACN,CAAC;QAED,OAAO,IAAI,CAAA;IACf,CAAC;IAGD,OAAO,CAAC,kBAA0D;QAC9D,IAAI,CAAC,MAAM,GAAG,kBAAkB,CAAA;QAChC,OAAO,IAAI,CAAA;IACf,CAAC;CACJ;AAED,kBAAe,OAAO,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "landaxs",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Landaxs is a lightweight library for dynamic input binding with two-way data flow.",
|
|
5
|
+
"keywords": ["forms", "binding", "javascript", "typescript"],
|
|
6
|
+
"homepage": "https://github.com/Rakhmadi/Landaxs#readme",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/Rakhmadi/Landaxs/issues"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/Rakhmadi/Landaxs.git"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": "rakhmadi",
|
|
16
|
+
"type": "commonjs",
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"files": ["dist"],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"prepublishOnly": "npm run build"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"typescript": "^5.9.3"
|
|
26
|
+
}
|
|
27
|
+
}
|