@sitecore-feaas/clientside 0.3.7 → 0.3.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/build/ui/FEAASExternal.js +10 -1
- package/build/ui/FEAASExternal.js.map +1 -1
- package/build/ui/react.js +7 -7
- package/build/ui/react.js.map +1 -1
- package/dist/browser/headless.esm.js.map +1 -1
- package/dist/browser/index.esm.js.map +1 -1
- package/dist/browser/react.cjs +5 -5
- package/dist/browser/react.cjs.map +3 -3
- package/dist/browser/react.esm.js +5 -5
- package/dist/browser/react.esm.js.map +1 -1
- package/dist/node/react.cjs +4 -4
- package/dist/node/react.cjs.map +3 -3
- package/dist/node/react.esm.js +4 -4
- package/dist/node/react.esm.js.map +3 -3
- package/package.json +1 -1
- package/react.cjs +5 -5
- package/react.cjs.map +3 -3
- package/react.js +5 -5
- package/react.js.map +3 -3
- package/src/ui/FEAASExternal.tsx +10 -1
- package/src/ui/react.tsx +18 -12
- package/types/tsbuildinfo +1 -1
- package/types/ui/FEAASExternal.d.ts +1 -0
- package/types/ui/FEAASExternal.d.ts.map +1 -1
- package/types/ui/react.d.ts +1 -1
- package/types/ui/react.d.ts.map +1 -1
- package/types/ui/tsbuildinfo +1 -1
package/src/ui/FEAASExternal.tsx
CHANGED
|
@@ -109,10 +109,19 @@ export default class FEAASExternal extends FEAASElement<FEAASExternalProps, Reac
|
|
|
109
109
|
return Promise.resolve({ React, ReactDOM })
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
update() {
|
|
113
|
+
const { dataExternalId: id } = this.props
|
|
114
|
+
const Component = FEAASExternal.registered[id]?.component
|
|
115
|
+
if (!Component && this.childNodes.length > 0) return
|
|
116
|
+
return super.update()
|
|
117
|
+
}
|
|
118
|
+
|
|
112
119
|
render(props: FEAASExternalProps, { React }: ReactModules): ReactJSX {
|
|
113
120
|
const { dataExternalId: id } = props
|
|
114
121
|
const Component = FEAASExternal.registered[id]?.component
|
|
115
|
-
if (!Component)
|
|
122
|
+
if (!Component) {
|
|
123
|
+
console.warn('FEAASExternal: The component you requested is not registered')
|
|
124
|
+
}
|
|
116
125
|
return <>{Component && <Component {...props} />}</>
|
|
117
126
|
}
|
|
118
127
|
|
package/src/ui/react.tsx
CHANGED
|
@@ -40,12 +40,16 @@ export function FEAASReactComponent({ data, ...props }: FEAASReactComponentProps
|
|
|
40
40
|
let children: null | React.ReactNode
|
|
41
41
|
|
|
42
42
|
if ('template' in props && props.template) {
|
|
43
|
-
children = parseHTMLContent(props.template, data || {}).map((node) =>
|
|
44
|
-
HTMLNodeToReact(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
children = parseHTMLContent(props.template, data || {}).map((node, index) =>
|
|
44
|
+
HTMLNodeToReact(
|
|
45
|
+
node,
|
|
46
|
+
(node) => {
|
|
47
|
+
if (node.localName == 'feaas-external' && getComponent(node.getAttribute('data-external-id'))) {
|
|
48
|
+
return [FEAASReactExternal, {}]
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
index
|
|
52
|
+
)
|
|
49
53
|
)
|
|
50
54
|
}
|
|
51
55
|
|
|
@@ -63,7 +67,7 @@ export function FEAASReactComponent({ data, ...props }: FEAASReactComponentProps
|
|
|
63
67
|
)}
|
|
64
68
|
<feaas-component
|
|
65
69
|
{...props}
|
|
66
|
-
suppressHydrationWarning
|
|
70
|
+
suppressHydrationWarning
|
|
67
71
|
template={null}
|
|
68
72
|
data={typeof data == 'string' ? data : data ? JSON.stringify(data) : null}
|
|
69
73
|
>
|
|
@@ -75,9 +79,10 @@ export function FEAASReactComponent({ data, ...props }: FEAASReactComponentProps
|
|
|
75
79
|
|
|
76
80
|
export function FEAASReactExternal(props: { 'data-external-id': string }) {
|
|
77
81
|
const Component = getComponent(props['data-external-id'])?.component
|
|
82
|
+
// execute component as a function to supress hydration errors inside
|
|
78
83
|
return (
|
|
79
|
-
<feaas-external {...props}>
|
|
80
|
-
<Component {...props} />
|
|
84
|
+
<feaas-external {...props} suppressHydrationWarning>
|
|
85
|
+
{typeof Component == 'function' ? Component({ ...props }) : <Component {...props} />}
|
|
81
86
|
</feaas-external>
|
|
82
87
|
)
|
|
83
88
|
}
|
|
@@ -85,12 +90,13 @@ export function FEAASReactExternal(props: { 'data-external-id': string }) {
|
|
|
85
90
|
/** Turn HTMLNode into React tree. It accepts callback to customize the behavior */
|
|
86
91
|
export function HTMLNodeToReact(
|
|
87
92
|
node: HTMLNode,
|
|
88
|
-
callback?: (node: HTMLNode) => [tagName: any, attributes: Record<string, any>]
|
|
93
|
+
callback?: (node: HTMLNode) => [tagName: any, attributes: Record<string, any>],
|
|
94
|
+
key?: any
|
|
89
95
|
): React.ReactNode {
|
|
90
96
|
if (node.nodeType === 3) {
|
|
91
97
|
return node.textContent
|
|
92
98
|
}
|
|
93
|
-
const children = Array.from(node.childNodes).map((child) => HTMLNodeToReact(child, callback))
|
|
99
|
+
const children = Array.from(node.childNodes).map((child, index) => HTMLNodeToReact(child, callback, index))
|
|
94
100
|
|
|
95
101
|
const attributes: { [key: string]: string } = {}
|
|
96
102
|
for (let i = 0; i < node.attributes.length; i++) {
|
|
@@ -100,7 +106,7 @@ export function HTMLNodeToReact(
|
|
|
100
106
|
|
|
101
107
|
const reactNode = callback?.(node)
|
|
102
108
|
const reactName = reactNode?.[0] || node.nodeName.toLowerCase()
|
|
103
|
-
const reactAttributes = Object.assign(attributes,
|
|
109
|
+
const reactAttributes = Object.assign({ key, suppressHydrationWarning: true }, attributes, reactNode?.[1] || {})
|
|
104
110
|
return React.createElement(reactName, reactAttributes, ['img', 'br', 'input'].includes(reactName) ? null : children)
|
|
105
111
|
}
|
|
106
112
|
|