@sitecore-feaas/clientside 0.5.7 → 0.5.9
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 +11 -9
- package/build/ui/FEAASExternal.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 +6 -6
- package/dist/browser/react.esm.js.map +1 -1
- package/dist/node/react.cjs +1 -1
- package/dist/node/react.cjs.map +3 -3
- package/dist/node/react.esm.js +1 -1
- package/dist/node/react.esm.js.map +3 -3
- package/package.json +2 -2
- 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 +14 -12
- package/test/FEAASExternal.test.tsx +12 -0
- package/types/ui/FEAASExternal.d.ts +7 -5
- package/types/ui/FEAASExternal.d.ts.map +1 -1
package/src/ui/FEAASExternal.tsx
CHANGED
|
@@ -5,18 +5,19 @@ import { FEAASElement } from '../components/FEAASElement.js'
|
|
|
5
5
|
import { ReactJSX, ReactModules } from '../components/FEAASReactElement.js'
|
|
6
6
|
import { Component, FEAASComponentProps } from './react.js'
|
|
7
7
|
|
|
8
|
-
export const FEAASExternalPropsObject = BYOC.
|
|
8
|
+
export const FEAASExternalPropsObject = BYOC.getMergedComponentProperties
|
|
9
9
|
|
|
10
|
-
export function FEAASExternalProps(element: FEAASElement):
|
|
10
|
+
export function FEAASExternalProps(element: FEAASElement): FEAASExternalProps {
|
|
11
11
|
const props = BYOC.objectKeysToCamelCase(
|
|
12
12
|
Array.from(element.attributes).reduce((prev, { name, value }) => {
|
|
13
|
+
if (name == 'data-external-id') name = 'component-name'
|
|
13
14
|
return Object.assign(prev, { [name]: value })
|
|
14
15
|
}, {} as any)
|
|
15
|
-
)
|
|
16
|
-
return FEAASExternalPropsObject(props.
|
|
16
|
+
) as FEAASExternalProps
|
|
17
|
+
return FEAASExternalPropsObject(props).merged
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
export type FEAASExternalProps =
|
|
20
|
+
export type FEAASExternalProps = { componentName: string; [key: string]: any }
|
|
20
21
|
|
|
21
22
|
export default class FEAASExternal extends FEAASElement<FEAASExternalProps, ReactModules> {
|
|
22
23
|
load() {
|
|
@@ -24,20 +25,21 @@ export default class FEAASExternal extends FEAASElement<FEAASExternalProps, Reac
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
update() {
|
|
27
|
-
const
|
|
28
|
-
const Component = BYOC.getComponent(id)?.component
|
|
28
|
+
const Component = BYOC.getComponent(this.getComponentName())?.component
|
|
29
29
|
if (!Component && this.getAttribute('hydrate') == 'false') return
|
|
30
30
|
return super.update()
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
render(props: FEAASExternalProps, { React }: ReactModules): ReactJSX {
|
|
34
|
-
const
|
|
35
|
-
console.log(props)
|
|
36
|
-
const Component = BYOC.getComponent(id)?.component
|
|
34
|
+
const Component = BYOC.getComponent(this.getComponentName())?.component
|
|
37
35
|
if (!Component) {
|
|
38
|
-
console.warn(`FEAASExternal: \`${
|
|
36
|
+
console.warn(`FEAASExternal: \`${this.getComponentName()}\` is not registered`)
|
|
39
37
|
}
|
|
40
|
-
return <>{Component && <Component {...props} />}</>
|
|
38
|
+
return <>{Component && <Component componentName={this.getComponentName()} {...props} />}</>
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getComponentName() {
|
|
42
|
+
return this.getAttribute('data-external-id')
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
getProps() {
|
|
@@ -63,6 +63,8 @@ describe('External', () => {
|
|
|
63
63
|
Clientside.External.registerComponent(Hello, helloSchema)
|
|
64
64
|
document.body.innerHTML =
|
|
65
65
|
'<feaas-external id="external-component" class="-component" data-attributes-keys="first-name,telephone" first-name="Chuck" telephone="45657890875643" data-attributes="{"first-name":"Chuck","telephone":"45657890875643"}" data-external-id="MyTestComponent" contenteditable="false"></feaas-external>'
|
|
66
|
+
debugger
|
|
67
|
+
|
|
66
68
|
const component = document.getElementById('external-component') as FEAASExternal
|
|
67
69
|
await expect(component.whenRendered).resolves.toEqual(component)
|
|
68
70
|
expect(component.innerHTML).toEqual('<div>Hello my name is Chuck and my tel is 45657890875643</div>')
|
|
@@ -96,4 +98,14 @@ describe('External', () => {
|
|
|
96
98
|
'<div>Text: this is a string, Number + 1: 6, Boolean: it is true, Array (joined): 1, 2, 3, 4, 5, Object: object value</div>'
|
|
97
99
|
)
|
|
98
100
|
})
|
|
101
|
+
it('can spread data', async () => {
|
|
102
|
+
Clientside.External.registerComponent(TypesComponent, typesComponentSchema)
|
|
103
|
+
document.body.innerHTML = `<feaas-external id="types-component" class="-component" datasources='{"my": {"arrayProp": [1,2,3], "objectProp": {"value": 333}, "numberProp": 1, "booleanProp": false, "stringProp": "Hey"}}' data-external-id="TypesComponent" contenteditable="false"></feaas-external>`
|
|
104
|
+
const typesComponent = document.getElementById('types-component') as FEAASExternal
|
|
105
|
+
|
|
106
|
+
await expect(typesComponent.whenRendered).resolves.toEqual(typesComponent)
|
|
107
|
+
expect(typesComponent.innerHTML).toEqual(
|
|
108
|
+
'<div>Text: Hey, Number + 1: 2, Boolean: error, Array (joined): 1, 2, 3, Object: 333</div>'
|
|
109
|
+
)
|
|
110
|
+
})
|
|
99
111
|
})
|
|
@@ -4,10 +4,11 @@ import ReactDOM from 'react-dom';
|
|
|
4
4
|
import { FEAASElement } from '../components/FEAASElement.js';
|
|
5
5
|
import { ReactJSX, ReactModules } from '../components/FEAASReactElement.js';
|
|
6
6
|
import { FEAASComponentProps } from './react.js';
|
|
7
|
-
export declare const FEAASExternalPropsObject: typeof BYOC.
|
|
8
|
-
export declare function FEAASExternalProps(element: FEAASElement):
|
|
9
|
-
export type FEAASExternalProps =
|
|
10
|
-
|
|
7
|
+
export declare const FEAASExternalPropsObject: typeof BYOC.getMergedComponentProperties;
|
|
8
|
+
export declare function FEAASExternalProps(element: FEAASElement): FEAASExternalProps;
|
|
9
|
+
export type FEAASExternalProps = {
|
|
10
|
+
componentName: string;
|
|
11
|
+
[key: string]: any;
|
|
11
12
|
};
|
|
12
13
|
export default class FEAASExternal extends FEAASElement<FEAASExternalProps, ReactModules> {
|
|
13
14
|
load(): Promise<{
|
|
@@ -16,7 +17,8 @@ export default class FEAASExternal extends FEAASElement<FEAASExternalProps, Reac
|
|
|
16
17
|
}>;
|
|
17
18
|
update(): any;
|
|
18
19
|
render(props: FEAASExternalProps, { React }: ReactModules): ReactJSX;
|
|
19
|
-
|
|
20
|
+
getComponentName(): string;
|
|
21
|
+
getProps(): FEAASExternalProps;
|
|
20
22
|
static Preview(props: Partial<FEAASComponentProps<any>> & {
|
|
21
23
|
src: string;
|
|
22
24
|
}): JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FEAASExternal.d.ts","sourceRoot":"","sources":["../../src/ui/FEAASExternal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAA;AACtC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,QAAQ,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAC5D,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAA;AAC3E,OAAO,EAAa,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAE3D,eAAO,MAAM,wBAAwB,
|
|
1
|
+
{"version":3,"file":"FEAASExternal.d.ts","sourceRoot":"","sources":["../../src/ui/FEAASExternal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAA;AACtC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,QAAQ,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAC5D,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAA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