@teleporthq/teleport-plugin-html-base-component 0.40.4 → 0.40.8
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/cjs/node-handlers.d.ts.map +1 -1
- package/dist/cjs/node-handlers.js +85 -33
- package/dist/cjs/node-handlers.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/node-handlers.d.ts.map +1 -1
- package/dist/esm/node-handlers.js +85 -33
- package/dist/esm/node-handlers.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/node-handlers.ts +105 -34
package/src/node-handlers.ts
CHANGED
|
@@ -136,7 +136,8 @@ export const generateHtmlSyntax: NodeToHTML<
|
|
|
136
136
|
propDefinitions,
|
|
137
137
|
stateDefinitions,
|
|
138
138
|
subComponentOptions,
|
|
139
|
-
structure
|
|
139
|
+
structure,
|
|
140
|
+
resolvedExpressions
|
|
140
141
|
)
|
|
141
142
|
return dynamicNode
|
|
142
143
|
|
|
@@ -232,6 +233,29 @@ export const generateHtmlSyntax: NodeToHTML<
|
|
|
232
233
|
return generatedNode
|
|
233
234
|
}
|
|
234
235
|
|
|
236
|
+
// Fallback: support simple prop/state expressions outside of repeater context
|
|
237
|
+
if (content[0] && (propDefinitions?.[content[0]] || stateDefinitions?.[content[0]])) {
|
|
238
|
+
const isProp = Boolean(propDefinitions?.[content[0]])
|
|
239
|
+
const uidlDynamicRef: UIDLDynamicReference = {
|
|
240
|
+
type: 'dynamic',
|
|
241
|
+
content: {
|
|
242
|
+
referenceType: isProp ? 'prop' : 'state',
|
|
243
|
+
refPath: content.slice(1),
|
|
244
|
+
id: content[0],
|
|
245
|
+
},
|
|
246
|
+
}
|
|
247
|
+
const generatedNode = await generateDynamicNode(
|
|
248
|
+
uidlDynamicRef,
|
|
249
|
+
compName,
|
|
250
|
+
nodesLookup,
|
|
251
|
+
isProp ? propDefinitions : stateDefinitions,
|
|
252
|
+
stateDefinitions,
|
|
253
|
+
subComponentOptions,
|
|
254
|
+
structure
|
|
255
|
+
)
|
|
256
|
+
return generatedNode
|
|
257
|
+
}
|
|
258
|
+
|
|
235
259
|
return HASTBuilders.createComment('Expressions are not supported in HTML')
|
|
236
260
|
case 'cms-list-repeater':
|
|
237
261
|
return generateRepeaterNode(
|
|
@@ -664,18 +688,27 @@ const generateComponentContent = async (
|
|
|
664
688
|
const propKeyFromAttr = Object.keys(combinedProps).find((key) => key === ctxId)
|
|
665
689
|
|
|
666
690
|
const resolvedValue = combinedProps[propKeyFromAttr]
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
691
|
+
const hasRefPath = refPath.length > 0
|
|
692
|
+
// Build the path using repeater index when available
|
|
693
|
+
const fullRefPath =
|
|
694
|
+
typeof resolvedExpressions?.currentIndex === 'number' && hasRefPath
|
|
695
|
+
? [resolvedExpressions.currentIndex.toString(), ...refPath]
|
|
696
|
+
: refPath
|
|
697
|
+
|
|
698
|
+
if (Array.isArray(resolvedValue)) {
|
|
699
|
+
// If the resolved value itself is an array definition, pass it through
|
|
700
|
+
propsForInstance[propKey] = resolvedValue
|
|
701
|
+
} else {
|
|
702
|
+
const defaultVal = resolvedValue?.defaultValue
|
|
703
|
+
const extracted =
|
|
704
|
+
hasRefPath && defaultVal !== undefined
|
|
705
|
+
? extractDefaultValueFromRefPath(defaultVal, fullRefPath)
|
|
706
|
+
: defaultVal ?? null
|
|
707
|
+
propsForInstance[propKey] = {
|
|
708
|
+
...resolvedValue,
|
|
709
|
+
defaultValue: extracted,
|
|
710
|
+
}
|
|
711
|
+
}
|
|
679
712
|
}
|
|
680
713
|
|
|
681
714
|
if (
|
|
@@ -724,7 +757,8 @@ const generateComponentContent = async (
|
|
|
724
757
|
propsForInstance,
|
|
725
758
|
statesForInstance,
|
|
726
759
|
subComponentOptions,
|
|
727
|
-
structure
|
|
760
|
+
structure,
|
|
761
|
+
resolvedExpressions
|
|
728
762
|
)
|
|
729
763
|
|
|
730
764
|
const cssPlugin = createCSSPlugin({
|
|
@@ -786,7 +820,8 @@ const generateDynamicNode: NodeToHTML<
|
|
|
786
820
|
propDefinitions,
|
|
787
821
|
stateDefinitions,
|
|
788
822
|
subComponentOptions,
|
|
789
|
-
structure
|
|
823
|
+
structure,
|
|
824
|
+
resolvedExpressions?
|
|
790
825
|
): Promise<HastNode | HastText | Array<HastNode | HastText>> => {
|
|
791
826
|
if (node.content.referenceType === 'locale') {
|
|
792
827
|
const localeTag = HASTBuilders.createHTMLNode('span')
|
|
@@ -807,33 +842,53 @@ const generateDynamicNode: NodeToHTML<
|
|
|
807
842
|
// Let's say users are biding the prop to a node using something like this "fields.Title"
|
|
808
843
|
// But the fields in the object is the value where the object is defined either in propDefinitions
|
|
809
844
|
// or on the attrs. So, we just need to parsed the rest of the object path and get the value from the object.
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
usedReferenceValue.defaultValue as Record<string, UIDLPropDefinition>,
|
|
814
|
-
node.content.refPath
|
|
815
|
-
)
|
|
816
|
-
)
|
|
845
|
+
const extracted = extractDefaultValueFromRefPath(
|
|
846
|
+
usedReferenceValue.defaultValue as Record<string, UIDLPropDefinition>,
|
|
847
|
+
node.content.refPath
|
|
817
848
|
)
|
|
849
|
+
if (extracted === undefined || extracted === null) {
|
|
850
|
+
return HASTBuilders.createTextNode('')
|
|
851
|
+
}
|
|
852
|
+
return HASTBuilders.createTextNode(String(extracted))
|
|
818
853
|
}
|
|
819
854
|
|
|
820
855
|
if (usedReferenceValue.type === 'element') {
|
|
821
856
|
const elementNode = usedReferenceValue.defaultValue as UIDLElementNode
|
|
822
857
|
if (elementNode) {
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
858
|
+
// In repeater context, avoid reusing cached nodes; uniquify key per iteration
|
|
859
|
+
if (resolvedExpressions && typeof resolvedExpressions.currentIndex === 'number') {
|
|
860
|
+
const elementClone = UIDLUtils.cloneObject<UIDLElementNode>(elementNode)
|
|
861
|
+
if (elementClone?.content?.key) {
|
|
862
|
+
elementClone.content.key = `${elementClone.content.key}-${resolvedExpressions.currentIndex}`
|
|
863
|
+
}
|
|
864
|
+
const iterElementTag = await generateHtmlSyntax(
|
|
865
|
+
elementClone,
|
|
828
866
|
compName,
|
|
829
867
|
nodesLookup,
|
|
830
868
|
propDefinitions,
|
|
831
869
|
stateDefinitions,
|
|
832
870
|
subComponentOptions,
|
|
833
|
-
structure
|
|
871
|
+
structure,
|
|
872
|
+
resolvedExpressions
|
|
834
873
|
)
|
|
835
|
-
return
|
|
874
|
+
return iterElementTag
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
if (elementNode.content.key in nodesLookup) {
|
|
878
|
+
return nodesLookup[elementNode.content.key]
|
|
836
879
|
}
|
|
880
|
+
|
|
881
|
+
const generatedElementTag = await generateHtmlSyntax(
|
|
882
|
+
elementNode,
|
|
883
|
+
compName,
|
|
884
|
+
nodesLookup,
|
|
885
|
+
propDefinitions,
|
|
886
|
+
stateDefinitions,
|
|
887
|
+
subComponentOptions,
|
|
888
|
+
structure,
|
|
889
|
+
resolvedExpressions
|
|
890
|
+
)
|
|
891
|
+
return generatedElementTag
|
|
837
892
|
}
|
|
838
893
|
|
|
839
894
|
const spanTagWrapper = HASTBuilders.createHTMLNode('span')
|
|
@@ -958,9 +1013,8 @@ const handleAttributes = (
|
|
|
958
1013
|
content.referenceType === 'prop' ? propDefinitions : stateDefinitions
|
|
959
1014
|
)
|
|
960
1015
|
|
|
961
|
-
const
|
|
962
|
-
|
|
963
|
-
)
|
|
1016
|
+
const extracted = extractDefaultValueFromRefPath(value.defaultValue, content.refPath)
|
|
1017
|
+
const extractedValue = String(extracted)
|
|
964
1018
|
|
|
965
1019
|
if (
|
|
966
1020
|
(elementType === 'img' || elementType === 'video') &&
|
|
@@ -1060,8 +1114,25 @@ const getValueFromReference = (
|
|
|
1060
1114
|
const extractDefaultValueFromRefPath = (
|
|
1061
1115
|
propDefaultValue: PropDefaultValueTypes,
|
|
1062
1116
|
refPath?: string[]
|
|
1063
|
-
) => {
|
|
1064
|
-
if (
|
|
1117
|
+
): PropDefaultValueTypes => {
|
|
1118
|
+
if (!refPath || refPath.length === 0) {
|
|
1119
|
+
return propDefaultValue
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
// Directly handle array indexing for the first segment when applicable
|
|
1123
|
+
if (Array.isArray(propDefaultValue)) {
|
|
1124
|
+
const [first, ...rest] = refPath
|
|
1125
|
+
const idx = Number(first)
|
|
1126
|
+
if (!Number.isNaN(idx) && idx >= 0 && idx < propDefaultValue.length) {
|
|
1127
|
+
const nextVal = propDefaultValue[idx] as PropDefaultValueTypes
|
|
1128
|
+
if (rest.length === 0) {
|
|
1129
|
+
return nextVal
|
|
1130
|
+
}
|
|
1131
|
+
return extractDefaultValueFromRefPath(nextVal, rest)
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
if (typeof propDefaultValue !== 'object') {
|
|
1065
1136
|
return propDefaultValue
|
|
1066
1137
|
}
|
|
1067
1138
|
|