@sitecore-feaas/clientside 0.1.24 → 0.1.27
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/basic.js +1 -0
- package/build/basic.js.map +1 -1
- package/build/cloud.js +9 -1
- package/build/cloud.js.map +1 -1
- package/build/components/FEAASBase.js +6 -5
- package/build/components/FEAASBase.js.map +1 -1
- package/build/components/FEAASComponent.js +10 -10
- package/build/components/FEAASComponent.js.map +1 -1
- package/build/components/FEAASElement.js +1 -1
- package/build/components/FEAASElement.js.map +1 -1
- package/build/dom.js +29 -6
- package/build/dom.js.map +1 -1
- package/build/fetch.js +0 -1
- package/build/fetch.js.map +1 -1
- package/build/node.js +10 -0
- package/build/node.js.map +1 -0
- package/build/ui/FEAASContext.js +4 -0
- package/build/ui/FEAASContext.js.map +1 -1
- package/build/ui/node.js +3 -0
- package/build/ui/node.js.map +1 -0
- package/dist/browser/basic.esm.js +5 -5
- package/dist/browser/basic.esm.js.map +1 -1
- package/dist/browser/basic.js +5 -5
- package/dist/browser/basic.js.map +1 -1
- package/dist/browser/index.esm.js +5 -5
- package/dist/browser/index.esm.js.map +1 -1
- package/dist/browser/index.js +5 -5
- package/dist/browser/index.js.map +1 -1
- package/dist/node/basic.esm.js +4 -4
- package/dist/node/basic.esm.js.map +7 -1
- package/dist/node/basic.js +4 -4
- package/dist/node/basic.js.map +7 -1
- package/dist/node/index.esm.js +4 -4
- package/dist/node/index.esm.js.map +7 -1
- package/dist/node/index.js +4 -4
- package/dist/node/index.js.map +7 -1
- package/package.json +21 -13
- package/scripts/build.js +1 -1
- package/src/basic.ts +1 -0
- package/src/cloud.ts +19 -1
- package/src/components/FEAASBase.tsx +3 -2
- package/src/components/FEAASComponent.tsx +2 -2
- package/src/components/FEAASElement.tsx +1 -1
- package/src/dom.ts +28 -5
- package/src/fetch.ts +0 -1
- package/src/node.ts +10 -0
- package/src/ui/FEAASContext.tsx +5 -0
- package/src/ui/FEAASEditor.tsx +1 -1
- package/src/ui/FEAASPicker.tsx +1 -1
- package/src/ui/node.ts +2 -0
- package/test/render.ts +91 -93
- package/test/tsconfig.json +1 -1
- package/types/basic.d.ts +1 -0
- package/types/basic.d.ts.map +1 -1
- package/types/cloud.d.ts +3 -1
- package/types/cloud.d.ts.map +1 -1
- package/types/components/FEAASBase.d.ts +2 -2
- package/types/components/FEAASBase.d.ts.map +1 -1
- package/types/components/FEAASComponent.d.ts +1 -1
- package/types/components/FEAASComponent.d.ts.map +1 -1
- package/types/components/FEAASElement.d.ts +3 -3
- package/types/components/FEAASElement.d.ts.map +1 -1
- package/types/components/FEAASLoader.d.ts +1 -1
- package/types/components/FEAASLoader.d.ts.map +1 -1
- package/types/components/FEAASStylesheet.d.ts +3 -3
- package/types/components/FEAASStylesheet.d.ts.map +1 -1
- package/types/dom.d.ts +4 -3
- package/types/dom.d.ts.map +1 -1
- package/types/fetch.d.ts.map +1 -1
- package/types/node.d.ts +4 -0
- package/types/node.d.ts.map +1 -0
- package/types/tsbuildinfo +1 -1
- package/types/tsbuildinfo_ui +1 -1
- package/types/ui/FEAASContext.d.ts +2 -1
- package/types/ui/FEAASContext.d.ts.map +1 -1
- package/types/ui/FEAASEditor.d.ts +3 -3
- package/types/ui/FEAASEditor.d.ts.map +1 -1
- package/types/ui/FEAASPicker.d.ts +2 -2
- package/types/ui/FEAASPicker.d.ts.map +1 -1
- package/types/ui/node.d.ts +3 -0
- package/types/ui/node.d.ts.map +1 -0
package/package.json
CHANGED
|
@@ -1,43 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-feaas/clientside",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.27",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"start": "webpack serve --open",
|
|
6
|
-
"build": "rm -rf dist;npm run
|
|
6
|
+
"build": "rm -rf dist;npm run types; npm run build:esbuild; npm run build:sourcemaps",
|
|
7
7
|
"build:esbuild": "node scripts/build.js",
|
|
8
|
-
"build:sourcemaps": "npx merge-source-maps dist
|
|
9
|
-
"
|
|
10
|
-
"test": "npx vitest --config ../frontend/vite.config.ts $FLAGS",
|
|
8
|
+
"build:sourcemaps": "npx merge-source-maps dist/browser/*.js --inline-sources",
|
|
9
|
+
"test": "npx vitest --config ../frontend/vite.config.ts",
|
|
11
10
|
"test:watch": "npx vitest --config ../frontend/vite.config.ts",
|
|
12
11
|
"prepublishOnly": "npm run build",
|
|
13
12
|
"check": "npx tsc --noEmit",
|
|
13
|
+
"types": "tsc --build",
|
|
14
14
|
"postpublish": "node ../cdn/upload-package.js clientside $npm_package_version"
|
|
15
15
|
},
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"react-dom": ">=16.8.0"
|
|
19
19
|
},
|
|
20
|
-
"main": "./dist/
|
|
21
|
-
"browser": "./dist/browser/index.
|
|
20
|
+
"main": "./dist/node/index.js",
|
|
21
|
+
"browser": "./dist/browser/index.js",
|
|
22
22
|
"module": "./dist/node/index.esm.js",
|
|
23
23
|
"types": "./types/ui/index.d.js",
|
|
24
24
|
"type": "module",
|
|
25
25
|
"exports": {
|
|
26
26
|
".": {
|
|
27
|
-
"
|
|
27
|
+
"localhost": "./build/ui/index.js",
|
|
28
28
|
"types": "./types/ui/index.d.ts",
|
|
29
|
+
"browser": "./dist/browser/index.esm.js",
|
|
30
|
+
"import": "./dist/node/index.esm.js",
|
|
29
31
|
"require": "./dist/node/index.js",
|
|
32
|
+
"default": "./dist/node/index.esm.js"
|
|
33
|
+
},
|
|
34
|
+
"./server": {
|
|
30
35
|
"import": "./dist/node/index.esm.js",
|
|
31
|
-
"browser": "./dist/browser/index.esm.js",
|
|
32
36
|
"default": "./dist/node/index.js"
|
|
33
37
|
},
|
|
34
38
|
"./basic": {
|
|
35
|
-
"
|
|
39
|
+
"localhost": "./build/basic.js",
|
|
36
40
|
"types": "./types/basic.d.ts",
|
|
37
|
-
"require": "./dist/node/basic.js",
|
|
38
|
-
"import": "./dist/node/basic.esm.js",
|
|
39
41
|
"browser": "./dist/browser/basic.esm.js",
|
|
40
|
-
"
|
|
42
|
+
"import": "./dist/node/inbasicdex.esm.js",
|
|
43
|
+
"require": "./dist/node/basic.js",
|
|
44
|
+
"default": "./dist/node/basic.esm.js"
|
|
41
45
|
}
|
|
42
46
|
},
|
|
43
47
|
"typedoc": {
|
|
@@ -49,7 +53,11 @@
|
|
|
49
53
|
"@types/jsonpath-plus": "^5.0.2",
|
|
50
54
|
"esbuild": "^0.16.17",
|
|
51
55
|
"esbuild-plugin-replace-regex": "^0.0.2",
|
|
56
|
+
"htmlparser2": "^8.0.1",
|
|
52
57
|
"jsonpath-plus": "^7.2.0",
|
|
53
58
|
"merge-source-maps": "^0.6.1"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"linkedom": "^0.14.22"
|
|
54
62
|
}
|
|
55
63
|
}
|
package/scripts/build.js
CHANGED
|
@@ -16,7 +16,7 @@ function compile({ input, output, ...step }) {
|
|
|
16
16
|
outfile: path.resolve(__dirname, '../' + output),
|
|
17
17
|
bundle: true,
|
|
18
18
|
write: false,
|
|
19
|
-
external: ['node:crypto', 'node-fetch', 'MAGIC_IMPORT_COMMENTS_ESBUILD_WORKAROUND'],
|
|
19
|
+
external: ['node:crypto', 'node-fetch', 'MAGIC_IMPORT_COMMENTS_ESBUILD_WORKAROUND', 'linkedom'],
|
|
20
20
|
|
|
21
21
|
...step,
|
|
22
22
|
|
package/src/basic.ts
CHANGED
|
@@ -2,6 +2,7 @@ import FEAASElement from './components/FEAASElement.js'
|
|
|
2
2
|
|
|
3
3
|
export * from './dom.js'
|
|
4
4
|
export * from './fetch.js'
|
|
5
|
+
export * from './cloud.js'
|
|
5
6
|
export * from './components/FEAASBase.js'
|
|
6
7
|
export * from './components/FEAASElement.js'
|
|
7
8
|
export * from './components/FEAASComponent.js'
|
package/src/cloud.ts
CHANGED
|
@@ -36,7 +36,11 @@ export function getStylesheetURL({
|
|
|
36
36
|
return `${cdn || hostname}/styles/${library}/${revision}.css`
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export async function
|
|
39
|
+
export async function fetchAndRevalidateComponent(
|
|
40
|
+
props: CloudTemplate,
|
|
41
|
+
callback?: (html: string) => void,
|
|
42
|
+
dontRevalidate = false
|
|
43
|
+
) {
|
|
40
44
|
const onlyIfNotDeleted = (response: Response) => {
|
|
41
45
|
return response.headers.get('x-ms-meta-versionDeletedAt') == null
|
|
42
46
|
}
|
|
@@ -68,6 +72,7 @@ export async function fetchComponent(props: CloudTemplate, callback: (html: stri
|
|
|
68
72
|
console.log('Using fork!', results)
|
|
69
73
|
}
|
|
70
74
|
parseResponse(result.response)
|
|
75
|
+
|
|
71
76
|
return refetchAndValidate({ ...result, callback: parseResponse }).catch((e) => {
|
|
72
77
|
if (results[0] == result) {
|
|
73
78
|
invalidateRequest({ ...result, callback: null, validator: null })
|
|
@@ -82,6 +87,19 @@ export async function fetchComponent(props: CloudTemplate, callback: (html: stri
|
|
|
82
87
|
})
|
|
83
88
|
}
|
|
84
89
|
|
|
90
|
+
/** Fetches HTML of a component. */
|
|
91
|
+
export async function fetchComponentHTML(props: CloudTemplate) {
|
|
92
|
+
var result: string
|
|
93
|
+
await fetchAndRevalidateComponent(
|
|
94
|
+
props,
|
|
95
|
+
(html) => {
|
|
96
|
+
result = html
|
|
97
|
+
},
|
|
98
|
+
false
|
|
99
|
+
)
|
|
100
|
+
return result
|
|
101
|
+
}
|
|
102
|
+
|
|
85
103
|
export async function fetchStylesheet(props: CloudStylesheet, callback: (css: string) => void) {
|
|
86
104
|
return fetchAndRevalidate(
|
|
87
105
|
getStylesheetURL(props),
|
|
@@ -223,7 +223,7 @@ export class FEAASBase<Props = any, Payload = any> extends WebComponent {
|
|
|
223
223
|
})
|
|
224
224
|
.map((child: FEAASBase<any, any>, index) => {
|
|
225
225
|
return React.createElement(this.getReactWrapper(child), {
|
|
226
|
-
key:
|
|
226
|
+
key: child.tagName + '-' + child.getUID(),
|
|
227
227
|
slot: child.getAttribute('slot')
|
|
228
228
|
})
|
|
229
229
|
})
|
|
@@ -244,6 +244,7 @@ export class FEAASBase<Props = any, Payload = any> extends WebComponent {
|
|
|
244
244
|
}
|
|
245
245
|
})
|
|
246
246
|
Object.assign(Wrapper, {
|
|
247
|
+
key: this.tagName + '-' + this.getUID(),
|
|
247
248
|
displayName: displayName
|
|
248
249
|
})
|
|
249
250
|
return Wrapper
|
|
@@ -259,7 +260,7 @@ export class FEAASBase<Props = any, Payload = any> extends WebComponent {
|
|
|
259
260
|
* Render method that is pretty much the same as React Functional component, but with extra second argument for
|
|
260
261
|
* payload (usually result of import, it is expected to have React in scope).
|
|
261
262
|
*/
|
|
262
|
-
render?(props: React.PropsWithChildren<
|
|
263
|
+
render?(props: React.PropsWithChildren<Props>, payload: Payload): ReactNode | ReactElement
|
|
263
264
|
|
|
264
265
|
useShadowRoot: boolean
|
|
265
266
|
getShadowRoot() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fetchAndRevalidateComponent } from '../cloud.js'
|
|
2
2
|
import { renderDOMContent, renderDOMElement } from '../dom.js'
|
|
3
3
|
import { FEAASBase, OptionalExcept } from './FEAASBase.js'
|
|
4
4
|
import { FEAASLoader } from './FEAASLoader.js'
|
|
@@ -103,7 +103,7 @@ export class FEAASComponent extends FEAASBase<FEAASComponentsProps, string> {
|
|
|
103
103
|
return
|
|
104
104
|
}
|
|
105
105
|
try {
|
|
106
|
-
|
|
106
|
+
fetchAndRevalidateComponent(this.props, this.onLoad)
|
|
107
107
|
} catch {
|
|
108
108
|
console.error(
|
|
109
109
|
`FEAAS: Could not fetch component: ${this.props.component}/${this.props.version}/${this.props.revision}`
|
|
@@ -13,7 +13,7 @@ export type FEAASReactRender<P> = {
|
|
|
13
13
|
export default class FEAASElement<P> extends FEAASBase<P, ReactModules> {
|
|
14
14
|
load() {
|
|
15
15
|
return Promise.all([
|
|
16
|
-
// @ts-ignore
|
|
16
|
+
// @ts-ignore @webpack-ignore
|
|
17
17
|
import('https://cdn.skypack.dev/react'),
|
|
18
18
|
// @ts-ignore
|
|
19
19
|
import('https://cdn.skypack.dev/react-dom')
|
package/src/dom.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSONPath } from 'jsonpath-plus'
|
|
2
|
-
import { CloudStylesheet, CloudTemplate,
|
|
2
|
+
import { CloudStylesheet, CloudTemplate, fetchAndRevalidateComponent, fetchStylesheet } from './cloud.js'
|
|
3
3
|
|
|
4
4
|
export interface FEAASCustomizations {
|
|
5
5
|
processTemplate?: (element: HTMLElement, template: string, data: any) => string
|
|
@@ -300,14 +300,19 @@ export function renderDOMElement(
|
|
|
300
300
|
}
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
|
-
for (var i = 0;
|
|
304
|
-
|
|
303
|
+
for (var i = 0, child: Node; (child = element.childNodes[i++]); ) {
|
|
304
|
+
if (isElement(child)) {
|
|
305
|
+
renderDOMElement(child, datascopes, config, true)
|
|
306
|
+
}
|
|
305
307
|
}
|
|
306
308
|
if (!isNested) {
|
|
307
309
|
config?.onRender?.(element, datascopes)
|
|
308
310
|
}
|
|
309
311
|
return element
|
|
310
312
|
}
|
|
313
|
+
function isElement(node: Node): node is HTMLElement {
|
|
314
|
+
return node.nodeType == 1
|
|
315
|
+
}
|
|
311
316
|
|
|
312
317
|
export function renderDOMContent(root: HTMLElement, template: string, data?: Datascopes, config?: FEAASCustomizations) {
|
|
313
318
|
const newTemplate = config?.processTemplate?.(root, template, data) || template
|
|
@@ -316,11 +321,29 @@ export function renderDOMContent(root: HTMLElement, template: string, data?: Dat
|
|
|
316
321
|
// fixme, jss needs to assign theme classes to component instead
|
|
317
322
|
const anchor = root.closest('.component.feaas') || root
|
|
318
323
|
if (anchor.className.includes('-theme--')) {
|
|
319
|
-
for (
|
|
324
|
+
for (var i = 0, child: Node; (child = root.childNodes[i++]); ) {
|
|
325
|
+
if (isElement(child)) {
|
|
326
|
+
child.className = child.className.replace(/(\s|^)-theme--[^\s]+\s*/g, '$1')
|
|
327
|
+
}
|
|
328
|
+
}
|
|
320
329
|
}
|
|
321
330
|
return renderDOMElement(root, data, config)
|
|
322
331
|
}
|
|
323
332
|
|
|
333
|
+
export function renderHTMLContent(template: string, data?: Datascopes, config?: FEAASCustomizations, fakeDOM = false) {
|
|
334
|
+
const newTemplate = config?.processTemplate?.(null, template, data) || template
|
|
335
|
+
if (typeof document === 'undefined' || fakeDOM) {
|
|
336
|
+
const { parseHTML } = require('linkedom')
|
|
337
|
+
const { document } = parseHTML(newTemplate)
|
|
338
|
+
return renderDOMElement(document, data, config).toString()
|
|
339
|
+
} else {
|
|
340
|
+
const root = document.createElement('div')
|
|
341
|
+
root.innerHTML = newTemplate
|
|
342
|
+
renderDOMElement(root, data, config)
|
|
343
|
+
return root.innerHTML
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
324
347
|
export function renderStylesheet(props: CloudStylesheet, style?: HTMLStyleElement) {
|
|
325
348
|
renderStylesheetPromise(props, (style ||= document.createElement('style')))
|
|
326
349
|
return style
|
|
@@ -344,7 +367,7 @@ export async function renderComponentPromise(props: FEAASComponentProps, root?:
|
|
|
344
367
|
if ('template' in props) {
|
|
345
368
|
return renderDOMContent(root, props.template, props.data, props)
|
|
346
369
|
} else {
|
|
347
|
-
return
|
|
370
|
+
return fetchAndRevalidateComponent(props, (template) => {
|
|
348
371
|
return renderDOMContent(root, template, props.data, props)
|
|
349
372
|
}).then(() => root)
|
|
350
373
|
}
|
package/src/fetch.ts
CHANGED
|
@@ -36,7 +36,6 @@ export async function fetchAndValidate(
|
|
|
36
36
|
phase: 'initial' | 'updated' | 'check' = 'initial'
|
|
37
37
|
) {
|
|
38
38
|
const date = new Date()
|
|
39
|
-
console.log('fetch', phase, url)
|
|
40
39
|
const response = await fetch(url, options)
|
|
41
40
|
if (!response.ok) throw new Error('Fetch failed')
|
|
42
41
|
if (validator?.(response) === false) throw new Error('Response is not valid')
|
package/src/node.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { parseHTML } from 'linkedom'
|
|
2
|
+
import { Datascopes, FEAASCustomizations, renderDOMContent, renderDOMElement } from './dom.js'
|
|
3
|
+
|
|
4
|
+
export * from './basic.js'
|
|
5
|
+
|
|
6
|
+
export function renderHTMLContent(template: string, data?: Datascopes, config?: FEAASCustomizations) {
|
|
7
|
+
const newTemplate = config?.processTemplate?.(null, template, data) || template
|
|
8
|
+
const { document } = parseHTML(newTemplate)
|
|
9
|
+
return renderDOMElement(document, data, config).toString()
|
|
10
|
+
}
|
package/src/ui/FEAASContext.tsx
CHANGED
|
@@ -27,6 +27,11 @@ export class FEAASContext extends FEAASBase<FEAASContextProps, typeof FEAASConte
|
|
|
27
27
|
return import(/* @vite-ignore */ /* webpackIgnore: true */ this.formatURL(this.props.src, this.props.frontend))
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
isReadyToLoad() {
|
|
31
|
+
console.log('Is ready?', this.props, super.isReadyToLoad() && this.props.library != null)
|
|
32
|
+
return super.isReadyToLoad() && this.props.library != null
|
|
33
|
+
}
|
|
34
|
+
|
|
30
35
|
// Remove global styles
|
|
31
36
|
getTheme(theme: FEAASContextImports.Chakra.Theme): FEAASContextImports.Chakra.Theme {
|
|
32
37
|
return theme
|
package/src/ui/FEAASEditor.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type * as FEAASEditorImports from '@sitecore-feaas/frontend/types/
|
|
1
|
+
import type * as FEAASEditorImports from '@sitecore-feaas/frontend/types/entries/editor.js'
|
|
2
2
|
import { FEAASBase, OptionalExcept } from '../components/FEAASBase.js'
|
|
3
3
|
import { FEAASLoader } from '../components/FEAASLoader.js'
|
|
4
4
|
|
package/src/ui/FEAASPicker.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type * as FEAASPickerImports from '@sitecore-feaas/frontend/types/
|
|
1
|
+
import type * as FEAASPickerImports from '@sitecore-feaas/frontend/types/entries/picker.js'
|
|
2
2
|
import { FEAASBase } from '../components/FEAASBase.js'
|
|
3
3
|
|
|
4
4
|
export function FEAASPickerProps(element: FEAASBase<any, any> = this) {
|
package/src/ui/node.ts
ADDED