@sitecore-feaas/clientside 0.1.52 → 0.1.53
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 +42 -0
- package/build/ui/FEAASExternal.js +40 -14
- package/build/ui/FEAASExternal.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/react.cjs +3 -3
- package/dist/node/react.cjs.map +3 -3
- package/dist/node/react.esm.js +3 -3
- package/dist/node/react.esm.js.map +3 -3
- 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/ui/FEAASExternal.tsx +33 -7
- package/test/FEAASExternal.test.tsx +13 -2
- package/types/tsbuildinfo_ui +1 -1
- package/types/ui/FEAASExternal.d.ts +1 -1
- package/types/ui/FEAASExternal.d.ts.map +1 -1
- package/test/cjs/bundles.ts +0 -52
- package/test/cjs/package.json +0 -1
package/src/ui/FEAASExternal.tsx
CHANGED
|
@@ -20,12 +20,38 @@ const convertSchemaPropertiesToKebabCase = (schema: any) => {
|
|
|
20
20
|
return { ...schema, properties: kebabSchemaProperties, required: kebabRequiredProperties }
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
// TODO: parse object, number, array, boolean etc props
|
|
24
|
+
|
|
25
|
+
export const parseProps = (propName: string, propValue: string, properties: any) => {
|
|
26
|
+
switch (properties?.[propName]?.type) {
|
|
27
|
+
case 'string':
|
|
28
|
+
return propValue
|
|
29
|
+
case 'object':
|
|
30
|
+
return JSON.parse(propValue)
|
|
31
|
+
case 'array':
|
|
32
|
+
return JSON.parse(propValue)
|
|
33
|
+
case 'number':
|
|
34
|
+
return +propValue
|
|
35
|
+
case 'integer':
|
|
36
|
+
return +propValue
|
|
37
|
+
case 'boolean':
|
|
38
|
+
return propValue === 'true'
|
|
39
|
+
default:
|
|
40
|
+
return propValue
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
23
44
|
export function FEAASExternalProps(element: FEAASBase = this) {
|
|
24
45
|
const attributes = element.getAttributeNames()
|
|
46
|
+
const id = element.getAttribute('data-external-id')
|
|
47
|
+
const schema: any = FEAASExternal.registered[id]?.schema
|
|
25
48
|
const props = attributes.reduce((prev, curr) => {
|
|
26
|
-
if (!curr.startsWith('data-attribute') && !['class', 'id', 'contenteditable'].includes(curr))
|
|
27
|
-
|
|
28
|
-
|
|
49
|
+
if (!curr.startsWith('data-attribute') && !['class', 'id', 'contenteditable'].includes(curr)) {
|
|
50
|
+
const value = element.getAttribute(curr)
|
|
51
|
+
return { ...prev, [reverseKebabCase(curr)]: parseProps(curr, value, schema?.properties) }
|
|
52
|
+
} else {
|
|
53
|
+
return prev
|
|
54
|
+
}
|
|
29
55
|
}, {})
|
|
30
56
|
return props
|
|
31
57
|
}
|
|
@@ -63,8 +89,8 @@ export default class FEAASExternal extends FEAASBase<FEAASExternalProps, ReactMo
|
|
|
63
89
|
const components = Object.keys(FEAASExternal.registered).map((name) => ({
|
|
64
90
|
...FEAASExternal.registered[name],
|
|
65
91
|
name,
|
|
66
|
-
schema: convertSchemaPropertiesToKebabCase(FEAASExternal.registered[name].schema)
|
|
67
|
-
component: FEAASExternal.registered[name].component.toString()
|
|
92
|
+
schema: convertSchemaPropertiesToKebabCase(FEAASExternal.registered[name].schema)
|
|
93
|
+
//component: FEAASExternal.registered[name].component.toString()
|
|
68
94
|
}))
|
|
69
95
|
|
|
70
96
|
// send components from iframe to parent window
|
|
@@ -79,7 +105,7 @@ export default class FEAASExternal extends FEAASBase<FEAASExternalProps, ReactMo
|
|
|
79
105
|
}
|
|
80
106
|
}
|
|
81
107
|
|
|
82
|
-
static loadComponents() {
|
|
108
|
+
/*static loadComponents() {
|
|
83
109
|
const components = JSON.parse(sessionStorage.getItem('feaas-external-components'))
|
|
84
110
|
components.forEach((c: { name: string; schema: any; component: React.FC }) => {
|
|
85
111
|
const name = c.name
|
|
@@ -87,7 +113,7 @@ export default class FEAASExternal extends FEAASBase<FEAASExternalProps, ReactMo
|
|
|
87
113
|
const component = eval('(' + c.component + ')')
|
|
88
114
|
FEAASExternal.registerComponent(component, schema, name)
|
|
89
115
|
})
|
|
90
|
-
}
|
|
116
|
+
}*/
|
|
91
117
|
|
|
92
118
|
static Preview(props: Partial<FEAASComponentProps<any>> & { src: string }) {
|
|
93
119
|
const src =
|
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it } from 'vitest'
|
|
2
2
|
import React from 'react'
|
|
3
3
|
import * as Clientside from '../src/ui/react.js'
|
|
4
|
-
import FEAASExternal from
|
|
4
|
+
import FEAASExternal from '../src/ui/FEAASExternal.js'
|
|
5
5
|
|
|
6
6
|
describe('External', () => {
|
|
7
7
|
function Hello(props: { firstName: string; telephone: string }) {
|
|
8
8
|
return React.createElement('div', {}, `Hello my name is ${props.firstName} and my tel is ${props.telephone}`)
|
|
9
9
|
}
|
|
10
|
+
const helloSchema = {
|
|
11
|
+
properties: {
|
|
12
|
+
firstName: {
|
|
13
|
+
type: 'string'
|
|
14
|
+
},
|
|
15
|
+
telephone: {
|
|
16
|
+
type: 'number'
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
10
20
|
function Hello2(props: { firstName: string; address: string }) {
|
|
11
21
|
return React.createElement('div', {}, `Hello my name is ${props.firstName} and my address is ${props.address}`)
|
|
12
22
|
}
|
|
13
23
|
it('can register and render component', async () => {
|
|
14
|
-
Clientside.External.registerComponent(Hello,
|
|
24
|
+
Clientside.External.registerComponent(Hello, helloSchema, 'MyTestComponent')
|
|
15
25
|
document.body.innerHTML =
|
|
16
26
|
'<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>'
|
|
17
27
|
const component = document.getElementById('external-component') as FEAASExternal
|
|
@@ -46,4 +56,5 @@ describe('External', () => {
|
|
|
46
56
|
await expect(component2.whenRendered).resolves.toEqual(component2)
|
|
47
57
|
expect(component2.innerHTML).toEqual('<div>Hello my name is George and my address is Test street 12</div>')
|
|
48
58
|
})
|
|
59
|
+
// TODO: add test for props parsing
|
|
49
60
|
})
|