@superblocksteam/custom-components 0.0.22 → 0.0.23
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/dist/exportedTypes.js +1 -2
- package/dist/hooksPlumbing.d.ts +48 -0
- package/dist/hooksPlumbing.js +24 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -5
- package/dist/useSuperblocksContext.js +4 -20
- package/dist/useSuperblocksIsLoading.d.ts +5 -0
- package/dist/useSuperblocksIsLoading.js +16 -0
- package/dist/useSuperblocksWidgetSize.d.ts +7 -0
- package/dist/useSuperblocksWidgetSize.js +16 -0
- package/package.json +6 -4
package/dist/exportedTypes.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
interface MutableRefObject<T> {
|
|
2
|
+
current: T;
|
|
3
|
+
}
|
|
4
|
+
/** The size of the area that is available for the custom component to render in */
|
|
5
|
+
export interface WidgetSize {
|
|
6
|
+
/** The width in grid units */
|
|
7
|
+
widthGrid: number;
|
|
8
|
+
/** The height in grid units */
|
|
9
|
+
heightGrid: number;
|
|
10
|
+
/** The width in pixels */
|
|
11
|
+
widthPx: number;
|
|
12
|
+
/** The height in pixels */
|
|
13
|
+
heightPx: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The information that is passed down to each custom component. This information is specific to the widget that is
|
|
17
|
+
* currently being rendered. This is the information that is used to implement all superblocks hooks for custom components.
|
|
18
|
+
* We pass that information down via a React Context.
|
|
19
|
+
*/
|
|
20
|
+
interface CCRenderingContext {
|
|
21
|
+
widgetId: string;
|
|
22
|
+
/** This is the value returned by the `useSuperblocksContext` hook */
|
|
23
|
+
superblocksContext: any;
|
|
24
|
+
/**
|
|
25
|
+
* This is the set of subscribers to the `isLoading` property: each time the value of `isLoading` changes, these functions
|
|
26
|
+
* will be called. This is used internally by the `useSuperblocksIsLoading` hook.
|
|
27
|
+
*/
|
|
28
|
+
isLoadingSubscribers: Set<(isLoading: boolean) => void>;
|
|
29
|
+
/** The current value of the `isLoading` property. Is is used internally by the `useSuperblocksIsLoading` hook */
|
|
30
|
+
isLoadingRef: MutableRefObject<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* The set of subscribers to the widget size object: each time the size of the widget changes, we need to
|
|
33
|
+
* call these functions to notify all custom components that have expressed interest in being notified of such
|
|
34
|
+
* changes. It is used internally by the `useSuperblocksWidgetSize` hook
|
|
35
|
+
*/
|
|
36
|
+
widgetSizeSubscribers: Set<(widgetSize: WidgetSize) => void>;
|
|
37
|
+
/** The current size of the widget. Is is used internally by the `useSuperblocksWidgetSize` hook */
|
|
38
|
+
widgetSizeRef: MutableRefObject<WidgetSize>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A React hook that is used internally by all superblocks hooks for custom components.
|
|
42
|
+
* @returns The React library namespace object used by custom components and the CCRenderingContext object provided by the UI
|
|
43
|
+
*/
|
|
44
|
+
export declare function useHooksInternalContext(): {
|
|
45
|
+
React: any;
|
|
46
|
+
ccRenderingContext: CCRenderingContext;
|
|
47
|
+
};
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// This files contains the basic plumbing that is needed to implement all hooks that are used by custom components.
|
|
2
|
+
// The place where we store the `CCReactInfo` object
|
|
3
|
+
const ccReactInfoRegister = globalThis.__cc_react_info;
|
|
4
|
+
/**
|
|
5
|
+
* A React hook that is used internally by all superblocks hooks for custom components.
|
|
6
|
+
* @returns The React library namespace object used by custom components and the CCRenderingContext object provided by the UI
|
|
7
|
+
*/
|
|
8
|
+
export function useHooksInternalContext() {
|
|
9
|
+
if (ccReactInfoRegister === undefined) {
|
|
10
|
+
throw new Error("Cannot find the context object provided by the Superblocks Application Builder UI");
|
|
11
|
+
}
|
|
12
|
+
if (ccReactInfoRegister.current === undefined) {
|
|
13
|
+
throw new Error("No custom components have been registered, are you using the hook in the right place?");
|
|
14
|
+
}
|
|
15
|
+
const { React, SuperblocksCCReactContext } = ccReactInfoRegister.current;
|
|
16
|
+
const ccRenderingContext = React.useContext(SuperblocksCCReactContext);
|
|
17
|
+
if (ccRenderingContext === undefined) {
|
|
18
|
+
throw new Error("No React context found, are you using the hook in the right place?");
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
React,
|
|
22
|
+
ccRenderingContext,
|
|
23
|
+
};
|
|
24
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
tslib_1.__exportStar(require("./useSuperblocksContext"), exports);
|
|
1
|
+
export * from "./exportedTypes";
|
|
2
|
+
export * from "./useSuperblocksContext";
|
|
3
|
+
export * from "./useSuperblocksIsLoading";
|
|
4
|
+
export * from "./useSuperblocksWidgetSize";
|
|
@@ -1,26 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useSuperblocksContext = void 0;
|
|
4
|
-
// The place where we store the `CCReactInfo` object
|
|
5
|
-
const ccReactInfoRegister = globalThis.__cc_react_info;
|
|
6
|
-
// === End of internal types ===
|
|
1
|
+
import { useHooksInternalContext } from "./hooksPlumbing";
|
|
7
2
|
/**
|
|
8
3
|
* A React hook that can be used to get the Superblocks context object that contains methods that enable custom components
|
|
9
4
|
* to interact with the Superblocks Application.
|
|
10
5
|
* @returns The Superblocks context object
|
|
11
6
|
*/
|
|
12
|
-
function useSuperblocksContext() {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
if (ccReactInfoRegister.current === undefined) {
|
|
17
|
-
throw new Error("No custom components have been registered, are you using the hook in the right place?");
|
|
18
|
-
}
|
|
19
|
-
const { React, SuperblocksCCReactContext } = ccReactInfoRegister.current;
|
|
20
|
-
const ccRenderingContext = React.useContext(SuperblocksCCReactContext);
|
|
21
|
-
if (ccRenderingContext === undefined) {
|
|
22
|
-
throw new Error("No React context found, are you using the hook in the right place?");
|
|
23
|
-
}
|
|
24
|
-
return ccRenderingContext === null || ccRenderingContext === void 0 ? void 0 : ccRenderingContext.superblocksContext;
|
|
7
|
+
export function useSuperblocksContext() {
|
|
8
|
+
const { ccRenderingContext } = useHooksInternalContext();
|
|
9
|
+
return ccRenderingContext.superblocksContext;
|
|
25
10
|
}
|
|
26
|
-
exports.useSuperblocksContext = useSuperblocksContext;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A React hook that returns a boolean that indicates whether the current custom component depends on any data that is
|
|
3
|
+
* currently being loaded. This can be used to show a loading indicator in your custom component.
|
|
4
|
+
*/
|
|
5
|
+
export declare function useSuperblocksIsLoading(): boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useHooksInternalContext } from "./hooksPlumbing";
|
|
2
|
+
/**
|
|
3
|
+
* A React hook that returns a boolean that indicates whether the current custom component depends on any data that is
|
|
4
|
+
* currently being loaded. This can be used to show a loading indicator in your custom component.
|
|
5
|
+
*/
|
|
6
|
+
export function useSuperblocksIsLoading() {
|
|
7
|
+
const { React, ccRenderingContext } = useHooksInternalContext();
|
|
8
|
+
const [isLoading, setIsLoading] = React.useState(ccRenderingContext.isLoadingRef.current);
|
|
9
|
+
ccRenderingContext.isLoadingSubscribers.add(setIsLoading);
|
|
10
|
+
React.useEffect(() => {
|
|
11
|
+
return () => {
|
|
12
|
+
ccRenderingContext.isLoadingSubscribers.delete(setIsLoading);
|
|
13
|
+
};
|
|
14
|
+
}, []);
|
|
15
|
+
return isLoading;
|
|
16
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { WidgetSize } from "./hooksPlumbing";
|
|
2
|
+
export { WidgetSize };
|
|
3
|
+
/**
|
|
4
|
+
* A React hook that returns the size of the area that is available for the custom component to render in. Calling this
|
|
5
|
+
* hook will cause your custom component to be re-rendered whenever that size changes.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useSuperblocksWidgetSize(): WidgetSize;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useHooksInternalContext } from "./hooksPlumbing";
|
|
2
|
+
/**
|
|
3
|
+
* A React hook that returns the size of the area that is available for the custom component to render in. Calling this
|
|
4
|
+
* hook will cause your custom component to be re-rendered whenever that size changes.
|
|
5
|
+
*/
|
|
6
|
+
export function useSuperblocksWidgetSize() {
|
|
7
|
+
const { React, ccRenderingContext } = useHooksInternalContext();
|
|
8
|
+
const [widgetSize, setWidgetSize] = React.useState(ccRenderingContext.widgetSizeRef.current);
|
|
9
|
+
ccRenderingContext.widgetSizeSubscribers.add(setWidgetSize);
|
|
10
|
+
React.useEffect(() => {
|
|
11
|
+
return () => {
|
|
12
|
+
ccRenderingContext.widgetSizeSubscribers.delete(setWidgetSize);
|
|
13
|
+
};
|
|
14
|
+
}, []);
|
|
15
|
+
return widgetSize;
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superblocksteam/custom-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"description": "Official Superblocks SDK for developing custom components",
|
|
5
5
|
"homepage": "https://www.superblocks.com/",
|
|
6
6
|
"keywords": [
|
|
@@ -18,10 +18,12 @@
|
|
|
18
18
|
"clean": "npm run clean:build && rm -rf node_modules",
|
|
19
19
|
"clean:build": "tsc --build --clean && rm -rf dist tsconfig.tsbuildinfo",
|
|
20
20
|
"lint": "eslint . --ext .ts --config .eslintrc.json",
|
|
21
|
-
"lint:fix": "eslint . --ext .ts --config .eslintrc.json --fix"
|
|
21
|
+
"lint:fix": "eslint . --ext .ts --config .eslintrc.json --fix",
|
|
22
|
+
"typecheck": "tsc --noEmit"
|
|
22
23
|
},
|
|
23
24
|
"engines": {
|
|
24
|
-
"node": ">=
|
|
25
|
+
"node": ">=16.0.0",
|
|
26
|
+
"npm": ">=8.0.0"
|
|
25
27
|
},
|
|
26
28
|
"devDependencies": {
|
|
27
29
|
"@typescript-eslint/eslint-plugin": "^5.60.1",
|
|
@@ -35,7 +37,7 @@
|
|
|
35
37
|
"typescript": "^5.1.6"
|
|
36
38
|
},
|
|
37
39
|
"dependencies": {
|
|
38
|
-
"@superblocksteam/util": "
|
|
40
|
+
"@superblocksteam/util": "0.0.23",
|
|
39
41
|
"tslib": "^2.6.1"
|
|
40
42
|
}
|
|
41
43
|
}
|