@adaas/are-html 0.0.23 → 0.0.25

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.
Files changed (81) hide show
  1. package/dist/browser/index.d.mts +18 -2
  2. package/dist/browser/index.mjs +35 -10
  3. package/dist/browser/index.mjs.map +1 -1
  4. package/dist/node/directives/AreDirectiveIf.directive.d.mts +17 -1
  5. package/dist/node/directives/AreDirectiveIf.directive.d.ts +17 -1
  6. package/dist/node/directives/AreDirectiveIf.directive.js +29 -6
  7. package/dist/node/directives/AreDirectiveIf.directive.js.map +1 -1
  8. package/dist/node/directives/AreDirectiveIf.directive.mjs +29 -6
  9. package/dist/node/directives/AreDirectiveIf.directive.mjs.map +1 -1
  10. package/dist/node/engine/AreHTML.compiler.d.mts +3 -1
  11. package/dist/node/engine/AreHTML.compiler.d.ts +3 -1
  12. package/dist/node/engine/AreHTML.compiler.js +7 -4
  13. package/dist/node/engine/AreHTML.compiler.js.map +1 -1
  14. package/dist/node/engine/AreHTML.compiler.mjs +7 -4
  15. package/dist/node/engine/AreHTML.compiler.mjs.map +1 -1
  16. package/examples/for-perf/dist/index.html +1 -1
  17. package/examples/for-perf/dist/{mqj1mpf2-z4aokv.js → mqp8i2py-vltsx0.js} +2488 -2373
  18. package/examples/lazy-loading/README.md +76 -0
  19. package/examples/lazy-loading/concept.ts +55 -0
  20. package/examples/lazy-loading/containers/UI.container.ts +215 -0
  21. package/examples/lazy-loading/dist/app.js +3803 -0
  22. package/examples/{for-perf/dist/mqj1mpff-4fr7mw.js → lazy-loading/dist/chunks/chunk-6K72IBO4.js} +2688 -5897
  23. package/examples/lazy-loading/dist/index.html +36 -0
  24. package/examples/lazy-loading/dist/lazy/about-page.js +59 -0
  25. package/examples/lazy-loading/dist/lazy/reports-page.js +65 -0
  26. package/examples/lazy-loading/dist/lazy/settings-page.js +54 -0
  27. package/examples/lazy-loading/public/index.html +36 -0
  28. package/examples/lazy-loading/src/components/AppShell.component.ts +44 -0
  29. package/examples/lazy-loading/src/components/HomePage.component.ts +59 -0
  30. package/examples/lazy-loading/src/components/LazyOutlet.component.ts +108 -0
  31. package/examples/lazy-loading/src/components/NavBar.component.ts +98 -0
  32. package/examples/lazy-loading/src/concept.ts +116 -0
  33. package/examples/lazy-loading/src/lazy/AboutPage.component.ts +54 -0
  34. package/examples/lazy-loading/src/lazy/ReportsPage.component.ts +56 -0
  35. package/examples/lazy-loading/src/lazy/SettingsPage.component.ts +45 -0
  36. package/examples/lazy-loading/src/runtime/ComponentManifest.fragment.ts +61 -0
  37. package/examples/lazy-loading/src/runtime/LazyComponentResolver.fragment.ts +77 -0
  38. package/examples/os-desktop/README.md +91 -0
  39. package/examples/os-desktop/concept.ts +54 -0
  40. package/examples/os-desktop/containers/OS.container.ts +198 -0
  41. package/examples/os-desktop/containers/apps/AppBackend.ts +29 -0
  42. package/examples/os-desktop/containers/apps/GanttApp.backend.ts +56 -0
  43. package/examples/os-desktop/containers/apps/MarketingApp.backend.ts +68 -0
  44. package/examples/os-desktop/dist/app.js +4410 -0
  45. package/examples/os-desktop/dist/apps/gantt/app.js +271 -0
  46. package/examples/os-desktop/dist/apps/marketing/app.js +346 -0
  47. package/examples/os-desktop/dist/chunks/chunk-6K72IBO4.js +12455 -0
  48. package/examples/os-desktop/dist/chunks/chunk-EIIGUL6N.js +30 -0
  49. package/examples/os-desktop/dist/chunks/chunk-WOH7L5UR.js +30 -0
  50. package/examples/os-desktop/dist/index.html +33 -0
  51. package/examples/os-desktop/public/index.html +33 -0
  52. package/examples/os-desktop/src/apps/gantt/GanttApp.component.ts +41 -0
  53. package/examples/os-desktop/src/apps/gantt/GanttChart.component.ts +126 -0
  54. package/examples/os-desktop/src/apps/gantt/GanttStore.ts +47 -0
  55. package/examples/os-desktop/src/apps/gantt/GanttToolbar.component.ts +73 -0
  56. package/examples/os-desktop/src/apps/gantt/index.ts +13 -0
  57. package/examples/os-desktop/src/apps/marketing/MarketingApp.component.ts +53 -0
  58. package/examples/os-desktop/src/apps/marketing/MarketingStore.ts +34 -0
  59. package/examples/os-desktop/src/apps/marketing/PostEditor.component.ts +153 -0
  60. package/examples/os-desktop/src/apps/marketing/PostPreview.component.ts +110 -0
  61. package/examples/os-desktop/src/apps/marketing/index.ts +16 -0
  62. package/examples/os-desktop/src/concept.ts +126 -0
  63. package/examples/os-desktop/src/os/AppStage.component.ts +112 -0
  64. package/examples/os-desktop/src/os/AppWindow.component.ts +102 -0
  65. package/examples/os-desktop/src/os/Desktop.component.ts +106 -0
  66. package/examples/os-desktop/src/os/Dock.component.ts +174 -0
  67. package/examples/os-desktop/src/os/Hud.component.ts +83 -0
  68. package/examples/os-desktop/src/os/Launchpad.component.ts +191 -0
  69. package/examples/os-desktop/src/os/MenuBar.component.ts +156 -0
  70. package/examples/os-desktop/src/runtime/AppComponentResolver.fragment.ts +121 -0
  71. package/examples/os-desktop/src/runtime/AppRegistry.fragment.ts +104 -0
  72. package/examples/os-desktop/src/signals/MouseState.signal.ts +34 -0
  73. package/examples/os-desktop/src/signals/OSRoute.signal.ts +37 -0
  74. package/examples/os-desktop/src/signals/SelectionState.signal.ts +34 -0
  75. package/examples/signal-routing/dist/index.html +1 -1
  76. package/examples/signal-routing/dist/{mqiwo23h-bhcolu.js → mqp8hgce-4d6rh0.js} +2911 -2708
  77. package/package.json +11 -7
  78. package/src/directives/AreDirectiveIf.directive.ts +33 -4
  79. package/src/engine/AreHTML.compiler.ts +12 -2
  80. package/tests/PropPropagation.test.ts +181 -0
  81. package/tests/jest.setup.ts +11 -0
@@ -27,7 +27,23 @@ import '@adaas/a-utils/a-execution';
27
27
  declare class AreDirectiveIf extends AreDirective {
28
28
  transform(attribute: AreDirectiveAttribute, scope: A_Scope, store: AreStore, scene: AreScene, logger: A_Logger, ...args: any[]): void;
29
29
  compile(attribute: AreDirectiveAttribute, store: AreStore, scene: AreScene, syntax: AreSyntax, directiveContext?: AreDirectiveContext, ...args: any[]): void;
30
- update(attribute: AreDirectiveAttribute, store: AreStore, scope: A_Scope, syntax: AreSyntax, scene: AreScene, ...args: any[]): void;
30
+ update(attribute: AreDirectiveAttribute, store: AreStore, scope: A_Scope, syntax: AreSyntax, scene: AreScene, directiveContext?: AreDirectiveContext, ...args: any[]): void;
31
+ /**
32
+ * Evaluates the `$if` condition defensively.
33
+ *
34
+ * A condition can reference data that is momentarily unavailable — most
35
+ * commonly a nested `$if` (e.g. `$if="selected.fields.length"`) living
36
+ * inside a parent `$if="selected"` whose object has just become `null`.
37
+ * Because the nested directive is still subscribed to the store, its
38
+ * update fires on that same change and the raw expression would throw
39
+ * `Cannot read properties of null`, crashing the whole update pipeline.
40
+ *
41
+ * Treating an evaluation error as `false` is the correct contract for a
42
+ * conditional: if the condition cannot be resolved, the subtree simply
43
+ * stays hidden until the referenced data is present again (at which point
44
+ * the parent `$if` re-activates and re-evaluates this one).
45
+ */
46
+ private evaluateCondition;
31
47
  }
32
48
 
33
49
  export { AreDirectiveIf };
@@ -27,7 +27,23 @@ import '@adaas/a-utils/a-execution';
27
27
  declare class AreDirectiveIf extends AreDirective {
28
28
  transform(attribute: AreDirectiveAttribute, scope: A_Scope, store: AreStore, scene: AreScene, logger: A_Logger, ...args: any[]): void;
29
29
  compile(attribute: AreDirectiveAttribute, store: AreStore, scene: AreScene, syntax: AreSyntax, directiveContext?: AreDirectiveContext, ...args: any[]): void;
30
- update(attribute: AreDirectiveAttribute, store: AreStore, scope: A_Scope, syntax: AreSyntax, scene: AreScene, ...args: any[]): void;
30
+ update(attribute: AreDirectiveAttribute, store: AreStore, scope: A_Scope, syntax: AreSyntax, scene: AreScene, directiveContext?: AreDirectiveContext, ...args: any[]): void;
31
+ /**
32
+ * Evaluates the `$if` condition defensively.
33
+ *
34
+ * A condition can reference data that is momentarily unavailable — most
35
+ * commonly a nested `$if` (e.g. `$if="selected.fields.length"`) living
36
+ * inside a parent `$if="selected"` whose object has just become `null`.
37
+ * Because the nested directive is still subscribed to the store, its
38
+ * update fires on that same change and the raw expression would throw
39
+ * `Cannot read properties of null`, crashing the whole update pipeline.
40
+ *
41
+ * Treating an evaluation error as `false` is the correct contract for a
42
+ * conditional: if the condition cannot be resolved, the subtree simply
43
+ * stays hidden until the referenced data is present again (at which point
44
+ * the parent `$if` re-activates and re-evaluates this one).
45
+ */
46
+ private evaluateCondition;
31
47
  }
32
48
 
33
49
  export { AreDirectiveIf };
@@ -35,9 +35,7 @@ exports.AreDirectiveIf = class AreDirectiveIf extends AreDirective_component.Are
35
35
  attribute.template = ifTemplate;
36
36
  }
37
37
  compile(attribute, store, scene, syntax, directiveContext, ...args) {
38
- attribute.value = syntax.evaluate(attribute.content, store, {
39
- ...directiveContext?.scope || {}
40
- });
38
+ attribute.value = this.evaluateCondition(syntax, attribute, store, directiveContext);
41
39
  const hostInstruction = scene.host;
42
40
  const commentIdentifier = ` --- if: ${attribute.template.id} --- `;
43
41
  const declaration = new AddComment_instruction.AddCommentInstruction({ content: commentIdentifier });
@@ -49,9 +47,9 @@ exports.AreDirectiveIf = class AreDirectiveIf extends AreDirective_component.Are
49
47
  else
50
48
  attribute.template.scene.deactivate();
51
49
  }
52
- update(attribute, store, scope, syntax, scene, ...args) {
50
+ update(attribute, store, scope, syntax, scene, directiveContext, ...args) {
53
51
  const previous = !!attribute.value;
54
- const next = !!syntax.evaluate(attribute.content, store);
52
+ const next = this.evaluateCondition(syntax, attribute, store, directiveContext);
55
53
  attribute.value = next;
56
54
  if (previous === next) return;
57
55
  if (next) {
@@ -62,6 +60,30 @@ exports.AreDirectiveIf = class AreDirectiveIf extends AreDirective_component.Are
62
60
  attribute.template.scene.deactivate();
63
61
  }
64
62
  }
63
+ /**
64
+ * Evaluates the `$if` condition defensively.
65
+ *
66
+ * A condition can reference data that is momentarily unavailable — most
67
+ * commonly a nested `$if` (e.g. `$if="selected.fields.length"`) living
68
+ * inside a parent `$if="selected"` whose object has just become `null`.
69
+ * Because the nested directive is still subscribed to the store, its
70
+ * update fires on that same change and the raw expression would throw
71
+ * `Cannot read properties of null`, crashing the whole update pipeline.
72
+ *
73
+ * Treating an evaluation error as `false` is the correct contract for a
74
+ * conditional: if the condition cannot be resolved, the subtree simply
75
+ * stays hidden until the referenced data is present again (at which point
76
+ * the parent `$if` re-activates and re-evaluates this one).
77
+ */
78
+ evaluateCondition(syntax, attribute, store, directiveContext) {
79
+ try {
80
+ return !!syntax.evaluate(attribute.content, store, {
81
+ ...directiveContext?.scope || {}
82
+ });
83
+ } catch {
84
+ return false;
85
+ }
86
+ }
65
87
  };
66
88
  __decorateClass([
67
89
  AreDirective_component.AreDirective.Transform,
@@ -85,7 +107,8 @@ __decorateClass([
85
107
  __decorateParam(1, aConcept.A_Inject(are.AreStore)),
86
108
  __decorateParam(2, aConcept.A_Inject(aConcept.A_Scope)),
87
109
  __decorateParam(3, aConcept.A_Inject(are.AreSyntax)),
88
- __decorateParam(4, aConcept.A_Inject(are.AreScene))
110
+ __decorateParam(4, aConcept.A_Inject(are.AreScene)),
111
+ __decorateParam(5, aConcept.A_Inject(AreDirective_context.AreDirectiveContext))
89
112
  ], exports.AreDirectiveIf.prototype, "update", 1);
90
113
  exports.AreDirectiveIf = __decorateClass([
91
114
  core.A_Frame.Define({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/directives/AreDirectiveIf.directive.ts"],"names":["AreDirectiveIf","AreDirective","AddCommentInstruction","A_Caller","A_Scope","AreStore","AreScene","A_Logger","AreSyntax","AreDirectiveContext","A_Frame"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkCaA,sBAAA,GAAN,6BAA6BC,mCAAA,CAAa;AAAA,EAI7C,UACwB,SAAA,EACD,KAAA,EAEC,KAAA,EACA,KAAA,EACA,WACjB,IAAA,EACL;AACE,IAAA,MAAA,CAAO,MAAM,CAAA,+BAAA,EAAkC,SAAA,CAAU,MAAM,KAAA,CAAM,QAAA,EAAU,CAAA,CAAA,CAAG,CAAA;AAElF,IAAA,MAAM,OAAO,SAAA,CAAU,KAAA;AAKvB,IAAA,MAAM,UAAA,GAAa,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A,CAAa,MAAA;AAAA,EAET,qCAASE,iBAAQ,CAAA,CAAA;AAAA,EACjB,qCAASE,YAAQ,CAAA,CAAA;AAAA,EACjB,qCAASD,gBAAO,CAAA,CAAA;AAAA,EAChB,qCAASI,aAAS,CAAA,CAAA;AAAA,EAClB,qCAASF,YAAQ,CAAA;AAAA,CAAA,EA9FbN,sBAAA,CAyFT,SAAA,EAAA,QAAA,EAAA,CAAA,CAAA;AAzFSA,sBAAA,GAAN,eAAA,CAAA;AAAA,EALNU,aAAQ,MAAA,CAAO;AAAA,IACZ,SAAA,EAAW,YAAA;AAAA,IACX,WAAA,EAAa;AAAA,GAChB,CAAA;AAAA,EACAT,mCAAA,CAAa,SAAS,CAAC;AAAA,CAAA,EACXD,sBAAA,CAAA","file":"AreDirectiveIf.directive.js","sourcesContent":["import { A_Caller, A_Inject, A_Scope } from \"@adaas/a-concept\";\nimport { A_Logger } from \"@adaas/a-utils/a-logger\";\nimport { AreDirectiveAttribute } from \"@adaas/are-html/attributes/AreDirective.attribute\";\nimport { AreScene, AreStore, AreSyntax } from \"@adaas/are\";\nimport { AreDirective } from \"@adaas/are-html/directive/AreDirective.component\";\nimport { AddCommentInstruction } from \"@adaas/are-html/instructions/AddComment.instruction\";\nimport { AreDirectiveContext } from \"@adaas/are-html/directive/AreDirective.context\";\nimport { A_Frame } from \"@adaas/a-frame/core\";\n\n\n\n/**\n * `$if` directive — conditionally renders a node based on an expression.\n *\n * ⚠️ Known limitation: do NOT use `$if` and `$for` on the SAME element.\n * Doing so produces duplicated DOM on toggle because the two directives\n * share an owner node and clone its scope independently. Wrap one in a\n * parent element instead, e.g.:\n *\n * <div $if=\"visible\">\n * <li $for=\"item in items\">{{item.name}}</li>\n * </div>\n *\n * or\n *\n * <ul $for=\"item in items\">\n * <li $if=\"item.visible\">{{item.name}}</li>\n * </ul>\n */\n@A_Frame.Define({\n namespace: 'a-are-html',\n description: 'Built-in $if directive. Conditionally renders a subtree based on a store expression. Replaces the target element with a stable comment anchor when the condition is false and restores the fully rendered subtree when it becomes true, preventing any leaking of the host element between states.'\n})\n@AreDirective.Priority(2)\nexport class AreDirectiveIf extends AreDirective {\n\n\n @AreDirective.Transform\n transform(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(A_Scope) scope: A_Scope,\n\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreScene) scene: AreScene,\n @A_Inject(A_Logger) logger: A_Logger,\n ...args: any[]\n ) {\n logger.debug(`[Transform] directive $IF for <${attribute.owner.aseid.toString()}>`)\n\n const node = attribute.owner;\n\n /**\n * We have to keep this node as a group node, and copy all data into the child node that would be actual node. \n */\n const ifTemplate = node.cloneWithScope();\n\n const ifAttr = ifTemplate.attributes.find(d => d.name === attribute.name);\n\n if (ifAttr) {\n ifTemplate.scope.deregister(ifAttr);\n node.scope.register(ifAttr);\n }\n\n node.init();\n\n node.addChild(ifTemplate);\n\n /**\n * Resolve or create a directive context for the item node. This is needed to hold the item-specific store values (e.g. the \"item\" and \"index\" in a \"for\" loop) that the template's bindings will reference during compile and update. The context is shared among all clones of the same template, but that's fine because each clone gets its own scope values assigned here.\n */\n // let directiveContext = ifTemplate.scope.resolveFlat(AreDirectiveContext);\n\n // if (!directiveContext) {\n // directiveContext = new AreDirectiveContext(ifTemplate.aseid);\n // ifTemplate.scope.register(directiveContext);\n // }\n\n ifTemplate.scene.deactivate();\n\n attribute.template = ifTemplate;\n\n }\n\n\n @AreDirective.Compile\n compile(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreScene) scene: AreScene,\n @A_Inject(AreSyntax) syntax: AreSyntax,\n\n @A_Inject(AreDirectiveContext) directiveContext?: AreDirectiveContext,\n ...args: any[]\n ): void {\n /**\n * 1. Extract the value from the store based on the attribute content\n * (which is the path to the value in the store)\n */\n attribute.value = syntax.evaluate(attribute.content, store, {\n ...(directiveContext?.scope || {}),\n });\n\n /**\n * 2. If the value is falsy, remove the node from the scene by planning a RemoveElement instruction.\n * If the value is truthy, ensure the node is in the scene by planning an AddElement instruction if it's not already planned.\n */\n const hostInstruction = scene.host!;\n const commentIdentifier = ` --- if: ${attribute.template!.id} --- `;\n const declaration = new AddCommentInstruction({ content: commentIdentifier })\n\n scene.setHost(declaration);\n scene.planBefore(declaration, hostInstruction);\n scene.unPlan(hostInstruction);\n\n if (attribute.value)\n attribute.template!.scene.activate();\n else\n attribute.template!.scene.deactivate();\n }\n\n\n\n @AreDirective.Update\n update(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(A_Scope) scope: A_Scope,\n @A_Inject(AreSyntax) syntax: AreSyntax,\n @A_Inject(AreScene) scene: AreScene,\n ...args: any[]\n ): void {\n /**\n * 1. Extract the value from the store based on the attribute content\n * (which is the path to the value in the store)\n */\n const previous = !!attribute.value;\n const next = !!syntax.evaluate(attribute.content, store);\n attribute.value = next;\n\n // Skip when truthiness has not changed — avoids redundant mount/unmount.\n if (previous === next) return;\n\n if (next) {\n attribute.template!.scene.activate();\n attribute.template!.mount();\n } else {\n attribute.template!.unmount();\n attribute.template!.scene.deactivate();\n }\n }\n\n}"]}
1
+ {"version":3,"sources":["../../../src/directives/AreDirectiveIf.directive.ts"],"names":["AreDirectiveIf","AreDirective","AddCommentInstruction","A_Caller","A_Scope","AreStore","AreScene","A_Logger","AreSyntax","AreDirectiveContext","A_Frame"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkCaA,sBAAA,GAAN,6BAA6BC,mCAAA,CAAa;AAAA,EAI7C,UACwB,SAAA,EACD,KAAA,EAEC,KAAA,EACA,KAAA,EACA,WACjB,IAAA,EACL;AACE,IAAA,MAAA,CAAO,MAAM,CAAA,+BAAA,EAAkC,SAAA,CAAU,MAAM,KAAA,CAAM,QAAA,EAAU,CAAA,CAAA,CAAG,CAAA;AAElF,IAAA,MAAM,OAAO,SAAA,CAAU,KAAA;AAKvB,IAAA,MAAM,UAA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SAAA,EAAA,WAAA,EAAA,CAAA,CAAA;AA+CA,eAAA,CAAA;AAAA,EADCC,mCAAA,CAAa,OAAA;AAAA,EAET,qCAASE,iBAAQ,CAAA,CAAA;AAAA,EACjB,qCAASE,YAAQ,CAAA,CAAA;AAAA,EACjB,qCAASC,YAAQ,CAAA,CAAA;AAAA,EACjB,qCAASE,aAAS,CAAA,CAAA;AAAA,EAElB,qCAASC,wCAAmB,CAAA;AAAA,CAAA,EAzDxBT,sBAAA,CAmDT,SAAA,EAAA,SAAA,EAAA,CAAA,CAAA;AAoCA,eAAA,CAAA;AAAA,EADCC,mCAAA,CAAa,MAAA;AAAA,EAET,qCAASE,iBAAQ,CAAA,CAAA;AAAA,EACjB,qCAASE,YAAQ,CAAA,CAAA;AAAA,EACjB,qCAASD,gBAAO,CAAA,CAAA;AAAA,EAChB,qCAASI,aAAS,CAAA,CAAA;AAAA,EAClB,qCAASF,YAAQ,CAAA,CAAA;AAAA,EACjB,qCAASG,wCAAmB,CAAA;AAAA,CAAA,EA7FxBT,sBAAA,CAuFT,SAAA,EAAA,QAAA,EAAA,CAAA,CAAA;AAvFSA,sBAAA,GAAN,eAAA,CAAA;AAAA,EALNU,aAAQ,MAAA,CAAO;AAAA,IACZ,SAAA,EAAW,YAAA;AAAA,IACX,WAAA,EAAa;AAAA,GAChB,CAAA;AAAA,EACAT,mCAAA,CAAa,SAAS,CAAC;AAAA,CAAA,EACXD,sBAAA,CAAA","file":"AreDirectiveIf.directive.js","sourcesContent":["import { A_Caller, A_Inject, A_Scope } from \"@adaas/a-concept\";\nimport { A_Logger } from \"@adaas/a-utils/a-logger\";\nimport { AreDirectiveAttribute } from \"@adaas/are-html/attributes/AreDirective.attribute\";\nimport { AreScene, AreStore, AreSyntax } from \"@adaas/are\";\nimport { AreDirective } from \"@adaas/are-html/directive/AreDirective.component\";\nimport { AddCommentInstruction } from \"@adaas/are-html/instructions/AddComment.instruction\";\nimport { AreDirectiveContext } from \"@adaas/are-html/directive/AreDirective.context\";\nimport { A_Frame } from \"@adaas/a-frame/core\";\n\n\n\n/**\n * `$if` directive — conditionally renders a node based on an expression.\n *\n * ⚠️ Known limitation: do NOT use `$if` and `$for` on the SAME element.\n * Doing so produces duplicated DOM on toggle because the two directives\n * share an owner node and clone its scope independently. Wrap one in a\n * parent element instead, e.g.:\n *\n * <div $if=\"visible\">\n * <li $for=\"item in items\">{{item.name}}</li>\n * </div>\n *\n * or\n *\n * <ul $for=\"item in items\">\n * <li $if=\"item.visible\">{{item.name}}</li>\n * </ul>\n */\n@A_Frame.Define({\n namespace: 'a-are-html',\n description: 'Built-in $if directive. Conditionally renders a subtree based on a store expression. Replaces the target element with a stable comment anchor when the condition is false and restores the fully rendered subtree when it becomes true, preventing any leaking of the host element between states.'\n})\n@AreDirective.Priority(2)\nexport class AreDirectiveIf extends AreDirective {\n\n\n @AreDirective.Transform\n transform(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(A_Scope) scope: A_Scope,\n\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreScene) scene: AreScene,\n @A_Inject(A_Logger) logger: A_Logger,\n ...args: any[]\n ) {\n logger.debug(`[Transform] directive $IF for <${attribute.owner.aseid.toString()}>`)\n\n const node = attribute.owner;\n\n /**\n * We have to keep this node as a group node, and copy all data into the child node that would be actual node. \n */\n const ifTemplate = node.cloneWithScope();\n\n const ifAttr = ifTemplate.attributes.find(d => d.name === attribute.name);\n\n if (ifAttr) {\n ifTemplate.scope.deregister(ifAttr);\n node.scope.register(ifAttr);\n }\n\n node.init();\n\n node.addChild(ifTemplate);\n\n /**\n * Resolve or create a directive context for the item node. This is needed to hold the item-specific store values (e.g. the \"item\" and \"index\" in a \"for\" loop) that the template's bindings will reference during compile and update. The context is shared among all clones of the same template, but that's fine because each clone gets its own scope values assigned here.\n */\n // let directiveContext = ifTemplate.scope.resolveFlat(AreDirectiveContext);\n\n // if (!directiveContext) {\n // directiveContext = new AreDirectiveContext(ifTemplate.aseid);\n // ifTemplate.scope.register(directiveContext);\n // }\n\n ifTemplate.scene.deactivate();\n\n attribute.template = ifTemplate;\n\n }\n\n\n @AreDirective.Compile\n compile(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreScene) scene: AreScene,\n @A_Inject(AreSyntax) syntax: AreSyntax,\n\n @A_Inject(AreDirectiveContext) directiveContext?: AreDirectiveContext,\n ...args: any[]\n ): void {\n /**\n * 1. Extract the value from the store based on the attribute content\n * (which is the path to the value in the store)\n */\n attribute.value = this.evaluateCondition(syntax, attribute, store, directiveContext);\n\n /**\n * 2. If the value is falsy, remove the node from the scene by planning a RemoveElement instruction.\n * If the value is truthy, ensure the node is in the scene by planning an AddElement instruction if it's not already planned.\n */\n const hostInstruction = scene.host!;\n const commentIdentifier = ` --- if: ${attribute.template!.id} --- `;\n const declaration = new AddCommentInstruction({ content: commentIdentifier })\n\n scene.setHost(declaration);\n scene.planBefore(declaration, hostInstruction);\n scene.unPlan(hostInstruction);\n\n if (attribute.value)\n attribute.template!.scene.activate();\n else\n attribute.template!.scene.deactivate();\n }\n\n\n\n @AreDirective.Update\n update(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(A_Scope) scope: A_Scope,\n @A_Inject(AreSyntax) syntax: AreSyntax,\n @A_Inject(AreScene) scene: AreScene,\n @A_Inject(AreDirectiveContext) directiveContext?: AreDirectiveContext,\n ...args: any[]\n ): void {\n /**\n * 1. Extract the value from the store based on the attribute content\n * (which is the path to the value in the store)\n */\n const previous = !!attribute.value;\n const next = this.evaluateCondition(syntax, attribute, store, directiveContext);\n attribute.value = next;\n\n // Skip when truthiness has not changed — avoids redundant mount/unmount.\n if (previous === next) return;\n\n if (next) {\n attribute.template!.scene.activate();\n attribute.template!.mount();\n } else {\n attribute.template!.unmount();\n attribute.template!.scene.deactivate();\n }\n }\n\n /**\n * Evaluates the `$if` condition defensively.\n *\n * A condition can reference data that is momentarily unavailable — most\n * commonly a nested `$if` (e.g. `$if=\"selected.fields.length\"`) living\n * inside a parent `$if=\"selected\"` whose object has just become `null`.\n * Because the nested directive is still subscribed to the store, its\n * update fires on that same change and the raw expression would throw\n * `Cannot read properties of null`, crashing the whole update pipeline.\n *\n * Treating an evaluation error as `false` is the correct contract for a\n * conditional: if the condition cannot be resolved, the subtree simply\n * stays hidden until the referenced data is present again (at which point\n * the parent `$if` re-activates and re-evaluates this one).\n */\n private evaluateCondition(\n syntax: AreSyntax,\n attribute: AreDirectiveAttribute,\n store: AreStore,\n directiveContext?: AreDirectiveContext,\n ): boolean {\n try {\n return !!syntax.evaluate(attribute.content, store, {\n ...(directiveContext?.scope || {}),\n });\n } catch {\n return false;\n }\n }\n\n}"]}
@@ -23,9 +23,7 @@ let AreDirectiveIf = class extends AreDirective {
23
23
  attribute.template = ifTemplate;
24
24
  }
25
25
  compile(attribute, store, scene, syntax, directiveContext, ...args) {
26
- attribute.value = syntax.evaluate(attribute.content, store, {
27
- ...directiveContext?.scope || {}
28
- });
26
+ attribute.value = this.evaluateCondition(syntax, attribute, store, directiveContext);
29
27
  const hostInstruction = scene.host;
30
28
  const commentIdentifier = ` --- if: ${attribute.template.id} --- `;
31
29
  const declaration = new AddCommentInstruction({ content: commentIdentifier });
@@ -37,9 +35,9 @@ let AreDirectiveIf = class extends AreDirective {
37
35
  else
38
36
  attribute.template.scene.deactivate();
39
37
  }
40
- update(attribute, store, scope, syntax, scene, ...args) {
38
+ update(attribute, store, scope, syntax, scene, directiveContext, ...args) {
41
39
  const previous = !!attribute.value;
42
- const next = !!syntax.evaluate(attribute.content, store);
40
+ const next = this.evaluateCondition(syntax, attribute, store, directiveContext);
43
41
  attribute.value = next;
44
42
  if (previous === next) return;
45
43
  if (next) {
@@ -50,6 +48,30 @@ let AreDirectiveIf = class extends AreDirective {
50
48
  attribute.template.scene.deactivate();
51
49
  }
52
50
  }
51
+ /**
52
+ * Evaluates the `$if` condition defensively.
53
+ *
54
+ * A condition can reference data that is momentarily unavailable — most
55
+ * commonly a nested `$if` (e.g. `$if="selected.fields.length"`) living
56
+ * inside a parent `$if="selected"` whose object has just become `null`.
57
+ * Because the nested directive is still subscribed to the store, its
58
+ * update fires on that same change and the raw expression would throw
59
+ * `Cannot read properties of null`, crashing the whole update pipeline.
60
+ *
61
+ * Treating an evaluation error as `false` is the correct contract for a
62
+ * conditional: if the condition cannot be resolved, the subtree simply
63
+ * stays hidden until the referenced data is present again (at which point
64
+ * the parent `$if` re-activates and re-evaluates this one).
65
+ */
66
+ evaluateCondition(syntax, attribute, store, directiveContext) {
67
+ try {
68
+ return !!syntax.evaluate(attribute.content, store, {
69
+ ...directiveContext?.scope || {}
70
+ });
71
+ } catch {
72
+ return false;
73
+ }
74
+ }
53
75
  };
54
76
  __decorateClass([
55
77
  AreDirective.Transform,
@@ -73,7 +95,8 @@ __decorateClass([
73
95
  __decorateParam(1, A_Inject(AreStore)),
74
96
  __decorateParam(2, A_Inject(A_Scope)),
75
97
  __decorateParam(3, A_Inject(AreSyntax)),
76
- __decorateParam(4, A_Inject(AreScene))
98
+ __decorateParam(4, A_Inject(AreScene)),
99
+ __decorateParam(5, A_Inject(AreDirectiveContext))
77
100
  ], AreDirectiveIf.prototype, "update", 1);
78
101
  AreDirectiveIf = __decorateClass([
79
102
  A_Frame.Define({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/directives/AreDirectiveIf.directive.ts"],"names":[],"mappings":";;;;;;;;;AAkCO,IAAM,cAAA,GAAN,cAA6B,YAAA,CAAa;AAAA,EAI7C,UACwB,SAAA,EACD,KAAA,EAEC,KAAA,EACA,KAAA,EACA,WACjB,IAAA,EACL;AACE,IAAA,MAAA,CAAO,MAAM,CAAA,+BAAA,EAAkC,SAAA,CAAU,MAAM,KAAA,CAAM,QAAA,EAAU,CAAA,CAAA,CAAG,CAAA;AAElF,IAAA,MAAM,OAAO,SAAA,CAAU,KAAA;AAKvB,IAAA,MAAM,UAAA,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A;AAAA,EAET,4BAAS,QAAQ,CAAA,CAAA;AAAA,EACjB,4BAAS,QAAQ,CAAA,CAAA;AAAA,EACjB,4BAAS,OAAO,CAAA,CAAA;AAAA,EAChB,4BAAS,SAAS,CAAA,CAAA;AAAA,EAClB,4BAAS,QAAQ,CAAA;AAAA,CAAA,EA9Fb,cAAA,CAyFT,SAAA,EAAA,QAAA,EAAA,CAAA,CAAA;AAzFS,cAAA,GAAN,eAAA,CAAA;AAAA,EALN,QAAQ,MAAA,CAAO;AAAA,IACZ,SAAA,EAAW,YAAA;AAAA,IACX,WAAA,EAAa;AAAA,GAChB,CAAA;AAAA,EACA,YAAA,CAAa,SAAS,CAAC;AAAA,CAAA,EACX,cAAA,CAAA","file":"AreDirectiveIf.directive.mjs","sourcesContent":["import { A_Caller, A_Inject, A_Scope } from \"@adaas/a-concept\";\nimport { A_Logger } from \"@adaas/a-utils/a-logger\";\nimport { AreDirectiveAttribute } from \"@adaas/are-html/attributes/AreDirective.attribute\";\nimport { AreScene, AreStore, AreSyntax } from \"@adaas/are\";\nimport { AreDirective } from \"@adaas/are-html/directive/AreDirective.component\";\nimport { AddCommentInstruction } from \"@adaas/are-html/instructions/AddComment.instruction\";\nimport { AreDirectiveContext } from \"@adaas/are-html/directive/AreDirective.context\";\nimport { A_Frame } from \"@adaas/a-frame/core\";\n\n\n\n/**\n * `$if` directive — conditionally renders a node based on an expression.\n *\n * ⚠️ Known limitation: do NOT use `$if` and `$for` on the SAME element.\n * Doing so produces duplicated DOM on toggle because the two directives\n * share an owner node and clone its scope independently. Wrap one in a\n * parent element instead, e.g.:\n *\n * <div $if=\"visible\">\n * <li $for=\"item in items\">{{item.name}}</li>\n * </div>\n *\n * or\n *\n * <ul $for=\"item in items\">\n * <li $if=\"item.visible\">{{item.name}}</li>\n * </ul>\n */\n@A_Frame.Define({\n namespace: 'a-are-html',\n description: 'Built-in $if directive. Conditionally renders a subtree based on a store expression. Replaces the target element with a stable comment anchor when the condition is false and restores the fully rendered subtree when it becomes true, preventing any leaking of the host element between states.'\n})\n@AreDirective.Priority(2)\nexport class AreDirectiveIf extends AreDirective {\n\n\n @AreDirective.Transform\n transform(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(A_Scope) scope: A_Scope,\n\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreScene) scene: AreScene,\n @A_Inject(A_Logger) logger: A_Logger,\n ...args: any[]\n ) {\n logger.debug(`[Transform] directive $IF for <${attribute.owner.aseid.toString()}>`)\n\n const node = attribute.owner;\n\n /**\n * We have to keep this node as a group node, and copy all data into the child node that would be actual node. \n */\n const ifTemplate = node.cloneWithScope();\n\n const ifAttr = ifTemplate.attributes.find(d => d.name === attribute.name);\n\n if (ifAttr) {\n ifTemplate.scope.deregister(ifAttr);\n node.scope.register(ifAttr);\n }\n\n node.init();\n\n node.addChild(ifTemplate);\n\n /**\n * Resolve or create a directive context for the item node. This is needed to hold the item-specific store values (e.g. the \"item\" and \"index\" in a \"for\" loop) that the template's bindings will reference during compile and update. The context is shared among all clones of the same template, but that's fine because each clone gets its own scope values assigned here.\n */\n // let directiveContext = ifTemplate.scope.resolveFlat(AreDirectiveContext);\n\n // if (!directiveContext) {\n // directiveContext = new AreDirectiveContext(ifTemplate.aseid);\n // ifTemplate.scope.register(directiveContext);\n // }\n\n ifTemplate.scene.deactivate();\n\n attribute.template = ifTemplate;\n\n }\n\n\n @AreDirective.Compile\n compile(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreScene) scene: AreScene,\n @A_Inject(AreSyntax) syntax: AreSyntax,\n\n @A_Inject(AreDirectiveContext) directiveContext?: AreDirectiveContext,\n ...args: any[]\n ): void {\n /**\n * 1. Extract the value from the store based on the attribute content\n * (which is the path to the value in the store)\n */\n attribute.value = syntax.evaluate(attribute.content, store, {\n ...(directiveContext?.scope || {}),\n });\n\n /**\n * 2. If the value is falsy, remove the node from the scene by planning a RemoveElement instruction.\n * If the value is truthy, ensure the node is in the scene by planning an AddElement instruction if it's not already planned.\n */\n const hostInstruction = scene.host!;\n const commentIdentifier = ` --- if: ${attribute.template!.id} --- `;\n const declaration = new AddCommentInstruction({ content: commentIdentifier })\n\n scene.setHost(declaration);\n scene.planBefore(declaration, hostInstruction);\n scene.unPlan(hostInstruction);\n\n if (attribute.value)\n attribute.template!.scene.activate();\n else\n attribute.template!.scene.deactivate();\n }\n\n\n\n @AreDirective.Update\n update(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(A_Scope) scope: A_Scope,\n @A_Inject(AreSyntax) syntax: AreSyntax,\n @A_Inject(AreScene) scene: AreScene,\n ...args: any[]\n ): void {\n /**\n * 1. Extract the value from the store based on the attribute content\n * (which is the path to the value in the store)\n */\n const previous = !!attribute.value;\n const next = !!syntax.evaluate(attribute.content, store);\n attribute.value = next;\n\n // Skip when truthiness has not changed — avoids redundant mount/unmount.\n if (previous === next) return;\n\n if (next) {\n attribute.template!.scene.activate();\n attribute.template!.mount();\n } else {\n attribute.template!.unmount();\n attribute.template!.scene.deactivate();\n }\n }\n\n}"]}
1
+ {"version":3,"sources":["../../../src/directives/AreDirectiveIf.directive.ts"],"names":[],"mappings":";;;;;;;;;AAkCO,IAAM,cAAA,GAAN,cAA6B,YAAA,CAAa;AAAA,EAI7C,UACwB,SAAA,EACD,KAAA,EAEC,KAAA,EACA,KAAA,EACA,WACjB,IAAA,EACL;AACE,IAAA,MAAA,CAAO,MAAM,CAAA,+BAAA,EAAkC,SAAA,CAAU,MAAM,KAAA,CAAM,QAAA,EAAU,CAAA,CAAA,CAAG,CAAA;AAElF,IAAA,MAAM,OAAO,SAAA,CAAU,KAAA;AAKvB,IAAA,MAAM,UAAA,GAAa,KAAK,cAAA,EAAe;AAEvC,IAAA,MAAM,MAAA,GAAS,WAAW,UAAA,CAAW,IAAA,CAAK,OAAK,CAAA,CAAE,IAAA,KAAS,UAAU,IAAI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S,QAAQ,CAAA,CAAA;AAAA,EACjB,4BAAS,QAAQ,CAAA,CAAA;AAAA,EACjB,4BAAS,SAAS,CAAA,CAAA;AAAA,EAElB,4BAAS,mBAAmB,CAAA;AAAA,CAAA,EAzDxB,cAAA,CAmDT,SAAA,EAAA,SAAA,EAAA,CAAA,CAAA;AAoCA,eAAA,CAAA;AAAA,EADC,YAAA,CAAa,MAAA;AAAA,EAET,4BAAS,QAAQ,CAAA,CAAA;AAAA,EACjB,4BAAS,QAAQ,CAAA,CAAA;AAAA,EACjB,4BAAS,OAAO,CAAA,CAAA;AAAA,EAChB,4BAAS,SAAS,CAAA,CAAA;AAAA,EAClB,4BAAS,QAAQ,CAAA,CAAA;AAAA,EACjB,4BAAS,mBAAmB,CAAA;AAAA,CAAA,EA7FxB,cAAA,CAuFT,SAAA,EAAA,QAAA,EAAA,CAAA,CAAA;AAvFS,cAAA,GAAN,eAAA,CAAA;AAAA,EALN,QAAQ,MAAA,CAAO;AAAA,IACZ,SAAA,EAAW,YAAA;AAAA,IACX,WAAA,EAAa;AAAA,GAChB,CAAA;AAAA,EACA,YAAA,CAAa,SAAS,CAAC;AAAA,CAAA,EACX,cAAA,CAAA","file":"AreDirectiveIf.directive.mjs","sourcesContent":["import { A_Caller, A_Inject, A_Scope } from \"@adaas/a-concept\";\nimport { A_Logger } from \"@adaas/a-utils/a-logger\";\nimport { AreDirectiveAttribute } from \"@adaas/are-html/attributes/AreDirective.attribute\";\nimport { AreScene, AreStore, AreSyntax } from \"@adaas/are\";\nimport { AreDirective } from \"@adaas/are-html/directive/AreDirective.component\";\nimport { AddCommentInstruction } from \"@adaas/are-html/instructions/AddComment.instruction\";\nimport { AreDirectiveContext } from \"@adaas/are-html/directive/AreDirective.context\";\nimport { A_Frame } from \"@adaas/a-frame/core\";\n\n\n\n/**\n * `$if` directive — conditionally renders a node based on an expression.\n *\n * ⚠️ Known limitation: do NOT use `$if` and `$for` on the SAME element.\n * Doing so produces duplicated DOM on toggle because the two directives\n * share an owner node and clone its scope independently. Wrap one in a\n * parent element instead, e.g.:\n *\n * <div $if=\"visible\">\n * <li $for=\"item in items\">{{item.name}}</li>\n * </div>\n *\n * or\n *\n * <ul $for=\"item in items\">\n * <li $if=\"item.visible\">{{item.name}}</li>\n * </ul>\n */\n@A_Frame.Define({\n namespace: 'a-are-html',\n description: 'Built-in $if directive. Conditionally renders a subtree based on a store expression. Replaces the target element with a stable comment anchor when the condition is false and restores the fully rendered subtree when it becomes true, preventing any leaking of the host element between states.'\n})\n@AreDirective.Priority(2)\nexport class AreDirectiveIf extends AreDirective {\n\n\n @AreDirective.Transform\n transform(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(A_Scope) scope: A_Scope,\n\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreScene) scene: AreScene,\n @A_Inject(A_Logger) logger: A_Logger,\n ...args: any[]\n ) {\n logger.debug(`[Transform] directive $IF for <${attribute.owner.aseid.toString()}>`)\n\n const node = attribute.owner;\n\n /**\n * We have to keep this node as a group node, and copy all data into the child node that would be actual node. \n */\n const ifTemplate = node.cloneWithScope();\n\n const ifAttr = ifTemplate.attributes.find(d => d.name === attribute.name);\n\n if (ifAttr) {\n ifTemplate.scope.deregister(ifAttr);\n node.scope.register(ifAttr);\n }\n\n node.init();\n\n node.addChild(ifTemplate);\n\n /**\n * Resolve or create a directive context for the item node. This is needed to hold the item-specific store values (e.g. the \"item\" and \"index\" in a \"for\" loop) that the template's bindings will reference during compile and update. The context is shared among all clones of the same template, but that's fine because each clone gets its own scope values assigned here.\n */\n // let directiveContext = ifTemplate.scope.resolveFlat(AreDirectiveContext);\n\n // if (!directiveContext) {\n // directiveContext = new AreDirectiveContext(ifTemplate.aseid);\n // ifTemplate.scope.register(directiveContext);\n // }\n\n ifTemplate.scene.deactivate();\n\n attribute.template = ifTemplate;\n\n }\n\n\n @AreDirective.Compile\n compile(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreScene) scene: AreScene,\n @A_Inject(AreSyntax) syntax: AreSyntax,\n\n @A_Inject(AreDirectiveContext) directiveContext?: AreDirectiveContext,\n ...args: any[]\n ): void {\n /**\n * 1. Extract the value from the store based on the attribute content\n * (which is the path to the value in the store)\n */\n attribute.value = this.evaluateCondition(syntax, attribute, store, directiveContext);\n\n /**\n * 2. If the value is falsy, remove the node from the scene by planning a RemoveElement instruction.\n * If the value is truthy, ensure the node is in the scene by planning an AddElement instruction if it's not already planned.\n */\n const hostInstruction = scene.host!;\n const commentIdentifier = ` --- if: ${attribute.template!.id} --- `;\n const declaration = new AddCommentInstruction({ content: commentIdentifier })\n\n scene.setHost(declaration);\n scene.planBefore(declaration, hostInstruction);\n scene.unPlan(hostInstruction);\n\n if (attribute.value)\n attribute.template!.scene.activate();\n else\n attribute.template!.scene.deactivate();\n }\n\n\n\n @AreDirective.Update\n update(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(A_Scope) scope: A_Scope,\n @A_Inject(AreSyntax) syntax: AreSyntax,\n @A_Inject(AreScene) scene: AreScene,\n @A_Inject(AreDirectiveContext) directiveContext?: AreDirectiveContext,\n ...args: any[]\n ): void {\n /**\n * 1. Extract the value from the store based on the attribute content\n * (which is the path to the value in the store)\n */\n const previous = !!attribute.value;\n const next = this.evaluateCondition(syntax, attribute, store, directiveContext);\n attribute.value = next;\n\n // Skip when truthiness has not changed — avoids redundant mount/unmount.\n if (previous === next) return;\n\n if (next) {\n attribute.template!.scene.activate();\n attribute.template!.mount();\n } else {\n attribute.template!.unmount();\n attribute.template!.scene.deactivate();\n }\n }\n\n /**\n * Evaluates the `$if` condition defensively.\n *\n * A condition can reference data that is momentarily unavailable — most\n * commonly a nested `$if` (e.g. `$if=\"selected.fields.length\"`) living\n * inside a parent `$if=\"selected\"` whose object has just become `null`.\n * Because the nested directive is still subscribed to the store, its\n * update fires on that same change and the raw expression would throw\n * `Cannot read properties of null`, crashing the whole update pipeline.\n *\n * Treating an evaluation error as `false` is the correct contract for a\n * conditional: if the condition cannot be resolved, the subtree simply\n * stays hidden until the referenced data is present again (at which point\n * the parent `$if` re-activates and re-evaluates this one).\n */\n private evaluateCondition(\n syntax: AreSyntax,\n attribute: AreDirectiveAttribute,\n store: AreStore,\n directiveContext?: AreDirectiveContext,\n ): boolean {\n try {\n return !!syntax.evaluate(attribute.content, store, {\n ...(directiveContext?.scope || {}),\n });\n } catch {\n return false;\n }\n }\n\n}"]}
@@ -4,7 +4,9 @@ import { AreCompiler, AreScene, AreStore, AreSyntax } from '@adaas/are';
4
4
  import { e as AreHTMLNode, f as AreStaticAttribute, b as AreDirectiveAttribute, c as AreEventAttribute, A as AreBindingAttribute } from '../AreBinding.attribute-BWzEIw6H.mjs';
5
5
  import { AreInterpolation } from '../nodes/AreInterpolation.mjs';
6
6
  import { AreText } from '../nodes/AreText.mjs';
7
+ import { AreDirectiveContext } from '../lib/AreDirective/AreDirective.context.mjs';
7
8
  import '../lib/AreStyle/AreStyle.context.mjs';
9
+ import '@adaas/a-utils/a-execution';
8
10
 
9
11
  declare class AreHTMLCompiler extends AreCompiler {
10
12
  /**
@@ -28,7 +30,7 @@ declare class AreHTMLCompiler extends AreCompiler {
28
30
  compileStaticAttribute(attribute: AreStaticAttribute, scene: AreScene, ...args: any[]): void;
29
31
  compileDirectiveAttribute(directive: AreDirectiveAttribute, store: AreStore, feature: A_Feature, logger?: A_Logger, ...args: any[]): void;
30
32
  compileEventAttribute(attribute: AreEventAttribute, scene: AreScene, ...args: any[]): void;
31
- compileBindingAttribute(attribute: AreBindingAttribute, scene: AreScene, parentStore: AreStore, store: AreStore, syntax: AreSyntax, ...args: any[]): void;
33
+ compileBindingAttribute(attribute: AreBindingAttribute, scene: AreScene, parentStore: AreStore, store: AreStore, syntax: AreSyntax, directiveContext?: AreDirectiveContext, ...args: any[]): void;
32
34
  }
33
35
 
34
36
  export { AreHTMLCompiler };
@@ -4,7 +4,9 @@ import { AreCompiler, AreScene, AreStore, AreSyntax } from '@adaas/are';
4
4
  import { e as AreHTMLNode, f as AreStaticAttribute, b as AreDirectiveAttribute, c as AreEventAttribute, A as AreBindingAttribute } from '../AreBinding.attribute-GpT-5Qmf.js';
5
5
  import { AreInterpolation } from '../nodes/AreInterpolation.js';
6
6
  import { AreText } from '../nodes/AreText.js';
7
+ import { AreDirectiveContext } from '../lib/AreDirective/AreDirective.context.js';
7
8
  import '../lib/AreStyle/AreStyle.context.js';
9
+ import '@adaas/a-utils/a-execution';
8
10
 
9
11
  declare class AreHTMLCompiler extends AreCompiler {
10
12
  /**
@@ -28,7 +30,7 @@ declare class AreHTMLCompiler extends AreCompiler {
28
30
  compileStaticAttribute(attribute: AreStaticAttribute, scene: AreScene, ...args: any[]): void;
29
31
  compileDirectiveAttribute(directive: AreDirectiveAttribute, store: AreStore, feature: A_Feature, logger?: A_Logger, ...args: any[]): void;
30
32
  compileEventAttribute(attribute: AreEventAttribute, scene: AreScene, ...args: any[]): void;
31
- compileBindingAttribute(attribute: AreBindingAttribute, scene: AreScene, parentStore: AreStore, store: AreStore, syntax: AreSyntax, ...args: any[]): void;
33
+ compileBindingAttribute(attribute: AreBindingAttribute, scene: AreScene, parentStore: AreStore, store: AreStore, syntax: AreSyntax, directiveContext?: AreDirectiveContext, ...args: any[]): void;
32
34
  }
33
35
 
34
36
  export { AreHTMLCompiler };
@@ -17,6 +17,7 @@ var AddListener_instruction = require('@adaas/are-html/instructions/AddListener.
17
17
  var AddStyle_instruction = require('@adaas/are-html/instructions/AddStyle.instruction');
18
18
  var AddStaticHTML_instruction = require('@adaas/are-html/instructions/AddStaticHTML.instruction');
19
19
  var node = require('@adaas/are-html/node');
20
+ var AreDirective_context = require('@adaas/are-html/directive/AreDirective.context');
20
21
 
21
22
  var __defProp = Object.defineProperty;
22
23
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -92,7 +93,7 @@ exports.AreHTMLCompiler = class AreHTMLCompiler extends are.AreCompiler {
92
93
  handler: attribute.content
93
94
  }));
94
95
  }
95
- compileBindingAttribute(attribute, scene, parentStore, store, syntax, ...args) {
96
+ compileBindingAttribute(attribute, scene, parentStore, store, syntax, directiveContext, ...args) {
96
97
  if (!scene.host)
97
98
  throw new are.AreCompilerError({
98
99
  title: "Scene Host Not Found",
@@ -128,11 +129,12 @@ exports.AreHTMLCompiler = class AreHTMLCompiler extends are.AreCompiler {
128
129
  }
129
130
  return value;
130
131
  };
132
+ const directiveScope = () => directiveContext?.scope ?? {};
131
133
  const watcher = {
132
134
  update: () => {
133
135
  try {
134
136
  parentStore.watch(watcher);
135
- const next = coerce(syntax.evaluate(attribute.content, parentStore));
137
+ const next = coerce(syntax.evaluate(attribute.content, parentStore, directiveScope()));
136
138
  parentStore.unwatch(watcher);
137
139
  store.set(propName, next);
138
140
  } catch (e) {
@@ -141,7 +143,7 @@ exports.AreHTMLCompiler = class AreHTMLCompiler extends are.AreCompiler {
141
143
  }
142
144
  };
143
145
  parentStore.watch(watcher);
144
- const initial = coerce(syntax.evaluate(attribute.content, parentStore));
146
+ const initial = coerce(syntax.evaluate(attribute.content, parentStore, directiveScope()));
145
147
  parentStore.unwatch(watcher);
146
148
  store.set(propName, initial);
147
149
  return;
@@ -197,7 +199,8 @@ __decorateClass([
197
199
  __decorateParam(2, aConcept.A_Dependency.Parent()),
198
200
  __decorateParam(2, aConcept.A_Inject(are.AreStore)),
199
201
  __decorateParam(3, aConcept.A_Inject(are.AreStore)),
200
- __decorateParam(4, aConcept.A_Inject(are.AreSyntax))
202
+ __decorateParam(4, aConcept.A_Inject(are.AreSyntax)),
203
+ __decorateParam(5, aConcept.A_Inject(AreDirective_context.AreDirectiveContext))
201
204
  ], exports.AreHTMLCompiler.prototype, "compileBindingAttribute", 1);
202
205
  exports.AreHTMLCompiler = __decorateClass([
203
206
  core.A_Frame.Define({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/engine/AreHTML.compiler.ts"],"names":["AreHTMLCompiler","AreCompiler","AddStaticHTMLInstruction","AddStyleInstruction","AddTextInstruction","AreCompilerError","AddAttributeInstruction","AreDirectiveFeatures","A_FormatterHelper","AddListenerInstruction","AreHTMLNode","A_Caller","AreScene","A_Logger","AreInterpolation","AreStore","AreText","AreStaticAttribute","AreDirectiveAttribute","A_Feature","AreEventAttribute","AreBindingAttribute","AreSyntax","A_Frame"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBaA,uBAAA,GAAN,8BAA8BC,eAAA,CAAY;AAAA,EAS7C,eAAA,CACwB,IAAA,EACA,KAAA,EACA,MAAA,EAAA,GACjB,IAAA,EACC;AACJ,IAAA,KAAA,CAAM,OAAA,CAAQ,IAAA,EAAM,KAAA,EAAO,MAAA,EAAQ,GAAG,IAAI,CAAA;AAU1C,IAAA,IAAI,IAAA,CAAK,cAAA,IAAkB,KAAA,CAAM,IAAA,EAAM;AACnC,MAAA,KAAA,CAAM,IAAA,CAAK,IAAIC,kDAAA,CAAyB,KAAA,CAAM,IAAA,EAAM,EAAE,IAAA,EAAM,IAAA,CAAK,eAAA,EAAkB,CAAC,CAAA;AAAA,IACxF;AAEA,IAAA,IAAI,IAAA,CAAK,QAAQ,MAAA,EAAQ;AACrB,MAAA,MAAM,OAAO,KAAA,CAAM,IAAA;AACnB,MAAA,IAAI,IAAA,EAAM;AACN,QAAA,KAAA,CAAM,IAAA,CAAK,IAAIC,wCAAA,CAAoB,IAAA,EAAM,EAAE,QAAQ,IAAA,CAAK,MAAA,CAAO,MAAA,EAAQ,CAAC,CAAA;AAAA,MAC5E;AAAA,IACJ;AAAA,EACJ;AAAA,EAeA,oBAAA,CACwB,aAAA,EACA,KAAA,EAEA,KAAA,EACA,WACjB,IAAA,EACL;AAeE,IAAA,KAAA,CAAM,IAAA,CAAK,IAAIC,sCAAA,CAAmB,EAAE,OAAA,EAAS,cAAc,OAAA,EAAS,QAAA,EAAU,IAAA,EAAM,CAAC,CAAA;AAAA,EACzF;AAAA,EAMA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,qCAASC,YAAQ,CAAA,CAAA;AAAA,EACjB,yCAAa,MAAA,EAAO,CAAA;AAAA,EACpB,qCAASG,YAAQ,CAAA,CAAA;AAAA,EACjB,qCAASA,YAAQ,CAAA,CAAA;AAAA,EACjB,qCAASO,aAAS,CAAA;AAAA,CAAA,EAnMdtB,uBAAA,CA6LT,SAAA,EAAA,yBAAA,EAAA,CAAA,CAAA;AA7LSA,uBAAA,GAAN,eAAA,CAAA;AAAA,EAJNuB,aAAQ,MAAA,CAAO;AAAA,IACZ,SAAA,EAAW,YAAA;AAAA,IACX,WAAA,EAAa;AAAA,GAChB;AAAA,CAAA,EACYvB,uBAAA,CAAA","file":"AreHTML.compiler.js","sourcesContent":["import { A_Caller, A_Dependency, A_Feature, A_FormatterHelper, A_Inject } from \"@adaas/a-concept\";\nimport { A_Logger } from \"@adaas/a-utils/a-logger\";\nimport { A_Frame } from \"@adaas/a-frame/core\";\nimport { AreCompiler, AreScene, AreCompilerError, AreStore, AreSyntax } from \"@adaas/are\";\nimport { AreDirectiveAttribute } from \"@adaas/are-html/attributes/AreDirective.attribute\";\nimport { AreStaticAttribute } from \"@adaas/are-html/attributes/AreStatic.attribute\";\nimport { AreDirectiveFeatures } from \"@adaas/are-html/directive/AreDirective.constants\";\nimport { AreEventAttribute } from \"@adaas/are-html/attributes/AreEvent.attribute\";\nimport { AreBindingAttribute } from \"@adaas/are-html/attributes/AreBinding.attribute\";\nimport { AreInterpolation } from \"@adaas/are-html/nodes/AreInterpolation\";\nimport { AreText } from \"@adaas/are-html/nodes/AreText\";\nimport { AddAttributeInstruction} from \"@adaas/are-html/instructions/AddAttribute.instruction\";\nimport { AddTextInstruction} from \"@adaas/are-html/instructions/AddText.instruction\";\nimport { AddListenerInstruction} from \"@adaas/are-html/instructions/AddListener.instruction\";\nimport { AddStyleInstruction } from \"@adaas/are-html/instructions/AddStyle.instruction\";\nimport { AddStaticHTMLInstruction } from \"@adaas/are-html/instructions/AddStaticHTML.instruction\";\nimport { AreHTMLNode } from \"@adaas/are-html/node\";\n\n\n\n\n@A_Frame.Define({\n namespace: 'a-are-html',\n description: 'HTML-specific compiler for A-Concept Rendering Engine (ARE) components, extending the base AreCompiler to handle HTML templates, styles, and rendering logic tailored for web environments.'\n})\nexport class AreHTMLCompiler extends AreCompiler {\n\n /**\n * Extends the base compile for all AreHTMLNode instances (elements, components, root nodes).\n * After the standard element/attribute/children instructions are emitted, checks whether\n * the node has a registered AreStyle and plans an AddStyleInstruction so the interpreter\n * can inject the CSS into the document head during mount.\n */\n @AreCompiler.Compile(AreHTMLNode)\n compileHTMLNode(\n @A_Inject(A_Caller) node: AreHTMLNode,\n @A_Inject(AreScene) scene: AreScene,\n @A_Inject(A_Logger) logger?: A_Logger,\n ...args: any[]\n ): void {\n super.compile(node, scene, logger, ...args);\n\n /**\n * Static-island materialisation. When the tokenizer flagged this node as\n * a static island its inner subtree was never exploded into child nodes,\n * so there is nothing for the base compiler to walk. Emit a single\n * AddStaticHTML instruction carrying the captured inner markup; the\n * interpreter injects it onto the host element in one pass (and decodes\n * HTML entities for free).\n */\n if (node.isStaticIsland && scene.host) {\n scene.plan(new AddStaticHTMLInstruction(scene.host, { html: node.staticInnerHTML! }));\n }\n\n if (node.styles?.styles) {\n const host = scene.host;\n if (host) {\n scene.plan(new AddStyleInstruction(host, { styles: node.styles.styles }));\n }\n }\n }\n\n // -----------------------------------------------------------------------------------------\n // -------------------------Are-Interpolation Compile Section-----------------------------------\n // -----------------------------------------------------------------------------------------\n /**\n * Default compile method for interpolations, which can be overridden by specific implementations if needed.\n * \n * @param interpolation \n * @param scope \n * @param scene \n * @param store \n * @param feature \n */\n @AreCompiler.Compile(AreInterpolation)\n compileInterpolation(\n @A_Inject(A_Caller) interpolation: AreInterpolation,\n @A_Inject(AreScene) scene: AreScene,\n\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(A_Logger) logger?: A_Logger,\n ...args: any[]\n ) {\n // if (scene.host)\n // console.log('Scene Host: ', scene.host);\n\n // let content = '';\n\n // logger?.debug('green', `AreHTMLCompiler: compile interpolation <${interpolation.aseid.toString()}> with key: \"${interpolation.content}\"`, store.get(interpolation.content));\n\n // try {\n // content = AreCommonHelper.evaluate(interpolation.content, store);\n\n // } catch (error) {\n // content = ''\n // }\n\n scene.plan(new AddTextInstruction({ content: interpolation.content, evaluate: true }));\n }\n\n // -----------------------------------------------------------------------------------------\n // ------------------------------Are-Text Compile Section-----------------------------------\n // -----------------------------------------------------------------------------------------\n @AreCompiler.Compile(AreText)\n compileText(\n @A_Inject(A_Caller) text: AreText,\n @A_Inject(AreScene) scene: AreScene,\n @A_Inject(A_Logger) logger?: A_Logger,\n ...args: any[]\n ) {\n logger?.debug('cyan', `AreHTMLCompiler: compile text node <${text.aseid.toString()}> with content: \"${text.content}\"`);\n if (scene.host)\n scene.unPlan(scene.host);\n\n scene.plan(new AddTextInstruction({ content: text.content }));\n\n }\n\n // -----------------------------------------------------------------------------------------\n // -------------------------Are-Attribute Compile Section-----------------------------------\n // -----------------------------------------------------------------------------------------\n\n @AreCompiler.Compile(AreStaticAttribute)\n compileStaticAttribute(\n @A_Inject(A_Caller) attribute: AreStaticAttribute,\n @A_Inject(AreScene) scene: AreScene,\n ...args: any[]\n ) {\n if (!scene.host)\n throw new AreCompilerError({\n title: 'Scene Host Not Found',\n description: `No host found for the scene with id: ${scene.id}. Please ensure that the scene is properly initialized and has a host before compiling binding attributes.`\n });\n\n const content = attribute.content;\n\n /**\n * If the attribute value contains {{ }} interpolations, transform them into\n * a JS string-concatenation expression so the interpreter can evaluate them.\n * e.g. \"color:{{expr}}\" → '\"color:\"+(expr)+\"\"'\n */\n if (content.includes('{{')) {\n const transformed = '\"' + content.replace(/\\{\\{([^}]+)\\}\\}/g, '\"+($1)+\"') + '\"';\n scene.plan(new AddAttributeInstruction(scene.host, {\n name: attribute.name,\n content: transformed,\n evaluate: true,\n }));\n return;\n }\n\n /**\n * Default case: regular static attribute rendered as-is.\n */\n scene.plan(new AddAttributeInstruction(scene.host, {\n name: attribute.name,\n content: attribute.content\n }));\n }\n\n @AreCompiler.Compile(AreDirectiveAttribute)\n compileDirectiveAttribute(\n @A_Inject(A_Caller) directive: AreDirectiveAttribute,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(A_Feature) feature: A_Feature,\n @A_Inject(A_Logger) logger?: A_Logger,\n ...args: any[]\n ) {\n store.watch(directive);\n\n /**\n * 3. If the attribute is a directive, then we should find a component that is responsible for\n * the directive compiling logic, and call it. \n * In case component is not found we just want to log a warning, \n * since the directive may be handled by some parent component or simply is a mistake in the template.\n */\n if (directive.component) {\n feature.chain(directive.component, AreDirectiveFeatures.Compile, directive.owner.scope);\n } else {\n logger?.warning(`Directive handler component not found for directive: ${directive.name}. Make sure to create a component named \"AreDirective${A_FormatterHelper.toPascalCase(directive.name)}\" to handle this directive.`);\n }\n\n store.unwatch(directive);\n }\n\n\n @AreCompiler.Compile(AreEventAttribute)\n compileEventAttribute(\n @A_Inject(A_Caller) attribute: AreEventAttribute,\n @A_Inject(AreScene) scene: AreScene,\n ...args: any[]\n ) {\n\n if (!scene.host)\n throw new AreCompilerError({\n title: 'Scene Host Not Found',\n description: `No host found for the scene with id: ${scene.id}. Please ensure that the scene is properly initialized and has a host before compiling binding attributes.`\n });\n /**\n * 2. In case the attribute is an event listener, then \n * we should simply add a callback handler that will be used to proxy an event \n * into the ComponentNode component. \n *[!] In this case AreAttribute is AreEventAttribute that has prepared callback function to be used \n * in the event listener. It is important to store callback function once \n * to prevent duplicated functions in case of multiple compilations during development.\n */\n scene.plan(new AddListenerInstruction(scene.host, {\n name: attribute.name,\n handler: attribute.content\n }));\n }\n\n\n @AreCompiler.Compile(AreBindingAttribute)\n compileBindingAttribute(\n @A_Inject(A_Caller) attribute: AreBindingAttribute,\n @A_Inject(AreScene) scene: AreScene,\n @A_Dependency.Parent()\n @A_Inject(AreStore) parentStore: AreStore,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreSyntax) syntax: AreSyntax,\n ...args: any[]\n ) {\n if (!scene.host)\n throw new AreCompilerError({\n title: 'Scene Host Not Found',\n description: `No host found for the scene with id: ${scene.id}. Please ensure that the scene is properly initialized and has a host before compiling binding attributes.`\n });\n\n\n const node = attribute.owner;\n const props = node.component?.props;\n\n // Component prop names are typically declared in camelCase, while template\n // markup uses kebab-case. Try both forms when matching.\n let propName: string | undefined;\n if (props) {\n if (props[attribute.name]) {\n propName = attribute.name;\n } else {\n const camel = A_FormatterHelper.toCamelCase(attribute.name);\n if (props[camel]) propName = camel;\n }\n }\n\n /**\n * 1. Component prop binding — evaluate against the parent store and\n * keep the child store reactive to upstream changes.\n */\n if (propName && props) {\n const propDefinition = props[propName];\n\n const coerce = (raw: any): any => {\n let value = raw;\n if (propDefinition.type) {\n switch (propDefinition.type) {\n case 'string': value = value === undefined || value === null ? '' : String(value); break;\n case 'number': value = Number(value); break;\n case 'boolean': value = Boolean(value); break;\n }\n }\n return value;\n };\n\n // The watcher entity below is registered against parentStore so that\n // updates to the bound expression in the parent flow into the child store.\n const watcher = {\n update: () => {\n try {\n parentStore.watch(watcher);\n const next = coerce(syntax.evaluate(attribute.content, parentStore));\n parentStore.unwatch(watcher);\n store.set(propName!, next);\n } catch (e) {\n parentStore.unwatch(watcher);\n }\n }\n };\n\n // Initial read with watch active so dependencies are recorded.\n parentStore.watch(watcher);\n const initial = coerce(syntax.evaluate(attribute.content, parentStore));\n parentStore.unwatch(watcher);\n\n store.set(propName, initial);\n return;\n }\n\n /**\n * 2. Default attribute binding — evaluated reactively against the local store.\n */\n const instruction = new AddAttributeInstruction(scene.host, {\n name: attribute.name,\n content: attribute.content,\n evaluate: true\n })\n\n scene.plan(instruction);\n }\n\n\n}"]}
1
+ {"version":3,"sources":["../../../src/engine/AreHTML.compiler.ts"],"names":["AreHTMLCompiler","AreCompiler","AddStaticHTMLInstruction","AddStyleInstruction","AddTextInstruction","AreCompilerError","AddAttributeInstruction","AreDirectiveFeatures","A_FormatterHelper","AddListenerInstruction","AreHTMLNode","A_Caller","AreScene","A_Logger","AreInterpolation","AreStore","AreText","AreStaticAttribute","AreDirectiveAttribute","A_Feature","AreEventAttribute","AreBindingAttribute","AreSyntax","AreDirectiveContext","A_Frame"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BaA,uBAAA,GAAN,8BAA8BC,eAAA,CAAY;AAAA,EAS7C,eAAA,CACwB,IAAA,EACA,KAAA,EACA,MAAA,EAAA,GACjB,IAAA,EACC;AACJ,IAAA,KAAA,CAAM,OAAA,CAAQ,IAAA,EAAM,KAAA,EAAO,MAAA,EAAQ,GAAG,IAAI,CAAA;AAU1C,IAAA,IAAI,IAAA,CAAK,cAAA,IAAkB,KAAA,CAAM,IAAA,EAAM;AACnC,MAAA,KAAA,CAAM,IAAA,CAAK,IAAIC,kDAAA,CAAyB,KAAA,CAAM,IAAA,EAAM,EAAE,IAAA,EAAM,IAAA,CAAK,eAAA,EAAkB,CAAC,CAAA;AAAA,IACxF;AAEA,IAAA,IAAI,IAAA,CAAK,QAAQ,MAAA,EAAQ;AACrB,MAAA,MAAM,OAAO,KAAA,CAAM,IAAA;AACnB,MAAA,IAAI,IAAA,EAAM;AACN,QAAA,KAAA,CAAM,IAAA,CAAK,IAAIC,wCAAA,CAAoB,IAAA,EAAM,EAAE,QAAQ,IAAA,CAAK,MAAA,CAAO,MAAA,EAAQ,CAAC,CAAA;AAAA,MAC5E;AAAA,IACJ;AAAA,EACJ;AAAA,EAeA,oBAAA,CACwB,aAAA,EACA,KAAA,EAEA,KAAA,EACA,WACjB,IAAA,EACL;AAeE,IAAA,KAAA,CAAM,IAAA,CAAK,IAAIC,sCAAA,CAAmB,EAAE,OAAA,EAAS,cAAc,OAAA,EAAS,QAAA,EAAU,IAAA,EAAM,CAAC,CAAA;AAAA,EACzF;AAAA,EAMA,WAAA,CACwB,IAAA,EACA,KAAA,EACA,MAAA,EAAA,GACjB,IAAA,EACL;AACE,IAAA,MAAA,EAAQ,KAAA,CAAM,MAAA,EAAQ,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jB,qCAASC,YAAQ,CAAA,CAAA;AAAA,EACjB,yCAAa,MAAA,EAAO,CAAA;AAAA,EACpB,qCAASG,YAAQ,CAAA,CAAA;AAAA,EACjB,qCAASA,YAAQ,CAAA,CAAA;AAAA,EACjB,qCAASO,aAAS,CAAA,CAAA;AAAA,EAClB,qCAASC,wCAAmB,CAAA;AAAA,CAAA,EApMxBvB,uBAAA,CA6LT,SAAA,EAAA,yBAAA,EAAA,CAAA,CAAA;AA7LSA,uBAAA,GAAN,eAAA,CAAA;AAAA,EAJNwB,aAAQ,MAAA,CAAO;AAAA,IACZ,SAAA,EAAW,YAAA;AAAA,IACX,WAAA,EAAa;AAAA,GAChB;AAAA,CAAA,EACYxB,uBAAA,CAAA","file":"AreHTML.compiler.js","sourcesContent":["import { A_Caller, A_Dependency, A_Feature, A_FormatterHelper, A_Inject } from \"@adaas/a-concept\";\nimport { A_Logger } from \"@adaas/a-utils/a-logger\";\nimport { A_Frame } from \"@adaas/a-frame/core\";\nimport { AreCompiler, AreScene, AreCompilerError, AreStore, AreSyntax } from \"@adaas/are\";\nimport { AreDirectiveAttribute } from \"@adaas/are-html/attributes/AreDirective.attribute\";\nimport { AreStaticAttribute } from \"@adaas/are-html/attributes/AreStatic.attribute\";\nimport { AreDirectiveFeatures } from \"@adaas/are-html/directive/AreDirective.constants\";\nimport { AreEventAttribute } from \"@adaas/are-html/attributes/AreEvent.attribute\";\nimport { AreBindingAttribute } from \"@adaas/are-html/attributes/AreBinding.attribute\";\nimport { AreInterpolation } from \"@adaas/are-html/nodes/AreInterpolation\";\nimport { AreText } from \"@adaas/are-html/nodes/AreText\";\nimport { AddAttributeInstruction} from \"@adaas/are-html/instructions/AddAttribute.instruction\";\nimport { AddTextInstruction} from \"@adaas/are-html/instructions/AddText.instruction\";\nimport { AddListenerInstruction} from \"@adaas/are-html/instructions/AddListener.instruction\";\nimport { AddStyleInstruction } from \"@adaas/are-html/instructions/AddStyle.instruction\";\nimport { AddStaticHTMLInstruction } from \"@adaas/are-html/instructions/AddStaticHTML.instruction\";\nimport { AreHTMLNode } from \"@adaas/are-html/node\";\nimport { AreDirectiveContext } from \"@adaas/are-html/directive/AreDirective.context\";\n\n\n\n\n@A_Frame.Define({\n namespace: 'a-are-html',\n description: 'HTML-specific compiler for A-Concept Rendering Engine (ARE) components, extending the base AreCompiler to handle HTML templates, styles, and rendering logic tailored for web environments.'\n})\nexport class AreHTMLCompiler extends AreCompiler {\n\n /**\n * Extends the base compile for all AreHTMLNode instances (elements, components, root nodes).\n * After the standard element/attribute/children instructions are emitted, checks whether\n * the node has a registered AreStyle and plans an AddStyleInstruction so the interpreter\n * can inject the CSS into the document head during mount.\n */\n @AreCompiler.Compile(AreHTMLNode)\n compileHTMLNode(\n @A_Inject(A_Caller) node: AreHTMLNode,\n @A_Inject(AreScene) scene: AreScene,\n @A_Inject(A_Logger) logger?: A_Logger,\n ...args: any[]\n ): void {\n super.compile(node, scene, logger, ...args);\n\n /**\n * Static-island materialisation. When the tokenizer flagged this node as\n * a static island its inner subtree was never exploded into child nodes,\n * so there is nothing for the base compiler to walk. Emit a single\n * AddStaticHTML instruction carrying the captured inner markup; the\n * interpreter injects it onto the host element in one pass (and decodes\n * HTML entities for free).\n */\n if (node.isStaticIsland && scene.host) {\n scene.plan(new AddStaticHTMLInstruction(scene.host, { html: node.staticInnerHTML! }));\n }\n\n if (node.styles?.styles) {\n const host = scene.host;\n if (host) {\n scene.plan(new AddStyleInstruction(host, { styles: node.styles.styles }));\n }\n }\n }\n\n // -----------------------------------------------------------------------------------------\n // -------------------------Are-Interpolation Compile Section-----------------------------------\n // -----------------------------------------------------------------------------------------\n /**\n * Default compile method for interpolations, which can be overridden by specific implementations if needed.\n * \n * @param interpolation \n * @param scope \n * @param scene \n * @param store \n * @param feature \n */\n @AreCompiler.Compile(AreInterpolation)\n compileInterpolation(\n @A_Inject(A_Caller) interpolation: AreInterpolation,\n @A_Inject(AreScene) scene: AreScene,\n\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(A_Logger) logger?: A_Logger,\n ...args: any[]\n ) {\n // if (scene.host)\n // console.log('Scene Host: ', scene.host);\n\n // let content = '';\n\n // logger?.debug('green', `AreHTMLCompiler: compile interpolation <${interpolation.aseid.toString()}> with key: \"${interpolation.content}\"`, store.get(interpolation.content));\n\n // try {\n // content = AreCommonHelper.evaluate(interpolation.content, store);\n\n // } catch (error) {\n // content = ''\n // }\n\n scene.plan(new AddTextInstruction({ content: interpolation.content, evaluate: true }));\n }\n\n // -----------------------------------------------------------------------------------------\n // ------------------------------Are-Text Compile Section-----------------------------------\n // -----------------------------------------------------------------------------------------\n @AreCompiler.Compile(AreText)\n compileText(\n @A_Inject(A_Caller) text: AreText,\n @A_Inject(AreScene) scene: AreScene,\n @A_Inject(A_Logger) logger?: A_Logger,\n ...args: any[]\n ) {\n logger?.debug('cyan', `AreHTMLCompiler: compile text node <${text.aseid.toString()}> with content: \"${text.content}\"`);\n if (scene.host)\n scene.unPlan(scene.host);\n\n scene.plan(new AddTextInstruction({ content: text.content }));\n\n }\n\n // -----------------------------------------------------------------------------------------\n // -------------------------Are-Attribute Compile Section-----------------------------------\n // -----------------------------------------------------------------------------------------\n\n @AreCompiler.Compile(AreStaticAttribute)\n compileStaticAttribute(\n @A_Inject(A_Caller) attribute: AreStaticAttribute,\n @A_Inject(AreScene) scene: AreScene,\n ...args: any[]\n ) {\n if (!scene.host)\n throw new AreCompilerError({\n title: 'Scene Host Not Found',\n description: `No host found for the scene with id: ${scene.id}. Please ensure that the scene is properly initialized and has a host before compiling binding attributes.`\n });\n\n const content = attribute.content;\n\n /**\n * If the attribute value contains {{ }} interpolations, transform them into\n * a JS string-concatenation expression so the interpreter can evaluate them.\n * e.g. \"color:{{expr}}\" → '\"color:\"+(expr)+\"\"'\n */\n if (content.includes('{{')) {\n const transformed = '\"' + content.replace(/\\{\\{([^}]+)\\}\\}/g, '\"+($1)+\"') + '\"';\n scene.plan(new AddAttributeInstruction(scene.host, {\n name: attribute.name,\n content: transformed,\n evaluate: true,\n }));\n return;\n }\n\n /**\n * Default case: regular static attribute rendered as-is.\n */\n scene.plan(new AddAttributeInstruction(scene.host, {\n name: attribute.name,\n content: attribute.content\n }));\n }\n\n @AreCompiler.Compile(AreDirectiveAttribute)\n compileDirectiveAttribute(\n @A_Inject(A_Caller) directive: AreDirectiveAttribute,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(A_Feature) feature: A_Feature,\n @A_Inject(A_Logger) logger?: A_Logger,\n ...args: any[]\n ) {\n store.watch(directive);\n\n /**\n * 3. If the attribute is a directive, then we should find a component that is responsible for\n * the directive compiling logic, and call it. \n * In case component is not found we just want to log a warning, \n * since the directive may be handled by some parent component or simply is a mistake in the template.\n */\n if (directive.component) {\n feature.chain(directive.component, AreDirectiveFeatures.Compile, directive.owner.scope);\n } else {\n logger?.warning(`Directive handler component not found for directive: ${directive.name}. Make sure to create a component named \"AreDirective${A_FormatterHelper.toPascalCase(directive.name)}\" to handle this directive.`);\n }\n\n store.unwatch(directive);\n }\n\n\n @AreCompiler.Compile(AreEventAttribute)\n compileEventAttribute(\n @A_Inject(A_Caller) attribute: AreEventAttribute,\n @A_Inject(AreScene) scene: AreScene,\n ...args: any[]\n ) {\n\n if (!scene.host)\n throw new AreCompilerError({\n title: 'Scene Host Not Found',\n description: `No host found for the scene with id: ${scene.id}. Please ensure that the scene is properly initialized and has a host before compiling binding attributes.`\n });\n /**\n * 2. In case the attribute is an event listener, then \n * we should simply add a callback handler that will be used to proxy an event \n * into the ComponentNode component. \n *[!] In this case AreAttribute is AreEventAttribute that has prepared callback function to be used \n * in the event listener. It is important to store callback function once \n * to prevent duplicated functions in case of multiple compilations during development.\n */\n scene.plan(new AddListenerInstruction(scene.host, {\n name: attribute.name,\n handler: attribute.content\n }));\n }\n\n\n @AreCompiler.Compile(AreBindingAttribute)\n compileBindingAttribute(\n @A_Inject(A_Caller) attribute: AreBindingAttribute,\n @A_Inject(AreScene) scene: AreScene,\n @A_Dependency.Parent()\n @A_Inject(AreStore) parentStore: AreStore,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreSyntax) syntax: AreSyntax,\n @A_Inject(AreDirectiveContext) directiveContext?: AreDirectiveContext,\n ...args: any[]\n ) {\n if (!scene.host)\n throw new AreCompilerError({\n title: 'Scene Host Not Found',\n description: `No host found for the scene with id: ${scene.id}. Please ensure that the scene is properly initialized and has a host before compiling binding attributes.`\n });\n\n\n const node = attribute.owner;\n const props = node.component?.props;\n\n // Component prop names are typically declared in camelCase, while template\n // markup uses kebab-case. Try both forms when matching.\n let propName: string | undefined;\n if (props) {\n if (props[attribute.name]) {\n propName = attribute.name;\n } else {\n const camel = A_FormatterHelper.toCamelCase(attribute.name);\n if (props[camel]) propName = camel;\n }\n }\n\n /**\n * 1. Component prop binding — evaluate against the parent store and\n * keep the child store reactive to upstream changes.\n */\n if (propName && props) {\n const propDefinition = props[propName];\n\n const coerce = (raw: any): any => {\n let value = raw;\n if (propDefinition.type) {\n switch (propDefinition.type) {\n case 'string': value = value === undefined || value === null ? '' : String(value); break;\n case 'number': value = Number(value); break;\n case 'boolean': value = Boolean(value); break;\n }\n }\n return value;\n };\n\n // Item-scoped variables from an enclosing directive (the `item`/`index`\n // of a `$for`, or any scope a `$if` merged in) so a prop binding like\n // `:title=\"item.name\"` resolves the loop variable — checked BEFORE the\n // store, exactly like plain attribute bindings do in the interpreter.\n // Read `.scope` lazily inside each evaluation so keyed `$for` updates\n // that reassign the context's scope are always reflected.\n const directiveScope = () => directiveContext?.scope ?? {};\n\n // The watcher entity below is registered against parentStore so that\n // updates to the bound expression in the parent flow into the child store.\n const watcher = {\n update: () => {\n try {\n parentStore.watch(watcher);\n const next = coerce(syntax.evaluate(attribute.content, parentStore, directiveScope()));\n parentStore.unwatch(watcher);\n store.set(propName!, next);\n } catch (e) {\n parentStore.unwatch(watcher);\n }\n }\n };\n\n // Initial read with watch active so dependencies are recorded.\n parentStore.watch(watcher);\n const initial = coerce(syntax.evaluate(attribute.content, parentStore, directiveScope()));\n parentStore.unwatch(watcher);\n\n store.set(propName, initial);\n return;\n }\n\n /**\n * 2. Default attribute binding — evaluated reactively against the local store.\n */\n const instruction = new AddAttributeInstruction(scene.host, {\n name: attribute.name,\n content: attribute.content,\n evaluate: true\n })\n\n scene.plan(instruction);\n }\n\n\n}"]}
@@ -16,6 +16,7 @@ import { AddListenerInstruction } from '@adaas/are-html/instructions/AddListener
16
16
  import { AddStyleInstruction } from '@adaas/are-html/instructions/AddStyle.instruction';
17
17
  import { AddStaticHTMLInstruction } from '@adaas/are-html/instructions/AddStaticHTML.instruction';
18
18
  import { AreHTMLNode } from '@adaas/are-html/node';
19
+ import { AreDirectiveContext } from '@adaas/are-html/directive/AreDirective.context';
19
20
 
20
21
  let AreHTMLCompiler = class extends AreCompiler {
21
22
  compileHTMLNode(node, scene, logger, ...args) {
@@ -80,7 +81,7 @@ let AreHTMLCompiler = class extends AreCompiler {
80
81
  handler: attribute.content
81
82
  }));
82
83
  }
83
- compileBindingAttribute(attribute, scene, parentStore, store, syntax, ...args) {
84
+ compileBindingAttribute(attribute, scene, parentStore, store, syntax, directiveContext, ...args) {
84
85
  if (!scene.host)
85
86
  throw new AreCompilerError({
86
87
  title: "Scene Host Not Found",
@@ -116,11 +117,12 @@ let AreHTMLCompiler = class extends AreCompiler {
116
117
  }
117
118
  return value;
118
119
  };
120
+ const directiveScope = () => directiveContext?.scope ?? {};
119
121
  const watcher = {
120
122
  update: () => {
121
123
  try {
122
124
  parentStore.watch(watcher);
123
- const next = coerce(syntax.evaluate(attribute.content, parentStore));
125
+ const next = coerce(syntax.evaluate(attribute.content, parentStore, directiveScope()));
124
126
  parentStore.unwatch(watcher);
125
127
  store.set(propName, next);
126
128
  } catch (e) {
@@ -129,7 +131,7 @@ let AreHTMLCompiler = class extends AreCompiler {
129
131
  }
130
132
  };
131
133
  parentStore.watch(watcher);
132
- const initial = coerce(syntax.evaluate(attribute.content, parentStore));
134
+ const initial = coerce(syntax.evaluate(attribute.content, parentStore, directiveScope()));
133
135
  parentStore.unwatch(watcher);
134
136
  store.set(propName, initial);
135
137
  return;
@@ -185,7 +187,8 @@ __decorateClass([
185
187
  __decorateParam(2, A_Dependency.Parent()),
186
188
  __decorateParam(2, A_Inject(AreStore)),
187
189
  __decorateParam(3, A_Inject(AreStore)),
188
- __decorateParam(4, A_Inject(AreSyntax))
190
+ __decorateParam(4, A_Inject(AreSyntax)),
191
+ __decorateParam(5, A_Inject(AreDirectiveContext))
189
192
  ], AreHTMLCompiler.prototype, "compileBindingAttribute", 1);
190
193
  AreHTMLCompiler = __decorateClass([
191
194
  A_Frame.Define({