leanweb 1.2.4 → 1.2.7

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
@@ -324,14 +324,13 @@ imageWidth = 400;
324
324
  `demo-parent.html`
325
325
 
326
326
  ```html
327
- <demo-child lw-input:parent="self" lw-input:userData="user"></demo-child>
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leanweb",
3
- "version": "1.2.4",
3
+ "version": "1.2.7",
4
4
  "description": "Builds framework agnostic web components.",
5
5
  "bin": {
6
6
  "leanweb": "leanweb.js",
@@ -35,10 +35,10 @@
35
35
  "node-watch": "^0.7.3",
36
36
  "parse5": "^7.0.0",
37
37
  "raw-loader": "^4.0.2",
38
- "sass": "^1.54.3",
38
+ "sass": "^1.54.4",
39
39
  "sass-loader": "^13.0.2",
40
40
  "semver": "^7.3.7",
41
41
  "webpack": "^5.74.0",
42
- "webpack-dev-server": "^4.9.3"
42
+ "webpack-dev-server": "^4.10.0"
43
43
  }
44
44
  }
@@ -77,6 +77,7 @@ globalThis.addEventListener('hashchange', () => {
77
77
  leanweb.componentsListeningOnUrlChanges.forEach(component => {
78
78
  setTimeout(() => {
79
79
  component?.urlHashChanged?.call(component);
80
+ component?.update?.call(component);
80
81
  });
81
82
  });
82
83
  }, false);
@@ -97,7 +98,6 @@ const nextAllSiblings = (el, selector) => {
97
98
  };
98
99
 
99
100
  export default class LWElement extends HTMLElement {
100
- self = this;
101
101
  constructor(ast) {
102
102
  super();
103
103
  this.ast = ast;
@@ -133,7 +133,7 @@ export default class LWElement extends HTMLElement {
133
133
 
134
134
  _getNodeContext(node) {
135
135
  const contextNode = node.closest('[lw-context]');
136
- return contextNode?.['lw-context'] ?? [this, globalThis];
136
+ return contextNode?.['lw-context'] ?? [{ 'this': this }, this, globalThis];
137
137
  }
138
138
 
139
139
  update(rootNode = this.shadowRoot) {
@@ -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;
@@ -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),