@superblocksteam/util 0.0.19 → 0.0.21

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.
@@ -0,0 +1,9 @@
1
+ export declare const supportedDataTypes: readonly ["string", "number", "boolean", "any"];
2
+ export type DataType = (typeof supportedDataTypes)[number];
3
+ interface TypeInfo {
4
+ tsType: string;
5
+ prompt: string;
6
+ }
7
+ export declare const dataTypeDefinions: Record<DataType, TypeInfo>;
8
+ export declare function isValidDataType(input: string): input is DataType;
9
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidDataType = exports.dataTypeDefinions = exports.supportedDataTypes = void 0;
4
+ exports.supportedDataTypes = [
5
+ "string",
6
+ "number",
7
+ "boolean",
8
+ "any",
9
+ ];
10
+ exports.dataTypeDefinions = {
11
+ string: {
12
+ tsType: "string",
13
+ prompt: "string",
14
+ },
15
+ number: {
16
+ tsType: "number",
17
+ prompt: "number",
18
+ },
19
+ boolean: {
20
+ tsType: "boolean",
21
+ prompt: "boolean",
22
+ },
23
+ any: {
24
+ tsType: "any",
25
+ prompt: "any (raw js expression)",
26
+ },
27
+ };
28
+ function isValidDataType(input) {
29
+ return Object.prototype.hasOwnProperty.call(exports.dataTypeDefinions, input);
30
+ }
31
+ exports.isValidDataType = isValidDataType;
@@ -1 +1,2 @@
1
- export declare function generateComponentTypesFile(config: any): string;
1
+ import { ComponentConfig } from "./types";
2
+ export declare function generateComponentTypesFile(config: ComponentConfig): string;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateComponentTypesFile = void 0;
4
- const input_types_1 = require("./input-types");
4
+ const data_types_1 = require("./data-types");
5
5
  const indent = (str, spaces) => {
6
6
  const spacesString = " ".repeat(spaces);
7
7
  return str
@@ -10,31 +10,24 @@ const indent = (str, spaces) => {
10
10
  .join("\n");
11
11
  };
12
12
  function renderInputTypeAsTS(name, type, trailingChars, indentSpaces) {
13
- return indent(`${name}: ${input_types_1.inputTypeDefinions[type].tsType}${trailingChars}`, indentSpaces);
13
+ return indent(`${name}: ${data_types_1.dataTypeDefinions[type].tsType}${trailingChars}`, indentSpaces);
14
14
  }
15
15
  function generateComponentTypesFile(config) {
16
16
  var _a, _b;
17
- const statefulProperties = (_a = config.statefulProperties) !== null && _a !== void 0 ? _a : [];
18
- const eventHandlers = (_b = config.eventHandlers) !== null && _b !== void 0 ? _b : [];
17
+ const properties = (_a = config.properties) !== null && _a !== void 0 ? _a : [];
18
+ const eventHandlers = (_b = config.events) !== null && _b !== void 0 ? _b : [];
19
19
  return `// WARNING: This file is automatically generated and managed by Superblocks CLI and should not be edited manually.
20
20
  // Use the \`superblocks components watch\` command to regenerate this file from its source in config.ts
21
21
 
22
- // All stateful properties of your component are defined here.
22
+ // All properties of your component are defined here.
23
23
  // These are the properties which are surfaced in the Superblocks properties panel
24
24
  // and can be referenced throughout your Superblocks Application
25
- export interface StatefulProperties {
26
- ${statefulProperties
27
- .map((v) => renderInputTypeAsTS(v.path, v.inputType, ";", 2) + "\n")
25
+ export interface Props {
26
+ ${properties
27
+ .map((v) => renderInputTypeAsTS(v.path, v.dataType, ";", 2) + "\n")
28
28
  .join("")}}
29
29
 
30
- export interface Props extends StatefulProperties {
31
- /**
32
- * Update one (or more) of your component's stateful properties. This will cause the component to rerender,
33
- * and will also notify any other components in your Application which depend on the updated properties, so they also rerender
34
- * @param props An object with the properties to update along with their new values
35
- */
36
- updateStatefulProperties: (props: Partial<StatefulProperties>) => void;
37
-
30
+ export interface EventTriggers {
38
31
  // Call the subsequent function(s) to trigger event(s) in Superblocks from your component.
39
32
  // These events can be wired up to event handlers in your Superblocks App
40
33
  ${eventHandlers.length === 0
package/dist/index.d.ts CHANGED
@@ -3,4 +3,5 @@ export * from "./component-configs";
3
3
  export * from "./file-uploader";
4
4
  export * from "./login";
5
5
  export * from "./resource-configs";
6
- export * from "./input-types";
6
+ export * from "./data-types";
7
+ export * from "./types";
package/dist/index.js CHANGED
@@ -6,4 +6,5 @@ tslib_1.__exportStar(require("./component-configs"), exports);
6
6
  tslib_1.__exportStar(require("./file-uploader"), exports);
7
7
  tslib_1.__exportStar(require("./login"), exports);
8
8
  tslib_1.__exportStar(require("./resource-configs"), exports);
9
- tslib_1.__exportStar(require("./input-types"), exports);
9
+ tslib_1.__exportStar(require("./data-types"), exports);
10
+ tslib_1.__exportStar(require("./types"), exports);
@@ -1,12 +1,9 @@
1
1
  export type SuperblocksMetadata = {
2
2
  cliVersion: string;
3
- lastUpdated: string;
4
- created: string;
5
3
  };
6
4
  export type SuperblocksResourceType = "APPLICATION" | "BACKEND";
7
5
  export type VersionedResourceConfig = {
8
6
  location: string;
9
- lastUpdated: string;
10
7
  resourceType: SuperblocksResourceType;
11
8
  };
12
9
  export type SuperblocksResourceConfig = {
@@ -0,0 +1,33 @@
1
+ /// <reference types="node" />
2
+ import { type UUID } from "node:crypto";
3
+ import { type DataType } from "./data-types";
4
+ interface PropertiesPanelDisplay {
5
+ controlType: "text" | "js-expr" | "switch";
6
+ label: string;
7
+ placeholder?: string;
8
+ exampleData?: string;
9
+ }
10
+ export interface Property {
11
+ path: string;
12
+ dataType: DataType;
13
+ propertiesPanelDisplay?: PropertiesPanelDisplay;
14
+ description?: string;
15
+ }
16
+ export interface ComponentConfig {
17
+ id: UUID;
18
+ name: string;
19
+ displayName: string;
20
+ componentPath: string;
21
+ properties: Property[];
22
+ /**
23
+ * Example: [{
24
+ * label: "On Click",
25
+ * path: "onClick",
26
+ * }]
27
+ */
28
+ events: Array<{
29
+ label: string;
30
+ path: string;
31
+ }>;
32
+ }
33
+ export {};
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -12,13 +12,13 @@ const componentSchema = {
12
12
  name: { type: "string" },
13
13
  displayName: { type: "string" },
14
14
  componentPath: { type: "string" },
15
- statefulProperties: {
15
+ properties: {
16
16
  type: "array",
17
17
  items: {
18
- $ref: "#/definitions/StatefulProperty",
18
+ $ref: "#/definitions/Property",
19
19
  },
20
20
  },
21
- eventHandlers: {
21
+ events: {
22
22
  type: "array",
23
23
  items: {
24
24
  $ref: "#/definitions/EventHandler",
@@ -30,21 +30,32 @@ const componentSchema = {
30
30
  "name",
31
31
  "displayName",
32
32
  "componentPath",
33
- "statefulProperties",
34
- "eventHandlers",
33
+ "properties",
34
+ "events",
35
35
  ],
36
36
  additionalProperties: false,
37
37
  definitions: {
38
- StatefulProperty: {
38
+ Property: {
39
39
  properties: {
40
- label: { type: "string" },
41
40
  path: { type: "string" },
42
- inputType: { enum: ["text", "number", "boolean", "js"] },
43
- placeholder: { type: "string" },
41
+ dataType: { enum: ["number", "boolean", "string", "any"] },
42
+ propertiesPanelDisplay: {
43
+ type: "object",
44
+ properties: {
45
+ label: { type: "string" },
46
+ controlType: { enum: ["text", "js-expr", "switch"] },
47
+ defaultValue: { type: "string" },
48
+ placeholder: { type: "string" },
49
+ exampleData: { type: "string" },
50
+ },
51
+ required: ["controlType", "label"],
52
+ additionalProperties: false,
53
+ },
54
+ description: { type: "string" },
44
55
  },
45
56
  type: "object",
46
57
  additionalProperties: false,
47
- required: ["label", "path", "inputType"],
58
+ required: ["path", "dataType"],
48
59
  },
49
60
  EventHandler: {
50
61
  properties: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superblocksteam/util",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "main": "dist/index.js",
5
5
  "homepage": "https://www.superblocks.com",
6
6
  "scripts": {
@@ -0,0 +1,39 @@
1
+ export const supportedDataTypes = [
2
+ "string",
3
+ "number",
4
+ "boolean",
5
+ "any",
6
+ ] as const;
7
+
8
+ export type DataType = (typeof supportedDataTypes)[number];
9
+
10
+ interface TypeInfo {
11
+ tsType: string;
12
+ prompt: string;
13
+ }
14
+
15
+ export const dataTypeDefinions: Record<DataType, TypeInfo> = {
16
+ string: {
17
+ tsType: "string",
18
+ prompt: "string",
19
+ },
20
+ number: {
21
+ tsType: "number",
22
+ prompt: "number",
23
+ },
24
+ boolean: {
25
+ tsType: "boolean",
26
+ prompt: "boolean",
27
+ },
28
+ any: {
29
+ tsType: "any",
30
+ prompt: "any (raw js expression)",
31
+ },
32
+ };
33
+
34
+ export function isValidDataType(input: string): input is DataType {
35
+ return Object.prototype.hasOwnProperty.call(
36
+ dataTypeDefinions,
37
+ input as DataType
38
+ );
39
+ }
@@ -1,4 +1,5 @@
1
- import { inputTypeDefinions, type InputType } from "./input-types";
1
+ import { dataTypeDefinions, type DataType } from "./data-types";
2
+ import { ComponentConfig } from "./types";
2
3
 
3
4
  const indent = (str: string, spaces: number) => {
4
5
  const spacesString = " ".repeat(spaces);
@@ -11,38 +12,31 @@ const indent = (str: string, spaces: number) => {
11
12
 
12
13
  function renderInputTypeAsTS(
13
14
  name: string,
14
- type: InputType,
15
+ type: DataType,
15
16
  trailingChars: string,
16
17
  indentSpaces: number
17
18
  ) {
18
19
  return indent(
19
- `${name}: ${inputTypeDefinions[type].tsType}${trailingChars}`,
20
+ `${name}: ${dataTypeDefinions[type].tsType}${trailingChars}`,
20
21
  indentSpaces
21
22
  );
22
23
  }
23
24
 
24
- export function generateComponentTypesFile(config: any) {
25
- const statefulProperties = config.statefulProperties ?? [];
26
- const eventHandlers = config.eventHandlers ?? [];
25
+ export function generateComponentTypesFile(config: ComponentConfig) {
26
+ const properties = config.properties ?? [];
27
+ const eventHandlers = config.events ?? [];
27
28
  return `// WARNING: This file is automatically generated and managed by Superblocks CLI and should not be edited manually.
28
29
  // Use the \`superblocks components watch\` command to regenerate this file from its source in config.ts
29
30
 
30
- // All stateful properties of your component are defined here.
31
+ // All properties of your component are defined here.
31
32
  // These are the properties which are surfaced in the Superblocks properties panel
32
33
  // and can be referenced throughout your Superblocks Application
33
- export interface StatefulProperties {
34
- ${statefulProperties
35
- .map((v: any) => renderInputTypeAsTS(v.path, v.inputType, ";", 2) + "\n")
34
+ export interface Props {
35
+ ${properties
36
+ .map((v) => renderInputTypeAsTS(v.path, v.dataType, ";", 2) + "\n")
36
37
  .join("")}}
37
38
 
38
- export interface Props extends StatefulProperties {
39
- /**
40
- * Update one (or more) of your component's stateful properties. This will cause the component to rerender,
41
- * and will also notify any other components in your Application which depend on the updated properties, so they also rerender
42
- * @param props An object with the properties to update along with their new values
43
- */
44
- updateStatefulProperties: (props: Partial<StatefulProperties>) => void;
45
-
39
+ export interface EventTriggers {
46
40
  // Call the subsequent function(s) to trigger event(s) in Superblocks from your component.
47
41
  // These events can be wired up to event handlers in your Superblocks App
48
42
  ${
package/src/index.ts CHANGED
@@ -3,4 +3,5 @@ export * from "./component-configs";
3
3
  export * from "./file-uploader";
4
4
  export * from "./login";
5
5
  export * from "./resource-configs";
6
- export * from "./input-types";
6
+ export * from "./data-types";
7
+ export * from "./types";
@@ -3,15 +3,12 @@ import { RESOURCE_CONFIG_PATH } from "./constants";
3
3
 
4
4
  export type SuperblocksMetadata = {
5
5
  cliVersion: string;
6
- lastUpdated: string;
7
- created: string;
8
6
  };
9
7
 
10
8
  export type SuperblocksResourceType = "APPLICATION" | "BACKEND";
11
9
 
12
10
  export type VersionedResourceConfig = {
13
11
  location: string;
14
- lastUpdated: string;
15
12
  resourceType: SuperblocksResourceType;
16
13
  };
17
14
 
package/src/types.ts ADDED
@@ -0,0 +1,58 @@
1
+ import { type UUID } from "node:crypto";
2
+ import { type DataType } from "./data-types";
3
+
4
+ interface PropertiesPanelDisplay {
5
+ // Determines what form item type is shown in the Superblocks properties panel.
6
+ controlType: "text" | "js-expr" | "switch";
7
+
8
+ // Determines form item label in the Superblocks properties panel.
9
+ label: string;
10
+
11
+ // Placeholder text appears as gray text in the properties panel. This only applies
12
+ // to text-like inputs.
13
+ placeholder?: string;
14
+
15
+ // This shows up in the popover as a user types into the properties panel.
16
+ // This is a documentation field that helps users understand what type of data is accepted
17
+ // by this property.
18
+ exampleData?: string;
19
+ }
20
+
21
+ export interface Property {
22
+ path: string;
23
+ dataType: DataType;
24
+
25
+ // The presence of this object determines whether or not this property
26
+ // shows up in the Superblocks properties panel.
27
+ propertiesPanelDisplay?: PropertiesPanelDisplay;
28
+
29
+ // A description of this property. This is used in the Superblocks properties panel
30
+ // as well as in the custom component's autocomplete.
31
+ description?: string;
32
+ }
33
+
34
+ export interface ComponentConfig {
35
+ id: UUID;
36
+
37
+ // Example: "myComponent"
38
+ name: string;
39
+
40
+ // Example: "My Component"
41
+ displayName: string;
42
+
43
+ // Example: "components/myComponent/component.tsx"
44
+ componentPath: string;
45
+
46
+ properties: Property[];
47
+
48
+ /**
49
+ * Example: [{
50
+ * label: "On Click",
51
+ * path: "onClick",
52
+ * }]
53
+ */
54
+ events: Array<{
55
+ label: string;
56
+ path: string;
57
+ }>;
58
+ }
package/src/validation.ts CHANGED
@@ -10,13 +10,13 @@ const componentSchema: Schema = {
10
10
  name: { type: "string" },
11
11
  displayName: { type: "string" },
12
12
  componentPath: { type: "string" },
13
- statefulProperties: {
13
+ properties: {
14
14
  type: "array",
15
15
  items: {
16
- $ref: "#/definitions/StatefulProperty",
16
+ $ref: "#/definitions/Property",
17
17
  },
18
18
  },
19
- eventHandlers: {
19
+ events: {
20
20
  type: "array",
21
21
  items: {
22
22
  $ref: "#/definitions/EventHandler",
@@ -28,21 +28,32 @@ const componentSchema: Schema = {
28
28
  "name",
29
29
  "displayName",
30
30
  "componentPath",
31
- "statefulProperties",
32
- "eventHandlers",
31
+ "properties",
32
+ "events",
33
33
  ],
34
34
  additionalProperties: false,
35
35
  definitions: {
36
- StatefulProperty: {
36
+ Property: {
37
37
  properties: {
38
- label: { type: "string" },
39
38
  path: { type: "string" },
40
- inputType: { enum: ["text", "number", "boolean", "js"] },
41
- placeholder: { type: "string" },
39
+ dataType: { enum: ["number", "boolean", "string", "any"] },
40
+ propertiesPanelDisplay: {
41
+ type: "object",
42
+ properties: {
43
+ label: { type: "string" },
44
+ controlType: { enum: ["text", "js-expr", "switch"] },
45
+ defaultValue: { type: "string" },
46
+ placeholder: { type: "string" },
47
+ exampleData: { type: "string" },
48
+ },
49
+ required: ["controlType", "label"],
50
+ additionalProperties: false,
51
+ },
52
+ description: { type: "string" },
42
53
  },
43
54
  type: "object",
44
55
  additionalProperties: false,
45
- required: ["label", "path", "inputType"],
56
+ required: ["path", "dataType"],
46
57
  },
47
58
  EventHandler: {
48
59
  properties: {
@@ -1,9 +0,0 @@
1
- export declare const supportedInputTypes: readonly ["text", "number", "boolean", "js"];
2
- export type InputType = (typeof supportedInputTypes)[number];
3
- interface TypeInfo {
4
- tsType: string;
5
- prompt: string;
6
- }
7
- export declare const inputTypeDefinions: Record<InputType, TypeInfo>;
8
- export declare function isValidInputType(input: string): input is InputType;
9
- export {};
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isValidInputType = exports.inputTypeDefinions = exports.supportedInputTypes = void 0;
4
- exports.supportedInputTypes = ["text", "number", "boolean", "js"];
5
- exports.inputTypeDefinions = {
6
- text: {
7
- tsType: "string",
8
- prompt: "text",
9
- },
10
- number: {
11
- tsType: "number",
12
- prompt: "number",
13
- },
14
- boolean: {
15
- tsType: "boolean",
16
- prompt: "boolean",
17
- },
18
- js: {
19
- tsType: "any",
20
- prompt: "any (raw js expression)",
21
- },
22
- };
23
- function isValidInputType(input) {
24
- return Object.prototype.hasOwnProperty.call(exports.inputTypeDefinions, input);
25
- }
26
- exports.isValidInputType = isValidInputType;
@@ -1,34 +0,0 @@
1
- export const supportedInputTypes = ["text", "number", "boolean", "js"] as const;
2
-
3
- export type InputType = (typeof supportedInputTypes)[number];
4
-
5
- interface TypeInfo {
6
- tsType: string;
7
- prompt: string;
8
- }
9
-
10
- export const inputTypeDefinions: Record<InputType, TypeInfo> = {
11
- text: {
12
- tsType: "string",
13
- prompt: "text",
14
- },
15
- number: {
16
- tsType: "number",
17
- prompt: "number",
18
- },
19
- boolean: {
20
- tsType: "boolean",
21
- prompt: "boolean",
22
- },
23
- js: {
24
- tsType: "any",
25
- prompt: "any (raw js expression)",
26
- },
27
- };
28
-
29
- export function isValidInputType(input: string): input is InputType {
30
- return Object.prototype.hasOwnProperty.call(
31
- inputTypeDefinions,
32
- input as InputType
33
- );
34
- }