@superblocksteam/util 0.0.20 → 0.0.22
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/data-types.d.ts +9 -0
- package/dist/data-types.js +31 -0
- package/dist/events.d.ts +9 -0
- package/dist/events.js +13 -0
- package/dist/file-uploader.d.ts +1 -0
- package/dist/file-uploader.js +2 -1
- package/dist/generate-component-types.d.ts +2 -1
- package/dist/generate-component-types.js +7 -7
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/resource-configs.d.ts +0 -1
- package/dist/resource-configs.js +1 -16
- package/dist/types.d.ts +58 -7
- package/dist/validation.js +23 -10
- package/package.json +1 -1
- package/src/data-types.ts +39 -0
- package/src/events.ts +9 -0
- package/src/file-uploader.ts +2 -0
- package/src/generate-component-types.ts +10 -9
- package/src/index.ts +2 -1
- package/src/resource-configs.ts +0 -19
- package/src/types.ts +65 -10
- package/src/validation.ts +23 -10
- package/dist/input-types.d.ts +0 -9
- package/dist/input-types.js +0 -26
- package/src/input-types.ts +0 -34
|
@@ -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;
|
package/dist/events.d.ts
ADDED
package/dist/events.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComponentEvent = void 0;
|
|
4
|
+
var ComponentEvent;
|
|
5
|
+
(function (ComponentEvent) {
|
|
6
|
+
ComponentEvent["CREATE"] = "create";
|
|
7
|
+
ComponentEvent["INIT"] = "init";
|
|
8
|
+
ComponentEvent["LOGIN"] = "login";
|
|
9
|
+
ComponentEvent["MIGRATE"] = "migrate";
|
|
10
|
+
ComponentEvent["PULL"] = "pull";
|
|
11
|
+
ComponentEvent["REGISTER"] = "register";
|
|
12
|
+
ComponentEvent["UPLOAD"] = "upload";
|
|
13
|
+
})(ComponentEvent || (exports.ComponentEvent = ComponentEvent = {}));
|
package/dist/file-uploader.d.ts
CHANGED
package/dist/file-uploader.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBucketeerUrlFromSuperblocksUrl = void 0;
|
|
3
|
+
exports.getBucketeerUrlFromSuperblocksUrl = exports.COMPONENT_EVENT_HEADER = void 0;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
|
+
exports.COMPONENT_EVENT_HEADER = "x-superblocks-component-event";
|
|
5
6
|
// retrieves bucketeer base URL given the superblocks server base URL
|
|
6
7
|
const getBucketeerUrlFromSuperblocksUrl = (superblocksBaseUrl) => {
|
|
7
8
|
// if superblocks base URL is an EE, return bucketeer's dev URL
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
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
|
|
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}: ${
|
|
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
|
|
18
|
-
const eventHandlers = (_b = config.
|
|
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
|
|
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
|
-
${
|
|
27
|
-
.map((v) => renderInputTypeAsTS(v.path, v.
|
|
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
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export * from "./constants";
|
|
2
2
|
export * from "./component-configs";
|
|
3
|
+
export * from "./events";
|
|
3
4
|
export * from "./file-uploader";
|
|
4
5
|
export * from "./login";
|
|
5
6
|
export * from "./resource-configs";
|
|
6
|
-
export * from "./
|
|
7
|
+
export * from "./data-types";
|
|
7
8
|
export * from "./types";
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./constants"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./component-configs"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./events"), exports);
|
|
6
7
|
tslib_1.__exportStar(require("./file-uploader"), exports);
|
|
7
8
|
tslib_1.__exportStar(require("./login"), exports);
|
|
8
9
|
tslib_1.__exportStar(require("./resource-configs"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./
|
|
10
|
+
tslib_1.__exportStar(require("./data-types"), exports);
|
|
10
11
|
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>;
|
package/dist/resource-configs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSuperblocksResourceConfigIfExists = exports.getSuperblocksBackendConfigJson = exports.getSuperblocksApplicationConfigJson = exports.
|
|
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,77 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { type UUID } from "node:crypto";
|
|
3
|
-
import { type
|
|
4
|
-
|
|
3
|
+
import { type DataType } from "./data-types";
|
|
4
|
+
interface PropertiesPanelDisplay {
|
|
5
|
+
/**
|
|
6
|
+
* Determines what form item type is shown in the Superblocks properties panel.
|
|
7
|
+
*/
|
|
8
|
+
controlType: "text" | "js-expr" | "switch";
|
|
9
|
+
/**
|
|
10
|
+
* Determines form item label in the Superblocks properties panel.
|
|
11
|
+
*/
|
|
5
12
|
label: string;
|
|
6
|
-
|
|
7
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Placeholder text appears as gray text in the properties panel. This only applies
|
|
15
|
+
* to text-like inputs.
|
|
16
|
+
*/
|
|
8
17
|
placeholder?: string;
|
|
18
|
+
/**
|
|
19
|
+
* This shows up in the popover as a user types into the properties panel.
|
|
20
|
+
* This is a documentation field that helps users understand what type of data is accepted
|
|
21
|
+
* by this property.
|
|
22
|
+
*/
|
|
23
|
+
exampleData?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface Property {
|
|
26
|
+
path: string;
|
|
27
|
+
dataType: DataType;
|
|
28
|
+
/**
|
|
29
|
+
* The presence of this object determines whether or not this property
|
|
30
|
+
* shows up in the Superblocks properties panel.
|
|
31
|
+
**/
|
|
32
|
+
propertiesPanelDisplay?: PropertiesPanelDisplay;
|
|
33
|
+
/**
|
|
34
|
+
* A description of this property. This is used in the Superblocks properties panel
|
|
35
|
+
* as well as in the custom component's autocomplete.
|
|
36
|
+
**/
|
|
37
|
+
description?: string;
|
|
38
|
+
/**
|
|
39
|
+
* By default, all your properties are readable from anywhere in Superblocks using dot notation
|
|
40
|
+
* (e.g. `myComponent.myProperty`). If you want to hide a property from the outside world,
|
|
41
|
+
* set this to false
|
|
42
|
+
* @default true
|
|
43
|
+
*/
|
|
44
|
+
isExternallyReadable?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* By default, all properties can have be used with Set Component Property and Reset Component to Default.
|
|
47
|
+
* @default true
|
|
48
|
+
**/
|
|
49
|
+
isExternallySettable?: boolean;
|
|
9
50
|
}
|
|
10
51
|
export interface ComponentConfig {
|
|
11
52
|
id: UUID;
|
|
53
|
+
/**
|
|
54
|
+
* @example: "myComponent"
|
|
55
|
+
*/
|
|
12
56
|
name: string;
|
|
57
|
+
/**
|
|
58
|
+
* @example "My Component"
|
|
59
|
+
*/
|
|
13
60
|
displayName: string;
|
|
61
|
+
/**
|
|
62
|
+
* @example "components/myComponent/component.tsx"
|
|
63
|
+
*/
|
|
14
64
|
componentPath: string;
|
|
15
|
-
|
|
65
|
+
properties: Property[];
|
|
16
66
|
/**
|
|
17
|
-
*
|
|
67
|
+
* @example [{
|
|
18
68
|
* label: "On Click",
|
|
19
69
|
* path: "onClick",
|
|
20
70
|
* }]
|
|
21
71
|
*/
|
|
22
|
-
|
|
72
|
+
events: Array<{
|
|
23
73
|
label: string;
|
|
24
74
|
path: string;
|
|
25
75
|
}>;
|
|
26
76
|
}
|
|
77
|
+
export {};
|
package/dist/validation.js
CHANGED
|
@@ -12,13 +12,13 @@ const componentSchema = {
|
|
|
12
12
|
name: { type: "string" },
|
|
13
13
|
displayName: { type: "string" },
|
|
14
14
|
componentPath: { type: "string" },
|
|
15
|
-
|
|
15
|
+
properties: {
|
|
16
16
|
type: "array",
|
|
17
17
|
items: {
|
|
18
|
-
$ref: "#/definitions/
|
|
18
|
+
$ref: "#/definitions/Property",
|
|
19
19
|
},
|
|
20
20
|
},
|
|
21
|
-
|
|
21
|
+
events: {
|
|
22
22
|
type: "array",
|
|
23
23
|
items: {
|
|
24
24
|
$ref: "#/definitions/EventHandler",
|
|
@@ -30,21 +30,34 @@ const componentSchema = {
|
|
|
30
30
|
"name",
|
|
31
31
|
"displayName",
|
|
32
32
|
"componentPath",
|
|
33
|
-
"
|
|
34
|
-
"
|
|
33
|
+
"properties",
|
|
34
|
+
"events",
|
|
35
35
|
],
|
|
36
36
|
additionalProperties: false,
|
|
37
37
|
definitions: {
|
|
38
|
-
|
|
38
|
+
Property: {
|
|
39
39
|
properties: {
|
|
40
|
-
label: { type: "string" },
|
|
41
40
|
path: { type: "string" },
|
|
42
|
-
|
|
43
|
-
|
|
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" },
|
|
55
|
+
isExternallySettable: { type: "boolean" },
|
|
56
|
+
isExternallyReadable: { type: "boolean" },
|
|
44
57
|
},
|
|
45
58
|
type: "object",
|
|
46
59
|
additionalProperties: false,
|
|
47
|
-
required: ["
|
|
60
|
+
required: ["path", "dataType"],
|
|
48
61
|
},
|
|
49
62
|
EventHandler: {
|
|
50
63
|
properties: {
|
package/package.json
CHANGED
|
@@ -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
|
+
}
|
package/src/events.ts
ADDED
package/src/file-uploader.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
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:
|
|
15
|
+
type: DataType,
|
|
15
16
|
trailingChars: string,
|
|
16
17
|
indentSpaces: number
|
|
17
18
|
) {
|
|
18
19
|
return indent(
|
|
19
|
-
`${name}: ${
|
|
20
|
+
`${name}: ${dataTypeDefinions[type].tsType}${trailingChars}`,
|
|
20
21
|
indentSpaces
|
|
21
22
|
);
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
export function generateComponentTypesFile(config:
|
|
25
|
-
const
|
|
26
|
-
const eventHandlers = config.
|
|
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
|
|
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
|
-
${
|
|
35
|
-
.map((v
|
|
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
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export * from "./constants";
|
|
2
2
|
export * from "./component-configs";
|
|
3
|
+
export * from "./events";
|
|
3
4
|
export * from "./file-uploader";
|
|
4
5
|
export * from "./login";
|
|
5
6
|
export * from "./resource-configs";
|
|
6
|
-
export * from "./
|
|
7
|
+
export * from "./data-types";
|
|
7
8
|
export * from "./types";
|
package/src/resource-configs.ts
CHANGED
|
@@ -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,34 +1,89 @@
|
|
|
1
1
|
import { type UUID } from "node:crypto";
|
|
2
|
-
import { type
|
|
2
|
+
import { type DataType } from "./data-types";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
interface PropertiesPanelDisplay {
|
|
5
|
+
/**
|
|
6
|
+
* Determines what form item type is shown in the Superblocks properties panel.
|
|
7
|
+
*/
|
|
8
|
+
controlType: "text" | "js-expr" | "switch";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Determines form item label in the Superblocks properties panel.
|
|
12
|
+
*/
|
|
5
13
|
label: string;
|
|
6
|
-
|
|
7
|
-
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Placeholder text appears as gray text in the properties panel. This only applies
|
|
17
|
+
* to text-like inputs.
|
|
18
|
+
*/
|
|
8
19
|
placeholder?: string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* This shows up in the popover as a user types into the properties panel.
|
|
23
|
+
* This is a documentation field that helps users understand what type of data is accepted
|
|
24
|
+
* by this property.
|
|
25
|
+
*/
|
|
26
|
+
exampleData?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface Property {
|
|
30
|
+
path: string;
|
|
31
|
+
dataType: DataType;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The presence of this object determines whether or not this property
|
|
35
|
+
* shows up in the Superblocks properties panel.
|
|
36
|
+
**/
|
|
37
|
+
propertiesPanelDisplay?: PropertiesPanelDisplay;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A description of this property. This is used in the Superblocks properties panel
|
|
41
|
+
* as well as in the custom component's autocomplete.
|
|
42
|
+
**/
|
|
43
|
+
description?: string;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* By default, all your properties are readable from anywhere in Superblocks using dot notation
|
|
47
|
+
* (e.g. `myComponent.myProperty`). If you want to hide a property from the outside world,
|
|
48
|
+
* set this to false
|
|
49
|
+
* @default true
|
|
50
|
+
*/
|
|
51
|
+
isExternallyReadable?: boolean;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* By default, all properties can have be used with Set Component Property and Reset Component to Default.
|
|
55
|
+
* @default true
|
|
56
|
+
**/
|
|
57
|
+
isExternallySettable?: boolean;
|
|
9
58
|
}
|
|
10
59
|
|
|
11
60
|
export interface ComponentConfig {
|
|
12
61
|
id: UUID;
|
|
13
62
|
|
|
14
|
-
|
|
63
|
+
/**
|
|
64
|
+
* @example: "myComponent"
|
|
65
|
+
*/
|
|
15
66
|
name: string;
|
|
16
67
|
|
|
17
|
-
|
|
68
|
+
/**
|
|
69
|
+
* @example "My Component"
|
|
70
|
+
*/
|
|
18
71
|
displayName: string;
|
|
19
72
|
|
|
20
|
-
|
|
73
|
+
/**
|
|
74
|
+
* @example "components/myComponent/component.tsx"
|
|
75
|
+
*/
|
|
21
76
|
componentPath: string;
|
|
22
77
|
|
|
23
|
-
|
|
78
|
+
properties: Property[];
|
|
24
79
|
|
|
25
80
|
/**
|
|
26
|
-
*
|
|
81
|
+
* @example [{
|
|
27
82
|
* label: "On Click",
|
|
28
83
|
* path: "onClick",
|
|
29
84
|
* }]
|
|
30
85
|
*/
|
|
31
|
-
|
|
86
|
+
events: Array<{
|
|
32
87
|
label: string;
|
|
33
88
|
path: string;
|
|
34
89
|
}>;
|
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
|
-
|
|
13
|
+
properties: {
|
|
14
14
|
type: "array",
|
|
15
15
|
items: {
|
|
16
|
-
$ref: "#/definitions/
|
|
16
|
+
$ref: "#/definitions/Property",
|
|
17
17
|
},
|
|
18
18
|
},
|
|
19
|
-
|
|
19
|
+
events: {
|
|
20
20
|
type: "array",
|
|
21
21
|
items: {
|
|
22
22
|
$ref: "#/definitions/EventHandler",
|
|
@@ -28,21 +28,34 @@ const componentSchema: Schema = {
|
|
|
28
28
|
"name",
|
|
29
29
|
"displayName",
|
|
30
30
|
"componentPath",
|
|
31
|
-
"
|
|
32
|
-
"
|
|
31
|
+
"properties",
|
|
32
|
+
"events",
|
|
33
33
|
],
|
|
34
34
|
additionalProperties: false,
|
|
35
35
|
definitions: {
|
|
36
|
-
|
|
36
|
+
Property: {
|
|
37
37
|
properties: {
|
|
38
|
-
label: { type: "string" },
|
|
39
38
|
path: { type: "string" },
|
|
40
|
-
|
|
41
|
-
|
|
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" },
|
|
53
|
+
isExternallySettable: { type: "boolean" },
|
|
54
|
+
isExternallyReadable: { type: "boolean" },
|
|
42
55
|
},
|
|
43
56
|
type: "object",
|
|
44
57
|
additionalProperties: false,
|
|
45
|
-
required: ["
|
|
58
|
+
required: ["path", "dataType"],
|
|
46
59
|
},
|
|
47
60
|
EventHandler: {
|
|
48
61
|
properties: {
|
package/dist/input-types.d.ts
DELETED
|
@@ -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 {};
|
package/dist/input-types.js
DELETED
|
@@ -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;
|
package/src/input-types.ts
DELETED
|
@@ -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
|
-
}
|