@superblocksteam/util 0.0.20 → 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,21 +10,21 @@ 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
25
  export interface Props {
26
- ${statefulProperties
27
- .map((v) => renderInputTypeAsTS(v.path, v.inputType, ";", 2) + "\n")
26
+ ${properties
27
+ .map((v) => renderInputTypeAsTS(v.path, v.dataType, ";", 2) + "\n")
28
28
  .join("")}}
29
29
 
30
30
  export interface EventTriggers {
package/dist/index.d.ts CHANGED
@@ -3,5 +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
7
  export * from "./types";
package/dist/index.js CHANGED
@@ -6,5 +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
10
  tslib_1.__exportStar(require("./types"), exports);
@@ -28,7 +28,6 @@ export type SuperblocksConfig = SuperblocksMonorepoConfig | SuperblocksApplicati
28
28
  * @param checkParentDir Whether to recursively check the parent directory for a Superblocks config file
29
29
  */
30
30
  export declare function getSuperblocksMonorepoConfigJson(checkParentDir?: boolean, pathPrefix?: string): Promise<[SuperblocksMonorepoConfig, string]>;
31
- export declare function updatedMonorepoConfig(version: string): Promise<void>;
32
31
  export declare function getSuperblocksApplicationConfigJson(): Promise<SuperblocksApplicationConfig>;
33
32
  export declare function getSuperblocksBackendConfigJson(): Promise<SuperblocksBackendConfig>;
34
33
  export declare function getSuperblocksResourceConfigIfExists(): Promise<SuperblocksResourceConfig | undefined>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSuperblocksResourceConfigIfExists = exports.getSuperblocksBackendConfigJson = exports.getSuperblocksApplicationConfigJson = exports.updatedMonorepoConfig = exports.getSuperblocksMonorepoConfigJson = void 0;
3
+ exports.getSuperblocksResourceConfigIfExists = exports.getSuperblocksBackendConfigJson = exports.getSuperblocksApplicationConfigJson = exports.getSuperblocksMonorepoConfigJson = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fs = tslib_1.__importStar(require("fs-extra"));
6
6
  const constants_1 = require("./constants");
@@ -35,21 +35,6 @@ async function getSuperblocksMonorepoConfigJson(checkParentDir = false, pathPref
35
35
  }
36
36
  }
37
37
  exports.getSuperblocksMonorepoConfigJson = getSuperblocksMonorepoConfigJson;
38
- async function updatedMonorepoConfig(version) {
39
- try {
40
- const [previousConfig, configPath] = await getSuperblocksMonorepoConfigJson(true);
41
- if (previousConfig.metadata.cliVersion !== version) {
42
- const newConfig = JSON.parse(JSON.stringify(previousConfig));
43
- newConfig.metadata.cliVersion = version;
44
- // update superblocks.json file
45
- await fs.writeFile(configPath, JSON.stringify(updatedMonorepoConfig, null, 2));
46
- }
47
- }
48
- catch {
49
- // This might fail for a brand-new project folder, which is deliberately ignored
50
- }
51
- }
52
- exports.updatedMonorepoConfig = updatedMonorepoConfig;
53
38
  async function getSuperblocksApplicationConfigJson() {
54
39
  let superblocksConfig;
55
40
  try {
package/dist/types.d.ts CHANGED
@@ -1,26 +1,33 @@
1
1
  /// <reference types="node" />
2
2
  import { type UUID } from "node:crypto";
3
- import { type InputType } from "./input-types";
4
- export interface StatefulProperty {
3
+ import { type DataType } from "./data-types";
4
+ interface PropertiesPanelDisplay {
5
+ controlType: "text" | "js-expr" | "switch";
5
6
  label: string;
6
- path: string;
7
- inputType: InputType;
8
7
  placeholder?: string;
8
+ exampleData?: string;
9
+ }
10
+ export interface Property {
11
+ path: string;
12
+ dataType: DataType;
13
+ propertiesPanelDisplay?: PropertiesPanelDisplay;
14
+ description?: string;
9
15
  }
10
16
  export interface ComponentConfig {
11
17
  id: UUID;
12
18
  name: string;
13
19
  displayName: string;
14
20
  componentPath: string;
15
- statefulProperties: StatefulProperty[];
21
+ properties: Property[];
16
22
  /**
17
23
  * Example: [{
18
24
  * label: "On Click",
19
25
  * path: "onClick",
20
26
  * }]
21
27
  */
22
- eventHandlers: Array<{
28
+ events: Array<{
23
29
  label: string;
24
30
  path: string;
25
31
  }>;
26
32
  }
33
+ export {};
@@ -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.20",
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,28 +12,28 @@ 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
34
  export interface Props {
34
- ${statefulProperties
35
- .map((v: any) => renderInputTypeAsTS(v.path, v.inputType, ";", 2) + "\n")
35
+ ${properties
36
+ .map((v) => renderInputTypeAsTS(v.path, v.dataType, ";", 2) + "\n")
36
37
  .join("")}}
37
38
 
38
39
  export interface EventTriggers {
package/src/index.ts CHANGED
@@ -3,5 +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
7
  export * from "./types";
@@ -75,25 +75,6 @@ export async function getSuperblocksMonorepoConfigJson(
75
75
  }
76
76
  }
77
77
 
78
- export async function updatedMonorepoConfig(version: string) {
79
- try {
80
- const [previousConfig, configPath] = await getSuperblocksMonorepoConfigJson(
81
- true
82
- );
83
- if (previousConfig.metadata.cliVersion !== version) {
84
- const newConfig = JSON.parse(JSON.stringify(previousConfig));
85
- newConfig.metadata.cliVersion = version;
86
- // update superblocks.json file
87
- await fs.writeFile(
88
- configPath,
89
- JSON.stringify(updatedMonorepoConfig, null, 2)
90
- );
91
- }
92
- } catch {
93
- // This might fail for a brand-new project folder, which is deliberately ignored
94
- }
95
- }
96
-
97
78
  export async function getSuperblocksApplicationConfigJson(): Promise<SuperblocksApplicationConfig> {
98
79
  let superblocksConfig;
99
80
  try {
package/src/types.ts CHANGED
@@ -1,11 +1,34 @@
1
1
  import { type UUID } from "node:crypto";
2
- import { type InputType } from "./input-types";
2
+ import { type DataType } from "./data-types";
3
3
 
4
- export interface StatefulProperty {
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.
5
9
  label: string;
6
- path: string;
7
- inputType: InputType;
10
+
11
+ // Placeholder text appears as gray text in the properties panel. This only applies
12
+ // to text-like inputs.
8
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;
9
32
  }
10
33
 
11
34
  export interface ComponentConfig {
@@ -20,7 +43,7 @@ export interface ComponentConfig {
20
43
  // Example: "components/myComponent/component.tsx"
21
44
  componentPath: string;
22
45
 
23
- statefulProperties: StatefulProperty[];
46
+ properties: Property[];
24
47
 
25
48
  /**
26
49
  * Example: [{
@@ -28,7 +51,7 @@ export interface ComponentConfig {
28
51
  * path: "onClick",
29
52
  * }]
30
53
  */
31
- eventHandlers: Array<{
54
+ events: Array<{
32
55
  label: string;
33
56
  path: string;
34
57
  }>;
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
- }