@sitecore-feaas/clientside 0.5.15 → 0.5.17
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.map +1 -1
- package/build/ui/react.js +15 -2
- package/build/ui/react.js.map +1 -1
- package/cdn/browser/index.esm.js +1 -0
- package/cdn/node/index.esm.js +1 -0
- package/dist/browser/react.cjs +7 -7
- package/dist/browser/react.cjs.map +3 -3
- package/dist/browser/react.esm.js +7 -7
- package/dist/browser/react.esm.js.map +1 -1
- package/dist/node/react.cjs +6 -6
- package/dist/node/react.cjs.map +3 -3
- package/dist/node/react.esm.js +6 -6
- package/dist/node/react.esm.js.map +3 -3
- package/package.json +3 -3
- package/react.cjs +7 -7
- package/react.cjs.map +3 -3
- package/react.js +7 -7
- package/react.js.map +3 -3
- package/src/ui/FEAASExternal.tsx +1 -1
- package/src/ui/react.tsx +19 -2
- package/test/FEAASComponent.react.test.tsx +54 -0
- package/types/ui/FEAASContext.d.ts +1 -1
- package/types/ui/react.d.ts +3 -2
- package/types/ui/react.d.ts.map +1 -1
package/src/ui/FEAASExternal.tsx
CHANGED
|
@@ -45,7 +45,7 @@ export default class FEAASExternal extends FEAASElement<FEAASExternalProps, Reac
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
render(props: FEAASExternalProps, { React }: ReactModules): ReactJSX {
|
|
48
|
-
const Component = BYOC.getComponent(this.getComponentName())?.component
|
|
48
|
+
const Component = BYOC.getComponent(this.getComponentName())?.component as any
|
|
49
49
|
if (!Component) {
|
|
50
50
|
console.warn(`FEAASExternal: \`${this.getComponentName()}\` is not registered`)
|
|
51
51
|
}
|
package/src/ui/react.tsx
CHANGED
|
@@ -24,7 +24,10 @@ var ReactElementComponents: Record<string, React.Component | React.FC> = {}
|
|
|
24
24
|
*
|
|
25
25
|
* @param Component
|
|
26
26
|
*/
|
|
27
|
-
export function setElementImplementation(
|
|
27
|
+
export function setElementImplementation(
|
|
28
|
+
tagName: string,
|
|
29
|
+
Component: React.Component<Record<string, string>> | React.FC<Record<string, string>>
|
|
30
|
+
) {
|
|
28
31
|
ReactElementComponents[tagName] = Component
|
|
29
32
|
}
|
|
30
33
|
|
|
@@ -40,6 +43,7 @@ export type FEAASReactComponentProps = FEAASComponentProps & {
|
|
|
40
43
|
fetch?: FEEASReactComponentFetch
|
|
41
44
|
preload?: boolean
|
|
42
45
|
lastModified?: Date | string
|
|
46
|
+
renderNode?: (node: HTMLNode, attributes: Record<string, any>) => JSX.Element | Record<string, any> | null
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
/**
|
|
@@ -96,6 +100,7 @@ export function FEAASReactComponent({
|
|
|
96
100
|
data,
|
|
97
101
|
lastModified,
|
|
98
102
|
fetchedData,
|
|
103
|
+
renderNode,
|
|
99
104
|
...props
|
|
100
105
|
}: FEAASReactComponentProps & { fetchedData?: any }) {
|
|
101
106
|
let preload = null
|
|
@@ -106,6 +111,17 @@ export function FEAASReactComponent({
|
|
|
106
111
|
HTMLNodeToReact(
|
|
107
112
|
node,
|
|
108
113
|
(node, attributes) => {
|
|
114
|
+
// invoke customization of HTML node rendering
|
|
115
|
+
if (renderNode) {
|
|
116
|
+
const override = renderNode?.(node, attributes)
|
|
117
|
+
if (override != null && 'type' in override) {
|
|
118
|
+
return [override.type, override.props]
|
|
119
|
+
}
|
|
120
|
+
attributes = {
|
|
121
|
+
...attributes,
|
|
122
|
+
...override
|
|
123
|
+
}
|
|
124
|
+
}
|
|
109
125
|
// Override rendering of html tag if user provided
|
|
110
126
|
if (ReactElementComponents[node.localName]) {
|
|
111
127
|
return [ReactElementComponents[node.localName], attributes]
|
|
@@ -197,10 +213,11 @@ export function HTMLNodeToReact(
|
|
|
197
213
|
attributes.dangerouslySetInnerHTML = { __html: children.join('\n') }
|
|
198
214
|
}
|
|
199
215
|
const reactAttributes = Object.assign({ key, suppressHydrationWarning: true }, reactNode?.[1] || attributes)
|
|
216
|
+
const reactChildren = reactNode?.[1]?.children || children
|
|
200
217
|
return React.createElement(
|
|
201
218
|
reactName,
|
|
202
219
|
reactAttributes,
|
|
203
|
-
['img', 'br', 'input', 'style'].includes(reactName) ? null :
|
|
220
|
+
['img', 'br', 'input', 'style'].includes(reactName) ? null : reactChildren
|
|
204
221
|
)
|
|
205
222
|
}
|
|
206
223
|
|
|
@@ -338,4 +338,58 @@ Typeof superobject object, {"a":1,"b":2})</div></feaas-external></feaas-componen
|
|
|
338
338
|
)
|
|
339
339
|
})
|
|
340
340
|
})
|
|
341
|
+
describe('renderNode', () => {
|
|
342
|
+
it(' should replace elements', async () => {
|
|
343
|
+
validate(
|
|
344
|
+
<section>
|
|
345
|
+
<Component
|
|
346
|
+
template={'<div data-path-src="abc">'}
|
|
347
|
+
data={{ abc: 321 }}
|
|
348
|
+
renderNode={(node, attributes) => {
|
|
349
|
+
if (node.localName == 'div') {
|
|
350
|
+
return <h2 data-as='div' {...attributes} />
|
|
351
|
+
}
|
|
352
|
+
}}
|
|
353
|
+
></Component>
|
|
354
|
+
</section>,
|
|
355
|
+
'<section><feaas-component class="-feaas" data="{"abc":321}"><h2 data-as="div" data-path-src="abc"></h2></feaas-component></section>'
|
|
356
|
+
)
|
|
357
|
+
})
|
|
358
|
+
it(' should replace parent elements', async () => {
|
|
359
|
+
validate(
|
|
360
|
+
<section>
|
|
361
|
+
<Component
|
|
362
|
+
template={'<div data-path-src="abc"><span>123</span></h2></div>'}
|
|
363
|
+
data={{ abc: 321 }}
|
|
364
|
+
renderNode={(node, attributes) => {
|
|
365
|
+
if (node.localName == 'div') {
|
|
366
|
+
return <h2 data-as='div' {...attributes} />
|
|
367
|
+
}
|
|
368
|
+
}}
|
|
369
|
+
></Component>
|
|
370
|
+
</section>,
|
|
371
|
+
'<section><feaas-component class="-feaas" data="{"abc":321}"><h2 data-as="div" data-path-src="abc"><span>123</span></h2></feaas-component></section>'
|
|
372
|
+
)
|
|
373
|
+
})
|
|
374
|
+
it(' should replace children elements', async () => {
|
|
375
|
+
validate(
|
|
376
|
+
<section>
|
|
377
|
+
<Component
|
|
378
|
+
template={'<div data-path-src="abc"><span>123</span></h2></div>'}
|
|
379
|
+
data={{ abc: 321 }}
|
|
380
|
+
renderNode={(node, attributes) => {
|
|
381
|
+
if (node.localName == 'div') {
|
|
382
|
+
return (
|
|
383
|
+
<h2 data-as='div' {...attributes}>
|
|
384
|
+
Replacement
|
|
385
|
+
</h2>
|
|
386
|
+
)
|
|
387
|
+
}
|
|
388
|
+
}}
|
|
389
|
+
></Component>
|
|
390
|
+
</section>,
|
|
391
|
+
'<section><feaas-component class="-feaas" data="{"abc":321}"><h2 data-as="div" data-path-src="abc">Replacement</h2></feaas-component></section>'
|
|
392
|
+
)
|
|
393
|
+
})
|
|
394
|
+
})
|
|
341
395
|
})
|
|
@@ -53,7 +53,7 @@ export declare class FEAASContext extends FEAASElement<FEAASContextProps, typeof
|
|
|
53
53
|
clientside: typeof FEAAS;
|
|
54
54
|
onStatusChange: FEAASContextImports.SDKStatusCallback;
|
|
55
55
|
whenSDKReady: ControlledPromise<FEAASContextImports.SDK>;
|
|
56
|
-
getPortalRoot(): HTMLElement |
|
|
56
|
+
getPortalRoot(): HTMLElement | FEAASElement<any, any> | ShadowRoot;
|
|
57
57
|
render({ children, library }: React.PropsWithChildren<FEAASContextProps>, { AppContext, Chakra: { Button, Tooltip }, React }: typeof this.payload): FEAASContextImports.React.JSX.Element;
|
|
58
58
|
}
|
|
59
59
|
declare global {
|
package/types/ui/react.d.ts
CHANGED
|
@@ -12,13 +12,14 @@ export { renderHTMLContent };
|
|
|
12
12
|
*
|
|
13
13
|
* @param Component
|
|
14
14
|
*/
|
|
15
|
-
export declare function setElementImplementation(tagName: string, Component: React.Component | React.FC): void;
|
|
15
|
+
export declare function setElementImplementation(tagName: string, Component: React.Component<Record<string, string>> | React.FC<Record<string, string>>): void;
|
|
16
16
|
type FEEASReactComponentFetch = string[] | string | null | undefined | boolean;
|
|
17
17
|
export declare function normalizeFetchAttribute(fetch: FEEASReactComponentFetch): any[];
|
|
18
18
|
export type FEAASReactComponentProps = FEAASComponentProps & {
|
|
19
19
|
fetch?: FEEASReactComponentFetch;
|
|
20
20
|
preload?: boolean;
|
|
21
21
|
lastModified?: Date | string;
|
|
22
|
+
renderNode?: (node: HTMLNode, attributes: Record<string, any>) => JSX.Element | Record<string, any> | null;
|
|
22
23
|
};
|
|
23
24
|
/**
|
|
24
25
|
* A component to include a stylesheet using a <link> tag. Placing one in the HEAD ensures that there will be no flash
|
|
@@ -43,7 +44,7 @@ export declare const FEAASReactServerComponent: ({ data, fetch, ...props }: FEAA
|
|
|
43
44
|
* @param {FEAASReactComponentProps} props - The properties for the component.
|
|
44
45
|
* @returns {JSX.Element} The JSX element representing the component.
|
|
45
46
|
*/
|
|
46
|
-
export declare function FEAASReactComponent({ data, lastModified, fetchedData, ...props }: FEAASReactComponentProps & {
|
|
47
|
+
export declare function FEAASReactComponent({ data, lastModified, fetchedData, renderNode, ...props }: FEAASReactComponentProps & {
|
|
47
48
|
fetchedData?: any;
|
|
48
49
|
}): React.JSX.Element;
|
|
49
50
|
/**
|
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,KAAK,IAAI,MAAM,sBAAsB,CAAA;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,QAAQ,EAAoB,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAE9E,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,mBAAmB,EAOpB,MAAM,YAAY,CAAA;AACnB,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACvF,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,iBAAiB,EAAE,CAAA;AAG5B;;;;GAIG;AACH,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