@superblocksteam/cli 2.0.0-next.6 → 2.0.0-next.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ $ npm install -g @superblocksteam/cli
|
|
|
14
14
|
$ superblocks COMMAND
|
|
15
15
|
running command...
|
|
16
16
|
$ superblocks (--version)
|
|
17
|
-
@superblocksteam/cli/2.0.0-next.
|
|
17
|
+
@superblocksteam/cli/2.0.0-next.8 linux-x64 node-v20.19.0
|
|
18
18
|
$ superblocks --help [COMMAND]
|
|
19
19
|
USAGE
|
|
20
20
|
$ superblocks COMMAND
|
|
@@ -24,7 +24,7 @@ init_cjs_shims();
|
|
|
24
24
|
|
|
25
25
|
// ../../../vite-plugin-file-sync/dist/ai-service/prompts/generated/subprompts/superblocks-api.js
|
|
26
26
|
init_cjs_shims();
|
|
27
|
-
var content = '### APIs\n\nThe Superblocks framework allows you to create backend APIs. The high level structure for creating APIs is as follows:\n\n1. APIs are defined using TypeScript files that live inside the apis directory inside the page they are scoped to. Example: /pages/Page1/apis/myApi.ts\n2. This pattern is a declarative workflow builder, where you define each API step, its configuration, and its execution order within the API workflow.\n3. To make the API available for use, you must import it into the scope file and register it with `SbApi()`, then import and destructure it in your page component for use.\n\n#### Example of creating and then registering a Superblocks API:\n\nCRITICAL: The name of the API must be consistent across the API\'s TypeScript definition, the API\'s file name, references in page files, and the key used to register it in the scope file. See the consistent use of \'myApi\' below as an example.\n\nCreate the API by adding the myApi.ts file:\n\n```ts\n// Path to this API definition: /pages/Page1/apis/myApi.ts\n\nimport { Api, JavaScript } from "@superblocksteam/library";\n\nexport default new Api("myApi", [\n new JavaScript("retrieve_orders", {\n fn: () => {\n return [\n {\n id: "ORD-001",\n customerName: "John Smith",\n total: 149.99,\n },\n {\n id: "ORD-002",\n customerName: "Sarah Jones",\n total: 89.5,\n },\n ];\n },\n }),\n]);\n```\n\nThen register the myApi API in the scope file:\n\n```ts\n// /pages/Page1/scope.ts\nimport { createSbScope, SbApi } from "@superblocksteam/library";\n\nexport const Page1Scope = createSbScope(\n () => ({\n // Register the API in the scope\n myApi: SbApi({}),\n }),\n {\n name: "Page1",\n },\n);\n\nexport const Page1 = Page1Scope.entities;\n```\n\nThen use the API in your page component:\n\n```tsx\n// /pages/Page1/index.tsx\n\nimport {\n SbPage,\n SbSection,\n SbColumn,\n SbButton,\n SbTable,\n sbComputed,\n SbEventFlow,\n registerPage,\n} from "@superblocksteam/library";\nimport { Page1, Page1Scope } from "./scope";\n\nconst Page1Component = () => {\n // Destructure the API from the scope entities to access its response\n const { myApi } = Page1;\n\n return (\n <SbPage name="Page1" height={Dim.fill()} width={Dim.fill()}>\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>\n <SbButton\n // APIs can be invoked with the SbEventFlow API\n onClick={SbEventFlow.runApis([myApi])}\n label="Fetch Data"\n />\n {/* Access API response using sbComputed */}\n <SbTable tableData={sbComputed(() => myApi.response)} />\n </SbColumn>\n </SbSection>\n </SbPage>\n );\n};\n\nexport default registerPage(Page1Component, Page1Scope);\n```\n\n#### Example 2: API where a step references the output of a previous step\n\nThink hard about how you access the output of previous steps. You MUST use the output property of the previous step variable. There is no other way to access the output of a previous step (other than using a Variable block, but that is not what you want in this case and should only be used in very specific cases).\n\n```ts\n// Path to this api would be: /pages/Page1/apis/getOrders.ts\n\nimport { JavaScript, Api } from "@superblocksteam/library";\n\nexport default new Api("getOrders", [\n new JavaScript("retrieve_orders", {\n fn: () => {\n return [\n {\n id: 1,\n customer: "John Smith",\n date: "2024-01-15",\n total: 199.99,\n status: "Pending",\n },\n {\n id: 2,\n customer: "Jane Doe",\n date: "2024-01-14",\n total: 149.99,\n status: "Shipped",\n },\n {\n id: 3,\n customer: "Bob Wilson",\n date: "2024-01-13",\n total: 299.99,\n status: "Delivered",\n },\n ];\n },\n }),\n new JavaScript("format_orders", {\n fn: ({ retrieve_orders }) => {\n return retrieve_orders.output.map((order) => ({\n ...order,\n date: new Date(order.date).toLocaleDateString(),\n }));\n },\n }),\n]);\n```\n\nThen you would register the API in your scope file and use it in your page component:\n\n```ts\n// /pages/Page1/scope.ts\nexport const Page1Scope = createSbScope(\n () => ({\n getOrders: SbApi({}),\n }),\n {\n name: "Page1",\n },\n);\n```\n\n```tsx\n// /pages/Page1/index.tsx\nimport {\n SbPage,\n SbSection,\n SbColumn,\n SbTable,\n sbComputed,\n registerPage,\n} from "@superblocksteam/library";\nimport { Page1, Page1Scope } from "./scope";\n\nconst Page1Component = () => {\n const { getOrders } = Page1;\n\n return (\n <SbPage name="Page1" height={Dim.fill()} width={Dim.fill()}>\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>\n <SbTable tableData={sbComputed(() => getOrders.response)} />\n </SbColumn>\n </SbSection>\n </SbPage>\n );\n};\n\nexport default registerPage(Page1Component, Page1Scope);\n```\n\n#### The Superblocks API TypeScript Type\n\nBelow is the full TypeScript spec for the APIs you create:\n\n````ts\n// @superblocksteam/types\n\nexport type JsonValue =\n | undefined\n | null\n | number\n | string\n | boolean\n | JsonValue[]\n | object;\nexport type State = { [key: string]: JsonValue };\nexport type Binding<T> = T | ((state: State) => T);\ntype Integrations = { id: string; description: string; metadata: JsonValue }[];\n\nclass Block {\n constructor(name: string) {}\n public run(): { output: JsonValue } {\n /* ... */\n }\n}\n\nclass Integration extends Block {\n constructor(name: string, integration_id: string) {}\n}\n\ntype State = Record<string, JsonValue>;\n\nclass JavaScript extends Integration {\n constructor(\n name: string,\n config: {\n fn: (\n {\n /* ... */\n },\n ) => JsonValue;\n },\n ) {\n super(name, "javascript");\n }\n}\n\nclass Python extends Integration {\n constructor(\n name: string,\n config: {\n // We want to just put the python function body here. The scope is the same as it would be if it were a JavaScript integration.\n fn: string;\n },\n ) {\n super(name, "python");\n }\n}\n\nclass Databricks extends Integration {\n static integrations: Integrations = [\n /* ... */\n ];\n\n /**\n * @param {string} name The name of the block.\n * @param {string} integration_id The id of the integration.\n * @param {object} config The config object.\n * @returns {void}\n */\n constructor(\n name: string,\n integration_id: string,\n config: {\n statement: Binding<string>;\n },\n ) {\n super(name, integration_id);\n }\n}\n\nclass Snowflake extends Integration {\n static integrations: Integrations = [\n /* ... */\n ];\n\n /**\n * @param {string} name The name of the block.\n * @param {string} integration_id The id of the integration.\n * @param {object} config The config object.\n * @returns {void}\n */\n constructor(\n name: string,\n integration_id: string,\n config: {\n statement: Binding<string>;\n },\n ) {\n super(name, integration_id);\n }\n}\n\nclass PostgreSQL extends Integration {\n static integrations: Integrations = [\n /* ... */\n ];\n\n /**\n * @param {string} name The name of the block.\n * @param {string} integration_id The id of the integration.\n * @param {object} config The config object.\n * @returns {void}\n */\n constructor(\n name: string,\n integration_id: string,\n config: {\n statement: Binding<string>;\n },\n ) {\n super(name, integration_id);\n }\n}\n\nclass RestApi extends Integration {\n constructor(\n name: string,\n config: {\n method:\n | "GET"\n | "POST"\n | "PUT"\n | "DELETE"\n | "PATCH"\n | "OPTIONS"\n | "HEAD"\n | "TRACE"\n | "CONNECT";\n url:\n | string\n | ((\n {\n /* ... */\n },\n ) => string);\n },\n ) {\n super(name);\n }\n}\n\nclass Email extends Integration {\n constructor(\n name: string,\n config: {\n from: Binding<string>;\n to: Binding<string>;\n subject: Binding<string>;\n cc?: Binding<string>;\n bcc?: Binding<string>;\n body?: Binding<string>;\n },\n ) {\n super(name);\n }\n}\n\nexport type Condition = {\n when: boolean | ((state: State) => boolean);\n then: Block[];\n};\n\nexport type Conditions = {\n if: Condition;\n elif?: Condition[];\n else?: Block[];\n};\n\nclass Conditional extends Block {\n constructor(name: string, config: Conditions) {\n super(name);\n }\n}\n\nclass TryCatch extends Block {\n constructor(\n name: string,\n config: {\n try: Block[];\n catch: Block[];\n finally?: Block[];\n variables: { error: string };\n },\n ) {\n super(name);\n }\n}\n\n/**\n * A Superblocks variable has the following access pattern:\n *\n * How to retrieve the value of a variable:\n * ```ts\n * CORRECT\n * my_variable.value\n *\n * // INCORRECT\n * my_variable\n * ```\n *\n * How to set the value of a variable:\n * ```ts\n * CORRECT\n * my_variable.set(value)\n *\n * // INCORRECT\n * my_variable = value\n * ```\n *\n */\n\nclass Variables extends Block {\n constructor(\n name: string,\n variables: {\n // The name of the variable.\n key: string;\n // The value of the variable.\n value: Binding<JsonValue>;\n }[],\n ) {\n super(name);\n }\n}\n\nclass Loop extends Block {\n constructor(\n name: string,\n config: {\n over: Binding<JsonValue[]>;\n variables: {\n // What the variable name for the current item is.\n item: string;\n // What the variable name for the current index is.\n index: string;\n };\n blocks: Block[];\n },\n ) {\n super(name);\n }\n}\n\nclass Parallel extends Block {\n constructor(\n name: string,\n config: {\n over: Binding<JsonValue[]>;\n variables: {\n // What the variable name for the current item is.\n item: string;\n };\n blocks: Block[];\n },\n ) {\n super(name);\n }\n}\n\nclass Throw extends Block {\n constructor(\n name: string,\n config: {\n error: Binding<JsonValue>;\n },\n ) {\n super(name);\n }\n}\n\nclass Return extends Block {\n constructor(\n name: string,\n config: {\n data: Binding<JsonValue>;\n },\n ) {\n super(name);\n }\n}\n\nclass Api {\n constructor(name: string, steps: Block[]) {}\n public get response(): JsonValue {\n /* ... */\n }\n public get error(): string | undefined {\n /* ... */\n }\n public run(): void {\n /* ... */\n }\n public cancel(): void {\n /* ... */\n }\n}\n````\n\n#### Example Usage\n\nBelow are examples of how you create Superblocks APIs, along with annotations to describe different pieces of functinality and expectations.\n\n##### Example 1: Simple API with conditional\n\n```ts\n// Path to this api would be: /pages/Page1/apis/getOrders.ts\n\nimport {\n Conditional,\n Condition,\n PostgreSQL,\n JavaScript,\n Api,\n} from "@superblocksteam/library";\n\nexport default new Api("getOrders", [\n new Conditional("my_conditional", {\n if: {\n when: true,\n then: [\n new PostgreSQL(\n "retrieve_orders",\n "" /* <- integration uuid goes here */,\n {\n statement: "SELECT * FROM orders",\n },\n ),\n ],\n },\n else: [\n new JavaScript("fallthrough", {\n fn: () => "we did not execute the sql query",\n }),\n ],\n }),\n]);\n```\n\nTo run register and run the API we defined above:\n\n```tsx\n// /pages/Page1/index.tsx\n\nimport {\n SbPage,\n SbApi,\n SbSection,\n SbColumn,\n SbTable,\n SbButton,\n SbEventFlow,\n registerPage,\n showAlert,\n} from "@superblocksteam/library";\n\nimport getOrders from "./apis/getOrders";\n\nconst Page1 = () => (\n <SbPage name="Page1" height={Dim.fill()} width={Dim.fill()}>\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>\n <SbButton\n // APIs can be invoked with the SBEventFlow API.\n onClick={SbEventFlow.runApis([getOrders])}\n />\n // ...\n <SbTable>\n // APIs are part of the state object just like components. tableData=\n {(state) => state.getOrders.response}\n </SbTable>\n </SbColumn>\n </SbSection>\n </SbPage>\n);\n\nexport default registerPage(Page1, {\n name: "MyPage",\n // You register APIs just like you would SbVariables.\n getOrders: SbApi(getOrders),\n});\n```\n\n#### Rules for using Superblocks APIs\n\nThink hard about the following important rules for correctly using Superblocks APIs:\n\n- You MUST use a destructured state object as the function parameter for dynamic block fields. The valid keys are (1) Superblocks entities (components, variables, etc) and (2) previous block outputs that are in the lexical scope. Example below:\n\n```ts\n// CORRECT: uses destructured state\n({ Dropdown1, TextInput1 }) => Dropdown1.selectedOptionsValue + TextInput1.value\n\n// INCORRECT: uses state object directly\n(state) => state.Dropdown1.selectedOptionsValue + state.TextInput1.value\n```\n\n- The result of each scope is the result of the last block in that scope. In the following example, the value of `sendEmail.response` is the result of the `return_summary` block. Use this information to carefully ensure that the last block in your API is the one that returns the value you want.\n\n```ts\nexport default new Api("sendEmail", [\n new Email("send_email", {\n from: "noreply@company.com",\n to: "test@test.com",\n subject: "Test Email",\n body: "This is a test email",\n }),\n new JavaScript("return_summary", {\n fn: () => "Email sent successfully!",\n }),\n]);\n```\n\n```tsx\nimport {\n SbPage,\n SbSection,\n SbColumn,\n SbTable,\n sbComputed,\n registerPage,\n SbApi,\n} from "@superblocksteam/library";\n\nconst scope = createSbScope<{\n Table1: any;\n}>({ sendEmail: SbApi({}) }, { name: "Page1" });\n\nexport default registerPage(\n () => (\n <SbPage name="Page1" height={Dim.fill()} width={Dim.fill()}>\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>\n // ...\n <SbTable\n bind={scope.entities.Table1}\n tableData={sbComputed(() => API1.response)}\n />\n // ...\n </SbColumn>\n </SbSection>\n </SbPage>\n ),\n scope,\n);\n```\n\n- Block outputs are immutable. Do not mutate the output of a block.\n\n- Do not reference variables that are not in scope. The ONLY things in scope in an API block are the outputs of previous steps and the state object.\n\n- Backend APIs CANNOT mutate frontend state inside of the API\n\n- APIs are registered in scope files using `SbApi()` and then accessed in page components by destructuring from the scope entities. Make sure you name the key used in registerScope the same as the imported API, but do not pass the imported Api into the SbApi() call.\n\n- To access API responses in your UI, use `sbComputed(() => apiName.response)` or `sbComputed(() => apiName.error)`.\n\n- You will not always be told which integrations to use in your API; you will have to determine that yourself based on the data you need to fetch.\n\n- Never add comments to code you (the ai) generate. User added comments are fine - leave those!\n';
|
|
27
|
+
var content = '### APIs\n\nThe Superblocks framework allows you to create backend APIs. The high level structure for creating APIs is as follows:\n\n1. APIs are defined using TypeScript files that live inside the apis directory inside the page they are scoped to. Example: /pages/Page1/apis/myApi.ts\n2. This pattern is a declarative workflow builder, where you define each API step, its configuration, and its execution order within the API workflow.\n3. To make the API available for use, you must import it into the scope file and register it with `SbApi()`, then import and destructure it in your page component for use.\n\n#### Example of creating and then registering a Superblocks API:\n\nCRITICAL: The name of the API must be consistent across the API\'s TypeScript definition, the API\'s file name, references in page files, and the key used to register it in the scope file. See the consistent use of \'myApi\' below as an example.\n\nCreate the API by adding the myApi.ts file:\n\n```ts\n// Path to this API definition: /pages/Page1/apis/myApi.ts\n\nimport { Api, JavaScript } from "@superblocksteam/library";\n\nexport default new Api("myApi", [\n new JavaScript("retrieve_orders", {\n fn: () => {\n return [\n {\n id: "ORD-001",\n customerName: "John Smith",\n total: 149.99,\n },\n {\n id: "ORD-002",\n customerName: "Sarah Jones",\n total: 89.5,\n },\n ];\n },\n }),\n]);\n```\n\nThen register the myApi API in the scope file:\n\n```ts\n// /pages/Page1/scope.ts\nimport { createSbScope, SbApi } from "@superblocksteam/library";\n\nexport const Page1Scope = createSbScope(\n () => ({\n // Register the API in the scope\n myApi: SbApi({}),\n }),\n {\n name: "Page1",\n },\n);\n\nexport const Page1 = Page1Scope.entities;\n```\n\nThen use the API in your page component:\n\n```tsx\n// /pages/Page1/index.tsx\n\nimport {\n SbPage,\n SbSection,\n SbColumn,\n SbButton,\n SbTable,\n sbComputed,\n SbEventFlow,\n registerPage,\n} from "@superblocksteam/library";\nimport { Page1, Page1Scope } from "./scope";\n\nconst Page1Component = () => {\n // Destructure the API from the scope entities to access its response\n const { myApi } = Page1;\n\n return (\n <SbPage name="Page1" height={Dim.fill()} width={Dim.fill()}>\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>\n <SbButton\n // APIs can be invoked with the SbEventFlow API\n onClick={SbEventFlow.runApis([myApi])}\n label="Fetch Data"\n />\n {/* Access API response using sbComputed */}\n <SbTable tableData={sbComputed(() => myApi.response)} />\n </SbColumn>\n </SbSection>\n </SbPage>\n );\n};\n\nexport default registerPage(Page1Component, Page1Scope);\n```\n\n#### Example 2: API where a step references the output of a previous step\n\nThink hard about how you access the output of previous steps. You MUST use the output property of the previous step variable. There is no other way to access the output of a previous step (other than using a Variable block, but that is not what you want in this case and should only be used in very specific cases).\n\n```ts\n// Path to this api would be: /pages/Page1/apis/getOrders.ts\n\nimport { JavaScript, Api } from "@superblocksteam/library";\n\nexport default new Api("getOrders", [\n new JavaScript("retrieve_orders", {\n fn: () => {\n return [\n {\n id: 1,\n customer: "John Smith",\n date: "2024-01-15",\n total: 199.99,\n status: "Pending",\n },\n {\n id: 2,\n customer: "Jane Doe",\n date: "2024-01-14",\n total: 149.99,\n status: "Shipped",\n },\n {\n id: 3,\n customer: "Bob Wilson",\n date: "2024-01-13",\n total: 299.99,\n status: "Delivered",\n },\n ];\n },\n }),\n new JavaScript("format_orders", {\n fn: ({ retrieve_orders }) => {\n return retrieve_orders.output.map((order) => ({\n ...order,\n date: new Date(order.date).toLocaleDateString(),\n }));\n },\n }),\n]);\n```\n\nThen you would register the API in your scope file and use it in your page component:\n\n```ts\n// /pages/Page1/scope.ts\nexport const Page1Scope = createSbScope(\n () => ({\n getOrders: SbApi({}),\n }),\n {\n name: "Page1",\n },\n);\n```\n\n```tsx\n// /pages/Page1/index.tsx\nimport {\n SbPage,\n SbSection,\n SbColumn,\n SbTable,\n sbComputed,\n registerPage,\n} from "@superblocksteam/library";\nimport { Page1, Page1Scope } from "./scope";\n\nconst Page1Component = () => {\n const { getOrders } = Page1;\n\n return (\n <SbPage name="Page1" height={Dim.fill()} width={Dim.fill()}>\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>\n <SbTable tableData={sbComputed(() => getOrders.response)} />\n </SbColumn>\n </SbSection>\n </SbPage>\n );\n};\n\nexport default registerPage(Page1Component, Page1Scope);\n```\n\n#### The Superblocks API TypeScript Type\n\nBelow is the full TypeScript spec for the APIs you create:\n\n````ts\n// @superblocksteam/types\n\nexport type JsonValue =\n | undefined\n | null\n | number\n | string\n | boolean\n | JsonValue[]\n | object;\nexport type State = { [key: string]: JsonValue };\nexport type Binding<T> = T | ((state: State) => T);\ntype Integrations = { id: string; description: string; metadata: JsonValue }[];\n\nclass Block {\n constructor(name: string) {}\n public run(): { output: JsonValue } {\n /* ... */\n }\n}\n\nclass Integration extends Block {\n constructor(name: string, integration_id: string) {}\n}\n\ntype State = Record<string, JsonValue>;\n\nclass JavaScript extends Integration {\n constructor(\n name: string,\n config: {\n fn: (\n {\n /* ... */\n },\n ) => JsonValue;\n },\n ) {\n super(name, "javascript");\n }\n}\n\nclass Python extends Integration {\n constructor(\n name: string,\n config: {\n // We want to just put the python function body here. The scope is the same as it would be if it were a JavaScript integration.\n fn: string;\n },\n ) {\n super(name, "python");\n }\n}\n\nclass Databricks extends Integration {\n static integrations: Integrations = [\n /* ... */\n ];\n\n /**\n * @param {string} name The name of the block.\n * @param {string} integration_id The id of the integration.\n * @param {object} config The config object.\n * @returns {void}\n */\n constructor(\n name: string,\n integration_id: string,\n config: {\n statement: Binding<string>;\n },\n ) {\n super(name, integration_id);\n }\n}\n\nclass Snowflake extends Integration {\n static integrations: Integrations = [\n /* ... */\n ];\n\n /**\n * @param {string} name The name of the block.\n * @param {string} integration_id The id of the integration.\n * @param {object} config The config object.\n * @returns {void}\n */\n constructor(\n name: string,\n integration_id: string,\n config: {\n statement: Binding<string>;\n },\n ) {\n super(name, integration_id);\n }\n}\n\nclass PostgreSQL extends Integration {\n static integrations: Integrations = [\n /* ... */\n ];\n\n /**\n * @param {string} name The name of the block.\n * @param {string} integration_id The id of the integration.\n * @param {object} config The config object.\n * @returns {void}\n */\n constructor(\n name: string,\n integration_id: string,\n config: {\n statement: Binding<string>;\n },\n ) {\n super(name, integration_id);\n }\n}\n\nclass RestApi extends Integration {\n constructor(\n name: string,\n config: {\n method:\n | "GET"\n | "POST"\n | "PUT"\n | "DELETE"\n | "PATCH"\n | "OPTIONS"\n | "HEAD"\n | "TRACE"\n | "CONNECT";\n url:\n | string\n | ((\n {\n /* ... */\n },\n ) => string);\n },\n ) {\n super(name);\n }\n}\n\nclass Email extends Integration {\n constructor(\n name: string,\n config: {\n from: Binding<string>;\n to: Binding<string>;\n subject: Binding<string>;\n cc?: Binding<string>;\n bcc?: Binding<string>;\n body?: Binding<string>;\n },\n ) {\n super(name);\n }\n}\n\nexport type Condition = {\n when: boolean | ((state: State) => boolean);\n then: Block[];\n};\n\nexport type Conditions = {\n if: Condition;\n elif?: Condition[];\n else?: Block[];\n};\n\nclass Conditional extends Block {\n constructor(name: string, config: Conditions) {\n super(name);\n }\n}\n\nclass TryCatch extends Block {\n constructor(\n name: string,\n config: {\n try: Block[];\n catch: Block[];\n finally?: Block[];\n variables: { error: string };\n },\n ) {\n super(name);\n }\n}\n\n/**\n * A Superblocks variable has the following access pattern:\n *\n * How to retrieve the value of a variable:\n * ```ts\n * CORRECT\n * my_variable.value\n *\n * // INCORRECT\n * my_variable\n * ```\n *\n * How to set the value of a variable:\n * ```ts\n * CORRECT\n * my_variable.set(value)\n *\n * // INCORRECT\n * my_variable = value\n * ```\n *\n */\n\nclass Variables extends Block {\n constructor(\n name: string,\n variables: {\n // The name of the variable.\n key: string;\n // The value of the variable.\n value: Binding<JsonValue>;\n }[],\n ) {\n super(name);\n }\n}\n\nclass Loop extends Block {\n constructor(\n name: string,\n config: {\n over: Binding<JsonValue[]>;\n variables: {\n // What the variable name for the current item is.\n item: string;\n // What the variable name for the current index is.\n index: string;\n };\n blocks: Block[];\n },\n ) {\n super(name);\n }\n}\n\nclass Parallel extends Block {\n constructor(\n name: string,\n config: {\n over: Binding<JsonValue[]>;\n variables: {\n // What the variable name for the current item is.\n item: string;\n };\n blocks: Block[];\n },\n ) {\n super(name);\n }\n}\n\nclass Throw extends Block {\n constructor(\n name: string,\n config: {\n error: Binding<JsonValue>;\n },\n ) {\n super(name);\n }\n}\n\nclass Return extends Block {\n constructor(\n name: string,\n config: {\n data: Binding<JsonValue>;\n },\n ) {\n super(name);\n }\n}\n\nclass Api {\n constructor(name: string, steps: Block[]) {}\n public get response(): JsonValue {\n /* ... */\n }\n public get error(): string | undefined {\n /* ... */\n }\n public run(): void {\n /* ... */\n }\n public cancel(): void {\n /* ... */\n }\n}\n````\n\n#### Example Usage\n\nBelow are examples of how you create Superblocks APIs, along with annotations to describe different pieces of functinality and expectations.\n\n##### Example 1: Simple API with conditional\n\n```ts\n// Path to this api would be: /pages/Page1/apis/getOrders.ts\n\nimport {\n Conditional,\n Condition,\n PostgreSQL,\n JavaScript,\n Api,\n} from "@superblocksteam/library";\n\nexport default new Api("getOrders", [\n new Conditional("my_conditional", {\n if: {\n when: true,\n then: [\n new PostgreSQL(\n "retrieve_orders",\n "" /* <- integration uuid goes here */,\n {\n statement: "SELECT * FROM orders",\n },\n ),\n ],\n },\n else: [\n new JavaScript("fallthrough", {\n fn: () => "we did not execute the sql query",\n }),\n ],\n }),\n]);\n```\n\nTo run register and run the API we defined above:\n\n```tsx\n// /pages/Page1/index.tsx\n\nimport {\n SbPage,\n SbApi,\n SbSection,\n SbColumn,\n SbTable,\n SbButton,\n SbEventFlow,\n registerPage,\n showAlert,\n} from "@superblocksteam/library";\n\nimport getOrders from "./apis/getOrders";\n\nconst Page1 = () => (\n <SbPage name="Page1" height={Dim.fill()} width={Dim.fill()}>\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>\n <SbButton\n // APIs can be invoked with the SBEventFlow API.\n onClick={SbEventFlow.runApis([getOrders])}\n />\n // ...\n <SbTable>\n // APIs are part of the state object just like components. tableData=\n {(state) => state.getOrders.response}\n </SbTable>\n </SbColumn>\n </SbSection>\n </SbPage>\n);\n\nexport default registerPage(Page1, {\n name: "MyPage",\n // You register APIs just like you would SbVariables.\n getOrders: SbApi(getOrders),\n});\n```\n\n#### Rules for using Superblocks APIs\n\nThink hard about the following important rules for correctly using Superblocks APIs:\n\n- You MUST use a destructured state object as the function parameter for dynamic block fields. The valid keys are (1) Superblocks entities (components, variables, etc) and (2) previous block outputs that are in the lexical scope. Example below:\n\n```ts\n// CORRECT: uses destructured state\n({ Dropdown1, TextInput1 }) => Dropdown1.selectedOptionsValue + TextInput1.value\n\n// INCORRECT: uses state object directly\n(state) => state.Dropdown1.selectedOptionsValue + state.TextInput1.value\n```\n\n- The result of each scope is the result of the last block in that scope. In the following example, the value of `sendEmail.response` is the result of the `return_summary` block. Use this information to carefully ensure that the last block in your API is the one that returns the value you want.\n\n```ts\nexport default new Api("sendEmail", [\n new Email("send_email", {\n from: "noreply@company.com",\n to: "test@test.com",\n subject: "Test Email",\n body: "This is a test email",\n }),\n new JavaScript("return_summary", {\n fn: () => "Email sent successfully!",\n }),\n]);\n```\n\n```tsx\nimport {\n SbPage,\n SbSection,\n SbColumn,\n SbTable,\n sbComputed,\n registerPage,\n SbApi,\n} from "@superblocksteam/library";\n\nconst scope = createSbScope<{\n Table1: any;\n}>(\n () => ({\n sendEmail: SbApi({}),\n }),\n { name: "Page1" },\n);\n\nexport default registerPage(\n () => (\n <SbPage name="Page1" height={Dim.fill()} width={Dim.fill()}>\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>\n // ...\n <SbTable\n bind={scope.entities.Table1}\n tableData={sbComputed(() => API1.response)}\n />\n // ...\n </SbColumn>\n </SbSection>\n </SbPage>\n ),\n scope,\n);\n```\n\n- Block outputs are immutable. Do not mutate the output of a block.\n\n- Do not reference variables that are not in scope. The ONLY things in scope in an API block are the outputs of previous steps and the state object.\n\n- Backend APIs CANNOT mutate frontend state inside of the API\n\n- APIs are registered in scope files using `SbApi()` and then accessed in page components by destructuring from the scope entities. Make sure you name the key used in registerScope the same as the imported API, but do not pass the imported Api into the SbApi() call.\n\n- To access API responses in your UI, use `sbComputed(() => apiName.response)` or `sbComputed(() => apiName.error)`.\n\n- You will not always be told which integrations to use in your API; you will have to determine that yourself based on the data you need to fetch.\n\n- Never add comments to code you (the ai) generate. User added comments are fine - leave those!\n';
|
|
28
28
|
|
|
29
29
|
// ../../../vite-plugin-file-sync/dist/ai-service/prompts/generated/subprompts/superblocks-components-rules.js
|
|
30
30
|
init_cjs_shims();
|
|
@@ -44,7 +44,7 @@ var content5 = '### Layout and Sizing in Superblocks\n\nAll layouts in Superbloc
|
|
|
44
44
|
|
|
45
45
|
// ../../../vite-plugin-file-sync/dist/ai-service/prompts/generated/subprompts/superblocks-page.js
|
|
46
46
|
init_cjs_shims();
|
|
47
|
-
var content6 = '### How to use SbPage\n\n- A page is a file that exports a default React component through the `registerPage` function.\n- Each page consists of two files: `index.tsx` (the page component) and `scope.ts` (the entity definitions).\n- For `export default registerPage(Page1, Page1Scope)`, Page1 is a function that returns a React component, and Page1Scope is the scope containing all entities.\n- A project consists of one or more pages. Each page is a directory in the `pages` directory.\n- Pages are registered in the `routes.json` file.\n\n### Page Structure\n\nEach page should have the following structure:\n\n**scope.ts** - Contains all entity definitions (variables, APIs, etc.):\n\n```ts\nimport {\n createSbScope,\n SbVariable,\n SbVariablePersistence,\n SbApi,\n SbText,\n} from "@superblocksteam/library";\n\nexport const Page1Scope = createSbScope<{\n Text1: any;\n}>(\n {\n // Define your entities here\n myVariable: SbVariable({\n defaultValue: "initial value",\n persistence: SbVariablePersistence.TEMPORARY,\n }),\n myApi: SbApi({}),\n },\n {\n name: "Page1",\n },\n);\n\nexport const Page1 = Page1Scope.entities;\n```\n\n**index.tsx** - Contains the page component:\n\n```tsx\nimport {\n SbPage,\n SbSection,\n SbColumn,\n SbText,\n registerPage,\n} from "@superblocksteam/library";\nimport { Page1, Page1Scope } from "./scope";\n\nfunction Page() {\n // Destructure entities from the scope for easy access\n const { Text1, myVariable, myApi } = Page1;\n\n return (\n <SbPage name="Page1" height={Dim.fill()} width={Dim.fill()}>\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>\n {/* Use entities in your components */}\n <SbText bind={Text1} text={sbComputed(() => myVariable.value)} />\n </SbColumn>\n </SbSection>\n </SbPage>\n );\n}\n\nexport default registerPage(Page, Page1Scope);\n```\n\n## How component bindings work\n\nIf you need to reference a component directly to get access to some of its state, you must use a binding inside the page scope.\n\nComponent bindings allow you to:\n\n- Access component properties and state from other components and APIs\n- Create reactive relationships between components\n- Reference component values in `sbComputed` expressions\n\n### Setting up component bindings\n\n1. **Define the binding type in your scope**: Add the component type to the scope\'s type definitions:\n\n```ts\nexport const Page1Scope = createSbScope<{\n Text1: any;\n UserInput: any;\n}>(\n {\n // Your other entities (variables, APIs, etc.)\n myVariable: SbVariable({ defaultValue: "Hello" }),\n },\n {\n name: "Page1",\n },\n);\n```\n\n2. **Bind the component in your JSX**: Use the `bind` prop to connect the component to the binding:\n\n```tsx\nfunction Page() {\n const { Text1, UserInput, myVariable } = Page1;\n\n return (\n <SbPage name="Page1" height={Dim.fill()} width={Dim.fill()}>\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>\n <SbInput bind={UserInput} placeholder="Enter your name" />\n <SbText\n bind={Text1}\n text={sbComputed(() => `Hello, ${UserInput.value}!`)}\n />\n </SbColumn>\n </SbSection>\n </SbPage>\n );\n}\n```\n\n3. **Access component state**: Use `sbComputed` to access properties of bound components:\n\n```tsx\n// Access input value\ntext={sbComputed(() => UserInput.value)}\n\n// Access text content\ntext={sbComputed(() => Text1.text)}\n\n// Combine with other state\ntext={sbComputed(() => `${myVariable.value}: ${UserInput.value}`)}\n```\n\n### Common binding use cases\n\n- **Form inputs**: Access user input values to display or validate\n- **Dynamic content**: Reference one component\'s state to update another\n- **Conditional rendering**: Use component state to control visibility or styling\n\n### Page load events\n\nYou can fire callbacks when a page is loaded using the onLoad property of the Page component. You must use the SbEventFlow API for any actions you want to run inside onLoad.\n\nExample:\n\n```tsx\nimport {\n registerPage,\n SbEventFlow,\n SbPage,\n SbSection,\n SbColumn,\n sbComputed,\n} from "@superblocksteam/library";\nimport { Page1, Page1Scope } from "./scope";\n\nconst Page1Component = () => {\n return (\n <SbPage\n name="Page1"\n height={Dim.fill()}\n width={Dim.fill()}\n onLoad={SbEventFlow.runJS(() => {\n console.log("Page loaded");\n })}\n >\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>...</SbColumn>\n </SbSection>\n </SbPage>\n );\n};\n\nexport default registerPage(Page1Component, Page1Scope);\n```\n\nA very common and helpful usage of this callback is to run APIs using SbEventFlow to fetch data when the page loads. Example:\n\n```tsx\nimport {\n SbPage,\n registerPage,\n SbEventFlow,\n SbSection,\n SbColumn,\n sbComputed,\n} from "@superblocksteam/library";\nimport { Page1, Page1Scope } from "./scope";\n\nconst Page1Component = () => {\n return (\n <SbPage\n name="Page1"\n height={Dim.fill()}\n width={Dim.fill()}\n onLoad={SbEventFlow.runApis([getOrders])}\n >\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>...</SbColumn>\n </SbSection>\n </SbPage>\n );\n};\n\nexport default registerPage(Page1Component, Page1Scope);\n```\n\nIn this example, the `getOrders` API would be defined in the scope.ts file like this:\n\n```ts\n// In scope.ts\n\n// We register the api in createSbScope by creating a key\n// with the same name as the file, and SbApi({}) with an empty object\n// Note: We DO NOT import the api file. It\'s not necessary.\nexport const Page1Scope = createSbScope(\n () => ({\n getOrders: SbApi({}),\n }),\n {\n name: "Page1",\n },\n);\n```\n';
|
|
47
|
+
var content6 = '### How to use SbPage\n\n- A page is a file that exports a default React component through the `registerPage` function.\n- Each page consists of two files: `index.tsx` (the page component) and `scope.ts` (the entity definitions).\n- For `export default registerPage(Page1, Page1Scope)`, Page1 is a function that returns a React component, and Page1Scope is the scope containing all entities.\n- A project consists of one or more pages. Each page is a directory in the `pages` directory.\n- Pages are registered in the `routes.json` file.\n\n### Page Structure\n\nEach page should have the following structure:\n\n**scope.ts** - Contains all entity definitions (variables, APIs, etc.):\n\n```ts\nimport {\n createSbScope,\n SbVariable,\n SbVariablePersistence,\n SbApi,\n SbText,\n} from "@superblocksteam/library";\n\nexport const Page1Scope = createSbScope<{\n Text1: any;\n}>(\n () => ({\n // Define your entities here\n myVariable: SbVariable({\n defaultValue: "initial value",\n persistence: SbVariablePersistence.TEMPORARY,\n }),\n myApi: SbApi({}),\n }),\n {\n name: "Page1",\n },\n);\n\nexport const Page1 = Page1Scope.entities;\n```\n\n**index.tsx** - Contains the page component:\n\n```tsx\nimport {\n SbPage,\n SbSection,\n SbColumn,\n SbText,\n registerPage,\n} from "@superblocksteam/library";\nimport { Page1, Page1Scope } from "./scope";\n\nfunction Page() {\n // Destructure entities from the scope for easy access\n const { Text1, myVariable, myApi } = Page1;\n\n return (\n <SbPage name="Page1" height={Dim.fill()} width={Dim.fill()}>\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>\n {/* Use entities in your components */}\n <SbText bind={Text1} text={sbComputed(() => myVariable.value)} />\n </SbColumn>\n </SbSection>\n </SbPage>\n );\n}\n\nexport default registerPage(Page, Page1Scope);\n```\n\n## How component bindings work\n\nIf you need to reference a component directly to get access to some of its state, you must use a binding inside the page scope.\n\nComponent bindings allow you to:\n\n- Access component properties and state from other components and APIs\n- Create reactive relationships between components\n- Reference component values in `sbComputed` expressions\n\n### Setting up component bindings\n\n1. **Define the binding type in your scope**: Add the component type to the scope\'s type definitions:\n\n```ts\nexport const Page1Scope = createSbScope<{\n Text1: any;\n UserInput: any;\n}>(\n () => ({\n // Your other entities (variables, APIs, etc.)\n myVariable: SbVariable({ defaultValue: "Hello" }),\n }),\n {\n name: "Page1",\n },\n);\n```\n\n2. **Bind the component in your JSX**: Use the `bind` prop to connect the component to the binding:\n\n```tsx\nfunction Page() {\n const { Text1, UserInput, myVariable } = Page1;\n\n return (\n <SbPage name="Page1" height={Dim.fill()} width={Dim.fill()}>\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>\n <SbInput bind={UserInput} placeholder="Enter your name" />\n <SbText\n bind={Text1}\n text={sbComputed(() => `Hello, ${UserInput.value}!`)}\n />\n </SbColumn>\n </SbSection>\n </SbPage>\n );\n}\n```\n\n3. **Access component state**: Use `sbComputed` to access properties of bound components:\n\n```tsx\n// Access input value\ntext={sbComputed(() => UserInput.value)}\n\n// Access text content\ntext={sbComputed(() => Text1.text)}\n\n// Combine with other state\ntext={sbComputed(() => `${myVariable.value}: ${UserInput.value}`)}\n```\n\n### Common binding use cases\n\n- **Form inputs**: Access user input values to display or validate\n- **Dynamic content**: Reference one component\'s state to update another\n- **Conditional rendering**: Use component state to control visibility or styling\n\n### Page load events\n\nYou can fire callbacks when a page is loaded using the onLoad property of the Page component. You must use the SbEventFlow API for any actions you want to run inside onLoad.\n\nExample:\n\n```tsx\nimport {\n registerPage,\n SbEventFlow,\n SbPage,\n SbSection,\n SbColumn,\n sbComputed,\n} from "@superblocksteam/library";\nimport { Page1, Page1Scope } from "./scope";\n\nconst Page1Component = () => {\n return (\n <SbPage\n name="Page1"\n height={Dim.fill()}\n width={Dim.fill()}\n onLoad={SbEventFlow.runJS(() => {\n console.log("Page loaded");\n })}\n >\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>...</SbColumn>\n </SbSection>\n </SbPage>\n );\n};\n\nexport default registerPage(Page1Component, Page1Scope);\n```\n\nA very common and helpful usage of this callback is to run APIs using SbEventFlow to fetch data when the page loads. Example:\n\n```tsx\nimport {\n SbPage,\n registerPage,\n SbEventFlow,\n SbSection,\n SbColumn,\n sbComputed,\n} from "@superblocksteam/library";\nimport { Page1, Page1Scope } from "./scope";\n\nconst Page1Component = () => {\n return (\n <SbPage\n name="Page1"\n height={Dim.fill()}\n width={Dim.fill()}\n onLoad={SbEventFlow.runApis([getOrders])}\n >\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>...</SbColumn>\n </SbSection>\n </SbPage>\n );\n};\n\nexport default registerPage(Page1Component, Page1Scope);\n```\n\nIn this example, the `getOrders` API would be defined in the scope.ts file like this:\n\n```ts\n// In scope.ts\n\n// We register the api in createSbScope by creating a key\n// with the same name as the file, and SbApi({}) with an empty object\n// Note: We DO NOT import the api file. It\'s not necessary.\nexport const Page1Scope = createSbScope(\n () => ({\n getOrders: SbApi({}),\n }),\n {\n name: "Page1",\n },\n);\n```\n';
|
|
48
48
|
|
|
49
49
|
// ../../../vite-plugin-file-sync/dist/ai-service/prompts/generated/subprompts/superblocks-routes.js
|
|
50
50
|
init_cjs_shims();
|
|
@@ -52,7 +52,7 @@ var content7 = '- The `routes.json` file maps URLs to pages.\n Example routes.j
|
|
|
52
52
|
|
|
53
53
|
// ../../../vite-plugin-file-sync/dist/ai-service/prompts/generated/subprompts/superblocks-state.js
|
|
54
54
|
init_cjs_shims();
|
|
55
|
-
var content8 = '**Superblocks State System**\n\nThe Superblocks state system is built around scopes that contain entities (variables, APIs, components). Here\'s how it works:\n\n### 1. Scopes\n\nScopes are defined in separate `scope.ts` files for each page and contain all the page\'s entities.\n\n- **Page scopes** are visible only within the current page\n- **App scopes** can be shared across pages (though you should primarily use page scopes)\n- Entities are accessed by importing and destructuring from the scope\n\n> **Parent \u2192 child rule**: Child scopes can read & write parent entities, but parents cannot reach into children.\n\n### 2. Scope Structure\n\nEach page has its own scope file that defines all entities:\n\n```ts\n// pages/Page1/scope.ts\nimport {\n createSbScope,\n SbVariable,\n SbVariablePersistence,\n SbApi,\n sbComputed,\n} from "@superblocksteam/library";\n\nexport const Page1Scope = createSbScope<{\n OrdersTable: any;\n}>(\n ({ entities: { counter } }) => ({\n // Static state variable with a simple default value\n counter: SbVariable({\n defaultValue: 0,\n persistence: SbVariablePersistence.TEMPORARY,\n }),\n // State variable with computed default value from other entities\n doubledCounter: SbVariable({\n defaultValue: sbComputed(() => counter.value * 2),\n persistence: SbVariablePersistence.TEMPORARY,\n }),\n myApi: SbApi({}),\n }),\n {\n name: "Page1",\n },\n);\n\nexport const Page1 = Page1Scope.entities;\n```\n\nThen in your page component, you import and destructure the entities:\n\n```tsx\n// pages/Page1/index.tsx\nimport {\n SbPage,\n SbSection,\n SbColumn,\n SbText,\n SbButton,\n sbComputed,\n SbEventFlow,\n registerPage,\n} from "@superblocksteam/library";\nimport { Page1, Page1Scope } from "./scope";\n\nfunction Page() {\n // Destructure entities for easy access\n const { counter, doubledCounter, myApi, OrdersTable } = Page1;\n\n return (\n <SbPage name="Page1" height={Dim.fill()} width={Dim.fill()}>\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>\n <SbText text={sbComputed(() => `Count: ${counter.value}`)} />\n <SbButton onClick={SbEventFlow.setStateVar("counter", 5)} />\n </SbColumn>\n </SbSection>\n </SbPage>\n );\n}\n\nexport default registerPage(Page, Page1Scope);\n```\n\n_You should NOT create any extra scopes other than page scopes in most cases._\n\n### 3. Computed Default Values\n\nState variables can have their `defaultValue` computed from other entities in the same scope at initialization time.\n\n**Static default value:**\n\n```ts\nstaticVar: SbVariable({\n defaultValue: "Hello World",\n});\n```\n\n**Computed default value:**\n\n```ts\n({ entities: { Input1, staticVar } }) => ({\n computedVar: SbVariable({\n defaultValue: sbComputed(() => `${staticVar.value} - ${Input1.value}`),\n }),\n});\n```\n\nWrap the entire scope object with the entities function and destructure needed entities from the `entities` parameter. This only sets the initial value - it doesn\'t create ongoing updates.\n\n### 4. Entity Types\n\n- **Component state**\n\n - Declared by defining the component type in the scope and using the `bind` prop\n - Accessed by destructuring the component entity and using `sbComputed(() => ComponentName.prop)`\n - Writable if the prop is marked writable in the schema\n\n- **State variable**\n\n - Declared with `SbVariable({ defaultValue })` or within `(({ entities }) => ({ ... }))` wrapper for computed defaults\n - `defaultValue` sets the initial value when the application loads\n - For static variables: Only JSON parsable data structures, no functions\n - For computed variables: Use `sbComputed` within defaultValue to reference other entities\n - Do not call `defaultValue` like a function. Set values with `SbEventFlow.setStateVar()` or read with `sbComputed(() => varName.value)`\n - Accessed with `sbComputed(() => varName.value)` \u2014 **always include `.value`**\n - Writable through SbEventFlow\n\n- **API**\n - Declared with `SbApi({})` in the scope file.\n - Accessed with `sbComputed(() => apiName.response)` or `sbComputed(() => apiName.error)`\n - Read\u2011only\n\n### 5. Reading State with sbComputed\n\n**CRITICAL**: There are two different patterns for accessing data in `sbComputed` depending on what you\'re accessing:\n\n#### 5.1. Scope Entities (Direct Access)\n\nFor entities defined in your scope file (variables, APIs, components), access them **directly** after destructuring:\n\n```tsx\nconst { UserSearchInput, myVariable, myApi } = Page1;\n\n// \u2705 CORRECT - Direct access for scope entities\n<SbText text={sbComputed(() => `Search: ${UserSearchInput.value}`)} />\n<SbText text={sbComputed(() => myVariable.value)} />\n<SbTable tableData={sbComputed(() => myApi.response)} />\n```\n\n#### 4.2. Global State (Import Access)\n\nFor global state like globals, theme, environment, and embedded data, import the globals directly from the library:\n\n```tsx\n// \u2705 CORRECT - Import globals directly\n<SbText\n text={sbComputed(() => `Welcome ${Global.user.name}!`)}\n textStyle={{\n textColor: {\n default: sbComputed(() => Theme.colors.neutral900)\n }\n }}\n/>\n<SbContainer backgroundColor={sbComputed(() => Theme.colors.primary)} />\n```\n\n#### 5.3. Mixed Access\n\nWhen you need both scope entities and global state in the same `sbComputed`:\n\n```tsx\nconst { orders } = Page1;\n\n// \u2705 CORRECT - Combine direct entity access with imported globals\n<SbText\n text={sbComputed(() => `${orders.length} orders for ${Global.user.name}`)}\n/>;\n```\n\n### 6. Writing State\n\nPreferred approach:\n\n```tsx\nSbEventFlow.setStateVar("pageSize", 50);\n```\n\nFallback for complex operations:\n\n```tsx\nSbEventFlow.runJS(() => {\n // Direct assignment works within SbEventFlow.runJS\n pageSize.value = 50;\n});\n```\n\n### 7. CRITICAL Rules\n\n1. **Use component state directly**; NEVER create a state variable for a value that is available directly from a component property.\n2. Use component bindings by defining component types in your scope and using the `bind` prop.\n3. Keep logic declarative \u2014 derive UI from state using `sbComputed` instead of mutating props at runtime.\n4. Always destructure entities from your scope for clean access patterns.\n5. **Use the correct sbComputedz pattern**: Direct access for scope entities, import globals (Global, Theme, Embed, Env) for global access.\n6. Always complete implement all features, don\'t stub out or skip anything.\n\n**\u2705 Example**\n\n```tsx\n// In your scope.ts file\nexport const Page1Scope = createSbScope<{\n ApplicantSelector: any;\n}>(\n {\n applicants: SbVariable({ defaultValue: [] }),\n },\n {\n name: "Page1",\n },\n);\n```\n\n```tsx\n// In your page component after destructuring entities\nconst { ApplicantSelector, applicants } = Page1;\n\n<SbDropdown bind={ApplicantSelector} options={/* ... */} />\n<SbTable tableData={sbComputed(() => applicants[ApplicantSelector.selectedOptionValue])} />\n```\n\n```tsx\n// In your scope.ts file\nexport const Page1Scope = createSbScope<{\n Country: any;\n}>(\n {\n applicants: SbVariable({ defaultValue: [] }),\n },\n FirstName: typeof SbInput;\n LastName: typeof SbInput;\n}>(\n ({ entities: { FirstName, LastName } }) => ({\n fullName: SbVariable({\n defaultValue: sbComputed(() =>\n `${FirstName.value} ${LastName.value}`.trim(),\n ),\n }),\n }),\n {\n name: "Page1",\n },\n);\n```\n\n```tsx\nconst { FirstName, LastName, fullName } = Page1;\n\n<SbInput bind={FirstName} placeholder="First name" />\n<SbInput bind={LastName} placeholder="Last name" />\n<SbText text={sbComputed(() => `Welcome ${fullName.value}!`)} />\n```\n\n```tsx\n{\n /* The user types in the search input, and the value is displayed */\n}\n// In your scope.ts file\nexport const Page1Scope = createSbScope<{\n searchTerm: any;\n}>(\n {},\n {\n name: "Page1",\n },\n);\n```\n\n```tsx\nconst { searchTerm } = Page1;\n\n<SbInput bind={searchTerm} />\n<SbText text={sbComputed(() => searchTerm.value)} />\n```\n\n```tsx\n{\n /* Switch to change into admin mode */\n}\n// In your scope.ts file\nexport const Page1Scope = createSbScope<{\n isAdmin: any;\n}>(\n {},\n {\n name: "Page1",\n },\n);\n```\n\n```tsx\nconst { isAdmin } = Page1;\n\n<SbSwitch bind={isAdmin} label="Use Admin Mode" defaultChecked={false} />;\n{\n /* Only enable the delete button when switched into Admin mode */\n}\n<SbButton\n disabled={sbComputed(() => !isAdmin.isChecked)}\n label="Delete profile"\n/>;\n```\n\n\u2705 ALWAYS USE DIRECT COMPONENT STATE ACCESS WITH sbComputed:\n\n```tsx\n// GOOD - DO THIS\n// In your scope.ts file\nexport const Page1Scope = createSbScope<{\n UserNameInput: any;\n}>(\n {},\n {\n name: "Page1",\n },\n);\n```\n\n```tsx\nconst { UserNameInput } = Page1;\n\n<SbTextInput bind={UserNameInput} />\n<SbText text={sbComputed(() => `Hello, ${UserNameInput.value}!`)} />\n```\n\n\u274C NEVER CREATE REDUNDANT STATE VARIABLES:\n\n```tsx\n// WRONG - DON\'T DO THIS\n<SbTextInput bind={UserNameInput} onChange={SbEventFlow.setStateVar(\'userNameVar\', \'myValue\')} />\n<SbText text={sbComputed(() => `Hello, ${userNameVar.value}!`)} />\n...\n// And then in scope.ts:\n{\n userNameVar: SbVariable({ defaultValue: "" }),\n}\n```\n\nTo reference a property of a component using `sbComputed`, the component must have a binding defined in your scope.\n\nThat\'s why you should ALWAYS define component bindings in your scope for the following component types when you need to access their state:\n\n- SbInput\n- SbDropdown\n- SbDatePicker\n- SbCheckbox\n- SbSwitch\n- SbForm\n- SbRadio\n- SbRichText\n- SbFilePicker\n- SbCodeEditor\n- SbChat\n\n\u274C DO NOT USE STATE VARIABLES AS FUNCTIONS:\n\nState variables are not functions. You cannot call them or store functions in defaultValue.\n\n```tsx\n// WRONG - DON\'T DO THIS\nfunction Page1() {\n const { customerNameFilter, filterOrders } = Page1;\n\n return (\n <SbPage name="Page1" height={Dim.fill()} width={Dim.fill()}>\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>\n <SbInput\n bind={customerNameFilter}\n label="Customer Name"\n placeholder="Filter by customer name"\n width={Dim.fill()}\n onTextChanged={SbEventFlow.runJS(() => {\n // This is wrong - you cannot call filterOrders as a function\n filterOrders();\n })}\n />\n </SbColumn>\n </SbSection>\n </SbPage>\n );\n}\n\n// And in scope.ts (WRONG):\n{\n filterOrders: SbVariable({\n defaultValue: () => {\n // This doesn\'t work - state variables are not functions\n const customerNameFilter = customerNameFilter.value.toLowerCase();\n // ... more logic\n },\n });\n}\n```\n\nInstead do the following:\n\n\u2705 COMPUTE VALUES WITH sbComputed AND SET STATE WITH SbEventFlow:\n\n```tsx\n// CORRECT - DO THIS\nimport {\n SbPage,\n SbSection,\n SbColumn,\n SbInput,\n SbButton,\n SbTable,\n sbComputed,\n SbEventFlow,\n registerPage,\n} from "@superblocksteam/library";\n\nfunction Page1() {\n const { customerNameFilter, filteredOrders, orders } = Page1;\n\n return (\n <SbPage name="Page1" height={Dim.fill()} width={Dim.fill()}>\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>\n <SbInput\n bind={customerNameFilter}\n label="Customer Name"\n placeholder="Filter by customer name"\n width={Dim.fill()}\n onTextChanged={SbEventFlow.runJS(() => {\n // Repeat the filtering logic inline - do NOT create helper functions\n const filtered = orders.value.filter((order) => {\n return (\n !customerNameFilter.value ||\n order.customerName\n .toLowerCase()\n .includes(customerNameFilter.value.toLowerCase())\n );\n });\n\n // Set the state variable with the computed result\n filteredOrders.value = filtered;\n })}\n />\n {/* If you need the same filtering logic elsewhere, repeat it inline */}\n <SbButton\n label="Apply Filter"\n onClick={SbEventFlow.runJS(() => {\n // Repeat the same filtering logic here - code repetition is preferred\n const filtered = orders.value.filter((order) => {\n return (\n !customerNameFilter.value ||\n order.customerName\n .toLowerCase()\n .includes(customerNameFilter.value.toLowerCase())\n );\n });\n\n filteredOrders.value = filtered;\n })}\n />\n <SbTable tableData={sbComputed(() => filteredOrders.value)} />\n </SbColumn>\n </SbSection>\n </SbPage>\n );\n}\n\nexport default registerPage(Page1, Page1Scope);\n```\n\nAnd in your scope.ts file:\n\n```ts\nexport const Page1Scope = createSbScope<{\n customerNameFilter: any;\n}>(\n {\n orders: SbVariable({\n defaultValue: [\n {\n id: "ORD-1001",\n customerName: "John Smith",\n orderType: "Grocery Delivery",\n },\n {\n id: "ORD-1002",\n customerName: "Emily Johnson",\n orderType: "Express Delivery",\n },\n ],\n persistence: SbVariablePersistence.TEMPORARY,\n }),\n filteredOrders: SbVariable({\n defaultValue: [],\n persistence: SbVariablePersistence.TEMPORARY,\n }),\n },\n {\n name: "Page1",\n },\n);\n```\n';
|
|
55
|
+
var content8 = '**Superblocks State System**\n\nThe Superblocks state system is built around scopes that contain entities (variables, APIs, components). Here\'s how it works:\n\n### 1. Scopes\n\nScopes are defined in separate `scope.ts` files for each page and contain all the page\'s entities.\n\n- **Page scopes** are visible only within the current page\n- **App scopes** can be shared across pages (though you should primarily use page scopes)\n- Entities are accessed by importing and destructuring from the scope\n\n> **Parent \u2192 child rule**: Child scopes can read & write parent entities, but parents cannot reach into children.\n\n### 2. Scope Structure\n\nEach page has its own scope file that defines all entities:\n\n```ts\n// pages/Page1/scope.ts\nimport {\n createSbScope,\n SbVariable,\n SbVariablePersistence,\n SbApi,\n sbComputed,\n} from "@superblocksteam/library";\n\nexport const Page1Scope = createSbScope<{\n OrdersTable: any;\n}>(\n ({ entities: { counter } }) => ({\n // Static state variable with a simple default value\n counter: SbVariable({\n defaultValue: 0,\n persistence: SbVariablePersistence.TEMPORARY,\n }),\n // State variable with computed default value from other entities\n doubledCounter: SbVariable({\n defaultValue: sbComputed(() => counter.value * 2),\n persistence: SbVariablePersistence.TEMPORARY,\n }),\n myApi: SbApi({}),\n }),\n {\n name: "Page1",\n },\n);\n\nexport const Page1 = Page1Scope.entities;\n```\n\nThen in your page component, you import and destructure the entities:\n\n```tsx\n// pages/Page1/index.tsx\nimport {\n SbPage,\n SbSection,\n SbColumn,\n SbText,\n SbButton,\n sbComputed,\n SbEventFlow,\n registerPage,\n} from "@superblocksteam/library";\nimport { Page1, Page1Scope } from "./scope";\n\nfunction Page() {\n // Destructure entities for easy access\n const { counter, doubledCounter, myApi, OrdersTable } = Page1;\n\n return (\n <SbPage name="Page1" height={Dim.fill()} width={Dim.fill()}>\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>\n <SbText text={sbComputed(() => `Count: ${counter.value}`)} />\n <SbButton onClick={SbEventFlow.setStateVar("counter", 5)} />\n </SbColumn>\n </SbSection>\n </SbPage>\n );\n}\n\nexport default registerPage(Page, Page1Scope);\n```\n\n_You should NOT create any extra scopes other than page scopes in most cases._\n\n### 3. Computed Default Values\n\nState variables can have their `defaultValue` computed from other entities in the same scope at initialization time.\n\n**Static default value:**\n\n```ts\nstaticVar: SbVariable({\n defaultValue: "Hello World",\n});\n```\n\n**Computed default value:**\n\n```ts\n({ entities: { Input1, staticVar } }) => ({\n computedVar: SbVariable({\n defaultValue: sbComputed(() => `${staticVar.value} - ${Input1.value}`),\n }),\n});\n```\n\nWrap the entire scope object with the entities function and destructure needed entities from the `entities` parameter. This only sets the initial value - it doesn\'t create ongoing updates.\n\n### 4. Entity Types\n\n- **Component state**\n\n - Declared by defining the component type in the scope and using the `bind` prop\n - Accessed by destructuring the component entity and using `sbComputed(() => ComponentName.prop)`\n - Writable if the prop is marked writable in the schema\n\n- **State variable**\n\n - Declared with `SbVariable({ defaultValue })` or within `(({ entities }) => ({ ... }))` wrapper for computed defaults\n - `defaultValue` sets the initial value when the application loads\n - For static variables: Only JSON parsable data structures, no functions\n - For computed variables: Use `sbComputed` within defaultValue to reference other entities\n - Do not call `defaultValue` like a function. Set values with `SbEventFlow.setStateVar()` or read with `sbComputed(() => varName.value)`\n - Accessed with `sbComputed(() => varName.value)` \u2014 **always include `.value`**\n - Writable through SbEventFlow\n\n- **API**\n - Declared with `SbApi({})` in the scope file.\n - Accessed with `sbComputed(() => apiName.response)` or `sbComputed(() => apiName.error)`\n - Read\u2011only\n\n### 5. Reading State with sbComputed\n\n**CRITICAL**: There are two different patterns for accessing data in `sbComputed` depending on what you\'re accessing:\n\n#### 5.1. Scope Entities (Direct Access)\n\nFor entities defined in your scope file (variables, APIs, components), access them **directly** after destructuring:\n\n```tsx\nconst { UserSearchInput, myVariable, myApi } = Page1;\n\n// \u2705 CORRECT - Direct access for scope entities\n<SbText text={sbComputed(() => `Search: ${UserSearchInput.value}`)} />\n<SbText text={sbComputed(() => myVariable.value)} />\n<SbTable tableData={sbComputed(() => myApi.response)} />\n```\n\n#### 4.2. Global State (Import Access)\n\nFor global state like globals, theme, environment, and embedded data, import the globals directly from the library:\n\n```tsx\n// \u2705 CORRECT - Import globals directly\n<SbText\n text={sbComputed(() => `Welcome ${Global.user.name}!`)}\n textStyle={{\n textColor: {\n default: sbComputed(() => Theme.colors.neutral900)\n }\n }}\n/>\n<SbContainer backgroundColor={sbComputed(() => Theme.colors.primary)} />\n```\n\n#### 5.3. Mixed Access\n\nWhen you need both scope entities and global state in the same `sbComputed`:\n\n```tsx\nconst { orders } = Page1;\n\n// \u2705 CORRECT - Combine direct entity access with imported globals\n<SbText\n text={sbComputed(() => `${orders.length} orders for ${Global.user.name}`)}\n/>;\n```\n\n### 6. Writing State\n\nPreferred approach:\n\n```tsx\nSbEventFlow.setStateVar("pageSize", 50);\n```\n\nFallback for complex operations:\n\n```tsx\nSbEventFlow.runJS(() => {\n // Direct assignment works within SbEventFlow.runJS\n pageSize.value = 50;\n});\n```\n\n### 7. CRITICAL Rules\n\n1. **Use component state directly**; NEVER create a state variable for a value that is available directly from a component property.\n2. Use component bindings by defining component types in your scope and using the `bind` prop.\n3. Keep logic declarative \u2014 derive UI from state using `sbComputed` instead of mutating props at runtime.\n4. Always destructure entities from your scope for clean access patterns.\n5. **Use the correct sbComputedz pattern**: Direct access for scope entities, import globals (Global, Theme, Embed, Env) for global access.\n6. Always complete implement all features, don\'t stub out or skip anything.\n\n**\u2705 Example**\n\n```tsx\n// In your scope.ts file\nexport const Page1Scope = createSbScope<{\n ApplicantSelector: any;\n}>(\n () => ({\n applicants: SbVariable({ defaultValue: [] }),\n }),\n {\n name: "Page1",\n },\n);\n```\n\n```tsx\n// In your page component after destructuring entities\nconst { ApplicantSelector, applicants } = Page1;\n\n<SbDropdown bind={ApplicantSelector} options={/* ... */} />\n<SbTable tableData={sbComputed(() => applicants[ApplicantSelector.selectedOptionValue])} />\n```\n\n```tsx\n// In your scope.ts file\nexport const Page1Scope = createSbScope<{\n FirstName: any;\n LastName: any;\n}>(\n ({ entities: { FirstName, LastName } }) => ({\n applicants: SbVariable({ defaultValue: [] }),\n fullName: SbVariable({\n defaultValue: sbComputed(() =>\n `${FirstName.value} ${LastName.value}`.trim(),\n ),\n }),\n }),\n {\n name: "Page1",\n },\n);\n```\n\n```tsx\nconst { FirstName, LastName, fullName } = Page1;\n\n<SbInput bind={FirstName} placeholder="First name" />\n<SbInput bind={LastName} placeholder="Last name" />\n<SbText text={sbComputed(() => `Welcome ${fullName.value}!`)} />\n```\n\n```tsx\n{\n /* The user types in the search input, and the value is displayed */\n}\n// In your scope.ts file\nexport const Page1Scope = createSbScope<{\n searchTerm: any;\n}>(() => ({}), {\n name: "Page1",\n});\n```\n\n```tsx\nconst { searchTerm } = Page1;\n\n<SbInput bind={searchTerm} />\n<SbText text={sbComputed(() => searchTerm.value)} />\n```\n\n```tsx\n{\n /* Switch to change into admin mode */\n}\n// In your scope.ts file\nexport const Page1Scope = createSbScope<{\n isAdmin: any;\n}>(() => ({}), {\n name: "Page1",\n});\n```\n\n```tsx\nconst { isAdmin } = Page1;\n\n<SbSwitch bind={isAdmin} label="Use Admin Mode" defaultChecked={false} />;\n{\n /* Only enable the delete button when switched into Admin mode */\n}\n<SbButton\n disabled={sbComputed(() => !isAdmin.isChecked)}\n label="Delete profile"\n/>;\n```\n\n\u2705 ALWAYS USE DIRECT COMPONENT STATE ACCESS WITH sbComputed:\n\n```tsx\n// GOOD - DO THIS\n// In your scope.ts file\nexport const Page1Scope = createSbScope<{\n UserNameInput: any;\n}>(() => ({}), {\n name: "Page1",\n});\n```\n\n```tsx\nconst { UserNameInput } = Page1;\n\n<SbTextInput bind={UserNameInput} />\n<SbText text={sbComputed(() => `Hello, ${UserNameInput.value}!`)} />\n```\n\n\u274C NEVER CREATE REDUNDANT STATE VARIABLES:\n\n```tsx\n// WRONG - DON\'T DO THIS\n<SbTextInput bind={UserNameInput} onChange={SbEventFlow.setStateVar(\'userNameVar\', \'myValue\')} />\n<SbText text={sbComputed(() => `Hello, ${userNameVar.value}!`)} />\n...\n// And then in scope.ts:\n{\n userNameVar: SbVariable({ defaultValue: "" }),\n}\n```\n\nTo reference a property of a component using `sbComputed`, the component must have a binding defined in your scope.\n\nThat\'s why you should ALWAYS define component bindings in your scope for the following component types when you need to access their state:\n\n- SbInput\n- SbDropdown\n- SbDatePicker\n- SbCheckbox\n- SbSwitch\n- SbForm\n- SbRadio\n- SbRichText\n- SbFilePicker\n- SbCodeEditor\n- SbChat\n\n\u274C DO NOT USE STATE VARIABLES AS FUNCTIONS:\n\nState variables are not functions. You cannot call them or store functions in defaultValue.\n\n```tsx\n// WRONG - DON\'T DO THIS\nfunction Page1() {\n const { customerNameFilter, filterOrders } = Page1;\n\n return (\n <SbPage name="Page1" height={Dim.fill()} width={Dim.fill()}>\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>\n <SbInput\n bind={customerNameFilter}\n label="Customer Name"\n placeholder="Filter by customer name"\n width={Dim.fill()}\n onTextChanged={SbEventFlow.runJS(() => {\n // This is wrong - you cannot call filterOrders as a function\n filterOrders();\n })}\n />\n </SbColumn>\n </SbSection>\n </SbPage>\n );\n}\n\n// And in scope.ts (WRONG):\n{\n filterOrders: SbVariable({\n defaultValue: () => {\n // This doesn\'t work - state variables are not functions\n const customerNameFilter = customerNameFilter.value.toLowerCase();\n // ... more logic\n },\n });\n}\n```\n\nInstead do the following:\n\n\u2705 COMPUTE VALUES WITH sbComputed AND SET STATE WITH SbEventFlow:\n\n```tsx\n// CORRECT - DO THIS\nimport {\n SbPage,\n SbSection,\n SbColumn,\n SbInput,\n SbButton,\n SbTable,\n sbComputed,\n SbEventFlow,\n registerPage,\n} from "@superblocksteam/library";\n\nfunction Page1() {\n const { customerNameFilter, filteredOrders, orders } = Page1;\n\n return (\n <SbPage name="Page1" height={Dim.fill()} width={Dim.fill()}>\n <SbSection height={Dim.fill()}>\n <SbColumn width={Dim.fill()}>\n <SbInput\n bind={customerNameFilter}\n label="Customer Name"\n placeholder="Filter by customer name"\n width={Dim.fill()}\n onTextChanged={SbEventFlow.runJS(() => {\n // Repeat the filtering logic inline - do NOT create helper functions\n const filtered = orders.value.filter((order) => {\n return (\n !customerNameFilter.value ||\n order.customerName\n .toLowerCase()\n .includes(customerNameFilter.value.toLowerCase())\n );\n });\n\n // Set the state variable with the computed result\n filteredOrders.value = filtered;\n })}\n />\n {/* If you need the same filtering logic elsewhere, repeat it inline */}\n <SbButton\n label="Apply Filter"\n onClick={SbEventFlow.runJS(() => {\n // Repeat the same filtering logic here - code repetition is preferred\n const filtered = orders.value.filter((order) => {\n return (\n !customerNameFilter.value ||\n order.customerName\n .toLowerCase()\n .includes(customerNameFilter.value.toLowerCase())\n );\n });\n\n filteredOrders.value = filtered;\n })}\n />\n <SbTable tableData={sbComputed(() => filteredOrders.value)} />\n </SbColumn>\n </SbSection>\n </SbPage>\n );\n}\n\nexport default registerPage(Page1, Page1Scope);\n```\n\nAnd in your scope.ts file:\n\n```ts\nexport const Page1Scope = createSbScope<{\n customerNameFilter: any;\n}>(\n () => ({\n orders: SbVariable({\n defaultValue: [\n {\n id: "ORD-1001",\n customerName: "John Smith",\n orderType: "Grocery Delivery",\n },\n {\n id: "ORD-1002",\n customerName: "Emily Johnson",\n orderType: "Express Delivery",\n },\n ],\n persistence: SbVariablePersistence.TEMPORARY,\n }),\n filteredOrders: SbVariable({\n defaultValue: [],\n persistence: SbVariablePersistence.TEMPORARY,\n }),\n }),\n {\n name: "Page1",\n },\n);\n```\n';
|
|
56
56
|
|
|
57
57
|
// ../../../vite-plugin-file-sync/dist/ai-service/prompts/generated/subprompts/superblocks-theming.js
|
|
58
58
|
init_cjs_shims();
|
package/dist/index.js
CHANGED
|
@@ -263726,7 +263726,7 @@ init_esm();
|
|
|
263726
263726
|
// ../sdk/package.json
|
|
263727
263727
|
var package_default = {
|
|
263728
263728
|
name: "@superblocksteam/sdk",
|
|
263729
|
-
version: "2.0.0-next.
|
|
263729
|
+
version: "2.0.0-next.8",
|
|
263730
263730
|
type: "module",
|
|
263731
263731
|
description: "Superblocks JS SDK",
|
|
263732
263732
|
homepage: "https://www.superblocks.com",
|
|
@@ -263763,8 +263763,8 @@ var package_default = {
|
|
|
263763
263763
|
"@rollup/wasm-node": "^4.35.0",
|
|
263764
263764
|
"@superblocksteam/bucketeer-sdk": "0.4.1",
|
|
263765
263765
|
"@superblocksteam/shared": "0.9122.0",
|
|
263766
|
-
"@superblocksteam/util": "2.0.0-next.
|
|
263767
|
-
"@superblocksteam/vite-plugin-file-sync": "2.0.0-next.
|
|
263766
|
+
"@superblocksteam/util": "2.0.0-next.8",
|
|
263767
|
+
"@superblocksteam/vite-plugin-file-sync": "2.0.0-next.8",
|
|
263768
263768
|
"@vitejs/plugin-react": "^4.3.4",
|
|
263769
263769
|
axios: "^1.4.0",
|
|
263770
263770
|
chokidar: "^4.0.3",
|
|
@@ -263908,11 +263908,12 @@ init_cjs_shims();
|
|
|
263908
263908
|
|
|
263909
263909
|
// ../../../library-shared/dist/utils/properties.js
|
|
263910
263910
|
init_cjs_shims();
|
|
263911
|
-
function PropertyInfo(value2, type2 = "STATIC") {
|
|
263911
|
+
function PropertyInfo(value2, type2 = "STATIC", extra) {
|
|
263912
263912
|
return {
|
|
263913
263913
|
__info: true,
|
|
263914
263914
|
value: value2,
|
|
263915
|
-
type: type2
|
|
263915
|
+
type: type2,
|
|
263916
|
+
...extra
|
|
263916
263917
|
};
|
|
263917
263918
|
}
|
|
263918
263919
|
var Property = {
|
|
@@ -263922,7 +263923,7 @@ var Property = {
|
|
|
263922
263923
|
Expression: (value2) => PropertyInfo(value2, "EXPRESSION"),
|
|
263923
263924
|
Event: (value2) => PropertyInfo(value2, "EVENT"),
|
|
263924
263925
|
Dimension: (value2) => PropertyInfo(value2, "DIMENSION"),
|
|
263925
|
-
Computed: (value2) => PropertyInfo(value2, "COMPUTED"),
|
|
263926
|
+
Computed: (value2, args) => PropertyInfo(value2, "COMPUTED", args ? { args } : {}),
|
|
263926
263927
|
Any: (value2, type2 = "STATIC") => PropertyInfo(value2, type2)
|
|
263927
263928
|
};
|
|
263928
263929
|
function isPropertyInfo(value2) {
|
|
@@ -276058,11 +276059,11 @@ function isValidJSXExpression(value2) {
|
|
|
276058
276059
|
}
|
|
276059
276060
|
}
|
|
276060
276061
|
var transformers = {
|
|
276061
|
-
oneLineArrow: (value2) => value2.startsWith("{") ? `() => (${value2})` : `() => ${value2}`,
|
|
276062
|
-
multiLineArrow: (value2) => `() => {
|
|
276062
|
+
oneLineArrow: (value2, argsString) => value2.startsWith("{") ? `(${argsString}) => (${value2})` : `(${argsString}) => ${value2}`,
|
|
276063
|
+
multiLineArrow: (value2, argsString) => `(${argsString}) => {
|
|
276063
276064
|
${value2}
|
|
276064
276065
|
}`,
|
|
276065
|
-
traditional: (value2) => `function (this: any) {
|
|
276066
|
+
traditional: (value2, argsString) => `function (this: any${argsString ? `, ${argsString}` : ""}) {
|
|
276066
276067
|
${value2}
|
|
276067
276068
|
}`,
|
|
276068
276069
|
computed: (value2) => `sbComputed(${value2})`
|
|
@@ -276070,24 +276071,28 @@ var transformers = {
|
|
|
276070
276071
|
function findFirstValidExpression(testCases) {
|
|
276071
276072
|
return testCases.find(isValidJSXExpression);
|
|
276072
276073
|
}
|
|
276073
|
-
function toCodeComputed(value2) {
|
|
276074
|
+
function toCodeComputed(value2, info) {
|
|
276075
|
+
let argsString = "";
|
|
276076
|
+
if (isComputedPropertyInfo(info)) {
|
|
276077
|
+
argsString = info.args ? `{ ${info.args.join(", ")} }` : "";
|
|
276078
|
+
}
|
|
276074
276079
|
const { hasThisReference, hasReturnStatement } = getFunctionBodyThisExpressionData(value2);
|
|
276075
276080
|
if (hasThisReference) {
|
|
276076
276081
|
if (!hasReturnStatement) {
|
|
276077
|
-
return transformers.computed(transformers.traditional(`return ${value2}
|
|
276082
|
+
return transformers.computed(transformers.traditional(`return ${value2}`, argsString));
|
|
276078
276083
|
}
|
|
276079
|
-
return transformers.computed(transformers.traditional(value2));
|
|
276084
|
+
return transformers.computed(transformers.traditional(value2, argsString));
|
|
276080
276085
|
}
|
|
276081
276086
|
const computedTestCases = [
|
|
276082
|
-
transformers.oneLineArrow(value2),
|
|
276083
|
-
transformers.multiLineArrow(value2),
|
|
276084
|
-
transformers.traditional(value2)
|
|
276087
|
+
transformers.oneLineArrow(value2, argsString),
|
|
276088
|
+
transformers.multiLineArrow(value2, argsString),
|
|
276089
|
+
transformers.traditional(value2, argsString)
|
|
276085
276090
|
];
|
|
276086
276091
|
const validComputedExpression = findFirstValidExpression(computedTestCases);
|
|
276087
276092
|
if (validComputedExpression) {
|
|
276088
276093
|
return transformers.computed(validComputedExpression);
|
|
276089
276094
|
}
|
|
276090
|
-
return transformers.computed(transformers.multiLineArrow(value2));
|
|
276095
|
+
return transformers.computed(transformers.multiLineArrow(value2, argsString));
|
|
276091
276096
|
}
|
|
276092
276097
|
|
|
276093
276098
|
// ../../../vite-plugin-file-sync/dist/parsing/computed/to-value-computed.js
|
|
@@ -276103,7 +276108,7 @@ function toValueComputed(expression) {
|
|
|
276103
276108
|
|
|
276104
276109
|
// ../../../vite-plugin-file-sync/dist/parsing/computed/index.js
|
|
276105
276110
|
var parser5 = {
|
|
276106
|
-
toCode: (value2) => toCodeComputed(value2),
|
|
276111
|
+
toCode: (value2, info) => toCodeComputed(value2, info),
|
|
276107
276112
|
toValue: (code) => toValueComputed(code)
|
|
276108
276113
|
};
|
|
276109
276114
|
|
|
@@ -277096,15 +277101,15 @@ function generateJSXElement({ id: id2, tagName, properties, children }) {
|
|
|
277096
277101
|
jsxElement.children = childElements;
|
|
277097
277102
|
return jsxElement;
|
|
277098
277103
|
}
|
|
277099
|
-
function generateJSXAttribute(name17,
|
|
277100
|
-
const valueNode = getPropertyExpression(
|
|
277104
|
+
function generateJSXAttribute(name17, info) {
|
|
277105
|
+
const valueNode = getPropertyExpression(info, name17);
|
|
277101
277106
|
if (import_types11.default.isStringLiteral(valueNode)) {
|
|
277102
277107
|
return import_types11.default.jsxAttribute(import_types11.default.jsxIdentifier(name17), valueNode);
|
|
277103
277108
|
} else {
|
|
277104
277109
|
return import_types11.default.jsxAttribute(import_types11.default.jsxIdentifier(name17), import_types11.default.jsxExpressionContainer(valueNode));
|
|
277105
277110
|
}
|
|
277106
277111
|
}
|
|
277107
|
-
function writeNestedProperty({ node, paths,
|
|
277112
|
+
function writeNestedProperty({ node, paths, info }) {
|
|
277108
277113
|
let currentNode = node;
|
|
277109
277114
|
const cleanedPaths = paths.map((path45) => {
|
|
277110
277115
|
if (path45.startsWith("[")) {
|
|
@@ -277123,16 +277128,16 @@ function writeNestedProperty({ node, paths, value: value2, type: type2 }) {
|
|
|
277123
277128
|
if (currentNode.isObjectExpression()) {
|
|
277124
277129
|
let property = currentNode.get("properties").find((prop) => prop.isObjectProperty() && getIdentiferName(prop.node.key) === currentKey);
|
|
277125
277130
|
if (!property) {
|
|
277126
|
-
const
|
|
277131
|
+
const value3 = cleanedPaths.length > 0 ? import_types11.default.objectExpression([]) : import_types11.default.stringLiteral("");
|
|
277127
277132
|
property = currentNode.pushContainer("properties", [
|
|
277128
|
-
import_types11.default.objectProperty(import_types11.default.identifier(currentKey.toString()),
|
|
277133
|
+
import_types11.default.objectProperty(import_types11.default.identifier(currentKey.toString()), value3)
|
|
277129
277134
|
])[0];
|
|
277130
277135
|
}
|
|
277131
|
-
const
|
|
277132
|
-
if (!
|
|
277136
|
+
const value2 = property?.get("value");
|
|
277137
|
+
if (!value2) {
|
|
277133
277138
|
break;
|
|
277134
277139
|
}
|
|
277135
|
-
currentNode = Array.isArray(
|
|
277140
|
+
currentNode = Array.isArray(value2) ? value2[0] : value2;
|
|
277136
277141
|
} else if (currentNode.isArrayExpression() && typeof currentKey === "number") {
|
|
277137
277142
|
const index = currentKey;
|
|
277138
277143
|
const nodeAtIndex = currentNode.get("elements")[index];
|
|
@@ -277157,7 +277162,7 @@ function writeNestedProperty({ node, paths, value: value2, type: type2 }) {
|
|
|
277157
277162
|
}
|
|
277158
277163
|
} else {
|
|
277159
277164
|
currentNode = currentNode.pushContainer("elements", [
|
|
277160
|
-
import_types11.default.stringLiteral(String(
|
|
277165
|
+
import_types11.default.stringLiteral(String(info.value))
|
|
277161
277166
|
])[0];
|
|
277162
277167
|
}
|
|
277163
277168
|
} else {
|
|
@@ -277166,18 +277171,19 @@ function writeNestedProperty({ node, paths, value: value2, type: type2 }) {
|
|
|
277166
277171
|
}
|
|
277167
277172
|
}
|
|
277168
277173
|
if (currentNode) {
|
|
277169
|
-
const valueNode = getPropertyExpression(
|
|
277174
|
+
const valueNode = getPropertyExpression(info, "");
|
|
277170
277175
|
currentNode.replaceWith(valueNode);
|
|
277171
277176
|
}
|
|
277172
277177
|
}
|
|
277173
|
-
function getPropertyExpression(
|
|
277178
|
+
function getPropertyExpression(info, fieldName = "") {
|
|
277174
277179
|
const logger3 = getLogger();
|
|
277180
|
+
const { value: value2, type: type2 } = info;
|
|
277175
277181
|
try {
|
|
277176
277182
|
if (type2 === "BINDING") {
|
|
277177
277183
|
const cleanedValue = typeof value2 === "string" ? value2.replaceAll("${", "\\${") : value2;
|
|
277178
277184
|
return stringToTaggedTemplate(cleanedValue);
|
|
277179
277185
|
} else if (type2 === "TEMPLATE") {
|
|
277180
|
-
const code = parsingRegistry.TEMPLATE.toCode(value2);
|
|
277186
|
+
const code = parsingRegistry.TEMPLATE.toCode(value2, info);
|
|
277181
277187
|
const expression = parseExpression(code);
|
|
277182
277188
|
if (expression) {
|
|
277183
277189
|
return expression;
|
|
@@ -277185,7 +277191,7 @@ function getPropertyExpression({ value: value2, type: type2 }, fieldName = "") {
|
|
|
277185
277191
|
return import_types11.default.stringLiteral(code);
|
|
277186
277192
|
}
|
|
277187
277193
|
} else if (type2 === "DIMENSION") {
|
|
277188
|
-
const code = parsingRegistry.DIMENSION.toCode(value2);
|
|
277194
|
+
const code = parsingRegistry.DIMENSION.toCode(value2, info);
|
|
277189
277195
|
const expression = parseExpression(code);
|
|
277190
277196
|
if (expression) {
|
|
277191
277197
|
return expression;
|
|
@@ -277194,7 +277200,7 @@ function getPropertyExpression({ value: value2, type: type2 }, fieldName = "") {
|
|
|
277194
277200
|
}
|
|
277195
277201
|
}
|
|
277196
277202
|
if (type2 === "EVENT") {
|
|
277197
|
-
const code = parsingRegistry.EVENT.toCode(value2);
|
|
277203
|
+
const code = parsingRegistry.EVENT.toCode(value2, info);
|
|
277198
277204
|
const expression = parseExpression(code);
|
|
277199
277205
|
if (expression) {
|
|
277200
277206
|
return expression;
|
|
@@ -277218,7 +277224,7 @@ function getPropertyExpression({ value: value2, type: type2 }, fieldName = "") {
|
|
|
277218
277224
|
}
|
|
277219
277225
|
if (parsed === void 0) {
|
|
277220
277226
|
try {
|
|
277221
|
-
const code = parsingRegistry.COMPUTED.toCode(value2);
|
|
277227
|
+
const code = parsingRegistry.COMPUTED.toCode(value2, info);
|
|
277222
277228
|
const computedExpression = parseExpression(code);
|
|
277223
277229
|
if (computedExpression) {
|
|
277224
277230
|
return computedExpression;
|
|
@@ -302669,7 +302675,7 @@ var SourceTracker = class {
|
|
|
302669
302675
|
* And you want to update the `accessor` property, you can use this function to do so, passing a property path like
|
|
302670
302676
|
* `columns.name.accessor`, rather than the entire columns object.
|
|
302671
302677
|
*/
|
|
302672
|
-
setNestedAttribute = ({ openingTag, property,
|
|
302678
|
+
setNestedAttribute = ({ openingTag, property, info }) => {
|
|
302673
302679
|
const [parent, ...paths] = splitJSPathAdvanced(property, []);
|
|
302674
302680
|
let parentAttr = openingTag.get("attributes").find((attr) => attr.isJSXAttribute() && attr.node.name.name === parent);
|
|
302675
302681
|
if (!parentAttr && parent) {
|
|
@@ -302686,14 +302692,13 @@ var SourceTracker = class {
|
|
|
302686
302692
|
writeNestedProperty({
|
|
302687
302693
|
node: currentNode,
|
|
302688
302694
|
paths,
|
|
302689
|
-
|
|
302690
|
-
type: type2
|
|
302695
|
+
info
|
|
302691
302696
|
});
|
|
302692
302697
|
};
|
|
302693
|
-
setAttribute = (openingTag, property,
|
|
302698
|
+
setAttribute = (openingTag, property, info) => {
|
|
302694
302699
|
const paths = splitJSPath(property);
|
|
302695
302700
|
if (Array.isArray(paths) && paths.length > 1) {
|
|
302696
|
-
this.setNestedAttribute({ openingTag, property,
|
|
302701
|
+
this.setNestedAttribute({ openingTag, property, info });
|
|
302697
302702
|
return;
|
|
302698
302703
|
}
|
|
302699
302704
|
let attr = openingTag.get("attributes").find((attr2) => attr2.isJSXAttribute() && attr2.node.name.name === property);
|
|
@@ -302702,6 +302707,7 @@ var SourceTracker = class {
|
|
|
302702
302707
|
import_types22.default.jsxAttribute(import_types22.default.jsxIdentifier(property), import_types22.default.stringLiteral(""))
|
|
302703
302708
|
])[0];
|
|
302704
302709
|
}
|
|
302710
|
+
const value2 = info.value;
|
|
302705
302711
|
if (value2 === void 0 || typeof value2 === "string" && value2 === "") {
|
|
302706
302712
|
attr.remove();
|
|
302707
302713
|
return;
|
|
@@ -302711,7 +302717,7 @@ var SourceTracker = class {
|
|
|
302711
302717
|
throw new Error("Attribute name not found");
|
|
302712
302718
|
}
|
|
302713
302719
|
const attrValue = attr.get("value");
|
|
302714
|
-
const jsxAttribute = generateJSXAttribute(property,
|
|
302720
|
+
const jsxAttribute = generateJSXAttribute(property, info);
|
|
302715
302721
|
if (jsxAttribute.value) {
|
|
302716
302722
|
attrValue.replaceWith(jsxAttribute.value);
|
|
302717
302723
|
}
|
|
@@ -302728,10 +302734,10 @@ var SourceTracker = class {
|
|
|
302728
302734
|
element.node.closingElement = import_types22.default.jsxClosingElement(import_types22.default.jsxIdentifier(getTagName(openingElement.node.name) ?? ""));
|
|
302729
302735
|
}
|
|
302730
302736
|
};
|
|
302731
|
-
setProperty = async ({ source: source2, property,
|
|
302737
|
+
setProperty = async ({ source: source2, property, info }) => {
|
|
302732
302738
|
await this.setProperties({
|
|
302733
302739
|
source: source2,
|
|
302734
|
-
changes: { [property]:
|
|
302740
|
+
changes: { [property]: info }
|
|
302735
302741
|
});
|
|
302736
302742
|
};
|
|
302737
302743
|
setProperties = async ({ source: source2, changes }) => {
|
|
@@ -302755,11 +302761,10 @@ var SourceTracker = class {
|
|
|
302755
302761
|
if (!openingTag.isJSXOpeningElement()) {
|
|
302756
302762
|
throw new Error(`Element ${source2.id} is not a JSXOpeningElement`);
|
|
302757
302763
|
}
|
|
302758
|
-
for (const [key2,
|
|
302759
|
-
const
|
|
302760
|
-
|
|
302761
|
-
|
|
302762
|
-
const requiredImports = REQUIRED_IMPORTS_BY_PROPERTY_TYPE[type2];
|
|
302764
|
+
for (const [key2, info] of Object.entries(changes)) {
|
|
302765
|
+
const jsxAttribute = this.setAttribute(openingTag, key2, info);
|
|
302766
|
+
if (info.type in REQUIRED_IMPORTS_BY_PROPERTY_TYPE) {
|
|
302767
|
+
const requiredImports = REQUIRED_IMPORTS_BY_PROPERTY_TYPE[info.type];
|
|
302763
302768
|
if (requiredImports) {
|
|
302764
302769
|
for (const { importName, importPath } of requiredImports) {
|
|
302765
302770
|
if (!this.fileToMeta[fileName].imports[importName]) {
|
|
@@ -302775,7 +302780,7 @@ var SourceTracker = class {
|
|
|
302775
302780
|
}
|
|
302776
302781
|
}
|
|
302777
302782
|
}
|
|
302778
|
-
if (
|
|
302783
|
+
if (info.type === "EVENT" && jsxAttribute) {
|
|
302779
302784
|
const referencedGlobalFunctions = getVariableReferences(jsxAttribute, GLOBAL_LIBRARY_NAMES);
|
|
302780
302785
|
referencedGlobalFunctions.forEach((funcName) => {
|
|
302781
302786
|
if (!this.fileToMeta[fileName].imports[funcName]) {
|
|
@@ -302790,7 +302795,7 @@ var SourceTracker = class {
|
|
|
302790
302795
|
}
|
|
302791
302796
|
});
|
|
302792
302797
|
}
|
|
302793
|
-
if (ATTRIBUTE_TYPES_WITH_STATE_ACCESS.includes(
|
|
302798
|
+
if (ATTRIBUTE_TYPES_WITH_STATE_ACCESS.includes(info.type) && jsxAttribute) {
|
|
302794
302799
|
const elementLocation = this.getElementToLocation(source2.id);
|
|
302795
302800
|
const scopeImports = this.sbScopeManager.getAndUpdateScopeImportsForCodeSnippet({
|
|
302796
302801
|
jsxAttribute,
|
|
@@ -303574,13 +303579,12 @@ export default registerPage(Page, { name: "${name17}" });
|
|
|
303574
303579
|
}
|
|
303575
303580
|
};
|
|
303576
303581
|
handleSetProperty = async (payload, writeFile8 = true) => {
|
|
303577
|
-
const { element: { source: source2 }, property, value:
|
|
303582
|
+
const { element: { source: source2 }, property, value: value2, transaction } = payload;
|
|
303578
303583
|
this.trackTransaction(transaction?.id);
|
|
303579
303584
|
await this.sourceTracker?.setProperty({
|
|
303580
303585
|
source: source2,
|
|
303581
303586
|
property,
|
|
303582
|
-
|
|
303583
|
-
type: type2
|
|
303587
|
+
info: value2
|
|
303584
303588
|
});
|
|
303585
303589
|
if (writeFile8) {
|
|
303586
303590
|
const changes = await this.sourceTracker?.getAndFlushChanges() ?? [];
|
|
@@ -308607,7 +308611,7 @@ async function startVite({ app, httpServer: httpServer2, root: root2, mode, port
|
|
|
308607
308611
|
};
|
|
308608
308612
|
const isCustomBuildEnabled2 = await isCustomComponentsEnabled();
|
|
308609
308613
|
const customFolder = path21.join(root2, "custom");
|
|
308610
|
-
const cdnUrl = "https://assets-cdn.superblocks.com/library/2.0.0-next.
|
|
308614
|
+
const cdnUrl = "https://assets-cdn.superblocks.com/library/2.0.0-next.8";
|
|
308611
308615
|
const env3 = loadEnv(mode, root2, "");
|
|
308612
308616
|
const hmrPort = await getFreePort();
|
|
308613
308617
|
const hmrOptions = {
|
|
@@ -315330,7 +315334,7 @@ init_cjs_shims();
|
|
|
315330
315334
|
init_cjs_shims();
|
|
315331
315335
|
var generated = {};
|
|
315332
315336
|
try {
|
|
315333
|
-
generated = await import("./generated-
|
|
315337
|
+
generated = await import("./generated-WWH6D7OC.js");
|
|
315334
315338
|
} catch (_error) {
|
|
315335
315339
|
getLogger().warn("[ai-service] Generated markdown modules not found. Run `pnpm generate:markdown` first.");
|
|
315336
315340
|
}
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superblocksteam/cli",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Official Superblocks CLI",
|
|
6
6
|
"homepage": "https://www.superblocks.com",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@eslint/js": "^9.16.0",
|
|
44
44
|
"@oclif/test": "^4.1.11",
|
|
45
|
-
"@superblocksteam/sdk": "2.0.0-next.
|
|
45
|
+
"@superblocksteam/sdk": "2.0.0-next.8",
|
|
46
46
|
"@superblocksteam/shared": "0.9122.0",
|
|
47
|
-
"@superblocksteam/util": "2.0.0-next.
|
|
47
|
+
"@superblocksteam/util": "2.0.0-next.8",
|
|
48
48
|
"@types/babel__core": "^7.20.0",
|
|
49
49
|
"@types/chai": "^4",
|
|
50
50
|
"@types/fs-extra": "^11.0.1",
|