leanweb 1.2.3 → 1.2.6
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
|
@@ -253,8 +253,8 @@ items = ["one", "two", "three"];
|
|
|
253
253
|
|
|
254
254
|
#### access DOM from lw-for
|
|
255
255
|
|
|
256
|
-
|
|
257
|
-
|
|
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
258
|
|
|
259
259
|
### lw-model and lw-on:
|
|
260
260
|
|
|
@@ -324,14 +324,13 @@ imageWidth = 400;
|
|
|
324
324
|
`demo-parent.html`
|
|
325
325
|
|
|
326
326
|
```html
|
|
327
|
-
<demo-child lw-input:parent="
|
|
327
|
+
<demo-child lw-input:parent="this" lw-input:userData="user"></demo-child>
|
|
328
328
|
```
|
|
329
329
|
|
|
330
330
|
`demo-parent.js`
|
|
331
331
|
|
|
332
332
|
```javascript
|
|
333
333
|
// ...
|
|
334
|
-
// self is defined in LWElement as `self = this`;
|
|
335
334
|
user = { firstname: "Qian", lastname: "Chen" };
|
|
336
335
|
// ...
|
|
337
336
|
```
|
package/package.json
CHANGED
|
@@ -97,7 +97,6 @@ const nextAllSiblings = (el, selector) => {
|
|
|
97
97
|
};
|
|
98
98
|
|
|
99
99
|
export default class LWElement extends HTMLElement {
|
|
100
|
-
self = this;
|
|
101
100
|
constructor(ast) {
|
|
102
101
|
super();
|
|
103
102
|
this.ast = ast;
|
|
@@ -133,7 +132,7 @@ export default class LWElement extends HTMLElement {
|
|
|
133
132
|
|
|
134
133
|
_getNodeContext(node) {
|
|
135
134
|
const contextNode = node.closest('[lw-context]');
|
|
136
|
-
return contextNode?.['lw-context'] ?? [this, globalThis];
|
|
135
|
+
return contextNode?.['lw-context'] ?? [{ 'this': this }, this, globalThis];
|
|
137
136
|
}
|
|
138
137
|
|
|
139
138
|
update(rootNode = this.shadowRoot) {
|
|
@@ -230,10 +229,9 @@ export default class LWElement extends HTMLElement {
|
|
|
230
229
|
}
|
|
231
230
|
eventNode[attrName] = true;
|
|
232
231
|
const interpolation = this.ast[attrValue];
|
|
233
|
-
|
|
234
|
-
const context = this._getNodeContext(eventNode);
|
|
235
232
|
interpolation.lwValue.split(',').forEach(eventType => {
|
|
236
233
|
eventNode.addEventListener(eventType.trim(), (event => {
|
|
234
|
+
const context = this._getNodeContext(eventNode);
|
|
237
235
|
const eventContext = { '$event': event, '$node': eventNode };
|
|
238
236
|
const parsed = parser.evaluate(interpolation.ast, [eventContext, ...context], interpolation.loc);
|
|
239
237
|
|
|
@@ -262,8 +260,8 @@ export default class LWElement extends HTMLElement {
|
|
|
262
260
|
}
|
|
263
261
|
modelNode['model_event_bound'] = true;
|
|
264
262
|
const interpolation = this.ast[key];
|
|
265
|
-
const context = this._getNodeContext(modelNode);
|
|
266
263
|
modelNode.addEventListener('input', (event => {
|
|
264
|
+
const context = this._getNodeContext(modelNode);
|
|
267
265
|
const astModel = interpolation.ast[0].expression;
|
|
268
266
|
let object;
|
|
269
267
|
let propertyExpr;
|
|
@@ -127,6 +127,14 @@ const nodeHandlers = {
|
|
|
127
127
|
return context[node.name];
|
|
128
128
|
}
|
|
129
129
|
},
|
|
130
|
+
'ThisExpression': (node, context) => {
|
|
131
|
+
if (Array.isArray(context)) {
|
|
132
|
+
const hitContext = context.find(contextObj => 'this' in contextObj);
|
|
133
|
+
return hitContext ? hitContext['this'] : undefined;
|
|
134
|
+
} else if (typeof context === 'object') {
|
|
135
|
+
return context['this'];
|
|
136
|
+
}
|
|
137
|
+
},
|
|
130
138
|
|
|
131
139
|
'CallExpression': (node, context) => callFunction(node, context),
|
|
132
140
|
'OptionalCallExpression': (node, context) => callFunction(node, context),
|