@sitecore-feaas/clientside 0.0.9 → 0.1.0

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.
Files changed (57) hide show
  1. package/README.md +5 -5
  2. package/dist/browser/basic.cjs +67 -0
  3. package/dist/browser/basic.js +67 -0
  4. package/dist/browser/index.cjs +68 -79
  5. package/dist/browser/index.js +68 -79
  6. package/dist/node/{react.cjs → basic.cjs} +436 -443
  7. package/dist/node/{react.js → basic.js} +432 -439
  8. package/dist/node/index.cjs +666 -291
  9. package/dist/node/index.js +666 -295
  10. package/examples/index.html +1 -1
  11. package/package.json +17 -17
  12. package/src/basic.ts +5 -0
  13. package/src/cloud.ts +9 -5
  14. package/src/components/FEAASBase.tsx +265 -0
  15. package/src/components/FEAASComponent.ts +98 -0
  16. package/src/components/FEAASContext.tsx +105 -0
  17. package/src/components/FEAASEditor.tsx +291 -0
  18. package/src/components/FEAASLoader.ts +113 -0
  19. package/src/components/FEAASPicker.tsx +98 -0
  20. package/src/components/FEAASStylesheet.ts +43 -0
  21. package/src/components/index.tsx +7 -0
  22. package/src/index.ts +4 -11
  23. package/test/components.js +11 -0
  24. package/test/components.ts +12 -0
  25. package/test/render.js +688 -0
  26. package/tsconfig.json +11 -6
  27. package/types/basic.d.ts +5 -0
  28. package/types/cloud.d.ts +18 -0
  29. package/types/components/FEAASBase.d.ts +70 -0
  30. package/types/components/FEAASComponent.d.ts +39 -0
  31. package/types/components/FEAASContext.d.ts +43 -0
  32. package/types/components/FEAASEditor.d.ts +70 -0
  33. package/types/components/FEAASLoader.d.ts +20 -0
  34. package/types/components/FEAASPicker.d.ts +61 -0
  35. package/types/components/FEAASStylesheet.d.ts +25 -0
  36. package/types/components/index.d.ts +7 -0
  37. package/types/dom.d.ts +29 -0
  38. package/types/fetch.d.ts +1 -0
  39. package/types/index.d.ts +4 -0
  40. package/types/tsbuildinfo +1 -0
  41. package/dist/browser/index.d.ts +0 -25
  42. package/dist/browser/react.cjs +0 -83
  43. package/dist/browser/react.d.ts +0 -36
  44. package/dist/browser/react.js +0 -83
  45. package/dist/browser/webcomponent-6b45b819.d.ts +0 -120
  46. package/dist/node/index.d.ts +0 -25
  47. package/dist/node/react.d.ts +0 -36
  48. package/dist/node/webcomponent-6b45b819.d.ts +0 -120
  49. package/index.cjs +0 -83
  50. package/index.d.ts +0 -25
  51. package/index.js +0 -83
  52. package/react.cjs +0 -83
  53. package/react.d.ts +0 -36
  54. package/react.js +0 -83
  55. package/src/react.ts +0 -66
  56. package/src/webcomponent.ts +0 -393
  57. package/webcomponent-6b45b819.d.ts +0 -120
package/tsconfig.json CHANGED
@@ -1,12 +1,17 @@
1
1
  {
2
- "extends": "../tsconfig.json",
2
+ "extends": "../tsconfig.base.json",
3
3
  "compilerOptions": {
4
- "strict": false /* Enable all strict type-checking options. */,
5
4
  "declaration": true,
6
- "forceConsistentCasingInFileNames": false,
7
5
  "outDir": "dist",
8
- "types": ["react", "react-dom"]
6
+ "rootDir": "src",
7
+ "tsBuildInfoFile": "./types/tsbuildinfo",
8
+ "declarationDir": "./types"
9
9
  },
10
- "include": ["**/*.ts", "**/*.tsx"],
11
- "exclude": ["../**/node_modules", "../**/dist", "../**/build"]
10
+ "references": [
11
+ {
12
+ "path": "../sdk"
13
+ }
14
+ ],
15
+ "include": ["src/**/*.ts", "src/**/*.tsx"],
16
+ "exclude": ["scripts/**", "test/**", "types/**", "build/**", "dist/**", "node_modules/**"]
12
17
  }
@@ -0,0 +1,5 @@
1
+ export * from './dom.js';
2
+ export * from './fetch.js';
3
+ export * from './components/FEAASLoader.js';
4
+ export * from './components/FEAASStylesheet.js';
5
+ export * from './components/FEAASComponent.js';
@@ -0,0 +1,18 @@
1
+ export interface CloudTemplate {
2
+ cdn?: string;
3
+ hostname?: string;
4
+ library: string;
5
+ component: string;
6
+ version: string;
7
+ revision?: string;
8
+ }
9
+ export interface CloudStylesheet {
10
+ cdn?: string;
11
+ hostname?: string;
12
+ library: string;
13
+ revision?: 'staging' | 'published' | 'saved' | number;
14
+ }
15
+ export declare function getComponentURL({ cdn, hostname, library, component, version, revision }: CloudTemplate): string;
16
+ export declare function getStylesheetURL({ cdn, hostname, library, revision }: CloudStylesheet): string;
17
+ export declare function fetchComponent(props: CloudTemplate, callback: (html: string) => void): Promise<Response>;
18
+ export declare function fetchStylesheet(props: CloudStylesheet, callback: (css: string) => void): Promise<Response>;
@@ -0,0 +1,70 @@
1
+ import { ReactElement, ReactNode } from 'react';
2
+ import type React from 'react';
3
+ export declare type OptionalExcept<T, K extends keyof T> = Pick<T, K> & Partial<Omit<T, K>>;
4
+ export declare class FEAASBase<Props = any, Payload = any> extends HTMLElement {
5
+ static observedAttributes: string[];
6
+ /** Return attributes as parsed values */
7
+ getProps(context?: HTMLElement): any;
8
+ /** Properties parsed in current tick */
9
+ props: Props;
10
+ overrides: Props;
11
+ /** Timer until next tick */
12
+ nextRender: number;
13
+ /** Is/was component in the dom? */
14
+ connected: Event;
15
+ /** Result of lazy loading */
16
+ payload: Payload;
17
+ refs: Record<string, FEAASBase>;
18
+ descendants: FEAASBase[];
19
+ /** Attaches shadow root if getShadowRootOptions any settings, or uses element itself */
20
+ getRoot(): FEAASBase | HTMLElement | ShadowRoot;
21
+ /** Attribute changes trigger props parsing and schedules re-rendering */
22
+ attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
23
+ /** Components parses its attributes when connected, and schedules rendeirng */
24
+ connectedCallback(): void;
25
+ /** Nothing special happens on disconnect, except setting a flag */
26
+ disconnectedCallback(): void;
27
+ /** Catch-all event handler that dispatches events to callback */
28
+ handleEvent(event: Event): void;
29
+ /** Act on children element being removed */
30
+ orphanCallback(event: Event): void;
31
+ /** Act on children element being added */
32
+ adoptedCallback(event: Event): boolean | void;
33
+ getComponentName(): string;
34
+ /**
35
+ * Check if lazy component is ready to be loaded. For example a component may stay unloaded unless certain attributes
36
+ * are set
37
+ */
38
+ isReadyToLoad(): boolean;
39
+ /** Load lazy component & render */
40
+ reify(): Promise<void>;
41
+ /** Invoke preloading logic that needs to finish before component can render */
42
+ load(): Promise<any>;
43
+ /** Payload is inside onLoad callback. For web components that use react, it has to provide React & ReactDOM props */
44
+ onLoad: (payload: Payload) => void;
45
+ /**
46
+ * Component-specific logic that updates the DOM. Default render implementation assume react rendering, in that case
47
+ * the component needs to provide React & ReactDOM references in its payload. Web component redefine its render to not
48
+ * use react at all
49
+ */
50
+ render(nested?: boolean): any;
51
+ invokeReactRendering(): ReactNode;
52
+ reactWrapper: (props?: any) => ReactNode;
53
+ getReactWrapper(target?: FEAASBase, displayName?: string): (props?: any) => any;
54
+ uid: string;
55
+ getUID(): string;
56
+ forceUpdateReact: (node?: ReactNode) => void;
57
+ /**
58
+ * Render method that is pretty much the same as React Functional component, but with extra second argument for
59
+ * payload (usually result of import, it is expected to have React in scope).
60
+ */
61
+ renderReact?(props: React.PropsWithChildren<typeof this.props>, payload: typeof this.payload): ReactNode | ReactElement;
62
+ getReactRoot(): HTMLElement | ShadowRoot;
63
+ /** Set props and return values on new next tick */
64
+ set(overrides?: Partial<Props>): void;
65
+ /** Schedule rendering on next tick, to batch multiple attribute changes */
66
+ scheduleRender(): void;
67
+ formatURL(src: string, hostname: string): string;
68
+ getContextAttribute(name: string, element?: this): string;
69
+ static register(tagName: string): void;
70
+ }
@@ -0,0 +1,39 @@
1
+ import { FEAASBase, OptionalExcept } from './FEAASBase.js';
2
+ export declare function FEAASComponentsProps(element?: FEAASBase): {
3
+ data: any;
4
+ library: string;
5
+ component: string;
6
+ version: string;
7
+ revision: string;
8
+ hostname: string;
9
+ cdn: string;
10
+ template: string;
11
+ };
12
+ export declare type FEAASComponentsProps = ReturnType<typeof FEAASComponentsProps>;
13
+ export declare class FEAASComponent extends FEAASBase<FEAASComponentsProps, string> {
14
+ static observedAttributes: string[];
15
+ needsRefresh: boolean;
16
+ setData(data: any): void;
17
+ getProps(): {
18
+ data: any;
19
+ library: string;
20
+ component: string;
21
+ version: string;
22
+ revision: string;
23
+ hostname: string;
24
+ cdn: string;
25
+ template: string;
26
+ };
27
+ attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
28
+ getOriginal(): FEAASComponent;
29
+ isReadyToLoad(): boolean;
30
+ load(): Promise<void>;
31
+ render(): void;
32
+ }
33
+ declare global {
34
+ namespace JSX {
35
+ interface IntrinsicElements {
36
+ 'feaas-component': OptionalExcept<FEAASComponentsProps, 'component' | 'version' | 'revision'>;
37
+ }
38
+ }
39
+ }
@@ -0,0 +1,43 @@
1
+ /// <reference types="react" resolution-mode="require"/>
2
+ import type * as FEAASContextImports from '@sitecore-feaas/frontend/src/components/providers/ContextProvider.jsx';
3
+ import { FEAASBase, OptionalExcept } from './FEAASBase.jsx';
4
+ export declare function FEAASContextProps(element?: HTMLElement): {
5
+ library: string;
6
+ src: string;
7
+ frontend: string;
8
+ backend: string;
9
+ cdn: string;
10
+ getToken: (options: any) => Promise<string>;
11
+ };
12
+ declare type FEAASContextProps = ReturnType<typeof FEAASContextProps>;
13
+ /**
14
+ * Context provides shared parameters and react providers for its nested elements. It loads lazily once any of its
15
+ * nested components load. Just placing it on the page without any consumers does not impose any overhead.
16
+ */
17
+ export declare class FEAASContext extends FEAASBase<FEAASContextProps, typeof FEAASContextImports> {
18
+ static observedAttributes: string[];
19
+ getProps(): {
20
+ library: string;
21
+ src: string;
22
+ frontend: string;
23
+ backend: string;
24
+ cdn: string;
25
+ getToken: (options: any) => Promise<string>;
26
+ };
27
+ load(): Promise<any>;
28
+ getTheme(theme: FEAASContextImports.Chakra.Theme): FEAASContextImports.Chakra.Theme;
29
+ getRoot(): HTMLElement | FEAASBase<any, any> | ShadowRoot;
30
+ reactRoot: HTMLDivElement;
31
+ getReactRoot(): HTMLDivElement;
32
+ /** Pull in children FEAAS react elements into the shadow DOM so they receieve the styles */
33
+ adoptedCallback(event: Event): void;
34
+ renderReact({ children, library }: React.PropsWithChildren<FEAASContextProps>, { AppContext, Chakra: { Button, Tooltip }, React: { useRef } }: typeof this.payload): JSX.Element;
35
+ }
36
+ declare global {
37
+ namespace JSX {
38
+ interface IntrinsicElements {
39
+ 'feaas-context': OptionalExcept<FEAASContextProps, 'library'>;
40
+ }
41
+ }
42
+ }
43
+ export {};
@@ -0,0 +1,70 @@
1
+ /// <reference types="react" resolution-mode="require"/>
2
+ import type * as FEAASEditorImports from '@sitecore-feaas/frontend/src/components/editor/Editor.jsx';
3
+ import { FEAASBase, OptionalExcept } from './FEAASBase.js';
4
+ export declare function getFramePosition(element: HTMLElement): {
5
+ left: number;
6
+ top: number;
7
+ };
8
+ export declare function FEAASEditorProps(element?: FEAASBase): {
9
+ context: {
10
+ new (): HTMLElement;
11
+ prototype: HTMLElement;
12
+ };
13
+ frontend: string;
14
+ src: string;
15
+ library: string;
16
+ component: string;
17
+ version: string;
18
+ revision: string;
19
+ hidden: boolean;
20
+ for: string;
21
+ };
22
+ declare type FEAASEditorProps = ReturnType<typeof FEAASEditorProps>;
23
+ declare type Rect = {
24
+ top: number;
25
+ left: number;
26
+ width: number;
27
+ height: number;
28
+ };
29
+ export declare class FEAASEditor extends FEAASBase<FEAASEditorProps, typeof FEAASEditorImports> {
30
+ chrome: HTMLElement;
31
+ wrapper: HTMLElement;
32
+ framePoint: Pick<Rect, 'top' | 'left'>;
33
+ wrapperRect: Rect;
34
+ bodyRect: Rect;
35
+ getProps(): {
36
+ context: {
37
+ new (): HTMLElement;
38
+ prototype: HTMLElement;
39
+ };
40
+ frontend: string;
41
+ src: string;
42
+ library: string;
43
+ component: string;
44
+ version: string;
45
+ revision: string;
46
+ hidden: boolean;
47
+ for: string;
48
+ };
49
+ getTarget: () => HTMLElement;
50
+ load(): Promise<any>;
51
+ onChromeMeasureElement: (element: HTMLElement, rect?: Rect) => {
52
+ left: number;
53
+ top: number;
54
+ width: number;
55
+ height: number;
56
+ };
57
+ onBeforeMeasure: FEAASEditorImports.EditorContext['onChromeBeforeMeasure'];
58
+ onMeasure: FEAASEditorImports.EditorContext['onChromeMeasure'];
59
+ onPosition: FEAASEditorImports.EditorContext['onChromePosition'];
60
+ renderReact({ children, component: componentId, version: versionId }: React.PropsWithChildren<FEAASEditorProps>, { Editor, VersionStatusList, Version, EditorUIUndo, EditorUIMode, React: { useEffect, useMemo, useState }, Chakra: { HStack, Box }, Chrome, ReactDOM, useSDK, useSlots, useModelObserver }: typeof FEAASEditorImports): FEAASEditorImports.React.ReactElement<any, string | FEAASEditorImports.React.JSXElementConstructor<any>>;
61
+ isReadyToLoad(): boolean;
62
+ }
63
+ declare global {
64
+ namespace JSX {
65
+ interface IntrinsicElements {
66
+ 'feaas-editor': OptionalExcept<FEAASEditorProps, 'component' | 'version'>;
67
+ }
68
+ }
69
+ }
70
+ export {};
@@ -0,0 +1,20 @@
1
+ import { FEAASBase } from './FEAASBase.js';
2
+ export declare function FEAASLoaderProps(element?: HTMLElement): {
3
+ hidden: boolean;
4
+ };
5
+ declare type FEAASLoaderProps = ReturnType<typeof FEAASLoaderProps>;
6
+ export declare class FEAASLoader extends FEAASBase<FEAASLoaderProps, string> {
7
+ stylesheet: HTMLStyleElement;
8
+ loader: HTMLDivElement;
9
+ static observedAttributes: string[];
10
+ attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
11
+ connectedCallback(): void;
12
+ }
13
+ declare global {
14
+ namespace JSX {
15
+ interface IntrinsicElements {
16
+ 'feaas-loader': any;
17
+ }
18
+ }
19
+ }
20
+ export {};
@@ -0,0 +1,61 @@
1
+ /// <reference types="react" resolution-mode="require"/>
2
+ import type * as FEAASPickerImports from '@sitecore-feaas/frontend/src/components/picker/Picker.jsx';
3
+ import { FEAASBase } from './FEAASBase.js';
4
+ export declare function FEAASPickerProps(element?: FEAASBase<any, any>): {
5
+ part: string;
6
+ slot: string;
7
+ mode: "library" | "stylesheet";
8
+ frontend: string;
9
+ src: string;
10
+ hidden: boolean;
11
+ context: HTMLElement | import("@ckeditor/ckeditor5-engine").Element;
12
+ onClose: (...args: any[]) => {};
13
+ };
14
+ declare type FEAASPickerProps = ReturnType<typeof FEAASPickerProps>;
15
+ export declare class FEAASPicker extends FEAASBase<FEAASPickerProps, typeof FEAASPickerImports> {
16
+ getProps(): {
17
+ part: string;
18
+ slot: string;
19
+ mode: "library" | "stylesheet";
20
+ frontend: string;
21
+ src: string;
22
+ hidden: boolean;
23
+ context: HTMLElement | import("@ckeditor/ckeditor5-engine").Element;
24
+ onClose: (...args: any[]) => {};
25
+ };
26
+ load(): Promise<any>;
27
+ renderReact({ context, mode, children }: React.PropsWithChildren<FEAASPickerProps>, { Picker, React, ReactDOM }: typeof FEAASPickerImports): JSX.Element;
28
+ }
29
+ declare global {
30
+ namespace JSX {
31
+ interface IntrinsicElements {
32
+ 'feaas-picker': Partial<typeof FEAASPickerImports>;
33
+ 'feaas-picker-lazy': Partial<typeof FEAASPickerImports>;
34
+ }
35
+ }
36
+ }
37
+ export declare function FEAASPickerLazyProps(element?: FEAASBase<any, any>): {
38
+ library: string;
39
+ mode: "library" | "stylesheet";
40
+ frontend: string;
41
+ src: string;
42
+ hidden: boolean;
43
+ context: HTMLElement | import("@ckeditor/ckeditor5-engine").Element;
44
+ getToken: (options: any) => Promise<string>;
45
+ };
46
+ declare type FEAASPickerLazyProps = ReturnType<typeof FEAASPickerLazyProps>;
47
+ export declare class FEAASPickerLazy extends FEAASBase<FEAASPickerLazyProps, typeof FEAASPickerImports> {
48
+ payload: any;
49
+ getProps(): {
50
+ library: string;
51
+ mode: "library" | "stylesheet";
52
+ frontend: string;
53
+ src: string;
54
+ hidden: boolean;
55
+ context: HTMLElement | import("@ckeditor/ckeditor5-engine").Element;
56
+ getToken: (options: any) => Promise<string>;
57
+ };
58
+ onClose: () => void;
59
+ render(): void;
60
+ }
61
+ export {};
@@ -0,0 +1,25 @@
1
+ import { FEAASBase } from './FEAASBase.js';
2
+ export declare function FEAASStylesheetProps(element?: FEAASBase): {
3
+ library: string;
4
+ revision: number | "published" | "staging" | "saved";
5
+ cdn: string;
6
+ };
7
+ export declare type FEAASStylesheetProps = ReturnType<typeof FEAASStylesheetProps>;
8
+ export declare class FEAASStylesheet extends FEAASBase<FEAASStylesheetProps, string> {
9
+ stylesheet: HTMLStyleElement;
10
+ getProps(): {
11
+ library: string;
12
+ revision: number | "published" | "staging" | "saved";
13
+ cdn: string;
14
+ };
15
+ isReadyToLoad(): boolean;
16
+ load(): Promise<void>;
17
+ render(): void;
18
+ }
19
+ declare global {
20
+ namespace JSX {
21
+ interface IntrinsicElements {
22
+ 'feaas-stylesheet': Partial<FEAASStylesheetProps>;
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,7 @@
1
+ export { FEAASBase } from './FEAASBase.jsx';
2
+ export { FEAASComponent } from './FEAASComponent.js';
3
+ export { FEAASContext } from './FEAASContext.jsx';
4
+ export { FEAASEditor } from './FEAASEditor.jsx';
5
+ export { FEAASLoader } from './FEAASLoader.js';
6
+ export { FEAASPicker } from './FEAASPicker.jsx';
7
+ export { FEAASStylesheet } from './FEAASStylesheet.js';
package/types/dom.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ import { CloudStylesheet, CloudTemplate } from './cloud.js';
2
+ export interface FEAASCustomizations {
3
+ processTemplate?: (element: HTMLElement, template: string, data: any) => string;
4
+ processData?: (element: HTMLElement, data: any) => any;
5
+ processValue?: (element: HTMLElement, property: string, value: any) => any;
6
+ shouldRepeat?: (element: HTMLElement, value: any) => boolean;
7
+ onRender?: (element: HTMLElement, data: any) => void;
8
+ }
9
+ export interface ExplicitTemplate {
10
+ template: string;
11
+ }
12
+ export declare type Datascopes = Record<string, any>;
13
+ export declare type FEAASComponentProps = {
14
+ data?: Datascopes;
15
+ } & (ExplicitTemplate | CloudTemplate) & FEAASCustomizations;
16
+ export declare function renderComponentElement(content: string, datasources?: Datascopes): HTMLDivElement;
17
+ export declare function cleanCollectionBit(path: string): string;
18
+ export declare function normalizeCollectionScope(path: string): string;
19
+ export declare function queryScopes(scopes: any, datapath: string, singleValue?: boolean, json?: any): any;
20
+ export declare function setDOMAttribute(element: HTMLElement, attribute: string, value: any, config?: FEAASCustomizations): void;
21
+ export declare function observeDOMElement(element: HTMLElement): MutationObserver;
22
+ export declare function autoloadScripts(element: HTMLElement, observe?: boolean): MutationObserver;
23
+ export declare function loadScript(element: HTMLElement, src: string): boolean;
24
+ export declare function renderDOMElement(input: HTMLElement | DocumentFragment, datascopes?: any, config?: FEAASCustomizations, isNested?: boolean): HTMLElement;
25
+ export declare function renderDOMContent(root: HTMLElement, template: string, data?: Datascopes, config?: FEAASCustomizations): HTMLElement;
26
+ export declare function renderStylesheet(props: CloudStylesheet, style?: HTMLStyleElement): HTMLStyleElement;
27
+ export declare function renderStylesheetPromise(props: CloudStylesheet, style?: HTMLStyleElement): Promise<HTMLStyleElement>;
28
+ export declare function renderComponent(props: FEAASComponentProps, root?: HTMLElement): HTMLElement;
29
+ export declare function renderComponentPromise(props: FEAASComponentProps, root?: HTMLElement): Promise<HTMLElement>;
@@ -0,0 +1 @@
1
+ export declare function fetchAndRevalidate(url: Parameters<typeof fetch>[0], options: Parameters<typeof fetch>[1], validator: (resposne: Response) => boolean, callback: (response: Response, status: 'cached' | 'valid') => void): Promise<Response>;
@@ -0,0 +1,4 @@
1
+ export * from './basic.js';
2
+ export * from './components/FEAASEditor.jsx';
3
+ export * from './components/FEAASPicker.jsx';
4
+ export * from './components/FEAASContext.jsx';