Skip to content

Commit 3d3380e

Browse files
committed
feat(Registry): add skipFallback option to prevent component name conflicts
1 parent 6eb291b commit 3d3380e

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

packages/core/src/registry/Registry.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ export type ComponentMeta = {
2727
icon?: string; // Icon name or svg string
2828
category?: string; // Grouping category
2929
namespace?: string; // Component namespace (e.g., 'ui', 'plugin-grid', 'field')
30+
/**
31+
* When true, prevents the component from being registered with a non-namespaced fallback.
32+
* Use this when a component should only be accessible via its full namespaced key.
33+
* This avoids conflicts with other components that share the same base name.
34+
*
35+
* @example
36+
* // Register as 'view:form' only, don't overwrite 'form'
37+
* registry.register('form', FormView, { namespace: 'view', skipFallback: true });
38+
*/
39+
skipFallback?: boolean;
3040
inputs?: ComponentInput[];
3141
defaultProps?: Record<string, any>; // Default props when dropped
3242
defaultChildren?: SchemaNode[]; // Default children when dropped
@@ -94,7 +104,8 @@ export class Registry<T = any> {
94104
// This allows "button" to work even when registered as "ui:button"
95105
// Note: If multiple namespaced components share the same short name,
96106
// the last registration wins for non-namespaced lookups
97-
if (meta?.namespace) {
107+
// Skip this if skipFallback is true to avoid overwriting other components
108+
if (meta?.namespace && !meta?.skipFallback) {
98109
this.components.set(type, {
99110
type: fullType, // Keep reference to namespaced type
100111
component,

packages/plugin-form/src/index.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ ComponentRegistry.register('object-form', ObjectFormRenderer, {
2929
]
3030
});
3131

32-
// Note: 'form' type is handled by @object-ui/components Form component
33-
// This plugin only handles 'object-form' which integrates with ObjectQL/ObjectStack
34-
// Do NOT register as 'form' - that would conflict with the low-level Form renderer
32+
// Register as view:form for the standard view protocol
33+
// This allows using { type: 'view:form', objectName: '...' } in schemas
34+
// skipFallback prevents overwriting the basic 'form' component from @object-ui/components
35+
ComponentRegistry.register('form', ObjectFormRenderer, {
36+
namespace: 'view',
37+
skipFallback: true,
38+
label: 'Data Form View',
39+
category: 'view',
40+
inputs: [
41+
{ name: 'objectName', type: 'string', label: 'Object Name', required: true },
42+
{ name: 'fields', type: 'array', label: 'Fields' },
43+
{ name: 'mode', type: 'enum', label: 'Mode', enum: ['create', 'edit', 'view'] },
44+
]
45+
});
46+
47+
// Note: 'form' type (without namespace) is handled by @object-ui/components Form component
48+
// This plugin registers as 'view:form' (with view namespace) for the view protocol
49+
// ObjectForm internally uses { type: 'form' } to render the basic Form component

0 commit comments

Comments
 (0)