@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.
@@ -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 p || 'component' in p) && p?.template == null) {
23
- const response = await fetchComponent(p)
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
- // p.lastModified = response.lastModified
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 }: FEAASComponentProps & { src?: string; preload?: boolean }) {
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 server component', async () => {
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="{&quot;data&quot;:&quot;1&quot;}">{"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="{&quot;data&quot;:&quot;2&quot;}">Test</feaas-component>`
42
+ )
43
+ })
33
44
  })