@sitecore-feaas/clientside 0.1.29 → 0.1.31
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/cdn.js +3 -0
- package/build/cdn.js.map +1 -1
- package/build/components/FEAASComponent.js +1 -1
- package/build/components/FEAASComponent.js.map +1 -1
- package/build/dom/stylesheet.js.map +1 -1
- package/build/ui/react.js.map +1 -1
- package/dist/browser/headless.esm.js +1 -1
- package/dist/browser/headless.esm.js.map +1 -1
- package/dist/browser/headless.js +1 -1
- package/dist/browser/headless.js.map +1 -1
- package/dist/browser/index.esm.js +5 -3
- package/dist/browser/index.esm.js.map +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/react.esm.js +69 -0
- package/dist/browser/react.esm.js.map +1 -0
- package/dist/browser/react.js +5 -3
- package/dist/browser/react.js.map +1 -1
- package/dist/node/headless.esm.js +3 -3
- package/dist/node/headless.esm.js.map +3 -3
- package/dist/node/headless.js +3 -3
- package/dist/node/headless.js.map +3 -3
- package/dist/node/index.esm.js +3 -3
- package/dist/node/index.esm.js.map +4 -4
- package/dist/node/index.js +1 -1
- package/dist/node/index.js.map +2 -2
- package/dist/node/react.esm.js +67 -0
- package/dist/node/react.esm.js.map +7 -0
- package/dist/node/react.js +1 -1
- package/dist/node/react.js.map +2 -2
- package/package.json +1 -1
- package/scripts/build.js +5 -4
- package/src/cdn.ts +5 -2
- package/src/components/FEAASComponent.tsx +1 -1
- package/src/dom/stylesheet.ts +8 -7
- package/src/ui/react.tsx +1 -2
- package/test/FEAASStylesheet.test.tsx +23 -1
- package/types/cdn.d.ts +2 -2
- package/types/cdn.d.ts.map +1 -1
- package/types/dom/stylesheet.d.ts +7 -7
- package/types/dom/stylesheet.d.ts.map +1 -1
- package/types/tsbuildinfo +1 -1
- package/types/tsbuildinfo_ui +1 -1
- package/types/ui/react.d.ts +1 -1
- package/types/ui/react.d.ts.map +1 -1
package/package.json
CHANGED
package/scripts/build.js
CHANGED
|
@@ -22,7 +22,8 @@ function compile({ input, output, ...step }) {
|
|
|
22
22
|
'_MAGIC_IMPORT_COMMENTS_ESBUILD_WORKAROUND__',
|
|
23
23
|
'linkedom',
|
|
24
24
|
'react',
|
|
25
|
-
'react-dom'
|
|
25
|
+
'react-dom',
|
|
26
|
+
'vm'
|
|
26
27
|
],
|
|
27
28
|
|
|
28
29
|
...step,
|
|
@@ -74,13 +75,13 @@ function compile({ input, output, ...step }) {
|
|
|
74
75
|
{ input: 'build/ui/index.js', output: 'dist/node/index.js', platform: 'node', format: 'cjs' },
|
|
75
76
|
{ input: 'build/ui/index.js', output: 'dist/node/index.esm.js', platform: 'node', format: 'esm' },
|
|
76
77
|
{ input: 'build/ui/react.js', output: 'dist/node/react.js', platform: 'node', format: 'cjs' },
|
|
77
|
-
{ input: 'build/ui/react.js', output: 'dist/node/
|
|
78
|
+
{ input: 'build/ui/react.js', output: 'dist/node/react.esm.js', platform: 'node', format: 'esm' },
|
|
78
79
|
{ input: 'build/headless.js', output: 'dist/node/headless.js', platform: 'node', format: 'cjs' },
|
|
79
80
|
{ input: 'build/headless.js', output: 'dist/node/headless.esm.js', platform: 'node', format: 'esm' },
|
|
80
81
|
{ input: 'build/ui/index.js', output: 'dist/browser/index.js', platform: 'browser', format: 'cjs' },
|
|
81
82
|
{ input: 'build/ui/index.js', output: 'dist/browser/index.esm.js', platform: 'browser', format: 'esm' },
|
|
82
|
-
{ input: 'build/ui/react.js', output: 'dist/browser/react.js', platform: '
|
|
83
|
-
{ input: 'build/ui/react.js', output: 'dist/browser/
|
|
83
|
+
{ input: 'build/ui/react.js', output: 'dist/browser/react.js', platform: 'browser', format: 'cjs' },
|
|
84
|
+
{ input: 'build/ui/react.js', output: 'dist/browser/react.esm.js', platform: 'browser', format: 'esm' },
|
|
84
85
|
{ input: 'build/headless.js', output: 'dist/browser/headless.js', platform: 'browser', format: 'cjs' },
|
|
85
86
|
{ input: 'build/headless.js', output: 'dist/browser/headless.esm.js', platform: 'browser', format: 'esm' }
|
|
86
87
|
].map((step) => {
|
package/src/cdn.ts
CHANGED
|
@@ -38,7 +38,7 @@ export interface FEAASCDNStylesheetParams {
|
|
|
38
38
|
export type FEAASCDNStylesheetSource = {
|
|
39
39
|
src: string
|
|
40
40
|
}
|
|
41
|
-
export type FEAASCDNStylesheetProps = FEAASCDNStylesheetParams | FEAASCDNStylesheetSource
|
|
41
|
+
export type FEAASCDNStylesheetProps = FEAASCDNStylesheetParams | FEAASCDNStylesheetSource | string
|
|
42
42
|
|
|
43
43
|
export function parseComponentSource(source: string): FEAASCDNComponentParams {
|
|
44
44
|
const match = source.match(/^(?:(.*?)\/components)?\/?([^\/]+)\/([^\/]+)(?:\/([^\/]+)(?:\/([^\/]+?)(?:\.html?)?)?)?$/)
|
|
@@ -87,6 +87,9 @@ export function getComponentURL(props: FEAASCDNComponentProps) {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
export function getStylesheetURL(props: FEAASCDNStylesheetProps) {
|
|
90
|
+
if (typeof props == 'string') {
|
|
91
|
+
props = { src: props }
|
|
92
|
+
}
|
|
90
93
|
if ('src' in props) {
|
|
91
94
|
props = {
|
|
92
95
|
...parseComponentSource(props.src)
|
|
@@ -164,7 +167,7 @@ export async function fetchComponent(props: FEAASCDNComponentProps | string) {
|
|
|
164
167
|
|
|
165
168
|
export type ValidatableStylesheetCallback = (css: string, phase: ValidatableRequestPhase) => void
|
|
166
169
|
export async function fetchAndRevalidateStylesheet(
|
|
167
|
-
props: FEAASCDNStylesheetProps
|
|
170
|
+
props: FEAASCDNStylesheetProps,
|
|
168
171
|
callback: ValidatableStylesheetCallback
|
|
169
172
|
) {
|
|
170
173
|
if (typeof props == 'string') props = { src: props }
|
|
@@ -127,7 +127,7 @@ export class FEAASComponent extends FEAASBase<FEAASComponentsProps, string> {
|
|
|
127
127
|
return
|
|
128
128
|
}
|
|
129
129
|
if (this.props.withStylesheet) {
|
|
130
|
-
var stylesheetPromise = loadStylesheetAllowStale(this.props).then(() => {
|
|
130
|
+
var stylesheetPromise = loadStylesheetAllowStale({ ...this.props, revision: 'published' }).then(() => {
|
|
131
131
|
stylesheetPromise = null
|
|
132
132
|
if (this.payload) {
|
|
133
133
|
this.onLoad(this.payload)
|
package/src/dom/stylesheet.ts
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
FEAASCDNStylesheetProps,
|
|
3
3
|
fetchAndRevalidateStylesheet,
|
|
4
4
|
getStylesheetURL,
|
|
5
5
|
ValidatableStylesheetCallback
|
|
6
6
|
} from '../cdn.js'
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
export function renderStylesheet(props: FEAASCDNStylesheetProps, style?: HTMLStyleElement) {
|
|
8
9
|
renderStylesheetPromise(props, (style ||= document.createElement('style')))
|
|
9
10
|
return style
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
export function renderStylesheetPromise(props:
|
|
13
|
+
export function renderStylesheetPromise(props: FEAASCDNStylesheetProps, stylesheet?: HTMLStyleElement) {
|
|
13
14
|
stylesheet ||= document.createElement('style')
|
|
14
15
|
return fetchAndRevalidateStylesheet(props, (cssText, phase) => {
|
|
15
16
|
stylesheet.textContent = cssText
|
|
16
17
|
}).then(() => stylesheet)
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
export function loadStylesheet(props:
|
|
20
|
+
export function loadStylesheet(props: FEAASCDNStylesheetProps, callback?: ValidatableStylesheetCallback) {
|
|
20
21
|
var foundStylesheet = findStylesheet(props) as HTMLStyleElement
|
|
21
22
|
if (!foundStylesheet) {
|
|
22
23
|
var createdStylesheet = createStylesheet(props)
|
|
@@ -29,17 +30,17 @@ export function loadStylesheet(props: FEAASCDNStylesheetParams, callback?: Valid
|
|
|
29
30
|
}).then(() => foundStylesheet || createdStylesheet)
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
export function loadStylesheetAllowStale(props:
|
|
33
|
+
export function loadStylesheetAllowStale(props: FEAASCDNStylesheetProps) {
|
|
33
34
|
return new Promise((resolve, reject) => {
|
|
34
35
|
loadStylesheet(props, resolve).catch(reject)
|
|
35
36
|
})
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
export function findStylesheet(props:
|
|
39
|
+
export function findStylesheet(props: FEAASCDNStylesheetProps) {
|
|
39
40
|
return document.head.querySelector(`style[data-href="${getStylesheetURL(props)}"]`)
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
export function createStylesheet(props:
|
|
43
|
+
export function createStylesheet(props: FEAASCDNStylesheetProps) {
|
|
43
44
|
const url = getStylesheetURL(props)
|
|
44
45
|
const stylesheet = document.createElement('style')
|
|
45
46
|
stylesheet.setAttribute('data-href', url)
|
package/src/ui/react.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { afterAll, beforeEach, beforeAll, describe, expect, it, vi } from 'vitest'
|
|
2
2
|
import { FEAASStylesheet } from '../src/components/FEAASStylesheet.js'
|
|
3
3
|
import { renderDOMContent } from '../src/dom/rendering.js'
|
|
4
|
-
import { clearFetchCache, loadStylesheet } from '../src/headless.js'
|
|
4
|
+
import { clearFetchCache, DEFAULT_CDN_URL, loadStylesheet } from '../src/headless.js'
|
|
5
5
|
|
|
6
6
|
const earliest = new Date(2000, 1, 1, 0, 0, 0)
|
|
7
7
|
const earlier = new Date(2000, 1, 2, 0, 0, 0)
|
|
@@ -46,6 +46,27 @@ describe('Stylesheet', () => {
|
|
|
46
46
|
|
|
47
47
|
expect(document.head.querySelector('style').textContent).toContain('TODAY')
|
|
48
48
|
})
|
|
49
|
+
it('should load stylesheet with minimum parameters(cold cache)', async () => {
|
|
50
|
+
const spy = vi.spyOn(global, 'fetch')
|
|
51
|
+
spy.mockImplementation(async (url: string, options: Parameters<typeof fetch>[1] = {}) => {
|
|
52
|
+
if (url.match(DEFAULT_CDN_URL + '/styles/L/published.css'))
|
|
53
|
+
return new Response('TODAY {}', {
|
|
54
|
+
headers: {
|
|
55
|
+
date: now.toUTCString(),
|
|
56
|
+
'last-modified': earlier.toUTCString()
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
document.body.innerHTML = '<feaas-stylesheet library="L"></feaas-stylesheet>'
|
|
62
|
+
|
|
63
|
+
const stylesheet = document.body.firstElementChild as FEAASStylesheet
|
|
64
|
+
|
|
65
|
+
await expect(stylesheet.whenRendered).resolves.toEqual(stylesheet)
|
|
66
|
+
expect(spy).toHaveBeenCalledTimes(1)
|
|
67
|
+
|
|
68
|
+
expect(document.head.querySelector('style').textContent).toContain('TODAY')
|
|
69
|
+
})
|
|
49
70
|
|
|
50
71
|
it('should invalidate stylesheet cache', async () => {
|
|
51
72
|
const spy = vi.spyOn(global, 'fetch')
|
|
@@ -155,5 +176,6 @@ describe('Stylesheet', () => {
|
|
|
155
176
|
revision: 'published'
|
|
156
177
|
}).then((r) => r.textContent)
|
|
157
178
|
).resolves.toEqual('TODAY {}')
|
|
179
|
+
await expect(loadStylesheet(`http://CDN/L/published.css`).then((r) => r.textContent)).resolves.toEqual('TODAY {}')
|
|
158
180
|
})
|
|
159
181
|
})
|
package/types/cdn.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export interface FEAASCDNStylesheetParams {
|
|
|
26
26
|
export type FEAASCDNStylesheetSource = {
|
|
27
27
|
src: string;
|
|
28
28
|
};
|
|
29
|
-
export type FEAASCDNStylesheetProps = FEAASCDNStylesheetParams | FEAASCDNStylesheetSource;
|
|
29
|
+
export type FEAASCDNStylesheetProps = FEAASCDNStylesheetParams | FEAASCDNStylesheetSource | string;
|
|
30
30
|
export declare function parseComponentSource(source: string): FEAASCDNComponentParams;
|
|
31
31
|
export declare function getComponentSource(props: FEAASCDNComponentParams): string;
|
|
32
32
|
export declare function getStylesheetSource(props: FEAASCDNStylesheetParams): string;
|
|
@@ -53,5 +53,5 @@ export declare function fetchComponent(props: FEAASCDNComponentProps | string):
|
|
|
53
53
|
instance?: string;
|
|
54
54
|
}>;
|
|
55
55
|
export type ValidatableStylesheetCallback = (css: string, phase: ValidatableRequestPhase) => void;
|
|
56
|
-
export declare function fetchAndRevalidateStylesheet(props: FEAASCDNStylesheetProps
|
|
56
|
+
export declare function fetchAndRevalidateStylesheet(props: FEAASCDNStylesheetProps, callback: ValidatableStylesheetCallback): Promise<Response>;
|
|
57
57
|
//# sourceMappingURL=cdn.d.ts.map
|
package/types/cdn.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cdn.d.ts","sourceRoot":"","sources":["../src/cdn.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,uBAAuB,EACxB,MAAM,YAAY,CAAA;AAEnB,eAAO,MAAM,eAAe,wDAAwD,CAAA;AACpF,MAAM,MAAM,uBAAuB,GAAG;IACpC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,SAAS,GAAG,WAAW,GAAG,OAAO,GAAG,MAAM,CAAA;IACrD,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IAEf,oCAAoC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AACD,MAAM,MAAM,uBAAuB,GAAG;IACpC,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AACD,MAAM,MAAM,qCAAqC,GAAG;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AACD,MAAM,MAAM,sBAAsB,GAAG,CAAC,uBAAuB,GAAG,uBAAuB,CAAC,GACtF,qCAAqC,CAAA;AAEvC,MAAM,WAAW,wBAAwB;IACvC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,SAAS,GAAG,WAAW,GAAG,OAAO,GAAG,MAAM,CAAA;IAErD,oCAAoC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAA;CA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,CAAC,MAAM,EAAE,MAAM,GAAG,uBAAuB,CAM5E;AACD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,UAahE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,UAIlE;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,wBAAwB,CAM9E;AACD,wBAAgB,eAAe,CAAC,KAAK,EAAE,sBAAsB,UAS5D;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,uBAAuB,UAY9D;AAED,wBAAsB,2BAA2B,CAC/C,KAAK,EAAE,sBAAsB,EAC7B,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EACjC,cAAc,UAAQ,0HA8CvB;AAED,mCAAmC;AACnC,wBAAsB,cAAc,CAAC,KAAK,EAAE,sBAAsB,GAAG,MAAM;;;;;;;;IA1IzE,oCAAoC;;;;;;;;GAqJrC;AAED,MAAM,MAAM,6BAA6B,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,uBAAuB,KAAK,IAAI,CAAA;AACjG,wBAAsB,4BAA4B,CAChD,KAAK,EAAE,uBAAuB,EAC9B,QAAQ,EAAE,6BAA6B,qBAoBxC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function renderStylesheet(props:
|
|
3
|
-
export declare function renderStylesheetPromise(props:
|
|
4
|
-
export declare function loadStylesheet(props:
|
|
5
|
-
export declare function loadStylesheetAllowStale(props:
|
|
6
|
-
export declare function findStylesheet(props:
|
|
7
|
-
export declare function createStylesheet(props:
|
|
1
|
+
import { FEAASCDNStylesheetProps, ValidatableStylesheetCallback } from '../cdn.js';
|
|
2
|
+
export declare function renderStylesheet(props: FEAASCDNStylesheetProps, style?: HTMLStyleElement): HTMLStyleElement;
|
|
3
|
+
export declare function renderStylesheetPromise(props: FEAASCDNStylesheetProps, stylesheet?: HTMLStyleElement): Promise<HTMLStyleElement>;
|
|
4
|
+
export declare function loadStylesheet(props: FEAASCDNStylesheetProps, callback?: ValidatableStylesheetCallback): Promise<HTMLStyleElement>;
|
|
5
|
+
export declare function loadStylesheetAllowStale(props: FEAASCDNStylesheetProps): Promise<unknown>;
|
|
6
|
+
export declare function findStylesheet(props: FEAASCDNStylesheetProps): Element;
|
|
7
|
+
export declare function createStylesheet(props: FEAASCDNStylesheetProps): HTMLStyleElement;
|
|
8
8
|
//# sourceMappingURL=stylesheet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stylesheet.d.ts","sourceRoot":"","sources":["../../src/dom/stylesheet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"stylesheet.d.ts","sourceRoot":"","sources":["../../src/dom/stylesheet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EAGvB,6BAA6B,EAC9B,MAAM,WAAW,CAAA;AAElB,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,uBAAuB,EAAE,KAAK,CAAC,EAAE,gBAAgB,oBAGxF;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,uBAAuB,EAAE,UAAU,CAAC,EAAE,gBAAgB,6BAKpG;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,uBAAuB,EAAE,QAAQ,CAAC,EAAE,6BAA6B,6BAWtG;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,uBAAuB,oBAItE;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,uBAAuB,WAE5D;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,uBAAuB,oBAM9D"}
|