@xaendar/core 0.9.27 → 0.9.29

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.
@@ -73,6 +73,26 @@ export declare type BaseWebComponentConstructor = Constructor<BaseWebComponent,
73
73
  observedAttributes: string[];
74
74
  }>;
75
75
 
76
+ /**
77
+ * Sets a static attribute value on an HTML element.
78
+ *
79
+ * @param element - The element to set the attribute on.
80
+ * @param name - The name of the attribute.
81
+ * @param getter - A function that returns the attribute value.
82
+ */
83
+ export declare function bindAttribute(element: Element, name: string, getter: NoArgsFunction<unknown>): void;
84
+
85
+ /**
86
+ * Sets a reactive attribute value on an HTML element that updates automatically
87
+ * whenever the underlying signal changes.
88
+ *
89
+ * @param context - The current template execution scope.
90
+ * @param element - The element to set the attribute on.
91
+ * @param name - The name of the attribute.
92
+ * @param getter - A function that returns the attribute value.
93
+ */
94
+ export declare function bindReactiveAttribute(context: Context, element: Element, name: string, getter: NoArgsFunction<unknown>): void;
95
+
76
96
  /**
77
97
  * Represents a single branch of a conditional structure (`if` / `else if` / `else`).
78
98
  *
@@ -518,7 +538,7 @@ declare type RenderElementAttribute = {
518
538
  /**
519
539
  * When `true`, the value is a static string literal; when `false`, it is a reactive expression.
520
540
  */
521
- reactive: boolean;
541
+ setter: typeof bindAttribute & typeof bindReactiveAttribute;
522
542
  };
523
543
 
524
544
  /**
@@ -744,8 +744,8 @@ function _renderElement(parentNode, context, anchor, tagName, attributes, events
744
744
  const element = context.createElement(tagName);
745
745
  mountNode(element, parentNode, context, anchor);
746
746
  for (let i = 0; i < attributes.length; i++) {
747
- const { name, value, reactive } = attributes[i];
748
- reactive ? context.listen(effect(() => element.setAttribute(name, String(value())))) : element.setAttribute(name, String(value()));
747
+ const { name, value, setter } = attributes[i];
748
+ setter === bindAttribute ? setter(element, name, value) : setter(context, element, name, value);
749
749
  }
750
750
  for (let i = 0; i < events.length; i++) {
751
751
  const event = events[i];
@@ -783,6 +783,28 @@ function createSVGElement(tagName) {
783
783
  function createMATHMLElement(tagName) {
784
784
  return document.createElementNS(MATHML_NS, tagName);
785
785
  }
786
+ /**
787
+ * Sets a static attribute value on an HTML element.
788
+ *
789
+ * @param element - The element to set the attribute on.
790
+ * @param name - The name of the attribute.
791
+ * @param getter - A function that returns the attribute value.
792
+ */
793
+ function bindAttribute(element, name, getter) {
794
+ element.setAttribute(name, String(getter()));
795
+ }
796
+ /**
797
+ * Sets a reactive attribute value on an HTML element that updates automatically
798
+ * whenever the underlying signal changes.
799
+ *
800
+ * @param context - The current template execution scope.
801
+ * @param element - The element to set the attribute on.
802
+ * @param name - The name of the attribute.
803
+ * @param getter - A function that returns the attribute value.
804
+ */
805
+ function bindReactiveAttribute(context, element, name, getter) {
806
+ context.listen(effect(() => element.setAttribute(name, String(getter()))));
807
+ }
786
808
  //#endregion
787
809
  //#region ../packages/core/src/utils/render-text.util.ts
788
810
  /**
@@ -847,4 +869,4 @@ function _switch(parentNode, parentContext, expression, blocks) {
847
869
  })));
848
870
  }
849
871
  //#endregion
850
- export { BaseWebComponent, Context, Event, Property, WebComponent, _for, _if, _iterationVariables, _renderElement, _renderLiteralText, _renderText, _switch, createAnchor, createElement, createMATHMLElement, createSVGElement, mountNode };
872
+ export { BaseWebComponent, Context, Event, Property, WebComponent, _for, _if, _iterationVariables, _renderElement, _renderLiteralText, _renderText, _switch, bindAttribute, bindReactiveAttribute, createAnchor, createElement, createMATHMLElement, createSVGElement, mountNode };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xaendar/core",
3
- "version": "0.9.27",
3
+ "version": "0.9.29",
4
4
  "description": "A library containing core utils such as webcomponent base classes and theming support",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -22,7 +22,7 @@
22
22
  }
23
23
  },
24
24
  "dependencies": {
25
- "@xaendar/signals": "0.9.27",
26
- "@xaendar/types": "0.9.27"
25
+ "@xaendar/signals": "0.9.29",
26
+ "@xaendar/types": "0.9.29"
27
27
  }
28
28
  }