leanweb 1.2.1 → 1.2.4
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 +25 -0
- package/package.json +3 -3
- package/templates/lib/lw-element.js +18 -10
package/README.md
CHANGED
|
@@ -251,6 +251,11 @@ items = ["one", "two", "three"];
|
|
|
251
251
|
2: three
|
|
252
252
|
```
|
|
253
253
|
|
|
254
|
+
#### access DOM from lw-for
|
|
255
|
+
|
|
256
|
+
You could access DOM nodes for each element in a `lw-for` loop by calling
|
|
257
|
+
`elem.getDom()` as long as `typeof elem` evaluates `object`.
|
|
258
|
+
|
|
254
259
|
### lw-model and lw-on:
|
|
255
260
|
|
|
256
261
|
```html
|
|
@@ -350,6 +355,8 @@ Here is a few examples how Leanweb helps web components work with form binding.
|
|
|
350
355
|
|
|
351
356
|
### Checkbox
|
|
352
357
|
|
|
358
|
+
#### Multiple chechboxes bound to an array
|
|
359
|
+
|
|
353
360
|
```javascript
|
|
354
361
|
// ...
|
|
355
362
|
items = ['one', 'two', 'three'];
|
|
@@ -375,6 +382,24 @@ checkedValues = [];
|
|
|
375
382
|
|
|
376
383
|
<img src='https://leanweb.app/images/leanweb-form-binding-checkbox.gif' alt='Leanweb Form Binding Checkbox'/>
|
|
377
384
|
|
|
385
|
+
#### Single checkbox bound to a boolean value
|
|
386
|
+
|
|
387
|
+
```javascript
|
|
388
|
+
checked = false;
|
|
389
|
+
toggleCheckbox() {
|
|
390
|
+
this.checked = !this.checked;
|
|
391
|
+
this.update();
|
|
392
|
+
}
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
```html
|
|
396
|
+
<button lw-on:click="toggleCheckbox()">Toggle Checkbox</button>
|
|
397
|
+
<div>
|
|
398
|
+
<input type="checkbox" lw-model="checked" />
|
|
399
|
+
<span lw>checked</span>
|
|
400
|
+
</div>
|
|
401
|
+
```
|
|
402
|
+
|
|
378
403
|
### Select
|
|
379
404
|
|
|
380
405
|
```javascript
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "leanweb",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "Builds framework agnostic web components.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"leanweb": "leanweb.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@babel/core": "^7.18.10",
|
|
24
|
-
"@babel/parser": "^7.18.
|
|
24
|
+
"@babel/parser": "^7.18.11",
|
|
25
25
|
"@babel/plugin-transform-runtime": "^7.18.10",
|
|
26
26
|
"@babel/preset-env": "^7.18.10",
|
|
27
27
|
"babel-loader": "^8.2.5",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"node-watch": "^0.7.3",
|
|
36
36
|
"parse5": "^7.0.0",
|
|
37
37
|
"raw-loader": "^4.0.2",
|
|
38
|
-
"sass": "^1.54.
|
|
38
|
+
"sass": "^1.54.3",
|
|
39
39
|
"sass-loader": "^13.0.2",
|
|
40
40
|
"semver": "^7.3.7",
|
|
41
41
|
"webpack": "^5.74.0",
|
|
@@ -284,16 +284,17 @@ export default class LWElement extends HTMLElement {
|
|
|
284
284
|
modelNode.do_not_update = true;
|
|
285
285
|
object[propertyExpr] = modelNode.value * 1;
|
|
286
286
|
} else if (modelNode.type === 'checkbox') {
|
|
287
|
-
if (
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
object[propertyExpr].splice(index, 1);
|
|
287
|
+
if (Array.isArray(object[propertyExpr])) {
|
|
288
|
+
if (modelNode.checked) {
|
|
289
|
+
object[propertyExpr].push(modelNode.value);
|
|
290
|
+
} else {
|
|
291
|
+
const index = object[propertyExpr].indexOf(modelNode.value);
|
|
292
|
+
if (index > -1) {
|
|
293
|
+
object[propertyExpr].splice(index, 1);
|
|
294
|
+
}
|
|
296
295
|
}
|
|
296
|
+
} else {
|
|
297
|
+
object[propertyExpr] = modelNode.checked;
|
|
297
298
|
}
|
|
298
299
|
} else if (modelNode.type === 'select-multiple') {
|
|
299
300
|
if (!Array.isArray(object[propertyExpr])) {
|
|
@@ -326,7 +327,11 @@ export default class LWElement extends HTMLElement {
|
|
|
326
327
|
const interpolation = this.ast[key];
|
|
327
328
|
const parsed = parser.evaluate(interpolation.ast, context, interpolation.loc);
|
|
328
329
|
if (modelNode.type === 'checkbox') {
|
|
329
|
-
|
|
330
|
+
if (Array.isArray(parsed[0])) {
|
|
331
|
+
modelNode.checked = parsed[0].includes?.(modelNode.value);
|
|
332
|
+
} else {
|
|
333
|
+
modelNode.checked = !!parsed[0];
|
|
334
|
+
}
|
|
330
335
|
} else if (modelNode.type === 'radio') {
|
|
331
336
|
modelNode.checked = parsed[0] === modelNode.value;
|
|
332
337
|
} else if (modelNode.type === 'select-multiple') {
|
|
@@ -457,6 +462,9 @@ export default class LWElement extends HTMLElement {
|
|
|
457
462
|
node.setAttribute('lw-context', '');
|
|
458
463
|
currentNode.insertAdjacentElement('afterend', node);
|
|
459
464
|
}
|
|
465
|
+
if (item && typeof item === 'object') {
|
|
466
|
+
item.getDom = () => node;
|
|
467
|
+
}
|
|
460
468
|
currentNode = node;
|
|
461
469
|
const itemContext = { [interpolation.itemExpr]: item };
|
|
462
470
|
if (interpolation.indexExpr) {
|