@apteva/apteva-kit 0.1.76 → 0.1.77
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 +20 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -606,6 +606,14 @@ function findMatchingBracket(text, startIndex) {
|
|
|
606
606
|
}
|
|
607
607
|
return -1;
|
|
608
608
|
}
|
|
609
|
+
function findOpeningBracket(text) {
|
|
610
|
+
const squareIndex = text.indexOf("[");
|
|
611
|
+
const curlyIndex = text.indexOf("{");
|
|
612
|
+
if (squareIndex === -1 && curlyIndex === -1) return null;
|
|
613
|
+
if (squareIndex === -1) return { index: curlyIndex, char: "{" };
|
|
614
|
+
if (curlyIndex === -1) return { index: squareIndex, char: "[" };
|
|
615
|
+
return squareIndex < curlyIndex ? { index: squareIndex, char: "[" } : { index: curlyIndex, char: "{" };
|
|
616
|
+
}
|
|
609
617
|
function parseWidgetsFromText(text) {
|
|
610
618
|
const segments = [];
|
|
611
619
|
let hasWidgets = false;
|
|
@@ -619,13 +627,14 @@ function parseWidgetsFromText(text) {
|
|
|
619
627
|
const typeMatch = afterStart.match(/^@ui:(\w+)/);
|
|
620
628
|
if (typeMatch) {
|
|
621
629
|
const widgetType = typeMatch[1];
|
|
622
|
-
const
|
|
623
|
-
|
|
630
|
+
const afterType = afterStart.slice(typeMatch[0].length);
|
|
631
|
+
const bracketInfo = findOpeningBracket(afterType);
|
|
632
|
+
if (!bracketInfo) {
|
|
624
633
|
processText = text.slice(0, lastWidgetStart);
|
|
625
634
|
pendingWidgetType = widgetType;
|
|
626
635
|
hasPendingWidget = true;
|
|
627
636
|
} else {
|
|
628
|
-
const fullBracketStart = lastWidgetStart +
|
|
637
|
+
const fullBracketStart = lastWidgetStart + typeMatch[0].length + bracketInfo.index;
|
|
629
638
|
const bracketEnd = findMatchingBracket(text, fullBracketStart);
|
|
630
639
|
if (bracketEnd === -1) {
|
|
631
640
|
if (STREAMABLE_WIDGET_TYPES.includes(widgetType)) {
|
|
@@ -667,16 +676,22 @@ function parseWidgetsFromText(text) {
|
|
|
667
676
|
if (hasPendingWidget) {
|
|
668
677
|
processText = processText.replace(/[\s:;\-–—\.]+$/g, "");
|
|
669
678
|
}
|
|
670
|
-
const startPattern = /@ui:(\w+)\[/g;
|
|
679
|
+
const startPattern = /@ui:(\w+)([\[{])/g;
|
|
671
680
|
let match;
|
|
672
681
|
while ((match = startPattern.exec(processText)) !== null) {
|
|
673
682
|
const widgetType = match[1];
|
|
683
|
+
const openingBracket = match[2];
|
|
674
684
|
const bracketStart = match.index + match[0].length - 1;
|
|
675
685
|
const bracketEnd = findMatchingBracket(processText, bracketStart);
|
|
676
686
|
if (bracketEnd === -1) {
|
|
677
687
|
continue;
|
|
678
688
|
}
|
|
679
|
-
|
|
689
|
+
let jsonContent;
|
|
690
|
+
if (openingBracket === "[") {
|
|
691
|
+
jsonContent = processText.slice(bracketStart + 1, bracketEnd);
|
|
692
|
+
} else {
|
|
693
|
+
jsonContent = processText.slice(bracketStart, bracketEnd + 1);
|
|
694
|
+
}
|
|
680
695
|
if (match.index > currentIndex) {
|
|
681
696
|
const textContent = processText.slice(currentIndex, match.index).trim();
|
|
682
697
|
if (textContent) {
|