@sitecore-feaas/clientside 0.1.44 → 0.1.45

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/src/ui/react.tsx CHANGED
@@ -1,11 +1,17 @@
1
1
  export * from './index.js'
2
- import { FEAASComponentProps, renderHTMLContent } from './index.js'
2
+ import { FEAASComponentProps, parseComponentSource, renderHTMLContent } from './index.js'
3
3
  import React from 'react'
4
4
 
5
5
  export function FEAASEmbed({ data, ...props }: FEAASComponentProps<any>) {
6
6
  if ('template' in props) {
7
7
  var html = renderHTMLContent(props.template, data || {})
8
8
  }
9
+ if ('src' in props) {
10
+ props = {
11
+ ...parseComponentSource(props.src),
12
+ ...props
13
+ }
14
+ }
9
15
  return (
10
16
  <feaas-component
11
17
  {...props}
@@ -15,7 +15,33 @@ describe('React', () => {
15
15
  </section>,
16
16
  div
17
17
  )
18
- expect(div.innerHTML).toEqual('<section><feaas-component src="library/test"></feaas-component></section>')
18
+ expect(div.innerHTML).toEqual(
19
+ '<section><feaas-component library="library" component="test" src="library/test"></feaas-component></section>'
20
+ )
21
+ })
22
+ it('render react component with src and overrides', () => {
23
+ const div = document.createElement('div')
24
+ const root = ReactDOM.render(
25
+ <section>
26
+ <Component src='library/test' component='test2'></Component>
27
+ </section>,
28
+ div
29
+ )
30
+ expect(div.innerHTML).toEqual(
31
+ '<section><feaas-component library="library" component="test2" src="library/test"></feaas-component></section>'
32
+ )
33
+ })
34
+ it('render react component with extras', () => {
35
+ const div = document.createElement('div')
36
+ const root = ReactDOM.render(
37
+ <section>
38
+ <Component src='library/test' version='v1'></Component>
39
+ </section>,
40
+ div
41
+ )
42
+ expect(div.innerHTML).toEqual(
43
+ '<section><feaas-component library="library" component="test" version="v1" src="library/test"></feaas-component></section>'
44
+ )
19
45
  })
20
46
  it('render react template', () => {
21
47
  const div = document.createElement('div')
@@ -26,7 +52,7 @@ describe('React', () => {
26
52
  div
27
53
  )
28
54
  expect(div.innerHTML).toEqual(
29
- '<section><feaas-component src="library/test"><div data-path-src="abc"></div></feaas-component></section>'
55
+ '<section><feaas-component library="library" component="test" src="library/test"><div data-path-src="abc"></div></feaas-component></section>'
30
56
  )
31
57
  })
32
58
  it('render template with data and src', () => {
@@ -38,7 +64,7 @@ describe('React', () => {
38
64
  div
39
65
  )
40
66
  expect(div.innerHTML).toEqual(
41
- '<section><feaas-component src="library/test" data="{&quot;abc&quot;:321}" library="library" component="test"><div data-path-src="abc"></div></feaas-component></section>'
67
+ '<section><feaas-component library="library" component="test" src="library/test" data="{&quot;abc&quot;:321}"><div data-path-src="abc"></div></feaas-component></section>'
42
68
  )
43
69
  })
44
70
  it('render template with data but without src', () => {
@@ -67,7 +93,7 @@ describe('React', () => {
67
93
  div
68
94
  )
69
95
  expect(div.innerHTML).toEqual(
70
- '<section><feaas-component src="library/test" data="{&quot;abc&quot;:321}" library="library" component="test"><div data-path-src="abc"></div></feaas-component></section>'
96
+ '<section><feaas-component library="library" component="test" src="library/test" data="{&quot;abc&quot;:321}"><div data-path-src="abc"></div></feaas-component></section>'
71
97
  )
72
98
  })
73
99
  it('render template with data and template', () => {