@xaendar/core 0.6.10 → 0.6.11

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.
@@ -366,6 +366,37 @@ declare type PropertyDecoratorOptionsWithRequired<ActualValue = unknown, Incomin
366
366
  required: true;
367
367
  };
368
368
 
369
+ export declare function _renderElement(parentNode: HTMLElement, context: Context, tagName: string, attributes: RenderElementAttribute[], events: RenderElementEvent[]): void;
370
+
371
+ declare type RenderElementAttribute = {
372
+ name: string;
373
+ value: string;
374
+ literal: boolean;
375
+ };
376
+
377
+ declare type RenderElementEvent = {
378
+ name: string;
379
+ handler: string;
380
+ };
381
+
382
+ /**
383
+ *
384
+ * @param parentNode
385
+ * @param text
386
+ * @param context
387
+ * @returns
388
+ */
389
+ export declare function _renderLiteralText(parentNode: HTMLElement, context: Context, text: string): void;
390
+
391
+ /**
392
+ *
393
+ * @param parentNode
394
+ * @param text
395
+ * @param context
396
+ * @returns
397
+ */
398
+ export declare function _renderText(parentNode: HTMLElement, context: Context, text: string): void;
399
+
369
400
  /**
370
401
  * Creates a writable reactive signal.
371
402
  *
@@ -400,7 +400,7 @@ function signal(value, options) {
400
400
  return getter;
401
401
  }
402
402
  //#endregion
403
- //#region ../packages/core/src/utils/context.utils.ts
403
+ //#region ../packages/core/src/utils/context.util.ts
404
404
  /**
405
405
  * Tracks identifier scope during run time template function execution
406
406
  * Each `Context` instance represents one lexical scope (e.g. a `@for` loop body)
@@ -479,7 +479,7 @@ var Context = class {
479
479
  }
480
480
  };
481
481
  //#endregion
482
- //#region ../packages/core/src/utils/for.utils.ts
482
+ //#region ../packages/core/src/utils/for.util.ts
483
483
  /**
484
484
  * Reactively iterates over a list of items, re-running the loop whenever the tracked condition changes.
485
485
  * Previous iteration side-effects are cleaned up before each re-evaluation.
@@ -530,7 +530,7 @@ function _iterationVariables(items, index, itemAlias, indexAlias) {
530
530
  };
531
531
  }
532
532
  //#endregion
533
- //#region ../packages/core/src/utils/if.utils.ts
533
+ //#region ../packages/core/src/utils/if.util.ts
534
534
  /**
535
535
  * Creates a reactive conditional structure from a list of branches.
536
536
  *
@@ -659,7 +659,61 @@ function checkAndUpdateState(parentNode, parentContext, state, newState, conditi
659
659
  }
660
660
  }
661
661
  //#endregion
662
- //#region ../packages/core/src/utils/switch.utils.ts
662
+ //#region ../packages/core/src/utils/render-text.util.ts
663
+ /**
664
+ *
665
+ * @param parentNode
666
+ * @param text
667
+ * @param context
668
+ * @returns
669
+ */
670
+ function _renderText(parentNode, context, text) {
671
+ const identifier = context.getIdentifier(text);
672
+ const node = document.createTextNode(identifier.get());
673
+ parentNode.appendChild(node);
674
+ context.listen(() => {
675
+ context.removeNode(node);
676
+ parentNode.removeChild(node);
677
+ });
678
+ if (identifier.reactive) context.listen(effect(() => node.textContent = identifier.get()));
679
+ }
680
+ /**
681
+ *
682
+ * @param parentNode
683
+ * @param text
684
+ * @param context
685
+ * @returns
686
+ */
687
+ function _renderLiteralText(parentNode, context, text) {
688
+ const node = document.createTextNode(text);
689
+ parentNode.appendChild(node);
690
+ context.listen(() => parentNode.removeChild(node));
691
+ }
692
+ //#endregion
693
+ //#region ../packages/core/src/utils/render-util.ts
694
+ function _renderElement(parentNode, context, tagName, attributes, events) {
695
+ const element = document.createElement(tagName);
696
+ parentNode.appendChild(element);
697
+ context.listen(() => {
698
+ context.removeNode(element);
699
+ parentNode.removeChild(element);
700
+ });
701
+ attributes.forEach(({ name, value, literal }) => {
702
+ if (literal) element.setAttribute(name, value);
703
+ else {
704
+ const identifier = context.getIdentifier(value);
705
+ identifier.reactive ? context.listen(effect(() => element.setAttribute(name, String(identifier.get())))) : element.setAttribute(name, String(identifier.get()));
706
+ }
707
+ });
708
+ events.forEach((event) => {
709
+ const handler = ($event) => context.getEventHandler(event.handler);
710
+ const name = event.name;
711
+ element.addEventListener(name, handler);
712
+ context.listen(() => element.removeEventListener(name, handler));
713
+ });
714
+ }
715
+ //#endregion
716
+ //#region ../packages/core/src/utils/switch.util.ts
663
717
  /**
664
718
  * Creates a reactive switch/case structure by converting it into an if/else-if chain
665
719
  * and delegating to {@link _if}.
@@ -692,4 +746,4 @@ function _switch(parentNode, parentContext, expression, blocks) {
692
746
  })));
693
747
  }
694
748
  //#endregion
695
- export { BaseWebComponent, Context, Event, Property, WebComponent, _for, _if, _iterationVariables, _switch, computed, effect, input, signal };
749
+ export { BaseWebComponent, Context, Event, Property, WebComponent, _for, _if, _iterationVariables, _renderElement, _renderLiteralText, _renderText, _switch, computed, effect, input, signal };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xaendar/core",
3
- "version": "0.6.10",
3
+ "version": "0.6.11",
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.10",
20
- "@xaendar/types": "0.6.10"
19
+ "@xaendar/signals": "0.6.11",
20
+ "@xaendar/types": "0.6.11"
21
21
  }
22
22
  }