landaxs 1.0.5 → 1.1.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 CHANGED
@@ -1,6 +1,5 @@
1
1
  Landaxs is library for dynamically managing input forms, supporting two-way binding and event handling with clean syntax.
2
2
 
3
- <img src="logo.png" width="200" />
4
3
  ## ✨ Features
5
4
  - Two-way data binding
6
5
  - Event handling
@@ -10,7 +9,7 @@ Landaxs is library for dynamically managing input forms, supporting two-way bind
10
9
  CDN
11
10
 
12
11
  ```html
13
- <script src="https://cdn.jsdelivr.net/npm/landaxs@1.0.2/dist/index.min.js"></script>
12
+ <script src="https://cdn.jsdelivr.net/npm/landaxs@1.1.0/dist/index.min.js"></script>
14
13
  ```
15
14
 
16
15
  ### Define input name
@@ -45,6 +44,11 @@ define the input tag input name into the input property
45
44
  form_login.input.email
46
45
  form_login.input.gender
47
46
  form_login.input.role
47
+ // to change input
48
+ form_login.input.username = "Darent"
49
+ form_login.input.email = "darent@example.com"
50
+ form_login.input.gender = "male"
51
+ form_login.input.role = "admin"
48
52
  </script>
49
53
  ```
50
54
 
@@ -161,6 +165,35 @@ register a method to the methods property
161
165
     
162
166
  </script>
163
167
  ```
168
+
169
+ ### setStyle & setClas
170
+ Apply styles and classes to Dom references
171
+ > For set style
172
+ ```js
173
+
174
+ const app = new Landaxs()
175
+ app
176
+     .defineInput({ nama: "", email: "" })
177
+     .setRef(["tombol", "kotak", "pesan"])
178
+ // Ubah style elemen
179
+ app.setStyle("kotak", {
180
+     backgroundColor : "#1e1e2e",
181
+     color           : "white",
182
+     padding         : "16px",
183
+     borderRadius    : "8px",
184
+     fontSize        : "14px",
185
+     display         : "flex",
186
+     gap             : "8px"
187
+ })
188
+ ```
189
+ >for set class
190
+ ```js
191
+     app.setClass("pesan", {
192
+         "hidden"    :  true,
193
+         "text-red"  : !true,
194
+         "text-green":  false
195
+     })
196
+ ```
164
197
  ### properties and methods of the Landaxs class
165
198
  ### 📦 Properties (Internal State)
166
199
 
@@ -180,6 +213,8 @@ register a method to the methods property
180
213
  | `setRef` | `string \| string[]` | Registers DOM references using `x_ref` |
181
214
  | `triggerInput` | `string \| string[]`, `callback` | Executes callback when input value changes |
182
215
  | methods | Record<string, Function> | Registers external custom methods into the instance |
216
+ | setStyle | `string \| sRecord<string, any> | Set style to reference DOM |
217
+ | setClass | `string \| Record<string, any> | set Class to reference DOM |
183
218
  >example use
184
219
  ```html
185
220
  <!DOCTYPE html>
@@ -189,7 +224,7 @@ register a method to the methods property
189
224
      <meta charset="UTF-8">
190
225
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
191
226
      <title>Document</title>
192
-     <script src="https://cdn.jsdelivr.net/npm/landaxs@1.0.1/dist/index.min.js"></script>
227
+     <script src="https://cdn.jsdelivr.net/npm/landaxs@1.1.0/dist/index.min.js"></script>
193
228
  <style>
194
229
      .form-control {
195
230
          display: flex;
@@ -364,4 +399,4 @@ form
364
399
  ✅ Safari 11+  
365
400
  ✅ Edge 79+  
366
401
 
367
- ---
402
+ ---
package/dist/index.d.ts CHANGED
@@ -7,5 +7,7 @@ declare class Landaxs {
7
7
  defineInput(data: Record<string, any>): this;
8
8
  setRef(data: string | Array<string>): this;
9
9
  triggerInput(name_input: string | Array<string>, callback: Function): this;
10
+ setStyle(name_reference: string, style: Record<string, any>): void;
11
+ setClass(name_reference: string, class_name: Record<string, any>): void;
10
12
  methods(function_parameter: Record<string, (...args: any[]) => any>): this;
11
13
  }
package/dist/index.js CHANGED
@@ -55,7 +55,7 @@ class Landaxs {
55
55
  if (ctx.value === this._data[key]) {
56
56
  ctx.checked = true;
57
57
  }
58
- ctx.addEventListener("change", (e) => {
58
+ ctx.addEventListener("input", (e) => {
59
59
  let target = e.currentTarget;
60
60
  this._data[key] = target.value;
61
61
  });
@@ -134,12 +134,25 @@ class Landaxs {
134
134
  return this;
135
135
  }
136
136
  setRef(data) {
137
+ let querySelectorLength = 1;
137
138
  if (typeof data === "string") {
138
- this.ref[data] = document.querySelectorAll(`[x_ref='${data}']`)[0];
139
+ let dom_reference = document.querySelectorAll(`[x_ref='${data}']`);
140
+ if (dom_reference.length > querySelectorLength) {
141
+ this.ref[data] = dom_reference;
142
+ }
143
+ else {
144
+ this.ref[data] = dom_reference[0];
145
+ }
139
146
  }
140
147
  else {
141
148
  data.forEach(ctx => {
142
- this.ref[ctx] = document.querySelectorAll(`[x_ref='${ctx}']`)[0];
149
+ let dom_reference = document.querySelectorAll(`[x_ref='${ctx}']`);
150
+ if (dom_reference.length > querySelectorLength) {
151
+ this.ref[ctx] = dom_reference;
152
+ }
153
+ else {
154
+ this.ref[ctx] = dom_reference[0];
155
+ }
143
156
  });
144
157
  }
145
158
  return this;
@@ -149,12 +162,12 @@ class Landaxs {
149
162
  document.querySelectorAll(`[x_input='${name_input}']`).forEach(ctx => {
150
163
  if (ctx.type === "file") {
151
164
  ctx.addEventListener("change", (e) => {
152
- callback(this._data);
165
+ callback(this.input);
153
166
  });
154
167
  }
155
168
  else {
156
169
  ctx.addEventListener("input", (e) => {
157
- callback(this._data);
170
+ callback(this.input);
158
171
  });
159
172
  }
160
173
  });
@@ -177,6 +190,22 @@ class Landaxs {
177
190
  }
178
191
  return this;
179
192
  }
193
+ setStyle(name_reference, style) {
194
+ for (let [key, value] of Object.entries(style)) {
195
+ this.ref[name_reference].style[key] = value;
196
+ }
197
+ }
198
+ setClass(name_reference, class_name) {
199
+ for (let [key, value] of Object.entries(class_name)) {
200
+ let MATCH_VALUE = true;
201
+ if (value === MATCH_VALUE) {
202
+ this.ref[name_reference].classList.add(key);
203
+ }
204
+ else {
205
+ this.ref[name_reference].classList.remove(key);
206
+ }
207
+ }
208
+ }
180
209
  methods(function_parameter) {
181
210
  this.method = { ...this.method, ...function_parameter };
182
211
  return this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "landaxs",
3
- "version": "1.0.5",
3
+ "version": "1.1.1",
4
4
  "description": "Landaxs is a lightweight library for dynamic input binding with two-way data flow.",
5
5
  "keywords": ["forms", "binding", "javascript", "typescript"],
6
6
  "homepage": "https://github.com/Rakhmadi/Landaxs#readme",