@sitecore-feaas/clientside 0.1.54 → 0.1.56
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/README.md +20 -20
- package/build/components/FEAASComponent.js +1 -1
- package/build/components/FEAASComponent.js.map +1 -1
- package/build/components/FEAASLoader.js +1 -1
- package/build/components/FEAASLoader.js.map +1 -1
- package/build/components/FEAASStylesheet.js +1 -1
- package/build/components/FEAASStylesheet.js.map +1 -1
- package/build/dom/thumbnail.js +247 -0
- package/build/dom/thumbnail.js.map +1 -0
- package/build/fetch.js +4 -2
- package/build/fetch.js.map +1 -1
- package/build/headless.js +1 -0
- package/build/headless.js.map +1 -1
- package/build/ui/FEAASContext.js +8 -3
- package/build/ui/FEAASContext.js.map +1 -1
- package/build/ui/FEAASEditor.js +5 -5
- package/build/ui/FEAASEditor.js.map +1 -1
- package/build/ui/FEAASExternal.js +8 -9
- package/build/ui/FEAASExternal.js.map +1 -1
- package/build/ui/FEAASPicker.js +5 -3
- package/build/ui/FEAASPicker.js.map +1 -1
- package/build/utils/promise.js.map +1 -1
- package/dist/browser/headless.cjs +8 -5
- package/dist/browser/headless.cjs.map +4 -4
- package/dist/browser/headless.esm.js +8 -5
- package/dist/browser/headless.esm.js.map +1 -1
- package/dist/browser/index.cjs +8 -5
- package/dist/browser/index.cjs.map +4 -4
- package/dist/browser/index.esm.js +8 -5
- package/dist/browser/index.esm.js.map +1 -1
- package/dist/browser/react.cjs +8 -5
- package/dist/browser/react.cjs.map +4 -4
- package/dist/browser/react.esm.js +8 -5
- package/dist/browser/react.esm.js.map +1 -1
- package/dist/node/headless.cjs +6 -3
- package/dist/node/headless.cjs.map +4 -4
- package/dist/node/headless.esm.js +6 -3
- package/dist/node/headless.esm.js.map +4 -4
- package/dist/node/index.cjs +6 -3
- package/dist/node/index.cjs.map +4 -4
- package/dist/node/index.esm.js +6 -3
- package/dist/node/index.esm.js.map +4 -4
- package/dist/node/react.cjs +6 -3
- package/dist/node/react.cjs.map +4 -4
- package/dist/node/react.esm.js +6 -3
- package/dist/node/react.esm.js.map +4 -4
- package/headless.cjs +6 -3
- package/headless.cjs.map +4 -4
- package/headless.js +6 -3
- package/headless.js.map +4 -4
- package/package.json +2 -1
- package/react.cjs +8 -5
- package/react.cjs.map +4 -4
- package/react.js +8 -5
- package/react.js.map +4 -4
- package/src/components/FEAASComponent.tsx +1 -1
- package/src/components/FEAASLoader.tsx +1 -1
- package/src/components/FEAASStylesheet.tsx +1 -1
- package/src/dom/thumbnail.ts +293 -0
- package/src/fetch.ts +5 -3
- package/src/headless.ts +1 -0
- package/src/ui/FEAASContext.tsx +9 -3
- package/src/ui/FEAASEditor.tsx +5 -5
- package/src/ui/FEAASExternal.tsx +7 -8
- package/src/ui/FEAASPicker.tsx +7 -2
- package/src/utils/promise.ts +2 -2
- package/test/FEAASComponent.react.test.tsx +3 -6
- package/types/components/FEAASComponent.d.ts +1 -1
- package/types/components/FEAASComponent.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 +1 -1
- package/types/components/FEAASStylesheet.d.ts.map +1 -1
- package/types/dom/thumbnail.d.ts +82 -0
- package/types/dom/thumbnail.d.ts.map +1 -0
- package/types/fetch.d.ts +6 -4
- package/types/fetch.d.ts.map +1 -1
- package/types/headless.d.ts +1 -0
- package/types/headless.d.ts.map +1 -1
- package/types/tsbuildinfo +1 -1
- package/types/tsbuildinfo_ui +1 -1
- package/types/ui/FEAASContext.d.ts +9 -5
- package/types/ui/FEAASContext.d.ts.map +1 -1
- package/types/ui/FEAASEditor.d.ts +2 -2
- package/types/ui/FEAASEditor.d.ts.map +1 -1
- package/types/ui/FEAASExternal.d.ts +1 -1
- package/types/ui/FEAASExternal.d.ts.map +1 -1
- package/types/ui/FEAASPicker.d.ts +2 -2
- package/types/ui/FEAASPicker.d.ts.map +1 -1
- package/types/utils/promise.d.ts +1 -1
- package/types/utils/promise.d.ts.map +1 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { VersionModel, ComponentModel } from '@sitecore-feaas/sdk';
|
|
2
|
+
export type Callback = (image: HTMLImageElement, isCached: boolean) => void;
|
|
3
|
+
export declare const convertBase64toBlob: (base64: string) => Promise<Blob>;
|
|
4
|
+
/** Parse fetch response as blob and turn it into HTMLImageElement off thread */
|
|
5
|
+
export declare const responseToImage: (response: Response) => Promise<HTMLImageElement>;
|
|
6
|
+
/**
|
|
7
|
+
* Retrieves the version of a given component that best fits a specific display width.
|
|
8
|
+
*
|
|
9
|
+
* The function ensures that the version data for the component is available and selects the one that is most suitable
|
|
10
|
+
* for a display width of 800 pixels.
|
|
11
|
+
*
|
|
12
|
+
* @param {ComponentModel} component - The component for which the version needs to be obtained.
|
|
13
|
+
* @returns {Promise<VersionModel>} - A promise that resolves to the most suitable version for a display width of 800
|
|
14
|
+
* pixels.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getVersionForThumbnail(component: ComponentModel): Promise<VersionModel>;
|
|
17
|
+
/**
|
|
18
|
+
* Ensures an up-to-date thumbnail for a specific component and version.
|
|
19
|
+
*
|
|
20
|
+
* This operation initiates thumbnail load and, if that fails or if file is out of date, a new thumbnail is generated.
|
|
21
|
+
* It can work with a callback, which is designed to potentially fire twice for enhancing user experience. This dual
|
|
22
|
+
* firing allows for an immediate display of a possibly stale cached image while downloading or generating new version
|
|
23
|
+
* in the background.
|
|
24
|
+
*
|
|
25
|
+
* 1. The first call can happen with the stale cached or outdated image.
|
|
26
|
+
* 2. The second call occurs with the up-to-date loaded or freshly generated generated image.
|
|
27
|
+
*
|
|
28
|
+
* @param {ComponentModel} component - Relevant component.
|
|
29
|
+
* @param {VersionModel} [version] - Relevant version (optional, falls back to responsive).
|
|
30
|
+
* @param {Callback} [callback] - Callback to handle the loaded or generated image (optional).
|
|
31
|
+
* @returns {Promise<HTMLImageElement | null>} - The final thumbnail image (either loaded or freshly generated).
|
|
32
|
+
*/
|
|
33
|
+
export declare function get(component: ComponentModel, version?: VersionModel, callback?: Callback): Promise<HTMLImageElement>;
|
|
34
|
+
/**
|
|
35
|
+
* Retrieves the thumbnail image for a given component/version combination, with a responsive default if version is not
|
|
36
|
+
* provided.
|
|
37
|
+
*
|
|
38
|
+
* The resulting HTML <img> element will have `width`, `height`, and `src` properties ready for use. Although it can
|
|
39
|
+
* operate as a regular promise that resolves when the thumbnail is loaded, it also supports a callback for an enhanced
|
|
40
|
+
* user experience. This callback may be invoked twice, depending on the state of the cache:
|
|
41
|
+
*
|
|
42
|
+
* 1. The first call occurs if the image was previously cached by the browser, but the cache is stale.
|
|
43
|
+
* 2. The second call happens when the image is updated from a fresh download. By this design, the user gets to see a
|
|
44
|
+
* cached image immediately while the updated image is being downloaded in the background.
|
|
45
|
+
*
|
|
46
|
+
* If the version of a component is known to be newer than remote file, the function will throw `InvalidResponse` error.
|
|
47
|
+
* As a way to handle that error, the `generate` function may be used to produce new thumbnail (@see render).
|
|
48
|
+
*
|
|
49
|
+
* @param {ComponentModel} component - The component to load a thumbnail for.
|
|
50
|
+
* @param {VersionModel} [version] - The version of the component to load a thumbnail for. If not provided, a version
|
|
51
|
+
* suitable for a responsive component is selected.
|
|
52
|
+
* @param {Callback} [callback] - A callback to handle the loaded image. This callback may be invoked twice for the
|
|
53
|
+
* reasons described above.
|
|
54
|
+
* @returns {Promise<HTMLImageElement>} - The thumbnail image for the component/version combination.
|
|
55
|
+
*/
|
|
56
|
+
export declare function load(component: ComponentModel, version?: VersionModel, callback?: Callback): Promise<HTMLImageElement>;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a thumbnail image for a given component and version.
|
|
59
|
+
*
|
|
60
|
+
* First, it determines the appropriate version to use. If not provided, it attempts to fetch one suitable for
|
|
61
|
+
* thumbnail. It then leverages `render` to generate an image with provided parameters and finally, if the component
|
|
62
|
+
* isn't new, uploads the generated as a Blob onto cdn for future retrieval.
|
|
63
|
+
*
|
|
64
|
+
* @param {ComponentModel} component - Component instance.
|
|
65
|
+
* @param {VersionModel} [version] - Version instance.
|
|
66
|
+
* @returns {Promise<HTMLImageElement | null>} Thumbnail image or null if generation isn't possible.
|
|
67
|
+
*/
|
|
68
|
+
export declare function generate(component: ComponentModel, version?: VersionModel): Promise<HTMLImageElement>;
|
|
69
|
+
/**
|
|
70
|
+
* Uploads a thumbnail Blob to a CDN, enabling it for future retrieval.
|
|
71
|
+
*
|
|
72
|
+
* It constructs a URL based on component and version information, if available. The thumbnail's blob is uploaded with
|
|
73
|
+
* several metadata points, including identifiers and timestamps. Upon successful upload, it sends a no-cache fetch
|
|
74
|
+
* request to the constructed URL to bust the cache.
|
|
75
|
+
*
|
|
76
|
+
* @param {ComponentModel} component - Component instance.
|
|
77
|
+
* @param {VersionModel} version - Version instance.
|
|
78
|
+
* @param {Blob} blob - Blob instance to upload.
|
|
79
|
+
* @returns {Promise<string>} URL of the uploaded Blob.
|
|
80
|
+
*/
|
|
81
|
+
export declare function upload(component: ComponentModel, version: VersionModel, blob: Blob): Promise<string>;
|
|
82
|
+
//# sourceMappingURL=thumbnail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thumbnail.d.ts","sourceRoot":"","sources":["../../src/dom/thumbnail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAInF,MAAM,MAAM,QAAQ,GAAG,CAAC,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAA;AAE3E,eAAO,MAAM,mBAAmB,WAAY,MAAM,kBAA4C,CAAA;AAE9F,gFAAgF;AAChF,eAAO,MAAM,eAAe,aAAc,QAAQ,KAAG,QAAQ,gBAAgB,CAUzE,CAAA;AAEJ;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAAC,SAAS,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAG7F;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,GAAG,CAAC,SAAS,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,QAAQ,6BAqB/F;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,IAAI,CACxB,SAAS,EAAE,cAAc,EACzB,OAAO,CAAC,EAAE,YAAY,EACtB,QAAQ,CAAC,EAAE,QAAQ,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAmC3B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,QAAQ,CAAC,SAAS,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,YAAY,6BAkB/E;AAkFD;;;;;;;;;;;GAWG;AACH,wBAAsB,MAAM,CAAC,SAAS,EAAE,cAAc,EAAE,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CA+B1G"}
|
package/types/fetch.d.ts
CHANGED
|
@@ -12,12 +12,12 @@ import { ControlledPromise } from './utils/promise.js';
|
|
|
12
12
|
* errors will not be caught. Function throws when unable to fetch valid response.
|
|
13
13
|
*/
|
|
14
14
|
declare const phases: readonly ["initial", "check", "updated"];
|
|
15
|
-
export type ValidatableRequestPhase = typeof phases[number];
|
|
15
|
+
export type ValidatableRequestPhase = (typeof phases)[number];
|
|
16
16
|
export type FetchCache = Record<string, FetchCacheRequest>;
|
|
17
17
|
export interface ValidatableRequest {
|
|
18
18
|
url: Parameters<typeof fetch>[0];
|
|
19
19
|
options?: Parameters<typeof fetch>[1];
|
|
20
|
-
validator?: (resposne: Response) => boolean;
|
|
20
|
+
validator?: (resposne: Response, isCached: boolean) => boolean;
|
|
21
21
|
callback?: (response: Response, status: ValidatableRequestPhase, isCached: boolean) => any;
|
|
22
22
|
isCached?: boolean;
|
|
23
23
|
response?: Response;
|
|
@@ -34,12 +34,14 @@ export declare var fetchCache: Record<string, FetchCacheRequest>;
|
|
|
34
34
|
export declare function clearFetchCache(): void;
|
|
35
35
|
export declare function fetchAndRevalidate(url: ValidatableRequest['url'], options?: ValidatableRequest['options'], validator?: ValidatableRequest['validator'], callback?: ValidatableRequest['callback'], cache?: FetchCache): Promise<Response>;
|
|
36
36
|
export declare function getFetchCache(url: Parameters<typeof fetch>[0], dontCreate?: boolean): FetchCacheRequest;
|
|
37
|
+
export declare class InvalidResponse extends Error {
|
|
38
|
+
}
|
|
37
39
|
export declare function fetchWithCacheAwareness({ url, options, validator, callback, cache }: ValidatableRequest, phase?: ValidatableRequestPhase): Promise<{
|
|
38
40
|
url: RequestInfo | URL;
|
|
39
41
|
options: RequestInit;
|
|
40
42
|
isCached: boolean;
|
|
41
43
|
response: Response;
|
|
42
|
-
validator: (resposne: Response) => boolean;
|
|
44
|
+
validator: (resposne: Response, isCached: boolean) => boolean;
|
|
43
45
|
callback: (response: Response, status: "initial" | "check" | "updated", isCached: boolean) => any;
|
|
44
46
|
cache: FetchCache;
|
|
45
47
|
}>;
|
|
@@ -49,7 +51,7 @@ export declare function fetchBypassingCache(request: ValidatableRequest): Promis
|
|
|
49
51
|
options: RequestInit;
|
|
50
52
|
isCached: boolean;
|
|
51
53
|
response: Response;
|
|
52
|
-
validator: (resposne: Response) => boolean;
|
|
54
|
+
validator: (resposne: Response, isCached: boolean) => boolean;
|
|
53
55
|
callback: (response: Response, status: "initial" | "check" | "updated", isCached: boolean) => any;
|
|
54
56
|
cache: FetchCache;
|
|
55
57
|
}>;
|
package/types/fetch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAEtD;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,MAAM,0CAA2C,CAAA;AACvD,MAAM,MAAM,uBAAuB,GAAG,OAAO,MAAM,CAAC,MAAM,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"f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AAsB,kBAAkB,CACtC,GAAG,EAAE,kBAAkB,CAAC,KAAK,CAAC,EAC9B,OAAO,CAAC,EAAE,kBAAkB,CAAC,SAAS,CAAC,EACvC,SAAS,CAAC,EAAE,kBAAkB,CAAC,WAAW,CAAC,EAC3C,QAAQ,CAAC,EAAE,kBAAkB,CAAC,UAAU,CAAC,EACzC,KAAK,GAAE,UAAuB,qBAM/B;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,UAAQ,qBAajF;AAED,qBAAa,eAAgB,SAAQ,KAAK;CAAG;AAE7C,wBAAsB,uBAAuB,CAC3C,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,kBAAkB,EAChE,KAAK,GAAE,uBAAmC;;;;;;;;GAmC3C;AAED,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,kBAAkB,GAAG,QAAQ,CAAC,IAAI,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC,gFA0B7E;AAED,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,kBAAkB;;;;;;;;GAWpE"}
|
package/types/headless.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export * from './components/FEAASComponent.js';
|
|
|
16
16
|
export * from './components/FEAASLoader.js';
|
|
17
17
|
export * from './components/FEAASStylesheet.js';
|
|
18
18
|
export * from './utils/datapath.js';
|
|
19
|
+
export * as Thumbnail from './dom/thumbnail.js';
|
|
19
20
|
declare global {
|
|
20
21
|
interface Window {
|
|
21
22
|
FEAASLoading: Promise<any>;
|
package/types/headless.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headless.d.ts","sourceRoot":"","sources":["../src/headless.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,YAAY,MAAM,8BAA8B,CAAA;AAEvD,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,2BAA2B,CAAA;AACzC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"headless.d.ts","sourceRoot":"","sources":["../src/headless.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,YAAY,MAAM,8BAA8B,CAAA;AAEvD,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,2BAA2B,CAAA;AACzC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,qBAAqB,CAAA;AACnC,OAAO,KAAK,SAAS,MAAM,oBAAoB,CAAA;AAE/C,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;QAC1B,YAAY,EAAE,OAAO,YAAY,CAAA;KAClC;CACF"}
|