@sitecore-feaas/clientside 0.3.6 → 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/dom/thumbnail.js +2 -1
- package/build/dom/thumbnail.js.map +1 -1
- package/build/ui/FEAASContext.js +4 -1
- package/build/ui/FEAASContext.js.map +1 -1
- 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/build/utils/data.js +3 -3
- package/build/utils/data.js.map +1 -1
- package/dist/browser/headless.cjs +2 -2
- package/dist/browser/headless.cjs.map +2 -2
- package/dist/browser/headless.esm.js +2 -2
- package/dist/browser/headless.esm.js.map +1 -1
- package/dist/browser/index.cjs +3 -3
- package/dist/browser/index.cjs.map +2 -2
- package/dist/browser/index.esm.js +3 -3
- 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/headless.cjs +4 -4
- package/dist/node/headless.cjs.map +2 -2
- package/dist/node/headless.esm.js +4 -4
- package/dist/node/headless.esm.js.map +2 -2
- package/dist/node/index.cjs +3 -3
- package/dist/node/index.cjs.map +2 -2
- package/dist/node/index.esm.js +3 -3
- package/dist/node/index.esm.js.map +2 -2
- 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/headless.cjs +4 -4
- package/headless.cjs.map +2 -2
- package/headless.js +4 -4
- package/headless.js.map +2 -2
- 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/dom/thumbnail.ts +2 -1
- package/src/ui/FEAASContext.tsx +5 -1
- package/src/ui/FEAASExternal.tsx +10 -1
- package/src/ui/react.tsx +18 -12
- package/src/utils/data.ts +3 -3
- package/test/dom.test.ts +21 -0
- package/types/dom/thumbnail.d.ts.map +1 -1
- package/types/tsbuildinfo +1 -1
- package/types/ui/FEAASContext.d.ts +1 -0
- package/types/ui/FEAASContext.d.ts.map +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/dom/thumbnail.ts
CHANGED
|
@@ -152,7 +152,8 @@ export async function generate(component: ComponentModel, version?: VersionModel
|
|
|
152
152
|
if (!sourceVersion || sourceVersion.isViewEmpty()) {
|
|
153
153
|
return null
|
|
154
154
|
}
|
|
155
|
-
const { stylesheet
|
|
155
|
+
const { stylesheet } = component.library
|
|
156
|
+
const { datasources } = component.sdk
|
|
156
157
|
const img = await render(
|
|
157
158
|
sourceVersion.classList,
|
|
158
159
|
stylesheet.getBreakpointForWidth(800, sourceVersion.getBreakpoints()),
|
package/src/ui/FEAASContext.tsx
CHANGED
|
@@ -90,12 +90,16 @@ export class FEAASContext extends FEAASElement<FEAASContextProps, typeof FEAASCo
|
|
|
90
90
|
this.sdk = sdk
|
|
91
91
|
})
|
|
92
92
|
|
|
93
|
+
getPortalRoot() {
|
|
94
|
+
return this.getRoot()
|
|
95
|
+
}
|
|
96
|
+
|
|
93
97
|
render(
|
|
94
98
|
{ children, library }: React.PropsWithChildren<FEAASContextProps>,
|
|
95
99
|
{ AppContext, Chakra: { Button, Tooltip }, React }: typeof this.payload
|
|
96
100
|
) {
|
|
97
101
|
const portalProps = {
|
|
98
|
-
containerRef: { current: this.
|
|
102
|
+
containerRef: { current: this.getPortalRoot() as HTMLElement }
|
|
99
103
|
}
|
|
100
104
|
Tooltip.defaultProps = {
|
|
101
105
|
hasArrow: true,
|
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
|
|
package/src/utils/data.ts
CHANGED
|
@@ -37,13 +37,13 @@ export function queryScopes(scopes: any, datapath: string, singleValue = false,
|
|
|
37
37
|
path.replace(/^.*?\./, ''),
|
|
38
38
|
// look up trimmed path in datasource
|
|
39
39
|
// datasourceId.path
|
|
40
|
-
path.replace(/^([^.]+)
|
|
40
|
+
path.replace(/^([^.]+).*?\.\$([\.\[])/, '$1$2'),
|
|
41
41
|
// look up trimmed path in catch all datasource
|
|
42
42
|
// _.path
|
|
43
|
-
path.replace(
|
|
43
|
+
path.replace(/^.*?\.\$([\.\[])/, '_$1'),
|
|
44
44
|
// look up trimmed path on root
|
|
45
45
|
// path
|
|
46
|
-
path.replace(
|
|
46
|
+
path.replace(/^.*?\.\$([\.\[])/, '$$$1'),
|
|
47
47
|
// for case of top-level object data mapping full path can be replaced to _
|
|
48
48
|
path.replace(/^[^.]+$/, '_')
|
|
49
49
|
]
|
package/test/dom.test.ts
CHANGED
|
@@ -126,6 +126,27 @@ describe('DOM Clientside', function () {
|
|
|
126
126
|
'<div><img data-path-src="context.test.$.image" src="a.jpg" /></div>'
|
|
127
127
|
)
|
|
128
128
|
})
|
|
129
|
+
it('should fall back to trimmed array path', function () {
|
|
130
|
+
assertRenderedHTML(
|
|
131
|
+
`<div><img data-path-src="context.test.$[1:2].image" /></div>`,
|
|
132
|
+
{ context: [{ image: 'a.jpg' }, { image: 'b.jpg' }] },
|
|
133
|
+
'<div><img data-path-src="context.test.$[1:2].image" src="b.jpg" /></div>'
|
|
134
|
+
)
|
|
135
|
+
})
|
|
136
|
+
it('should fall back to global path when using trimmed array', function () {
|
|
137
|
+
assertRenderedHTML(
|
|
138
|
+
`<div><img data-path-src="context.test.$[1:2].image" /></div>`,
|
|
139
|
+
[{ image: 'a.jpg' }, { image: 'b.jpg' }],
|
|
140
|
+
'<div><img data-path-src="context.test.$[1:2].image" src="b.jpg" /></div>'
|
|
141
|
+
)
|
|
142
|
+
})
|
|
143
|
+
it('should fall back to catch all path when using trimmed array', function () {
|
|
144
|
+
assertRenderedHTML(
|
|
145
|
+
`<div><img data-path-src="context.test.$[1:2].image" /></div>`,
|
|
146
|
+
{ _: [{ image: 'a.jpg' }, { image: 'b.jpg' }] },
|
|
147
|
+
'<div><img data-path-src="context.test.$[1:2].image" src="b.jpg" /></div>'
|
|
148
|
+
)
|
|
149
|
+
})
|
|
129
150
|
it('should fall back to catch all datasource only if path matches', function () {
|
|
130
151
|
assertRenderedHTML(
|
|
131
152
|
`<div><img data-path-src="context.image" /></div>`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thumbnail.d.ts","sourceRoot":"","sources":["../../src/dom/thumbnail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAInF,MAAM,MAAM,QAAQ,GAAG,CAAC,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAA;AAE3E,eAAO,MAAM,mBAAmB,WAAY,MAAM,kBAA4C,CAAA;AAE9F,gFAAgF;AAChF,eAAO,MAAM,eAAe,aAAc,QAAQ,KAAG,QAAQ,gBAAgB,CAUzE,CAAA;AAEJ;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAAC,SAAS,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAG7F;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,GAAG,CAAC,SAAS,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,QAAQ,6BAqB/F;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wB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