Repository navigation
Replies: 2 comments
|
Would love to see this implemented |
|
+1 on this. The One case the current API doesn't quite cover: besides build-time components like a donation button or social feed, I'm building a plugin where the template and props schema get authored at runtime and resolved by id, with a single renderer behind them. That mostly works as proposed, but it relates to the open questions: it would be extremely helpful if |
Uh oh!
There was an error while loading. Please reload this page.
Problem
Plugins cannot register widget components. Two gaps, both in core:
getWidgetComponents()inpackages/core/src/widgets/components.ts:103returns onlycoreWidgetComponents. The comment on line 101 reads: "For now, only returns core components. Plugin widgets will be added later."packages/core/src/components/WidgetRenderer.astro:19uses a hardcodedcomponentMapwith static imports. Even if a plugin registered a definition, there is no way to resolve a plugin-provided Astro component at render time.Issue #343 documents this, with the same two-part framing and 3 thumbs-up.
Use case: a plugin that ships reusable widget components (donation button, social feed, newsletter signup) that admins can place in any widget area through the admin UI, without the theme author importing and mapping each plugin component.
Precedent
Portable Text already solves this problem. Plugins export
blockComponentsfrom acomponentsEntrymodule,generateBlockComponentsModuleinpackages/core/src/astro/integration/virtual-modules.ts:339concatenates them into a virtual module at build time, and<PortableText>consumes the merged map.Widgets can use the same shape.
Proposed API
Plugins export a
widgetComponentsrecord from their existingcomponentsEntrymodule:Plugins also contribute widget definitions (id, label, props schema) via a new field on the plugin descriptor:
Integration sites
packages/core/src/astro/integration/virtual-modules.ts. AddgenerateWidgetComponentsModule(descriptors)next togenerateBlockComponentsModuleat line 339. Same filter oncomponentsEntry, sameimport { widgetComponents as wc0 } from ...shape, exportspluginWidgetComponents.packages/core/src/astro/integration/index.ts. Register the new virtual module alongside the block components virtual module.packages/core/src/widgets/components.ts.getWidgetComponents()mergescoreWidgetComponentswith plugin-contributedWidgetComponentDef[]pulled from active plugin descriptors.packages/core/src/components/WidgetRenderer.astro. Replace the hardcodedcomponentMapwith a merged map of core components plusvirtual:emdash/plugin-widget-components. Resolvewidget.componentIdagainst the merged map.packages/core/src/plugins/types.ts. AddwidgetDefinitions?: WidgetComponentDef[]to the trusted plugin descriptor.Rules
core:is reserved.export const pluginWidgetComponents = {};).Sandboxed plugins
Out of scope for this Discussion. The proposal covers trusted plugins only, which matches the current
componentsEntry+blockComponentsstory. Sandboxed widget components would require serializing component modules across the sandbox boundary, which is a separate design question.Open questions
PropDefmap today, consumed by the admin editor dropdown. Should plugin-contributedPropDefmaps go through a runtime zod-style check, or trust the trusted-plugin contract as is?defineWidget()helper co-located with the Astro component?Happy to open a PR once this is approved. Closes #343 if shipped.
All reactions