Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/forward-plugin-blocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"emdash": minor
---

Forward declarative `portableTextBlocks` and `fieldWidgets` from standard and sandboxed (from-config) plugins

Standard- and sandboxed-format plugins could already declare admin pages and dashboard widgets, but their declarative Portable Text block types and field widgets were dropped during adaptation — only native-format plugins surfaced them. Since the admin editor reads these from the manifest, the slash-menu entries and Block Kit forms never appeared for non-native plugins.

`adaptSandboxEntry` now forwards both for standard plugins and sandboxed plugins resolved from config (the `virtual-modules.ts` codegen path), so those formats can contribute Portable Text blocks and field widgets. The site-side render component (`componentsEntry`) still requires native format, which is unchanged.

Note: marketplace bundles loaded from R2 are not covered yet — the bundle manifest schema, both `extractManifest()` implementations, and the bundler don't carry these fields, so this is scoped to standard/sandboxed-from-config. Full marketplace support is tracked as a follow-up.
15 changes: 14 additions & 1 deletion packages/core/src/astro/integration/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
import type { AuthDescriptor, AuthProviderDescriptor } from "../../auth/types.js";
import type { DatabaseDescriptor } from "../../db/adapters.js";
import type { MediaProviderDescriptor } from "../../media/types.js";
import type { ResolvedPlugin } from "../../plugins/types.js";
import type {
FieldWidgetConfig,
PortableTextBlockConfig,
ResolvedPlugin,
} from "../../plugins/types.js";
import type { ExperimentalConfig } from "../../registry/types.js";
import type { StorageDescriptor } from "../storage/types.js";

Expand Down Expand Up @@ -98,6 +102,15 @@ export interface PluginDescriptor<TOptions = Record<string, unknown>> {
adminPages?: PluginAdminPage[];
/** Dashboard widgets */
adminWidgets?: PluginDashboardWidget[];
/**
* Portable Text block types this plugin contributes to the editor.
* Declarative (Block Kit) — surfaced in the admin slash menu and consumed
* from the manifest, so standard/sandboxed plugins can contribute blocks
* without a native render component.
*/
portableTextBlocks?: PortableTextBlockConfig[];
/** Field widget types this plugin contributes for schema-field editing UIs. */
fieldWidgets?: FieldWidgetConfig[];

// === Sandbox-specific fields (for sandboxed plugins) ===

Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/astro/integration/virtual-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ export function generatePluginsModule(descriptors: PluginDescriptor[]): string {
storage: descriptor.storage,
adminPages: descriptor.adminPages,
adminWidgets: descriptor.adminWidgets,
portableTextBlocks: descriptor.portableTextBlocks,
fieldWidgets: descriptor.fieldWidgets,
})})`,
);
} else {
Expand Down Expand Up @@ -589,6 +591,8 @@ export const sandboxedPlugins = [];
storage: ${JSON.stringify(descriptor.storage ?? {})},
adminPages: ${JSON.stringify(descriptor.adminPages ?? [])},
adminWidgets: ${JSON.stringify(descriptor.adminWidgets ?? [])},
portableTextBlocks: ${JSON.stringify(descriptor.portableTextBlocks ?? [])},
fieldWidgets: ${JSON.stringify(descriptor.fieldWidgets ?? [])},
adminEntry: ${JSON.stringify(descriptor.adminEntry)},
// Code read from: ${filePath}
code: ${JSON.stringify(code)},
Expand Down
22 changes: 18 additions & 4 deletions packages/core/src/emdash-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import type {
PublicPageContext,
PageMetadataContribution,
PageFragmentContribution,
PortableTextBlockConfig,
FieldWidgetConfig,
} from "./plugins/types.js";
import type { FieldType } from "./schema/types.js";
import { hashString } from "./utils/hash.js";
Expand Down Expand Up @@ -212,6 +214,10 @@ export interface SandboxedPluginEntry {
adminPages?: Array<{ path: string; label?: string; icon?: string }>;
/** Dashboard widgets */
adminWidgets?: Array<{ id: string; title?: string; size?: string }>;
/** Portable Text block types contributed to the editor (declarative Block Kit) */
portableTextBlocks?: PortableTextBlockConfig[];
/** Field widget types contributed for schema-field editing UIs */
fieldWidgets?: FieldWidgetConfig[];
/** Admin entry module */
adminEntry?: string;
/**
Expand Down Expand Up @@ -384,7 +390,10 @@ const marketplaceManifestCache = new Map<
{
id: string;
version: string;
admin?: { pages?: PluginAdminPage[]; widgets?: PluginDashboardWidget[] };
admin?: {
pages?: PluginAdminPage[];
widgets?: PluginDashboardWidget[];
};
}
>();
/** Route metadata for sandboxed plugins: pluginId -> routeName -> RouteMeta */
Expand Down Expand Up @@ -1570,6 +1579,8 @@ export class EmDashRuntime {
storage: entry.storage as never,
adminPages,
adminWidgets,
portableTextBlocks: entry.portableTextBlocks,
fieldWidgets: entry.fieldWidgets,
});
plugins.push(resolved);
console.log(
Expand Down Expand Up @@ -2096,9 +2107,6 @@ export class EmDashRuntime {
}

// Add sandboxed plugins (use entries for admin config)
// TODO: sandboxed plugins need fieldWidgets extracted from their manifest
// to support Block Kit field widgets. Currently only trusted plugins carry
// fieldWidgets through the admin.fieldWidgets path.
for (const entry of this.sandboxedPluginEntries) {
const status = this.pluginStates.get(entry.id);
const enabled = status === undefined || status === "active";
Expand All @@ -2110,9 +2118,15 @@ export class EmDashRuntime {
version: entry.version,
enabled,
sandboxed: true,
// `adminMode` reflects only admin pages/widgets. A plugin can
// contribute portableTextBlocks/fieldWidgets with adminMode "none" —
// the admin reads those from the manifest regardless, so don't gate
// admin contributions on `adminMode`.
adminMode: hasAdminPages || hasWidgets ? "blocks" : "none",
adminPages: entry.adminPages ?? [],
dashboardWidgets: entry.adminWidgets ?? [],
portableTextBlocks: entry.portableTextBlocks,
fieldWidgets: entry.fieldWidgets,
};
}

Expand Down
12 changes: 11 additions & 1 deletion packages/core/src/plugins/adapt-sandbox-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,24 @@ export function adaptSandboxEntry(
};
}

// Build admin config from descriptor
// Build admin config from descriptor.
// Portable Text blocks and field widgets are declarative (Block Kit), so they
// are forwarded for standard/sandboxed plugins just like pages and widgets —
// the admin editor consumes them from the manifest. Only the site-side render
// component (`componentsEntry`) stays native-only.
const admin: PluginAdminConfig = {};
if (descriptor.adminPages) {
admin.pages = descriptor.adminPages;
}
if (descriptor.adminWidgets) {
admin.widgets = descriptor.adminWidgets;
}
if (descriptor.portableTextBlocks) {
admin.portableTextBlocks = descriptor.portableTextBlocks;
}
if (descriptor.fieldWidgets) {
admin.fieldWidgets = descriptor.fieldWidgets;
}

return {
id: pluginId,
Expand Down
57 changes: 57 additions & 0 deletions packages/core/tests/unit/plugins/adapt-sandbox-entry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,63 @@ describe("adaptSandboxEntry", () => {

expect(result.admin.widgets).toEqual([{ id: "status", title: "Status", size: "half" }]);
});

it("carries portable text blocks from descriptor", () => {
const def: SandboxedPlugin = {};
const descriptor = createDescriptor({
portableTextBlocks: [
{
type: "faq",
label: "FAQ",
icon: "list",
category: "Sections",
fields: [
{
type: "repeater",
action_id: "items",
label: "Questions",
item_label: "Question",
fields: [
{ type: "text_input", action_id: "q", label: "Question" },
{ type: "text_input", action_id: "a", label: "Answer", multiline: true },
],
},
],
},
],
});

const result = adaptSandboxEntry(def, descriptor);

expect(result.admin.portableTextBlocks).toEqual(descriptor.portableTextBlocks);
});

it("carries field widgets from descriptor", () => {
const def: SandboxedPlugin = {};
const descriptor = createDescriptor({
fieldWidgets: [
{
name: "color-picker",
label: "Color Picker",
fieldTypes: ["string"],
},
],
});

const result = adaptSandboxEntry(def, descriptor);

expect(result.admin.fieldWidgets).toEqual(descriptor.fieldWidgets);
});

it("leaves admin block config undefined when the descriptor omits it", () => {
const def: SandboxedPlugin = {};
const descriptor = createDescriptor();

const result = adaptSandboxEntry(def, descriptor);

expect(result.admin.portableTextBlocks).toBeUndefined();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The three new cases cover adaptSandboxEntry in isolation, which is fine, but the PR's headline claim ("the marketplace manifest cache carry them") isn't exercised anywhere. A test that drives a synthetic PluginBundle through pluginManifestSchema.safeParse → reconcileManifestAccess and asserts that admin.portableTextBlocks / admin.fieldWidgets survive would have caught the issue that the manifest schema strips portableTextBlocks. Worth adding before claiming the marketplace path works.

expect(result.admin.fieldWidgets).toBeUndefined();
});
});

describe("hook adaptation", () => {
Expand Down
Loading