Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat: support create block with params (#668)

gbirman0469c8c68ae8
diff --git a/js/app/packages/app/component/split-layout/layoutManager.ts b/js/app/packages/app/component/split-layout/layoutManager.ts
index f568857915..d89e05c2fc 100644
--- a/js/app/packages/app/component/split-layout/layoutManager.ts
+++ b/js/app/packages/app/component/split-layout/layoutManager.ts
@@ -1,4 +1,9 @@
-import type { BlockAlias, BlockAliasContext, BlockName } from '@core/block';
+import type {
+ BlockAlias,
+ BlockAliasContext,
+ BlockComponentProps,
+ BlockName,
+} from '@core/block';
import type { ResizeZoneCtx } from '@core/component/Resize/types';
import { isBlockAlias, resolveBlockAlias } from '@core/constant/allBlocks';
import type {
@@ -29,7 +34,7 @@ export type SplitContent =
| {
type: BlockName | BlockAlias;
id: string;
- params?: Record<string, string>;
+ params?: BlockComponentProps[BlockName];
aliasContext?: BlockAliasContext;
}
| {
@@ -270,6 +275,7 @@ function createPinnedMount(
const blockType = resolveBlockAlias(content.type);
const handle = orchestrator.createBlockInstance(blockType, content.id, {
aliasContext: content.aliasContext,
+ params: content.params,
});
return {
diff --git a/js/app/packages/core/block.ts b/js/app/packages/core/block.ts
index bb0e60af88..391b35ad68 100644
--- a/js/app/packages/core/block.ts
+++ b/js/app/packages/core/block.ts
@@ -115,7 +115,6 @@ export type NestedState<Name extends BlockName> = {
parentId?: string;
parentName?: Name;
parentContext?: PreviewState;
- initArgs?: BlockComponentProps[Name];
};
const allBlockNames = new Set([...BlockRegistry]);
@@ -273,7 +272,7 @@ type ExtractSuccessType<T> = T extends [null, infer S]
export type ExtractLoadType<T extends LoadFunction<any, any>> =
ExtractSuccessType<Awaited<ReturnType<T>>>;
-interface BlockComponentProps extends Record<BlockName, ObjectLike> {
+export interface BlockComponentProps extends Record<BlockName, ObjectLike> {
canvas: BlockCanvasProps;
}
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/decorator/DocumentCard.tsx b/js/app/packages/core/component/LexicalMarkdown/component/decorator/DocumentCard.tsx
index 7e90a7379f..8dc67b6f38 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/decorator/DocumentCard.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/decorator/DocumentCard.tsx
@@ -206,9 +206,9 @@ export function DocumentCard(props: DocumentCardDecoratorProps) {
resolveBlockAlias(verifyBlockName(props.blockName)),
documentId,
{
+ params: previewData(),
nested: {
parentContext: previewContext(),
- initArgs: previewData(),
},
}
);
diff --git a/js/app/packages/core/orchestrator.tsx b/js/app/packages/core/orchestrator.tsx
index 838005aa63..3d16ccab4b 100644
--- a/js/app/packages/core/orchestrator.tsx
+++ b/js/app/packages/core/orchestrator.tsx
@@ -13,6 +13,7 @@ import { createStore } from 'solid-js/store';
import {
type BlockAliasContext,
Block as BlockComponent,
+ type BlockComponentProps,
type BlockName,
type NestedState,
ValidNestingCombinations,
@@ -84,10 +85,11 @@ type BlockInstance = {
handle: OwnedBlockHandle<any>;
};
-export type CreateBlockOptions = {
+export type CreateBlockOptions<Name extends BlockName = BlockName> = {
+ params?: BlockComponentProps[Name];
location?: Location;
nested?: NestedState<any>;
- sourceResolver?: (type: BlockName, id: string, location?: Location) => Source;
+ sourceResolver?: (type: Name, id: string, location?: Location) => Source;
aliasContext?: BlockAliasContext;
};
@@ -177,7 +179,14 @@ function createBlockElement({
return () => {
onMount(() => {
onElementMount?.();
- console.log('mounting block with id:', id, 'type:', type);
+ console.log(
+ 'mounting block with id:',
+ id,
+ 'type:',
+ type,
+ 'params:',
+ opts?.params
+ );
});
onCleanup(() => {
@@ -199,7 +208,7 @@ function createBlockElement({
handle={ownedHandle}
/>
<Suspense>
- <definition.component {...(opts?.nested?.initArgs ?? {})} />
+ <definition.component {...(opts?.params ?? {})} />
</Suspense>
<BlockEffectRunner />
</BlockComponent>