@superblocksteam/custom-components 0.0.20

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 ADDED
@@ -0,0 +1,32 @@
1
+ @superblocksteam/custom-components
2
+ =================
3
+
4
+ Provides utility functions to help develop custom components that can be used in Superblocks Applications.
5
+
6
+ ## Usage
7
+ <!-- usage -->
8
+ ```typescript
9
+ import React from "react";
10
+ import { useSuperblocksContext } from "@superblocksteam/custom-components";
11
+ import { type Props, type EventTriggers } from "./types";
12
+
13
+ export default function Component({
14
+ count,
15
+ }: Props) {
16
+ const {
17
+ updateStatefulProperties,
18
+ events: {
19
+ onChange,
20
+ },
21
+ } = useSuperblocksContext<Props, EventTriggers>();
22
+
23
+ return (
24
+ <button
25
+ onClick={() => {
26
+ updateStatefulProperties({ count: count + 1 });
27
+ onChange();
28
+ }}
29
+ >Increment</button>
30
+ );
31
+ }
32
+ ```
@@ -0,0 +1 @@
1
+ export { type ComponentConfig } from "@superblocksteam/util";
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export * from "./exportedTypes";
2
+ export * from "./useSuperblocksContext";
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./exportedTypes"), exports);
5
+ tslib_1.__exportStar(require("./useSuperblocksContext"), exports);
@@ -0,0 +1,21 @@
1
+ /**
2
+ * An object that contains some methods that enable custom components to interact with the Superblocks Application.
3
+ */
4
+ export interface SuperblocksContext<Props, EventTriggers> {
5
+ /**
6
+ * Update one (or more) of your component's stateful properties. This will cause the component to rerender,
7
+ * and will also notify any other components in your Application which depend on the updated properties, so they also rerender
8
+ * @param props An object with the properties to update along with their new values
9
+ */
10
+ updateStatefulProperties: (props: Partial<Props>) => void;
11
+ /**
12
+ * An object that contains methods that can be used to trigger events in Superblocks from your component.
13
+ */
14
+ events: EventTriggers;
15
+ }
16
+ /**
17
+ * A React hook that can be used to get the Superblocks context object that contains methods that enable custom components
18
+ * to interact with the Superblocks Application.
19
+ * @returns The Superblocks context object
20
+ */
21
+ export declare function useSuperblocksContext<Props, EventTriggers>(): SuperblocksContext<Props, EventTriggers>;
@@ -0,0 +1,26 @@
1
+ "use strict";
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 ===
7
+ /**
8
+ * A React hook that can be used to get the Superblocks context object that contains methods that enable custom components
9
+ * to interact with the Superblocks Application.
10
+ * @returns The Superblocks context object
11
+ */
12
+ function useSuperblocksContext() {
13
+ if (ccReactInfoRegister === undefined) {
14
+ throw new Error("Cannot find the context object provided by the Superblocks Application Builder UI");
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;
25
+ }
26
+ exports.useSuperblocksContext = useSuperblocksContext;
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@superblocksteam/custom-components",
3
+ "version": "0.0.20",
4
+ "description": "Official Superblocks SDK for developing custom components",
5
+ "homepage": "https://www.superblocks.com/",
6
+ "keywords": [
7
+ "superblocks"
8
+ ],
9
+ "license": "Superblocks Community Software License",
10
+ "main": "dist/index.js",
11
+ "types": "dist/index.d.ts",
12
+ "files": [
13
+ "/dist"
14
+ ],
15
+ "scripts": {
16
+ "dev": "tsc --watch",
17
+ "build": "tsc --build",
18
+ "clean": "npm run clean:build && rm -rf node_modules",
19
+ "clean:build": "tsc --build --clean && rm -rf dist tsconfig.tsbuildinfo",
20
+ "lint": "eslint . --ext .ts --config .eslintrc.json",
21
+ "lint:fix": "eslint . --ext .ts --config .eslintrc.json --fix"
22
+ },
23
+ "engines": {
24
+ "node": ">=14.0.0"
25
+ },
26
+ "devDependencies": {
27
+ "@typescript-eslint/eslint-plugin": "^5.60.1",
28
+ "@typescript-eslint/parser": "^5.60.1",
29
+ "eslint": "^8.45.0",
30
+ "eslint-config-prettier": "8.8.0",
31
+ "eslint-plugin-import": "2.27.5",
32
+ "eslint-plugin-prettier": "4.2.1",
33
+ "eslint-plugin-unicorn": "^47.0.0",
34
+ "prettier": "^2.8.8",
35
+ "typescript": "^5.1.6"
36
+ },
37
+ "dependencies": {
38
+ "@superblocksteam/util": "*",
39
+ "tslib": "^2.6.1"
40
+ }
41
+ }