@xaendar/core 0.9.28 → 0.9.30
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/xaendar-core.d.ts +22 -2
- package/dist/xaendar-core.js +26 -4
- package/package.json +3 -3
package/dist/xaendar-core.d.ts
CHANGED
|
@@ -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
|
*
|
|
@@ -290,7 +310,7 @@ export declare type EventOptions = Beautify<RequireOne<Omit<CustomEventInit, 'de
|
|
|
290
310
|
* `update` per aggiornare le variabili implicite in-place quando l'item
|
|
291
311
|
* viene riusato a un indice diverso.
|
|
292
312
|
*/
|
|
293
|
-
export declare function _for(parentNode: HTMLElement, parentContext: Context, condition: NoArgsFunction<unknown[]>, trackExpression: Function_2<[unknown], ForKey>, forFn: Function_2<[HTMLElement, Context, unknown[], number, Node | null], {
|
|
313
|
+
export declare function _for(parentNode: HTMLElement, parentContext: Context, condition: NoArgsFunction<unknown[]>, trackExpression: Function_2<[unknown, number], ForKey>, forFn: Function_2<[HTMLElement, Context, unknown[], number, Node | null], {
|
|
294
314
|
context: Context;
|
|
295
315
|
update?: (newIndex: number, items: unknown[]) => void;
|
|
296
316
|
}>): void;
|
|
@@ -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
|
-
|
|
541
|
+
setter: typeof bindAttribute & typeof bindReactiveAttribute;
|
|
522
542
|
};
|
|
523
543
|
|
|
524
544
|
/**
|
package/dist/xaendar-core.js
CHANGED
|
@@ -503,7 +503,7 @@ function _for(parentNode, parentContext, condition, trackExpression, forFn) {
|
|
|
503
503
|
let entries = /* @__PURE__ */ new Map();
|
|
504
504
|
const unlistener = effect(() => {
|
|
505
505
|
const items = condition();
|
|
506
|
-
const newKeys = items.map((item) => trackExpression(item));
|
|
506
|
+
const newKeys = items.map((item, i) => trackExpression(item, i));
|
|
507
507
|
const newKeySet = new Set(newKeys);
|
|
508
508
|
untracked(() => {
|
|
509
509
|
const newEntries = /* @__PURE__ */ new Map();
|
|
@@ -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,
|
|
748
|
-
|
|
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.
|
|
3
|
+
"version": "0.9.30",
|
|
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.
|
|
26
|
-
"@xaendar/types": "0.9.
|
|
25
|
+
"@xaendar/signals": "0.9.30",
|
|
26
|
+
"@xaendar/types": "0.9.30"
|
|
27
27
|
}
|
|
28
28
|
}
|