juxscript 1.1.286 → 1.1.289

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.
@@ -1 +1 @@
1
- {"version":3,"file":"pageState.d.ts","sourceRoot":"","sources":["../../../lib/state/pageState.ts"],"names":[],"mappings":"AAeA,cAAM,SAAS;IACX,OAAO,CAAC,SAAS,CAA0C;IAC3D,OAAO,CAAC,MAAM,CAAsB;IAEpC,MAAM,CAAC,QAAQ,CAAC,WAAW,mKAQhB;;IA2BX,OAAO,CAAC,qBAAqB;IAoF7B,OAAO,CAAC,SAAS;IA+DjB,OAAO,CAAC,UAAU;IAwBlB,OAAO,CAAC,YAAY;IAkBpB,OAAO,CAAC,cAAc;IAuBtB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,OAAO;IAqBf,OAAO,CAAC,MAAM;IAcd,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAGlC;AAID,eAAO,MAAM,SAAS,qBAAuB,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"pageState.d.ts","sourceRoot":"","sources":["../../../lib/state/pageState.ts"],"names":[],"mappings":"AAeA,cAAM,SAAS;IACX,OAAO,CAAC,SAAS,CAA0C;IAC3D,OAAO,CAAC,MAAM,CAAsB;IAEpC,MAAM,CAAC,QAAQ,CAAC,WAAW,mKAQhB;;IA2BX,OAAO,CAAC,qBAAqB;IAsG7B,OAAO,CAAC,SAAS;IA+DjB,OAAO,CAAC,UAAU;IAwBlB,OAAO,CAAC,YAAY;IAkBpB,OAAO,CAAC,cAAc;IAuBtB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,OAAO;IAqBf,OAAO,CAAC,MAAM;IAmBd,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAGlC;AAID,eAAO,MAAM,SAAS,qBAAuB,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -81,20 +81,40 @@ class PageState {
81
81
  comp[setterName](value);
82
82
  }
83
83
  // Fallback: direct DOM manipulation for known props
84
- else if (prop === 'content' || prop === 'value') {
84
+ else if (prop === 'value') {
85
85
  if (typeof comp.setValue === 'function') {
86
86
  comp.setValue(value);
87
87
  }
88
- else if (typeof comp.setContent === 'function') {
88
+ else {
89
+ const el = this._findElement(comp);
90
+ if (el && 'value' in el) {
91
+ el.value = value;
92
+ }
93
+ }
94
+ }
95
+ else if (prop === 'content') {
96
+ if (typeof comp.setContent === 'function') {
89
97
  comp.setContent(value);
90
98
  }
99
+ else {
100
+ // Direct DOM update for elements that don't have setContent
101
+ const el = this._findElement(comp);
102
+ if (el) {
103
+ el.textContent = value;
104
+ }
105
+ }
91
106
  }
92
107
  else if (prop === 'innerHTML') {
93
108
  if (typeof comp.setInnerHTML === 'function') {
94
109
  comp.setInnerHTML(value);
95
110
  }
111
+ else {
112
+ const el = this._findElement(comp);
113
+ if (el) {
114
+ el.innerHTML = value;
115
+ }
116
+ }
96
117
  }
97
- // Don't call fluent methods as setters — they return `this`
98
118
  // Update tracked props
99
119
  entry.props[prop] = value;
100
120
  // Notify listeners
@@ -252,7 +272,12 @@ class PageState {
252
272
  reactionDeps.set(reaction, new Set());
253
273
  activeReaction = reaction;
254
274
  try {
255
- fn();
275
+ const result = fn();
276
+ if (result && typeof result.catch === 'function') {
277
+ result.catch((err) => {
278
+ console.error('[pageState] async watch error:', err);
279
+ });
280
+ }
256
281
  }
257
282
  finally {
258
283
  activeReaction = null;
@@ -110,6 +110,14 @@ function getLineNumber(source, pos) {
110
110
  return line;
111
111
  }
112
112
 
113
+ function containsAwait(node) {
114
+ let found = false;
115
+ walkSimple(node, {
116
+ AwaitExpression() { found = true; }
117
+ });
118
+ return found;
119
+ }
120
+
113
121
  /**
114
122
  * @param {string} source - Raw .jux source code
115
123
  * @param {string} [filename] - For logging
@@ -236,7 +244,8 @@ export function autowrap(source, filename = '') {
236
244
  const indent = lines[startIdx].match(/^(\s*)/)[1];
237
245
  const newLines = [];
238
246
  for (const group of item.groups) {
239
- newLines.push(`${indent}pageState.__watch(() => {`);
247
+ const needsAsync = group.stmts && group.stmts.some(s => containsAwait(s));
248
+ newLines.push(`${indent}pageState.__watch(${needsAsync ? 'async ' : ''}() => {`);
240
249
  for (const gLine of group.lines) {
241
250
  newLines.push(`${indent} ${gLine.trim()}`);
242
251
  }
@@ -248,8 +257,16 @@ export function autowrap(source, filename = '') {
248
257
  const blockLines = lines.slice(startIdx, endIdx + 1);
249
258
  const indent = blockLines[0].match(/^(\s*)/)[1];
250
259
 
260
+ // Check if any of the original AST statements in this range contain await
261
+ const stmtsInRange = ast.body.filter(s => {
262
+ const sLine = getLineNumber(source, s.start);
263
+ const eLine = getLineNumber(source, s.end);
264
+ return sLine >= item.line && eLine <= item.endLine;
265
+ });
266
+ const needsAsync = stmtsInRange.some(s => containsAwait(s));
267
+
251
268
  const wrapped = [
252
- `${indent}pageState.__watch(() => {`,
269
+ `${indent}pageState.__watch(${needsAsync ? 'async ' : ''}() => {`,
253
270
  ...blockLines.map(l => `${indent} ${l.trim()}`),
254
271
  `${indent}});`,
255
272
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "juxscript",
3
- "version": "1.1.286",
3
+ "version": "1.1.289",
4
4
  "type": "module",
5
5
  "description": "A JavaScript UX authorship platform",
6
6
  "main": "./dist/lib/index.js",