@xaendar/core 0.6.5 → 0.6.6

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.
@@ -152,6 +152,16 @@ export { Event_2 as Event }
152
152
  */
153
153
  export declare type EventOptions = Beautify<RequireOne<Omit<CustomEventInit, 'detail'>>>;
154
154
 
155
+ /**
156
+ * Reactively iterates over a list of items, re-running the loop whenever the tracked condition changes.
157
+ * Previous iteration side-effects are cleaned up before each re-evaluation.
158
+ *
159
+ * @param unwatchFns - Array collecting cleanup functions for the parent scope.
160
+ * @param condition - A reactive function that returns the array of items to iterate over.
161
+ * @param forFn - A callback invoked for each item, receiving the item and its index. Must return an array of cleanup functions.
162
+ */
163
+ export declare function _for(unwatchFns: NoArgsVoidFunction[], condition: () => unknown[], forFn: (item: unknown, index: number) => NoArgsVoidFunction[]): void;
164
+
155
165
  /**
156
166
  * Creates a reactive conditional structure from a list of branches.
157
167
  *
@@ -227,6 +237,18 @@ export declare type InputSignalOptions<ActualValue = unknown, IncomingValue = Ac
227
237
  transform?: (value: IncomingValue) => ActualValue;
228
238
  };
229
239
 
240
+ /**
241
+ * Builds a record of iteration context variables for a given index in the loop.
242
+ * Provides the current item, index, and convenience flags (`$first`, `$last`, `$even`, `$odd`).
243
+ *
244
+ * @param items - The full array being iterated.
245
+ * @param index - The current iteration index.
246
+ * @param itemAlias - The template alias name for the current item.
247
+ * @param indexAlias - The template alias name for the current index.
248
+ * @returns A record mapping alias names and built-in variables to their values.
249
+ */
250
+ export declare function _iterationVariables(items: unknown[], index: number, itemAlias: string, indexAlias: string): Record<string, unknown>;
251
+
230
252
  /**
231
253
  * Rapresent the output type returned by an @Event Decorator in a Web Component.
232
254
  *
@@ -546,6 +546,51 @@ function unwatch(unwatchFns, localUnwatchFns) {
546
546
  }
547
547
  }
548
548
  //#endregion
549
+ //#region ../packages/core/src/utils/for.utils.ts
550
+ /**
551
+ * Reactively iterates over a list of items, re-running the loop whenever the tracked condition changes.
552
+ * Previous iteration side-effects are cleaned up before each re-evaluation.
553
+ *
554
+ * @param unwatchFns - Array collecting cleanup functions for the parent scope.
555
+ * @param condition - A reactive function that returns the array of items to iterate over.
556
+ * @param forFn - A callback invoked for each item, receiving the item and its index. Must return an array of cleanup functions.
557
+ */
558
+ function _for(unwatchFns, condition, forFn) {
559
+ const localUnwatchFns = new Array();
560
+ const unlistener = effect(() => {
561
+ unwatch(unwatchFns, localUnwatchFns);
562
+ const items = condition();
563
+ Signal.subtle.untrack(() => {
564
+ for (let i = 0; i < items.length; i++) {
565
+ localUnwatchFns.push(...forFn(items[i], i));
566
+ unwatchFns.push(...localUnwatchFns);
567
+ }
568
+ });
569
+ });
570
+ unwatchFns.push(unlistener);
571
+ }
572
+ /**
573
+ * Builds a record of iteration context variables for a given index in the loop.
574
+ * Provides the current item, index, and convenience flags (`$first`, `$last`, `$even`, `$odd`).
575
+ *
576
+ * @param items - The full array being iterated.
577
+ * @param index - The current iteration index.
578
+ * @param itemAlias - The template alias name for the current item.
579
+ * @param indexAlias - The template alias name for the current index.
580
+ * @returns A record mapping alias names and built-in variables to their values.
581
+ */
582
+ function _iterationVariables(items, index, itemAlias, indexAlias) {
583
+ const even = index % 2 === 0;
584
+ return {
585
+ [itemAlias]: items[index],
586
+ [indexAlias]: index,
587
+ $first: index === 0,
588
+ $last: index === items.length - 1,
589
+ $even: even,
590
+ $odd: !even
591
+ };
592
+ }
593
+ //#endregion
549
594
  //#region ../packages/core/src/utils/switch.utils.ts
550
595
  /**
551
596
  * Creates a reactive switch/case structure by converting it into an if/else-if chain
@@ -577,4 +622,4 @@ function _switch(unwatchFns, expression, blocks) {
577
622
  })));
578
623
  }
579
624
  //#endregion
580
- export { BaseWebComponent, Event, Property, WebComponent, _if, _switch, computed, effect, input, signal, unwatch };
625
+ export { BaseWebComponent, Event, Property, WebComponent, _for, _if, _iterationVariables, _switch, computed, effect, input, signal, unwatch };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xaendar/core",
3
- "version": "0.6.5",
3
+ "version": "0.6.6",
4
4
  "description": "A library containing core utils such as webcomponent base classes and theming support",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -16,7 +16,7 @@
16
16
  }
17
17
  },
18
18
  "dependencies": {
19
- "@xaendar/signals": "0.6.5",
20
- "@xaendar/types": "0.6.5"
19
+ "@xaendar/signals": "0.6.6",
20
+ "@xaendar/types": "0.6.6"
21
21
  }
22
22
  }