@sitecore-feaas/clientside 0.3.8 → 0.3.10
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 +3 -5
- package/build/ui/FEAASExternal.js.map +1 -1
- package/build/ui/react.js +15 -1
- package/build/ui/react.js.map +1 -1
- package/dist/browser/react.cjs +4 -4
- package/dist/browser/react.cjs.map +3 -3
- package/dist/browser/react.esm.js +4 -4
- package/dist/browser/react.esm.js.map +1 -1
- package/dist/node/react.cjs +5 -5
- 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 +4 -4
- package/react.cjs.map +3 -3
- package/react.js +4 -4
- package/react.js.map +3 -3
- package/src/ui/FEAASExternal.tsx +4 -6
- package/src/ui/react.tsx +17 -4
- package/test/FEAASComponent.react.test.tsx +2 -10
- package/test/ServerComponent.test.tsx +14 -0
- package/types/ui/FEAASExternal.d.ts +2 -2
- package/types/ui/FEAASExternal.d.ts.map +1 -1
- package/types/ui/react.d.ts +1 -2
- package/types/ui/react.d.ts.map +1 -1
- package/types/ui/tsbuildinfo +1 -1
package/src/ui/FEAASExternal.tsx
CHANGED
|
@@ -82,14 +82,12 @@ export const parseProps = (propName: string, propValue: string, properties: JSON
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
export function FEAASExternalProps(element: FEAASElement) {
|
|
86
|
-
const attributes = element.getAttributeNames()
|
|
85
|
+
export function FEAASExternalProps(element: FEAASElement): any {
|
|
87
86
|
const id = element.getAttribute('data-external-id')
|
|
88
87
|
const schema: JSONSchema = FEAASExternal.registered[id]?.schema
|
|
89
|
-
const props = attributes.reduce((prev,
|
|
90
|
-
if (!
|
|
91
|
-
|
|
92
|
-
return { ...prev, [reverseKebabCase(curr)]: parseProps(reverseKebabCase(curr), value, schema?.properties) }
|
|
88
|
+
const props = Array.from(element.attributes).reduce((prev, { name, value }) => {
|
|
89
|
+
if (!name.startsWith('data-attribute') && !['class', 'id', 'contenteditable'].includes(name)) {
|
|
90
|
+
return { ...prev, [reverseKebabCase(name)]: parseProps(reverseKebabCase(name), value, schema?.properties) }
|
|
93
91
|
} else {
|
|
94
92
|
return prev
|
|
95
93
|
}
|
package/src/ui/react.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
FEAASComponentProps,
|
|
3
|
+
FEAASElement,
|
|
3
4
|
fetchComponent,
|
|
4
5
|
getComponentURL,
|
|
5
6
|
getStylesheetURL,
|
|
@@ -15,11 +16,10 @@ export * from './index.js'
|
|
|
15
16
|
export * from '../headless.js'
|
|
16
17
|
|
|
17
18
|
export type FEAASReactComponentProps = FEAASComponentProps & {
|
|
18
|
-
src?: string
|
|
19
19
|
preload?: boolean
|
|
20
20
|
lastModified?: Date | string
|
|
21
21
|
}
|
|
22
|
-
export const ServerComponent = async (props:
|
|
22
|
+
export const ServerComponent = async (props: FEAASReactComponentProps) => {
|
|
23
23
|
const fetchedData = await DataSettings.fetch(props?.data || {})
|
|
24
24
|
|
|
25
25
|
const p: FEAASReactComponentProps = { ...props }
|
|
@@ -98,10 +98,23 @@ export function HTMLNodeToReact(
|
|
|
98
98
|
}
|
|
99
99
|
const children = Array.from(node.childNodes).map((child, index) => HTMLNodeToReact(child, callback, index))
|
|
100
100
|
|
|
101
|
-
const attributes: { [key: string]: string } = {}
|
|
101
|
+
const attributes: { [key: string]: string | Record<string, string> } = {}
|
|
102
102
|
for (let i = 0; i < node.attributes.length; i++) {
|
|
103
103
|
const { name, value } = node.attributes[i]
|
|
104
|
-
|
|
104
|
+
if (name == 'style') {
|
|
105
|
+
attributes[name] = String(value || '')
|
|
106
|
+
.trim()
|
|
107
|
+
.split(/\s*;\s*/)
|
|
108
|
+
.reduce((object, pair) => {
|
|
109
|
+
const [k, v] = pair.split(':')
|
|
110
|
+
return {
|
|
111
|
+
...object,
|
|
112
|
+
[k]: v
|
|
113
|
+
}
|
|
114
|
+
}, {})
|
|
115
|
+
} else {
|
|
116
|
+
attributes[name] = value
|
|
117
|
+
}
|
|
105
118
|
}
|
|
106
119
|
|
|
107
120
|
const reactNode = callback?.(node)
|
|
@@ -84,18 +84,10 @@ describe('React', () => {
|
|
|
84
84
|
'<section><feaas-component library="library" component="test" data="{"abc":321}"><div data-path-src="abc"></div></feaas-component></section>'
|
|
85
85
|
)
|
|
86
86
|
})
|
|
87
|
-
it('render template with
|
|
87
|
+
it('render template with style attribute', async () => {
|
|
88
88
|
test(
|
|
89
89
|
<section>
|
|
90
|
-
<Component
|
|
91
|
-
</section>,
|
|
92
|
-
'<section><feaas-component library="library" component="test" src="library/test" data="{"abc":321}"><div data-path-src="abc"></div></feaas-component></section>'
|
|
93
|
-
)
|
|
94
|
-
})
|
|
95
|
-
it('render template with data and template', async () => {
|
|
96
|
-
test(
|
|
97
|
-
<section>
|
|
98
|
-
<Component template={'<div data-path-src="abc">'} data={'{"abc":321}'}></Component>
|
|
90
|
+
<Component template={'<div data-path-src="abc">'} data={{ abc: 321 }}></Component>
|
|
99
91
|
</section>,
|
|
100
92
|
'<section><feaas-component data="{"abc":321}"><div data-path-src="abc"></div></feaas-component></section>'
|
|
101
93
|
)
|
|
@@ -53,6 +53,20 @@ describe('React Server', () => {
|
|
|
53
53
|
`<feaas-component library="library" component="test" src="library/test" data="{"value":0}">Hey: <var data-path="value">0</var>!</feaas-component>`
|
|
54
54
|
)
|
|
55
55
|
})
|
|
56
|
+
it('pre-render data with style attribute', async () => {
|
|
57
|
+
vi.spyOn(global, 'fetch').mockImplementation(
|
|
58
|
+
async (url: string, options: Parameters<typeof fetch>[1] = {}) =>
|
|
59
|
+
new Response(
|
|
60
|
+
'<p style="text-align: left; color: red;;"><b style="cursor: 1">Hey:</b> <var data-path="value"></var>!</p>'
|
|
61
|
+
)
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
const Component = await ServerComponent({ src: 'library/test', data: { value: 0 } })
|
|
65
|
+
await test(
|
|
66
|
+
<>{Component}</>,
|
|
67
|
+
`<feaas-component library="library" component="test" src="library/test" data="{"value":0}"><p style="text-align: left; color: red;"><b style="cursor: 1;">Hey:</b> <var data-path="value">0</var>!</p></feaas-component>`
|
|
68
|
+
)
|
|
69
|
+
})
|
|
56
70
|
it('render external component', async () => {
|
|
57
71
|
function MyComponent() {
|
|
58
72
|
return <h1>My Component</h1>
|
|
@@ -7,7 +7,7 @@ import { FEAASComponentProps } from './react.js';
|
|
|
7
7
|
import type { ExternalComponent, ExternalComponentOptions, JSONSchema } from '@sitecore-feaas/sdk';
|
|
8
8
|
/** Parses a property value based on its property name and type defined in the JSON properties object. */
|
|
9
9
|
export declare const parseProps: (propName: string, propValue: string, properties: JSONSchema['properties']) => any;
|
|
10
|
-
export declare function FEAASExternalProps(element: FEAASElement):
|
|
10
|
+
export declare function FEAASExternalProps(element: FEAASElement): any;
|
|
11
11
|
export type RegisteredComponents = {
|
|
12
12
|
[id: string]: ExternalComponent;
|
|
13
13
|
};
|
|
@@ -23,7 +23,7 @@ export default class FEAASExternal extends FEAASElement<FEAASExternalProps, Reac
|
|
|
23
23
|
}>;
|
|
24
24
|
update(): any;
|
|
25
25
|
render(props: FEAASExternalProps, { React }: ReactModules): ReactJSX;
|
|
26
|
-
getProps():
|
|
26
|
+
getProps(): any;
|
|
27
27
|
/**
|
|
28
28
|
* Register React component to be renderable as Sitecore component (in Components and Pages). Properties are defined
|
|
29
29
|
* as {@link https://json-schema.org JSON Schema}, from which a configuration form will be produced using
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FEAASExternal.d.ts","sourceRoot":"","sources":["../../src/ui/FEAASExternal.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,QAAQ,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAC5D,OAAO,EAAE,QAAQ,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7
|
export * from '../headless.js';
|
|
8
8
|
export type FEAASReactComponentProps = FEAASComponentProps & {
|
|
9
|
-
src?: string;
|
|
10
9
|
preload?: boolean;
|
|
11
10
|
lastModified?: Date | string;
|
|
12
11
|
};
|
|
13
|
-
export declare const ServerComponent: (props:
|
|
12
|
+
export declare const ServerComponent: (props: FEAASReactComponentProps) => Promise<JSX.Element>;
|
|
14
13
|
export declare function FEAASReactComponent({ data, ...props }: FEAASReactComponentProps): JSX.Element;
|
|
15
14
|
export declare function FEAASReactExternal(props: {
|
|
16
15
|
'data-external-id': string;
|
package/types/ui/react.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/ui/react.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/ui/react.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAMpB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAoB,MAAM,gBAAgB,CAAA;AAE9E,OAAO,EAAE,iBAAiB,EAAE,CAAA;AAE5B,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAC9F,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAE9B,MAAM,MAAM,wBAAwB,GAAG,mBAAmB,GAAG;IAC3D,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,YAAY,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;CAC7B,CAAA;AACD,eAAO,MAAM,eAAe,UAAiB,wBAAwB,yBAapE,CAAA;AAED,wBAAgB,mBAAmB,CAAC,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,EAAE,wBAAwB,eAyC/E;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE;IAAE,kBAAkB,EAAE,MAAM,CAAA;CAAE,eAQvE;AAED,mFAAmF;AACnF,wBAAgB,eAAe,CAC7B,IAAI,EAAE,QAAQ,EACd,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAC9E,GAAG,CAAC,EAAE,GAAG,GACR,KAAK,CAAC,SAAS,CA6BjB;AAED,eAAO,MAAM,SAAS,4BAAsB,CAAA"}
|