@antlur/backstage 1.2.0 → 1.2.2
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/cjs/client.js +2 -0
- package/dist/cjs/endpoints/blocks.js +16 -0
- package/dist/cjs/endpoints/website.js +4 -0
- package/dist/cjs/studio/define-block.js +13 -0
- package/dist/cjs/studio/types/field.js +9 -0
- package/dist/esm/client.d.ts +2 -0
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +2 -0
- package/dist/esm/endpoints/blocks.d.ts +13 -0
- package/dist/esm/endpoints/blocks.d.ts.map +1 -0
- package/dist/esm/endpoints/blocks.js +12 -0
- package/dist/esm/endpoints/website.d.ts +1 -0
- package/dist/esm/endpoints/website.d.ts.map +1 -1
- package/dist/esm/endpoints/website.js +4 -0
- package/dist/esm/studio/define-block.d.ts +5 -8
- package/dist/esm/studio/define-block.d.ts.map +1 -1
- package/dist/esm/studio/define-block.js +13 -0
- package/dist/esm/studio/define-field.d.ts +1 -1
- package/dist/esm/studio/define-field.d.ts.map +1 -1
- package/dist/esm/studio/define-schema.d.ts +2 -1
- package/dist/esm/studio/define-schema.d.ts.map +1 -1
- package/dist/esm/studio/types/block.d.ts +19 -13
- package/dist/esm/studio/types/block.d.ts.map +1 -1
- package/dist/esm/studio/types/field.d.ts +31 -5
- package/dist/esm/studio/types/field.d.ts.map +1 -1
- package/dist/esm/studio/types/field.js +9 -0
- package/dist/types/client.d.ts +2 -0
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/endpoints/blocks.d.ts +13 -0
- package/dist/types/endpoints/blocks.d.ts.map +1 -0
- package/dist/types/endpoints/website.d.ts +1 -0
- package/dist/types/endpoints/website.d.ts.map +1 -1
- package/dist/types/studio/define-block.d.ts +5 -8
- package/dist/types/studio/define-block.d.ts.map +1 -1
- package/dist/types/studio/define-field.d.ts +1 -1
- package/dist/types/studio/define-field.d.ts.map +1 -1
- package/dist/types/studio/define-schema.d.ts +2 -1
- package/dist/types/studio/define-schema.d.ts.map +1 -1
- package/dist/types/studio/types/block.d.ts +19 -13
- package/dist/types/studio/types/block.d.ts.map +1 -1
- package/dist/types/studio/types/field.d.ts +31 -5
- package/dist/types/studio/types/field.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +3 -0
- package/src/endpoints/blocks.ts +22 -0
- package/src/endpoints/website.ts +6 -0
- package/src/studio/define-block.ts +22 -9
- package/src/studio/define-field.ts +1 -1
- package/src/studio/define-schema.ts +3 -1
- package/src/studio/types/block.ts +18 -14
- package/src/studio/types/field.ts +43 -22
package/dist/cjs/client.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.BackstageClient = void 0;
|
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
const config_1 = require("./config");
|
|
9
9
|
const alerts_1 = require("./endpoints/alerts");
|
|
10
|
+
const blocks_1 = require("./endpoints/blocks");
|
|
10
11
|
const events_1 = require("./endpoints/events");
|
|
11
12
|
const locations_1 = require("./endpoints/locations");
|
|
12
13
|
const menus_1 = require("./endpoints/menus");
|
|
@@ -64,6 +65,7 @@ class BackstageClient {
|
|
|
64
65
|
});
|
|
65
66
|
// Initialize service instances
|
|
66
67
|
this.alerts = new alerts_1.AlertService(this);
|
|
68
|
+
this.blocks = new blocks_1.BlocksService(this);
|
|
67
69
|
this.events = new events_1.EventService(this);
|
|
68
70
|
this.locations = new locations_1.LocationService(this);
|
|
69
71
|
this.menus = new menus_1.MenuService(this);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BlocksService = void 0;
|
|
4
|
+
const base_1 = require("./base");
|
|
5
|
+
class BlocksService extends base_1.BaseService {
|
|
6
|
+
async all() { }
|
|
7
|
+
async create({ name, slug, schema }) {
|
|
8
|
+
const res = await this.client.post("/blocks", { name, slug, schema });
|
|
9
|
+
return res.data;
|
|
10
|
+
}
|
|
11
|
+
async update(id, { name, slug, schema }) {
|
|
12
|
+
const res = await this.client.put(`/blocks/${id}`, { name, slug, schema });
|
|
13
|
+
return res.data;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.BlocksService = BlocksService;
|
|
@@ -7,5 +7,9 @@ class WebsiteService extends base_1.BaseService {
|
|
|
7
7
|
const res = await this.client.get("/websites");
|
|
8
8
|
return res.data[0];
|
|
9
9
|
}
|
|
10
|
+
async routes() {
|
|
11
|
+
const website = await this.getWebsite();
|
|
12
|
+
return this.client.get(`/websites/${website.id}/routes`);
|
|
13
|
+
}
|
|
10
14
|
}
|
|
11
15
|
exports.WebsiteService = WebsiteService;
|
|
@@ -2,5 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defineBlock = defineBlock;
|
|
4
4
|
function defineBlock(options) {
|
|
5
|
+
// Runtime validation
|
|
6
|
+
if (!options.name || typeof options.name !== "string") {
|
|
7
|
+
throw new Error("Block name is required and must be a string");
|
|
8
|
+
}
|
|
9
|
+
if (!options.slug || typeof options.slug !== "string") {
|
|
10
|
+
throw new Error("Block slug is required and must be a string");
|
|
11
|
+
}
|
|
12
|
+
if (!options.schema || typeof options.schema !== "object") {
|
|
13
|
+
throw new Error("Block schema is required and must be an object");
|
|
14
|
+
}
|
|
15
|
+
if (!options.component) {
|
|
16
|
+
throw new Error("Block component is required");
|
|
17
|
+
}
|
|
5
18
|
return options;
|
|
6
19
|
}
|
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// export interface Field<T extends FieldType = FieldType> {
|
|
4
|
+
// name: string;
|
|
5
|
+
// slug: string;
|
|
6
|
+
// type: FieldType;
|
|
7
|
+
// value?: FieldTypeToValue[T];
|
|
8
|
+
// placeholder?: string;
|
|
9
|
+
// required?: boolean;
|
|
10
|
+
// options?: Array<{ label: string; value: any }>;
|
|
11
|
+
// }
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AxiosInstance, AxiosRequestConfig } from "axios";
|
|
2
2
|
import { BackstageUserConfig } from "./config";
|
|
3
3
|
import { AlertService } from "./endpoints/alerts";
|
|
4
|
+
import { BlocksService } from "./endpoints/blocks";
|
|
4
5
|
import { EventService } from "./endpoints/events";
|
|
5
6
|
import { LocationService } from "./endpoints/locations";
|
|
6
7
|
import { MenuService } from "./endpoints/menus";
|
|
@@ -11,6 +12,7 @@ import { WebsiteService } from "./endpoints/website";
|
|
|
11
12
|
export declare class BackstageClient {
|
|
12
13
|
private instance;
|
|
13
14
|
readonly alerts: AlertService;
|
|
15
|
+
readonly blocks: BlocksService;
|
|
14
16
|
readonly events: EventService;
|
|
15
17
|
readonly locations: LocationService;
|
|
16
18
|
readonly menus: MenuService;
|
package/dist/esm/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAE,kBAAkB,EAA6B,MAAM,OAAO,CAAC;AAC5F,OAAO,EAAmB,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAA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AW,CAAC;IACnC,SAAgB,UAAU,EAAE,iBAAiB,CAAC;IAC9C,SAAgB,KAAK,EAAE,WAAW,CAAC;IACnC,SAAgB,KAAK,EAAE,YAAY,CAAC;IACpC,SAAgB,OAAO,EAAE,cAAc,CAAC;gBAE5B,MAAM,CAAC,EAAE,mBAAmB;IAqE3B,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;IAKtE,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;IAKvF,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;IAKtF,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;IAKxF,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;IAK/E,gBAAgB,IAAI,aAAa;CAGzC"}
|
package/dist/esm/client.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import { getGlobalConfig } from "./config";
|
|
3
3
|
import { AlertService } from "./endpoints/alerts";
|
|
4
|
+
import { BlocksService } from "./endpoints/blocks";
|
|
4
5
|
import { EventService } from "./endpoints/events";
|
|
5
6
|
import { LocationService } from "./endpoints/locations";
|
|
6
7
|
import { MenuService } from "./endpoints/menus";
|
|
@@ -58,6 +59,7 @@ export class BackstageClient {
|
|
|
58
59
|
});
|
|
59
60
|
// Initialize service instances
|
|
60
61
|
this.alerts = new AlertService(this);
|
|
62
|
+
this.blocks = new BlocksService(this);
|
|
61
63
|
this.events = new EventService(this);
|
|
62
64
|
this.locations = new LocationService(this);
|
|
63
65
|
this.menus = new MenuService(this);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseService } from "./base";
|
|
2
|
+
interface BlockParams {
|
|
3
|
+
name: string;
|
|
4
|
+
slug: string;
|
|
5
|
+
schema: any;
|
|
6
|
+
}
|
|
7
|
+
export declare class BlocksService extends BaseService {
|
|
8
|
+
all(): Promise<void>;
|
|
9
|
+
create({ name, slug, schema }: BlockParams): Promise<BlockParams>;
|
|
10
|
+
update(id: string, { name, slug, schema }: BlockParams): Promise<BlockParams>;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=blocks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../../src/endpoints/blocks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,GAAG,CAAC;CACb;AAED,qBAAa,aAAc,SAAQ,WAAW;IACtC,GAAG;IAEH,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,WAAW;IAK1C,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,WAAW;CAI7D"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseService } from "./base";
|
|
2
|
+
export class BlocksService extends BaseService {
|
|
3
|
+
async all() { }
|
|
4
|
+
async create({ name, slug, schema }) {
|
|
5
|
+
const res = await this.client.post("/blocks", { name, slug, schema });
|
|
6
|
+
return res.data;
|
|
7
|
+
}
|
|
8
|
+
async update(id, { name, slug, schema }) {
|
|
9
|
+
const res = await this.client.put(`/blocks/${id}`, { name, slug, schema });
|
|
10
|
+
return res.data;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"website.d.ts","sourceRoot":"","sources":["../../../src/endpoints/website.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,qBAAa,cAAe,SAAQ,WAAW;IACvC,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"website.d.ts","sourceRoot":"","sources":["../../../src/endpoints/website.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,qBAAa,cAAe,SAAQ,WAAW;IACvC,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;IAK9B,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAKlC"}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { BlockSchema, BlockDefinition, BlockComponentProps
|
|
2
|
-
export
|
|
3
|
-
[K in keyof TFields]: TFields[K]["value"];
|
|
4
|
-
};
|
|
5
|
-
export declare function defineBlock<TFields extends Record<string, Field<any>>>(options: {
|
|
1
|
+
import { BlockSchema, BlockDefinition, BlockComponentProps } from "./types";
|
|
2
|
+
export declare function defineBlock(options: {
|
|
6
3
|
name: string;
|
|
7
4
|
slug: string;
|
|
8
|
-
schema: BlockSchema<
|
|
9
|
-
component: React.ComponentType<BlockComponentProps<
|
|
10
|
-
}): BlockDefinition<
|
|
5
|
+
schema: BlockSchema<any>;
|
|
6
|
+
component: React.ComponentType<BlockComponentProps<typeof options.schema>>;
|
|
7
|
+
}): BlockDefinition<typeof options.schema.fields>;
|
|
11
8
|
//# sourceMappingURL=define-block.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-block.d.ts","sourceRoot":"","sources":["../../../src/studio/define-block.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"define-block.d.ts","sourceRoot":"","sources":["../../../src/studio/define-block.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE5E,wBAAgB,WAAW,CAAC,OAAO,EAAE;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC;IACzB,SAAS,EAAE,KAAK,CAAC,aAAa,CAAC,mBAAmB,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;CAC5E,GAAG,eAAe,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAmBhD"}
|
|
@@ -1,3 +1,16 @@
|
|
|
1
1
|
export function defineBlock(options) {
|
|
2
|
+
// Runtime validation
|
|
3
|
+
if (!options.name || typeof options.name !== "string") {
|
|
4
|
+
throw new Error("Block name is required and must be a string");
|
|
5
|
+
}
|
|
6
|
+
if (!options.slug || typeof options.slug !== "string") {
|
|
7
|
+
throw new Error("Block slug is required and must be a string");
|
|
8
|
+
}
|
|
9
|
+
if (!options.schema || typeof options.schema !== "object") {
|
|
10
|
+
throw new Error("Block schema is required and must be an object");
|
|
11
|
+
}
|
|
12
|
+
if (!options.component) {
|
|
13
|
+
throw new Error("Block component is required");
|
|
14
|
+
}
|
|
2
15
|
return options;
|
|
3
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-field.d.ts","sourceRoot":"","sources":["../../../src/studio/define-field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,wBAAgB,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"define-field.d.ts","sourceRoot":"","sources":["../../../src/studio/define-field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,wBAAgB,WAAW,CAAC,CAAC,SAAS,KAAK,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAExD"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { BlockSchema, Field } from "./types";
|
|
2
|
-
export
|
|
2
|
+
export type SchemaFields = Record<string, Field>;
|
|
3
|
+
export declare function defineSchema<T extends SchemaFields>(schema: BlockSchema<T>): BlockSchema<T>;
|
|
3
4
|
//# sourceMappingURL=define-schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-schema.d.ts","sourceRoot":"","sources":["../../../src/studio/define-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAE7C,
|
|
1
|
+
{"version":3,"file":"define-schema.d.ts","sourceRoot":"","sources":["../../../src/studio/define-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAE7C,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAEjD,wBAAgB,YAAY,CAAC,CAAC,SAAS,YAAY,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,kBAE1E"}
|
|
@@ -1,25 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Field, FieldType, FieldTypeToValue } from "./field";
|
|
2
|
+
type FieldValues<T extends Record<string, Field>> = {
|
|
3
|
+
[K in keyof T]: T[K] extends {
|
|
4
|
+
type: infer Type;
|
|
5
|
+
} ? (Type extends FieldType ? FieldTypeToValue[Type] : never) : never;
|
|
6
|
+
};
|
|
7
|
+
export interface BlockSchema<TFields extends Record<string, Field>> {
|
|
4
8
|
fields: TFields;
|
|
5
9
|
properties?: BlockProperties;
|
|
6
10
|
}
|
|
7
|
-
export interface BlockDefinition<TFields extends Record<string, Field
|
|
11
|
+
export interface BlockDefinition<TFields extends Record<string, Field>> {
|
|
8
12
|
name: string;
|
|
13
|
+
slug: string;
|
|
9
14
|
schema: BlockSchema<TFields>;
|
|
10
|
-
component: React.ComponentType<BlockComponentProps<
|
|
15
|
+
component: React.ComponentType<BlockComponentProps<any>>;
|
|
11
16
|
}
|
|
12
|
-
export interface
|
|
17
|
+
export interface BlockProperties {
|
|
18
|
+
customClassName?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface BuilderBlock<TSchema extends BlockSchema<Record<string, Field>>> {
|
|
13
21
|
id: string;
|
|
14
22
|
type: string;
|
|
15
|
-
fields:
|
|
23
|
+
fields: FieldValues<TSchema["fields"]>;
|
|
16
24
|
properties?: BlockProperties;
|
|
17
25
|
}
|
|
18
|
-
export interface
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export interface BlockComponentProps<TFieldValues extends Record<string, any>> {
|
|
22
|
-
block: BuilderBlock<TFieldValues>;
|
|
23
|
-
onFieldChange: (blockId: string, fieldName: keyof TFieldValues, value: any) => void;
|
|
26
|
+
export interface BlockComponentProps<TSchema extends BlockSchema<Record<string, Field>>> {
|
|
27
|
+
block: BuilderBlock<TSchema>;
|
|
28
|
+
onFieldChange: (blockId: string, fieldName: keyof TSchema["fields"], value: any) => void;
|
|
24
29
|
}
|
|
30
|
+
export {};
|
|
25
31
|
//# sourceMappingURL=block.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../../../src/studio/types/block.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+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AAS,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACrF,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAC7B,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;CAC1F"}
|
|
@@ -1,14 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { MediaItem } from "../../types";
|
|
2
|
+
type Nullable<T> = T | null;
|
|
3
|
+
export type FieldTypeToValue = {
|
|
4
|
+
boolean: Nullable<boolean>;
|
|
5
|
+
event_select: Nullable<string>;
|
|
6
|
+
form_select: Nullable<string>;
|
|
7
|
+
image: Nullable<MediaItem>;
|
|
8
|
+
image_list: Nullable<MediaItem[]>;
|
|
9
|
+
list_array: Nullable<string[]>;
|
|
10
|
+
media: Nullable<MediaItem>;
|
|
11
|
+
menu_select: Nullable<string>;
|
|
12
|
+
number: Nullable<number>;
|
|
13
|
+
press_select: Nullable<string>;
|
|
14
|
+
repeater: Nullable<any[]>;
|
|
15
|
+
rich_text: Nullable<string>;
|
|
16
|
+
separator: never;
|
|
17
|
+
spacer: never;
|
|
18
|
+
text: Nullable<string>;
|
|
19
|
+
textarea: Nullable<string>;
|
|
20
|
+
url: Nullable<string>;
|
|
21
|
+
};
|
|
22
|
+
export type FieldType = keyof FieldTypeToValue;
|
|
23
|
+
export type BaseField = {
|
|
3
24
|
name: string;
|
|
4
25
|
slug: string;
|
|
5
|
-
type: FieldType;
|
|
6
|
-
value?: TValue;
|
|
7
26
|
placeholder?: string;
|
|
8
27
|
required?: boolean;
|
|
9
28
|
options?: Array<{
|
|
10
29
|
label: string;
|
|
11
30
|
value: any;
|
|
12
31
|
}>;
|
|
13
|
-
}
|
|
32
|
+
};
|
|
33
|
+
export type Field = {
|
|
34
|
+
[K in FieldType]: BaseField & {
|
|
35
|
+
type: K;
|
|
36
|
+
value?: FieldTypeToValue[K];
|
|
37
|
+
};
|
|
38
|
+
}[FieldType];
|
|
39
|
+
export {};
|
|
14
40
|
//# sourceMappingURL=field.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../../src/studio/types/field.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../../src/studio/types/field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAE5B,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC3B,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC/B,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,KAAK,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC3B,UAAU,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC;IAClC,UAAU,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAC/B,KAAK,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC3B,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACzB,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC/B,QAAQ,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;IAC1B,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC5B,SAAS,EAAE,KAAK,CAAC;IACjB,MAAM,EAAE,KAAK,CAAC;IACd,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACvB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3B,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;CACvB,CAAC;AACF,MAAM,MAAM,SAAS,GAAG,MAAM,gBAAgB,CAAC;AAE/C,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,GAAG,CAAA;KAAE,CAAC,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG;KACjB,CAAC,IAAI,SAAS,GAAG,SAAS,GAAG;QAC5B,IAAI,EAAE,CAAC,CAAC;QACR,KAAK,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;KAC7B;CACF,CAAC,SAAS,CAAC,CAAC"}
|
|
@@ -1 +1,10 @@
|
|
|
1
1
|
export {};
|
|
2
|
+
// export interface Field<T extends FieldType = FieldType> {
|
|
3
|
+
// name: string;
|
|
4
|
+
// slug: string;
|
|
5
|
+
// type: FieldType;
|
|
6
|
+
// value?: FieldTypeToValue[T];
|
|
7
|
+
// placeholder?: string;
|
|
8
|
+
// required?: boolean;
|
|
9
|
+
// options?: Array<{ label: string; value: any }>;
|
|
10
|
+
// }
|
package/dist/types/client.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AxiosInstance, AxiosRequestConfig } from "axios";
|
|
2
2
|
import { BackstageUserConfig } from "./config";
|
|
3
3
|
import { AlertService } from "./endpoints/alerts";
|
|
4
|
+
import { BlocksService } from "./endpoints/blocks";
|
|
4
5
|
import { EventService } from "./endpoints/events";
|
|
5
6
|
import { LocationService } from "./endpoints/locations";
|
|
6
7
|
import { MenuService } from "./endpoints/menus";
|
|
@@ -11,6 +12,7 @@ import { WebsiteService } from "./endpoints/website";
|
|
|
11
12
|
export declare class BackstageClient {
|
|
12
13
|
private instance;
|
|
13
14
|
readonly alerts: AlertService;
|
|
15
|
+
readonly blocks: BlocksService;
|
|
14
16
|
readonly events: EventService;
|
|
15
17
|
readonly locations: LocationService;
|
|
16
18
|
readonly menus: MenuService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAE,kBAAkB,EAA6B,MAAM,OAAO,CAAC;AAC5F,OAAO,EAAmB,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAgB;IAGhC,SAAgB,MAAM,EAAE,YAAY,CAAC;IACrC,SAAgB,MAAM,EAAE,YAAY,CAAC;IACrC,SAAgB,SAAS,EAAE,eAAe,CAAC;IAC3C,SAAgB,KAAK,EAAE,WAAW,CAAC;IACnC,SAAgB,UAAU,EAAE,iBAAiB,CAAC;IAC9C,SAAgB,KAAK,EAAE,WAAW,CAAC;IACnC,SAAgB,KAAK,EAAE,YAAY,CAAC;IACpC,SAAgB,OAAO,EAAE,cAAc,CAAC;gBAE5B,MAAM,CAAC,EAAE,mBAAmB;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot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AAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;IAKvF,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;IAKtF,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;IAKxF,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;IAK/E,gBAAgB,IAAI,aAAa;CAGzC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseService } from "./base";
|
|
2
|
+
interface BlockParams {
|
|
3
|
+
name: string;
|
|
4
|
+
slug: string;
|
|
5
|
+
schema: any;
|
|
6
|
+
}
|
|
7
|
+
export declare class BlocksService extends BaseService {
|
|
8
|
+
all(): Promise<void>;
|
|
9
|
+
create({ name, slug, schema }: BlockParams): Promise<BlockParams>;
|
|
10
|
+
update(id: string, { name, slug, schema }: BlockParams): Promise<BlockParams>;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=blocks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../../src/endpoints/blocks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,GAAG,CAAC;CACb;AAED,qBAAa,aAAc,SAAQ,WAAW;IACtC,GAAG;IAEH,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,WAAW;IAK1C,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,WAAW;CAI7D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"website.d.ts","sourceRoot":"","sources":["../../../src/endpoints/website.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,qBAAa,cAAe,SAAQ,WAAW;IACvC,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"website.d.ts","sourceRoot":"","sources":["../../../src/endpoints/website.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,qBAAa,cAAe,SAAQ,WAAW;IACvC,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;IAK9B,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAKlC"}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { BlockSchema, BlockDefinition, BlockComponentProps
|
|
2
|
-
export
|
|
3
|
-
[K in keyof TFields]: TFields[K]["value"];
|
|
4
|
-
};
|
|
5
|
-
export declare function defineBlock<TFields extends Record<string, Field<any>>>(options: {
|
|
1
|
+
import { BlockSchema, BlockDefinition, BlockComponentProps } from "./types";
|
|
2
|
+
export declare function defineBlock(options: {
|
|
6
3
|
name: string;
|
|
7
4
|
slug: string;
|
|
8
|
-
schema: BlockSchema<
|
|
9
|
-
component: React.ComponentType<BlockComponentProps<
|
|
10
|
-
}): BlockDefinition<
|
|
5
|
+
schema: BlockSchema<any>;
|
|
6
|
+
component: React.ComponentType<BlockComponentProps<typeof options.schema>>;
|
|
7
|
+
}): BlockDefinition<typeof options.schema.fields>;
|
|
11
8
|
//# sourceMappingURL=define-block.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-block.d.ts","sourceRoot":"","sources":["../../../src/studio/define-block.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"define-block.d.ts","sourceRoot":"","sources":["../../../src/studio/define-block.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE5E,wBAAgB,WAAW,CAAC,OAAO,EAAE;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC;IACzB,SAAS,EAAE,KAAK,CAAC,aAAa,CAAC,mBAAmB,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;CAC5E,GAAG,eAAe,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAmBhD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-field.d.ts","sourceRoot":"","sources":["../../../src/studio/define-field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,wBAAgB,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"define-field.d.ts","sourceRoot":"","sources":["../../../src/studio/define-field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,wBAAgB,WAAW,CAAC,CAAC,SAAS,KAAK,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAExD"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { BlockSchema, Field } from "./types";
|
|
2
|
-
export
|
|
2
|
+
export type SchemaFields = Record<string, Field>;
|
|
3
|
+
export declare function defineSchema<T extends SchemaFields>(schema: BlockSchema<T>): BlockSchema<T>;
|
|
3
4
|
//# sourceMappingURL=define-schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-schema.d.ts","sourceRoot":"","sources":["../../../src/studio/define-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAE7C,
|
|
1
|
+
{"version":3,"file":"define-schema.d.ts","sourceRoot":"","sources":["../../../src/studio/define-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAE7C,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAEjD,wBAAgB,YAAY,CAAC,CAAC,SAAS,YAAY,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,kBAE1E"}
|
|
@@ -1,25 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Field, FieldType, FieldTypeToValue } from "./field";
|
|
2
|
+
type FieldValues<T extends Record<string, Field>> = {
|
|
3
|
+
[K in keyof T]: T[K] extends {
|
|
4
|
+
type: infer Type;
|
|
5
|
+
} ? (Type extends FieldType ? FieldTypeToValue[Type] : never) : never;
|
|
6
|
+
};
|
|
7
|
+
export interface BlockSchema<TFields extends Record<string, Field>> {
|
|
4
8
|
fields: TFields;
|
|
5
9
|
properties?: BlockProperties;
|
|
6
10
|
}
|
|
7
|
-
export interface BlockDefinition<TFields extends Record<string, Field
|
|
11
|
+
export interface BlockDefinition<TFields extends Record<string, Field>> {
|
|
8
12
|
name: string;
|
|
13
|
+
slug: string;
|
|
9
14
|
schema: BlockSchema<TFields>;
|
|
10
|
-
component: React.ComponentType<BlockComponentProps<
|
|
15
|
+
component: React.ComponentType<BlockComponentProps<any>>;
|
|
11
16
|
}
|
|
12
|
-
export interface
|
|
17
|
+
export interface BlockProperties {
|
|
18
|
+
customClassName?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface BuilderBlock<TSchema extends BlockSchema<Record<string, Field>>> {
|
|
13
21
|
id: string;
|
|
14
22
|
type: string;
|
|
15
|
-
fields:
|
|
23
|
+
fields: FieldValues<TSchema["fields"]>;
|
|
16
24
|
properties?: BlockProperties;
|
|
17
25
|
}
|
|
18
|
-
export interface
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export interface BlockComponentProps<TFieldValues extends Record<string, any>> {
|
|
22
|
-
block: BuilderBlock<TFieldValues>;
|
|
23
|
-
onFieldChange: (blockId: string, fieldName: keyof TFieldValues, value: any) => void;
|
|
26
|
+
export interface BlockComponentProps<TSchema extends BlockSchema<Record<string, Field>>> {
|
|
27
|
+
block: BuilderBlock<TSchema>;
|
|
28
|
+
onFieldChange: (blockId: string, fieldName: keyof TSchema["fields"], value: any) => void;
|
|
24
29
|
}
|
|
30
|
+
export {};
|
|
25
31
|
//# sourceMappingURL=block.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../../../src/studio/types/block.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../../../src/studio/types/block.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE7D,KAAK,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI;KACjD,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS;QAAE,IAAI,EAAE,MAAM,IAAI,CAAA;KAAE,GAAG,CAAC,IAAI,SAAS,SAAS,GAAG,gBAAgB,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK;CACt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+
event_select: Nullable<string>;
|
|
6
|
+
form_select: Nullable<string>;
|
|
7
|
+
image: Nullable<MediaItem>;
|
|
8
|
+
image_list: Nullable<MediaItem[]>;
|
|
9
|
+
list_array: Nullable<string[]>;
|
|
10
|
+
media: Nullable<MediaItem>;
|
|
11
|
+
menu_select: Nullable<string>;
|
|
12
|
+
number: Nullable<number>;
|
|
13
|
+
press_select: Nullable<string>;
|
|
14
|
+
repeater: Nullable<any[]>;
|
|
15
|
+
rich_text: Nullable<string>;
|
|
16
|
+
separator: never;
|
|
17
|
+
spacer: never;
|
|
18
|
+
text: Nullable<string>;
|
|
19
|
+
textarea: Nullable<string>;
|
|
20
|
+
url: Nullable<string>;
|
|
21
|
+
};
|
|
22
|
+
export type FieldType = keyof FieldTypeToValue;
|
|
23
|
+
export type BaseField = {
|
|
3
24
|
name: string;
|
|
4
25
|
slug: string;
|
|
5
|
-
type: FieldType;
|
|
6
|
-
value?: TValue;
|
|
7
26
|
placeholder?: string;
|
|
8
27
|
required?: boolean;
|
|
9
28
|
options?: Array<{
|
|
10
29
|
label: string;
|
|
11
30
|
value: any;
|
|
12
31
|
}>;
|
|
13
|
-
}
|
|
32
|
+
};
|
|
33
|
+
export type Field = {
|
|
34
|
+
[K in FieldType]: BaseField & {
|
|
35
|
+
type: K;
|
|
36
|
+
value?: FieldTypeToValue[K];
|
|
37
|
+
};
|
|
38
|
+
}[FieldType];
|
|
39
|
+
export {};
|
|
14
40
|
//# sourceMappingURL=field.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../../src/studio/types/field.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../../src/studio/types/field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAE5B,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K,GAAG;KACjB,CAAC,IAAI,SAAS,GAAG,SAAS,GAAG;QAC5B,IAAI,EAAE,CAAC,CAAC;QACR,KAAK,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;KAC7B;CACF,CAAC,SAAS,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosError } from "axios";
|
|
2
2
|
import { getGlobalConfig, BackstageUserConfig } from "./config";
|
|
3
3
|
import { AlertService } from "./endpoints/alerts";
|
|
4
|
+
import { BlocksService } from "./endpoints/blocks";
|
|
4
5
|
import { EventService } from "./endpoints/events";
|
|
5
6
|
import { LocationService } from "./endpoints/locations";
|
|
6
7
|
import { MenuService } from "./endpoints/menus";
|
|
@@ -14,6 +15,7 @@ export class BackstageClient {
|
|
|
14
15
|
|
|
15
16
|
// Service Instances
|
|
16
17
|
public readonly alerts: AlertService;
|
|
18
|
+
public readonly blocks: BlocksService;
|
|
17
19
|
public readonly events: EventService;
|
|
18
20
|
public readonly locations: LocationService;
|
|
19
21
|
public readonly menus: MenuService;
|
|
@@ -81,6 +83,7 @@ export class BackstageClient {
|
|
|
81
83
|
|
|
82
84
|
// Initialize service instances
|
|
83
85
|
this.alerts = new AlertService(this);
|
|
86
|
+
this.blocks = new BlocksService(this);
|
|
84
87
|
this.events = new EventService(this);
|
|
85
88
|
this.locations = new LocationService(this);
|
|
86
89
|
this.menus = new MenuService(this);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ApiSingleResponse } from "../types";
|
|
2
|
+
import { BaseService } from "./base";
|
|
3
|
+
|
|
4
|
+
interface BlockParams {
|
|
5
|
+
name: string;
|
|
6
|
+
slug: string;
|
|
7
|
+
schema: any;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class BlocksService extends BaseService {
|
|
11
|
+
async all() {}
|
|
12
|
+
|
|
13
|
+
async create({ name, slug, schema }: BlockParams) {
|
|
14
|
+
const res = await this.client.post<ApiSingleResponse<BlockParams>>("/blocks", { name, slug, schema });
|
|
15
|
+
return res.data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async update(id: string, { name, slug, schema }: BlockParams) {
|
|
19
|
+
const res = await this.client.put<ApiSingleResponse<BlockParams>>(`/blocks/${id}`, { name, slug, schema });
|
|
20
|
+
return res.data;
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/endpoints/website.ts
CHANGED
|
@@ -6,4 +6,10 @@ export class WebsiteService extends BaseService {
|
|
|
6
6
|
const res = await this.client.get<ApiCollectionResponse<Website>>("/websites");
|
|
7
7
|
return res.data[0];
|
|
8
8
|
}
|
|
9
|
+
|
|
10
|
+
async routes(): Promise<string[]> {
|
|
11
|
+
const website = await this.getWebsite();
|
|
12
|
+
|
|
13
|
+
return this.client.get<string[]>(`/websites/${website.id}/routes`);
|
|
14
|
+
}
|
|
9
15
|
}
|
|
@@ -1,14 +1,27 @@
|
|
|
1
|
-
import { BlockSchema, BlockDefinition, BlockComponentProps
|
|
1
|
+
import { BlockSchema, BlockDefinition, BlockComponentProps } from "./types";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
[K in keyof TFields]: TFields[K]["value"];
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export function defineBlock<TFields extends Record<string, Field<any>>>(options: {
|
|
3
|
+
export function defineBlock(options: {
|
|
8
4
|
name: string;
|
|
9
5
|
slug: string;
|
|
10
|
-
schema: BlockSchema<
|
|
11
|
-
component: React.ComponentType<BlockComponentProps<
|
|
12
|
-
}): BlockDefinition<
|
|
6
|
+
schema: BlockSchema<any>;
|
|
7
|
+
component: React.ComponentType<BlockComponentProps<typeof options.schema>>;
|
|
8
|
+
}): BlockDefinition<typeof options.schema.fields> {
|
|
9
|
+
// Runtime validation
|
|
10
|
+
if (!options.name || typeof options.name !== "string") {
|
|
11
|
+
throw new Error("Block name is required and must be a string");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (!options.slug || typeof options.slug !== "string") {
|
|
15
|
+
throw new Error("Block slug is required and must be a string");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (!options.schema || typeof options.schema !== "object") {
|
|
19
|
+
throw new Error("Block schema is required and must be an object");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!options.component) {
|
|
23
|
+
throw new Error("Block component is required");
|
|
24
|
+
}
|
|
25
|
+
|
|
13
26
|
return options;
|
|
14
27
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { BlockSchema, Field } from "./types";
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export type SchemaFields = Record<string, Field>;
|
|
4
|
+
|
|
5
|
+
export function defineSchema<T extends SchemaFields>(schema: BlockSchema<T>) {
|
|
4
6
|
return schema;
|
|
5
7
|
}
|
|
@@ -1,29 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Field } from "./field";
|
|
1
|
+
import { Field, FieldType, FieldTypeToValue } from "./field";
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
type FieldValues<T extends Record<string, Field>> = {
|
|
4
|
+
[K in keyof T]: T[K] extends { type: infer Type } ? (Type extends FieldType ? FieldTypeToValue[Type] : never) : never;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export interface BlockSchema<TFields extends Record<string, Field>> {
|
|
5
8
|
fields: TFields;
|
|
6
9
|
properties?: BlockProperties;
|
|
7
10
|
}
|
|
8
11
|
|
|
9
|
-
export interface BlockDefinition<TFields extends Record<string, Field
|
|
12
|
+
export interface BlockDefinition<TFields extends Record<string, Field>> {
|
|
10
13
|
name: string;
|
|
14
|
+
slug: string;
|
|
11
15
|
schema: BlockSchema<TFields>;
|
|
12
|
-
component: React.ComponentType<BlockComponentProps<
|
|
16
|
+
component: React.ComponentType<BlockComponentProps<any>>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface BlockProperties {
|
|
20
|
+
customClassName?: string;
|
|
13
21
|
}
|
|
14
22
|
|
|
15
|
-
export interface BuilderBlock<
|
|
23
|
+
export interface BuilderBlock<TSchema extends BlockSchema<Record<string, Field>>> {
|
|
16
24
|
id: string;
|
|
17
25
|
type: string;
|
|
18
|
-
fields:
|
|
26
|
+
fields: FieldValues<TSchema["fields"]>;
|
|
19
27
|
properties?: BlockProperties;
|
|
20
28
|
}
|
|
21
29
|
|
|
22
|
-
export interface
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export interface BlockComponentProps<TFieldValues extends Record<string, any>> {
|
|
27
|
-
block: BuilderBlock<TFieldValues>;
|
|
28
|
-
onFieldChange: (blockId: string, fieldName: keyof TFieldValues, value: any) => void;
|
|
30
|
+
export interface BlockComponentProps<TSchema extends BlockSchema<Record<string, Field>>> {
|
|
31
|
+
block: BuilderBlock<TSchema>;
|
|
32
|
+
onFieldChange: (blockId: string, fieldName: keyof TSchema["fields"], value: any) => void;
|
|
29
33
|
}
|
|
@@ -1,28 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
| "boolean"
|
|
3
|
-
| "event_select"
|
|
4
|
-
| "form_select"
|
|
5
|
-
| "image"
|
|
6
|
-
| "image_list"
|
|
7
|
-
| "list_array"
|
|
8
|
-
| "media"
|
|
9
|
-
| "menu_select"
|
|
10
|
-
| "number"
|
|
11
|
-
| "press_select"
|
|
12
|
-
| "repeater"
|
|
13
|
-
| "rich_text"
|
|
14
|
-
| "separator"
|
|
15
|
-
| "spacer"
|
|
16
|
-
| "text"
|
|
17
|
-
| "textarea"
|
|
18
|
-
| "url";
|
|
1
|
+
import { MediaItem } from "../../types";
|
|
19
2
|
|
|
20
|
-
|
|
3
|
+
type Nullable<T> = T | null;
|
|
4
|
+
|
|
5
|
+
export type FieldTypeToValue = {
|
|
6
|
+
boolean: Nullable<boolean>;
|
|
7
|
+
event_select: Nullable<string>;
|
|
8
|
+
form_select: Nullable<string>;
|
|
9
|
+
image: Nullable<MediaItem>;
|
|
10
|
+
image_list: Nullable<MediaItem[]>;
|
|
11
|
+
list_array: Nullable<string[]>;
|
|
12
|
+
media: Nullable<MediaItem>;
|
|
13
|
+
menu_select: Nullable<string>;
|
|
14
|
+
number: Nullable<number>;
|
|
15
|
+
press_select: Nullable<string>;
|
|
16
|
+
repeater: Nullable<any[]>;
|
|
17
|
+
rich_text: Nullable<string>;
|
|
18
|
+
separator: never;
|
|
19
|
+
spacer: never;
|
|
20
|
+
text: Nullable<string>;
|
|
21
|
+
textarea: Nullable<string>;
|
|
22
|
+
url: Nullable<string>;
|
|
23
|
+
};
|
|
24
|
+
export type FieldType = keyof FieldTypeToValue;
|
|
25
|
+
|
|
26
|
+
export type BaseField = {
|
|
21
27
|
name: string;
|
|
22
28
|
slug: string;
|
|
23
|
-
type: FieldType;
|
|
24
|
-
value?: TValue;
|
|
25
29
|
placeholder?: string;
|
|
26
30
|
required?: boolean;
|
|
27
31
|
options?: Array<{ label: string; value: any }>;
|
|
28
|
-
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type Field = {
|
|
35
|
+
[K in FieldType]: BaseField & {
|
|
36
|
+
type: K;
|
|
37
|
+
value?: FieldTypeToValue[K];
|
|
38
|
+
};
|
|
39
|
+
}[FieldType];
|
|
40
|
+
|
|
41
|
+
// export interface Field<T extends FieldType = FieldType> {
|
|
42
|
+
// name: string;
|
|
43
|
+
// slug: string;
|
|
44
|
+
// type: FieldType;
|
|
45
|
+
// value?: FieldTypeToValue[T];
|
|
46
|
+
// placeholder?: string;
|
|
47
|
+
// required?: boolean;
|
|
48
|
+
// options?: Array<{ label: string; value: any }>;
|
|
49
|
+
// }
|