pupt-lib 1.2.1 → 1.2.2

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/index.js CHANGED
@@ -547,6 +547,57 @@ function createInputIterator(element, options = {}) {
547
547
  }
548
548
  return reqs.length;
549
549
  }
550
+ function followPath2(obj, path) {
551
+ return path.reduce((current, key) => {
552
+ if (current == null) return void 0;
553
+ return current[key];
554
+ }, obj);
555
+ }
556
+ function resolveIteratorPropValue(value) {
557
+ if (isPuptElement(value)) {
558
+ const elementProps = value[PROPS];
559
+ const elementName = elementProps.name;
560
+ if (elementName && values2.has(elementName)) {
561
+ return values2.get(elementName);
562
+ }
563
+ if (elementProps.default !== void 0) {
564
+ return elementProps.default;
565
+ }
566
+ return void 0;
567
+ }
568
+ if (isDeferredRef(value)) {
569
+ const elementProps = value.element[PROPS];
570
+ const elementName = elementProps.name;
571
+ let elementValue;
572
+ if (elementName && values2.has(elementName)) {
573
+ elementValue = values2.get(elementName);
574
+ } else if (elementProps.default !== void 0) {
575
+ elementValue = elementProps.default;
576
+ }
577
+ return followPath2(elementValue, value.path);
578
+ }
579
+ if (Array.isArray(value)) {
580
+ return value.map((item) => resolveIteratorPropValue(item));
581
+ }
582
+ if (value !== null && typeof value === "object" && !isPuptElement(value) && !isDeferredRef(value)) {
583
+ const resolved = {};
584
+ for (const [key, val] of Object.entries(value)) {
585
+ resolved[key] = resolveIteratorPropValue(val);
586
+ }
587
+ return resolved;
588
+ }
589
+ return value;
590
+ }
591
+ function resolveIteratorProps(props) {
592
+ if (props == null) {
593
+ return {};
594
+ }
595
+ const resolved = {};
596
+ for (const [key, value] of Object.entries(props)) {
597
+ resolved[key] = resolveIteratorPropValue(value);
598
+ }
599
+ return resolved;
600
+ }
550
601
  async function walkNode(node, context) {
551
602
  if (node === null || node === void 0 || node === false) {
552
603
  return;
@@ -571,8 +622,14 @@ function createInputIterator(element, options = {}) {
571
622
  return;
572
623
  }
573
624
  if (isComponentClass(type)) {
625
+ if (children && children.length > 0) {
626
+ for (const child of children) {
627
+ await walkNode(child, context);
628
+ }
629
+ }
574
630
  const instance = new type();
575
- const renderResult = instance.render({ ...props, children }, void 0, context);
631
+ const resolvedProps = resolveIteratorProps(props);
632
+ const renderResult = instance.render({ ...resolvedProps, children }, void 0, context);
576
633
  const result = renderResult instanceof Promise ? await renderResult : renderResult;
577
634
  if (result !== null && typeof result === "object") {
578
635
  await walkNode(result, context);
@@ -580,8 +637,14 @@ function createInputIterator(element, options = {}) {
580
637
  return;
581
638
  }
582
639
  if (typeof type === "function" && !isComponentClass(type)) {
640
+ if (children && children.length > 0) {
641
+ for (const child of children) {
642
+ await walkNode(child, context);
643
+ }
644
+ }
583
645
  const fn = type;
584
- const renderResult = fn({ ...props, children });
646
+ const resolvedProps = resolveIteratorProps(props);
647
+ const renderResult = fn({ ...resolvedProps, children });
585
648
  const result = renderResult instanceof Promise ? await renderResult : renderResult;
586
649
  if (result !== null && typeof result === "object") {
587
650
  await walkNode(result, context);
@@ -1 +1 @@
1
- {"version":3,"file":"input-iterator.d.ts","sourceRoot":"","sources":["../../src/services/input-iterator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAY,gBAAgB,EAAE,gBAAgB,EAAiB,MAAM,UAAU,CAAC;AAQzG,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,SAAS,CAAC;AA6CpD;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,OAAO,GAAG,MAAM,CAAC;AAExD,MAAM,WAAW,oBAAoB;IACnC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,0DAA0D;IAC1D,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,wBA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AAO,CAAC,IAAI,CAAC,CAAC;IACvB,OAAO,IAAI,gBAAgB,GAAG,IAAI,CAAC;IACnC,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAClD;;;OAGG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,MAAM,IAAI,OAAO,CAAC;IAClB,SAAS,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC;;;;;;OAMG;IACH,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACpD;AAID,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,WAAW,EACpB,OAAO,GAAE,oBAAyB,GACjC,aAAa,CA2sBf"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pupt-lib",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "TypeScript library for creating AI prompts using JSX syntax",
5
5
  "license": "MIT",
6
6
  "author": "",