@sitecore-feaas/clientside 0.3.1 → 0.3.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/README.md +8 -6
- package/build/ui/FEAASExternal.js +8 -0
- package/build/ui/FEAASExternal.js.map +1 -1
- package/build/ui/react.js +4 -4
- 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 +6 -6
- 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 +6 -6
- package/react.cjs.map +3 -3
- package/react.js +6 -6
- package/react.js.map +3 -3
- package/src/ui/FEAASExternal.tsx +10 -0
- package/src/ui/react.tsx +11 -6
- package/test/ServerComponent.test.tsx +12 -1
- package/types/tsbuildinfo +1 -1
- package/types/ui/FEAASExternal.d.ts +4 -0
- package/types/ui/FEAASExternal.d.ts.map +1 -1
- package/types/ui/FEAASPicker.d.ts +3 -3
- package/types/ui/react.d.ts +6 -4
- package/types/ui/react.d.ts.map +1 -1
- package/types/ui/tsbuildinfo +1 -1
package/src/ui/FEAASExternal.tsx
CHANGED
|
@@ -232,6 +232,14 @@ export default class FEAASExternal extends FEAASElement<FEAASExternalProps, Reac
|
|
|
232
232
|
props?.src || (typeof window !== 'undefined' ? window.location.search.match(/feaasSrc=([^&]+)/)?.[1] : null)
|
|
233
233
|
return src ? <Component src={src} {...props} /> : null
|
|
234
234
|
}
|
|
235
|
+
|
|
236
|
+
static linkComponents(components: Promise<any>[]): () => any {
|
|
237
|
+
return () => components.map((components) => null)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
static getComponent(id: string) {
|
|
241
|
+
return FEAASExternal.registered[id]
|
|
242
|
+
}
|
|
235
243
|
}
|
|
236
244
|
|
|
237
245
|
declare global {
|
|
@@ -251,4 +259,6 @@ FEAASExternal.register('feaas-external')
|
|
|
251
259
|
FEAASExternal.setRegistrationCallback()
|
|
252
260
|
|
|
253
261
|
export const registerComponent = FEAASExternal.registerComponent
|
|
262
|
+
export const linkComponents = FEAASExternal.linkComponents
|
|
263
|
+
export const getComponent = FEAASExternal.getComponent
|
|
254
264
|
export { FEAASExternal as External }
|
package/src/ui/react.tsx
CHANGED
|
@@ -10,26 +10,31 @@ import { renderHTMLContent } from '../dom/html.js'
|
|
|
10
10
|
import { DataSettings } from '../utils/settings.js'
|
|
11
11
|
|
|
12
12
|
export { renderHTMLContent }
|
|
13
|
-
export { External } from './FEAASExternal.js'
|
|
13
|
+
export { External, linkComponents, registerComponent, getComponent } from './FEAASExternal.js'
|
|
14
14
|
export * from './index.js'
|
|
15
15
|
export * from '../headless.js'
|
|
16
16
|
|
|
17
|
+
export type FEAASReactComponentProps = FEAASComponentProps & {
|
|
18
|
+
src?: string
|
|
19
|
+
preload?: boolean
|
|
20
|
+
lastModified?: Date | string
|
|
21
|
+
}
|
|
17
22
|
export const ServerComponent = async (props: FEAASComponentProps) => {
|
|
18
23
|
const fetchedData = await DataSettings.fetch(props?.data || {})
|
|
19
24
|
|
|
20
|
-
const p = { ...props }
|
|
25
|
+
const p: FEAASReactComponentProps = { ...props }
|
|
21
26
|
|
|
22
|
-
if (('src' in
|
|
23
|
-
const response = await fetchComponent(
|
|
27
|
+
if (('src' in props || 'component' in props) && props?.template == null) {
|
|
28
|
+
const response = await fetchComponent(props)
|
|
24
29
|
|
|
25
30
|
p.template = response.template
|
|
26
|
-
|
|
31
|
+
p.lastModified = response.lastModified
|
|
27
32
|
}
|
|
28
33
|
|
|
29
34
|
return FEAASReactComponent({ ...p, data: fetchedData })
|
|
30
35
|
}
|
|
31
36
|
|
|
32
|
-
export function FEAASReactComponent({ data, ...props }:
|
|
37
|
+
export function FEAASReactComponent({ data, ...props }: FEAASReactComponentProps) {
|
|
33
38
|
let html = ''
|
|
34
39
|
let preload = null
|
|
35
40
|
|
|
@@ -18,7 +18,7 @@ describe('React Server', () => {
|
|
|
18
18
|
document.write()
|
|
19
19
|
})
|
|
20
20
|
|
|
21
|
-
it('render
|
|
21
|
+
it('render with data settings', async () => {
|
|
22
22
|
vi.spyOn(global, 'fetch').mockImplementation(
|
|
23
23
|
async (url: string, options: Parameters<typeof fetch>[1] = {}) => new Response('{"data": "1"}')
|
|
24
24
|
)
|
|
@@ -30,4 +30,15 @@ describe('React Server', () => {
|
|
|
30
30
|
`<feaas-component library="library" component="test" src="library/test" data="{"data":"1"}">{"data": "1"}</feaas-component>`
|
|
31
31
|
)
|
|
32
32
|
})
|
|
33
|
+
it('render with object data', async () => {
|
|
34
|
+
vi.spyOn(global, 'fetch').mockImplementation(
|
|
35
|
+
async (url: string, options: Parameters<typeof fetch>[1] = {}) => new Response('Test')
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
const Component = await ServerComponent({ src: 'library/test', data: { data: '2' } })
|
|
39
|
+
await test(
|
|
40
|
+
<>{Component}</>,
|
|
41
|
+
`<feaas-component library="library" component="test" src="library/test" data="{"data":"2"}">Test</feaas-component>`
|
|
42
|
+
)
|
|
43
|
+
})
|
|
33
44
|
})
|