@matthesketh/utopia-compiler 0.7.0 → 0.7.2

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/dist/index.cjs CHANGED
@@ -418,7 +418,7 @@ function classifyDirective(name, value) {
418
418
  return null;
419
419
  }
420
420
  function isDirectiveKind(s) {
421
- return s === "on" || s === "bind" || s === "if" || s === "else" || s === "else-if" || s === "for" || s === "model" || s === "transition";
421
+ return s === "on" || s === "bind" || s === "if" || s === "else" || s === "else-if" || s === "for" || s === "model" || s === "html" || s === "transition";
422
422
  }
423
423
  var CodeGenerator = class {
424
424
  constructor(options) {
@@ -547,6 +547,9 @@ ${fnBody}
547
547
  case "model":
548
548
  this.genModel(elVar, dir, scope);
549
549
  break;
550
+ case "html":
551
+ this.genHtml(elVar, dir, scope);
552
+ break;
550
553
  case "transition":
551
554
  this.genTransition(elVar, dir);
552
555
  break;
@@ -560,6 +563,10 @@ ${fnBody}
560
563
  const OPTION_MODS = /* @__PURE__ */ new Set(["once", "capture", "passive"]);
561
564
  const handlerMods = modifiers.filter((m) => !OPTION_MODS.has(m));
562
565
  const optionMods = modifiers.filter((m) => OPTION_MODS.has(m));
566
+ const IS_HANDLER_REF = /^[\w$.]+$/;
567
+ const IS_ARROW_FN = /^\s*(?:\(.*?\)|[\w$]+)\s*=>/;
568
+ const hasExpression = handler !== "''";
569
+ const isInlineExpr = hasExpression && !IS_HANDLER_REF.test(handler) && !IS_ARROW_FN.test(handler);
563
570
  let handlerExpr = handler;
564
571
  if (handlerMods.length > 0) {
565
572
  const guards = [];
@@ -577,8 +584,18 @@ ${fnBody}
577
584
  break;
578
585
  }
579
586
  }
580
- const body = [...guards, ...calls, `(${handler})(_e)`].join("; ");
581
- handlerExpr = `(_e) => { ${body} }`;
587
+ if (!hasExpression) {
588
+ const body = [...guards, ...calls].join("; ");
589
+ handlerExpr = `(_e) => { ${body} }`;
590
+ } else if (isInlineExpr) {
591
+ const body = [...guards, ...calls, handler.replace(/\$event/g, "_e")].join("; ");
592
+ handlerExpr = `(_e) => { ${body} }`;
593
+ } else {
594
+ const body = [...guards, ...calls, `(${handler})(_e)`].join("; ");
595
+ handlerExpr = `(_e) => { ${body} }`;
596
+ }
597
+ } else if (isInlineExpr) {
598
+ handlerExpr = `(_e) => { ${handler.replace(/\$event/g, "_e")} }`;
582
599
  }
583
600
  const optionsStr = optionMods.length > 0 ? `, { ${optionMods.map((m) => `${m}: true`).join(", ")} }` : "";
584
601
  this.emit(`addEventListener(${elVar}, '${escapeStr(event)}', ${handlerExpr}${optionsStr})`);
@@ -598,6 +615,12 @@ ${fnBody}
598
615
  this.emit(`createEffect(() => setAttr(${elVar}, 'value', ${signalRef}()))`);
599
616
  this.emit(`addEventListener(${elVar}, 'input', (e) => ${signalRef}.set(e.target.value))`);
600
617
  }
618
+ // ---- u-html ---------------------------------------------------------------
619
+ genHtml(elVar, dir, scope) {
620
+ this.helpers.add("setHtml");
621
+ const expr = this.resolveExpression(dir.expression, scope);
622
+ this.emit(`setHtml(${elVar}, () => ${expr})`);
623
+ }
601
624
  // ---- u-transition ---------------------------------------------------------
602
625
  genTransition(elVar, dir) {
603
626
  this.helpers.add("createTransition");
package/dist/index.d.cts CHANGED
@@ -85,7 +85,7 @@ interface Directive {
85
85
  expression: string;
86
86
  modifiers: string[];
87
87
  }
88
- type DirectiveKind = 'on' | 'bind' | 'if' | 'else' | 'else-if' | 'for' | 'model' | 'transition';
88
+ type DirectiveKind = 'on' | 'bind' | 'if' | 'else' | 'else-if' | 'for' | 'model' | 'html' | 'transition';
89
89
  /** Exported for testing — parse a template string into an AST. */
90
90
  declare function parseTemplate(source: string): TemplateNode[];
91
91
 
package/dist/index.d.ts CHANGED
@@ -85,7 +85,7 @@ interface Directive {
85
85
  expression: string;
86
86
  modifiers: string[];
87
87
  }
88
- type DirectiveKind = 'on' | 'bind' | 'if' | 'else' | 'else-if' | 'for' | 'model' | 'transition';
88
+ type DirectiveKind = 'on' | 'bind' | 'if' | 'else' | 'else-if' | 'for' | 'model' | 'html' | 'transition';
89
89
  /** Exported for testing — parse a template string into an AST. */
90
90
  declare function parseTemplate(source: string): TemplateNode[];
91
91
 
package/dist/index.js CHANGED
@@ -385,7 +385,7 @@ function classifyDirective(name, value) {
385
385
  return null;
386
386
  }
387
387
  function isDirectiveKind(s) {
388
- return s === "on" || s === "bind" || s === "if" || s === "else" || s === "else-if" || s === "for" || s === "model" || s === "transition";
388
+ return s === "on" || s === "bind" || s === "if" || s === "else" || s === "else-if" || s === "for" || s === "model" || s === "html" || s === "transition";
389
389
  }
390
390
  var CodeGenerator = class {
391
391
  constructor(options) {
@@ -514,6 +514,9 @@ ${fnBody}
514
514
  case "model":
515
515
  this.genModel(elVar, dir, scope);
516
516
  break;
517
+ case "html":
518
+ this.genHtml(elVar, dir, scope);
519
+ break;
517
520
  case "transition":
518
521
  this.genTransition(elVar, dir);
519
522
  break;
@@ -527,6 +530,10 @@ ${fnBody}
527
530
  const OPTION_MODS = /* @__PURE__ */ new Set(["once", "capture", "passive"]);
528
531
  const handlerMods = modifiers.filter((m) => !OPTION_MODS.has(m));
529
532
  const optionMods = modifiers.filter((m) => OPTION_MODS.has(m));
533
+ const IS_HANDLER_REF = /^[\w$.]+$/;
534
+ const IS_ARROW_FN = /^\s*(?:\(.*?\)|[\w$]+)\s*=>/;
535
+ const hasExpression = handler !== "''";
536
+ const isInlineExpr = hasExpression && !IS_HANDLER_REF.test(handler) && !IS_ARROW_FN.test(handler);
530
537
  let handlerExpr = handler;
531
538
  if (handlerMods.length > 0) {
532
539
  const guards = [];
@@ -544,8 +551,18 @@ ${fnBody}
544
551
  break;
545
552
  }
546
553
  }
547
- const body = [...guards, ...calls, `(${handler})(_e)`].join("; ");
548
- handlerExpr = `(_e) => { ${body} }`;
554
+ if (!hasExpression) {
555
+ const body = [...guards, ...calls].join("; ");
556
+ handlerExpr = `(_e) => { ${body} }`;
557
+ } else if (isInlineExpr) {
558
+ const body = [...guards, ...calls, handler.replace(/\$event/g, "_e")].join("; ");
559
+ handlerExpr = `(_e) => { ${body} }`;
560
+ } else {
561
+ const body = [...guards, ...calls, `(${handler})(_e)`].join("; ");
562
+ handlerExpr = `(_e) => { ${body} }`;
563
+ }
564
+ } else if (isInlineExpr) {
565
+ handlerExpr = `(_e) => { ${handler.replace(/\$event/g, "_e")} }`;
549
566
  }
550
567
  const optionsStr = optionMods.length > 0 ? `, { ${optionMods.map((m) => `${m}: true`).join(", ")} }` : "";
551
568
  this.emit(`addEventListener(${elVar}, '${escapeStr(event)}', ${handlerExpr}${optionsStr})`);
@@ -565,6 +582,12 @@ ${fnBody}
565
582
  this.emit(`createEffect(() => setAttr(${elVar}, 'value', ${signalRef}()))`);
566
583
  this.emit(`addEventListener(${elVar}, 'input', (e) => ${signalRef}.set(e.target.value))`);
567
584
  }
585
+ // ---- u-html ---------------------------------------------------------------
586
+ genHtml(elVar, dir, scope) {
587
+ this.helpers.add("setHtml");
588
+ const expr = this.resolveExpression(dir.expression, scope);
589
+ this.emit(`setHtml(${elVar}, () => ${expr})`);
590
+ }
568
591
  // ---- u-transition ---------------------------------------------------------
569
592
  genTransition(elVar, dir) {
570
593
  this.helpers.add("createTransition");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matthesketh/utopia-compiler",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "Compiler for .utopia single-file components",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -38,11 +38,11 @@
38
38
  "files": [
39
39
  "dist"
40
40
  ],
41
- "dependencies": {
42
- "@matthesketh/utopia-core": "0.7.0"
43
- },
44
41
  "scripts": {
45
42
  "build": "tsup src/index.ts --format esm,cjs --dts",
46
43
  "dev": "tsup src/index.ts --format esm,cjs --dts --watch"
44
+ },
45
+ "dependencies": {
46
+ "@matthesketh/utopia-core": "^0.7.x"
47
47
  }
48
- }
48
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Matt Hesketh
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.