@sitecore-feaas/clientside 0.5.16-alpha.1 → 0.5.18
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/dom/thumbnail.js +1 -1
- package/build/dom/thumbnail.js.map +1 -1
- package/build/ui/FEAASExternal.js +1 -1
- package/build/ui/FEAASExternal.js.map +1 -1
- package/build/ui/FEAASPicker.js +2 -2
- package/build/ui/FEAASPicker.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/headless.cjs +1 -1
- package/dist/browser/headless.cjs.map +2 -2
- package/dist/browser/headless.esm.js +1 -1
- package/dist/browser/headless.esm.js.map +1 -1
- package/dist/browser/index.cjs +6 -6
- package/dist/browser/index.cjs.map +3 -3
- package/dist/browser/index.esm.js +5 -5
- package/dist/browser/index.esm.js.map +1 -1
- 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/headless.cjs +1 -1
- package/dist/node/headless.cjs.map +2 -2
- package/dist/node/headless.esm.js +1 -1
- package/dist/node/headless.esm.js.map +2 -2
- package/dist/node/index.cjs +2 -2
- package/dist/node/index.cjs.map +3 -3
- package/dist/node/index.esm.js +2 -2
- package/dist/node/index.esm.js.map +3 -3
- 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/headless.cjs +1 -1
- package/headless.cjs.map +2 -2
- package/headless.js +1 -1
- package/headless.js.map +2 -2
- 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/dom/thumbnail.ts +1 -1
- package/src/ui/FEAASExternal.tsx +1 -1
- package/src/ui/FEAASPicker.tsx +2 -2
- package/src/ui/react.tsx +19 -2
- package/test/FEAASComponent.react.test.tsx +54 -0
- package/types/ui/react.d.ts +3 -2
- package/types/ui/react.d.ts.map +1 -1
package/src/dom/thumbnail.ts
CHANGED
|
@@ -219,7 +219,7 @@ function render(
|
|
|
219
219
|
scale: Math.max(1.1, 1000 / Math.min(1401, Math.max(320, breakpoint.props.minWidth))),
|
|
220
220
|
width: Math.min(1401, Math.max(320, breakpoint.props.minWidth)),
|
|
221
221
|
height: Math.max(1, Math.min(2000, root.offsetHeight)),
|
|
222
|
-
windowWidth: breakpoint.props.minWidth + 'px',
|
|
222
|
+
windowWidth: breakpoint.props.minWidth || breakpoint.props.maxWidth + 'px',
|
|
223
223
|
windowHeight: 1000,
|
|
224
224
|
proxy: sdk.backend + '/proxy/media',
|
|
225
225
|
backgroundColor: '#ffffff'
|
package/src/ui/FEAASExternal.tsx
CHANGED
|
@@ -49,7 +49,7 @@ export default class FEAASExternal extends FEAASElement<FEAASExternalProps, Reac
|
|
|
49
49
|
if (!Component) {
|
|
50
50
|
console.warn(`FEAASExternal: \`${this.getComponentName()}\` is not registered`)
|
|
51
51
|
}
|
|
52
|
-
return <>{Component && <Component componentName={this.getComponentName()} {...
|
|
52
|
+
return <>{Component && <Component componentName={this.getComponentName()} {...this.getProps()} />}</>
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
getComponentName() {
|
package/src/ui/FEAASPicker.tsx
CHANGED
|
@@ -51,7 +51,7 @@ export class FEAASPicker extends FEAASElement<FEAASPickerProps, typeof FEAASPick
|
|
|
51
51
|
const library = useLibrary()
|
|
52
52
|
// @ts-ignore temporary workaround until we release all environments
|
|
53
53
|
const rules = library.stylesheets?.first?.rules || library?.stylesheet?.styles
|
|
54
|
-
const
|
|
54
|
+
const expandedComponents = useSDK('renderingHost.expandedComponents')
|
|
55
55
|
var settings = context?.getAttribute('data')
|
|
56
56
|
if (settings) {
|
|
57
57
|
try {
|
|
@@ -74,7 +74,7 @@ export class FEAASPicker extends FEAASElement<FEAASPickerProps, typeof FEAASPick
|
|
|
74
74
|
themeContext={context}
|
|
75
75
|
placeholder={placeholder}
|
|
76
76
|
embed={externalComponent}
|
|
77
|
-
externalComponents={
|
|
77
|
+
externalComponents={expandedComponents}
|
|
78
78
|
datasources={datasources}
|
|
79
79
|
data={settings}
|
|
80
80
|
versionId={context?.getAttribute('version')}
|
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
|
})
|
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;;;;G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