leanweb 1.2.2 → 1.2.5
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 +1 -1
- package/templates/lib/lw-element.js +5 -3
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
|
@@ -230,10 +230,9 @@ export default class LWElement extends HTMLElement {
|
|
|
230
230
|
}
|
|
231
231
|
eventNode[attrName] = true;
|
|
232
232
|
const interpolation = this.ast[attrValue];
|
|
233
|
-
|
|
234
|
-
const context = this._getNodeContext(eventNode);
|
|
235
233
|
interpolation.lwValue.split(',').forEach(eventType => {
|
|
236
234
|
eventNode.addEventListener(eventType.trim(), (event => {
|
|
235
|
+
const context = this._getNodeContext(eventNode);
|
|
237
236
|
const eventContext = { '$event': event, '$node': eventNode };
|
|
238
237
|
const parsed = parser.evaluate(interpolation.ast, [eventContext, ...context], interpolation.loc);
|
|
239
238
|
|
|
@@ -262,8 +261,8 @@ export default class LWElement extends HTMLElement {
|
|
|
262
261
|
}
|
|
263
262
|
modelNode['model_event_bound'] = true;
|
|
264
263
|
const interpolation = this.ast[key];
|
|
265
|
-
const context = this._getNodeContext(modelNode);
|
|
266
264
|
modelNode.addEventListener('input', (event => {
|
|
265
|
+
const context = this._getNodeContext(modelNode);
|
|
267
266
|
const astModel = interpolation.ast[0].expression;
|
|
268
267
|
let object;
|
|
269
268
|
let propertyExpr;
|
|
@@ -462,6 +461,9 @@ export default class LWElement extends HTMLElement {
|
|
|
462
461
|
node.setAttribute('lw-context', '');
|
|
463
462
|
currentNode.insertAdjacentElement('afterend', node);
|
|
464
463
|
}
|
|
464
|
+
if (item && typeof item === 'object') {
|
|
465
|
+
item.getDom = () => node;
|
|
466
|
+
}
|
|
465
467
|
currentNode = node;
|
|
466
468
|
const itemContext = { [interpolation.itemExpr]: item };
|
|
467
469
|
if (interpolation.indexExpr) {
|