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
53 changes: 8 additions & 45 deletions packages/base/card-api.gts
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,6 @@ interface Options {
isUsed?: true;
// Optional: per-usage configuration provider merged with FieldDef-level configuration
configuration?: ConfigurationInput<any>;
// Optional: per-usage edit component that overrides the FieldDef's
// `static edit` for this specific field declaration. Lets a parent
// card customize the editor for one of its fields without having
// to subclass the FieldDef or replace its own `static edit`.
// ComponentLike<any> rather than BaseDefComponent so that wrap-style
// overrides on collection fields (containsMany / linksToMany) can
// declare their own Args shape — e.g. accepting `@values` and
// `@defaultEditor`. The runtime contract per field type is documented
// at the rendering sites.
edit?: ComponentLike<any>;
}

interface RelationshipOptions extends Options {
Expand Down Expand Up @@ -555,15 +545,6 @@ export interface Field<
computeVia: undefined | (() => unknown);
// Optional per-usage configuration stored on the field descriptor
configuration?: ConfigurationInput<any>;
// Optional per-usage edit component override — when set, the field
// renders with this Component in edit format instead of the
// FieldDef's `static edit`.
// ComponentLike<any> rather than BaseDefComponent so that wrap-style
// overrides on collection fields (containsMany / linksToMany) can
// declare their own Args shape — e.g. accepting `@values` and
// `@defaultEditor`. The runtime contract per field type is documented
// at the rendering sites.
edit?: ComponentLike<any>;
// Declarative relationship query definition, if provided
queryDefinition?: QueryWithInterpolations;
captureQueryFieldSeedData?(
Expand Down Expand Up @@ -649,7 +630,6 @@ class ContainsMany<FieldT extends FieldDefConstructor> implements Field<
readonly computeVia: undefined | (() => unknown);
readonly name: string;
readonly description: string | undefined;
readonly edit?: ComponentLike<any>;
readonly isUsed: undefined | true;
readonly isPolymorphic: undefined | true;
configuration: ConfigurationInput<any> | undefined;
Expand Down Expand Up @@ -977,7 +957,6 @@ class Contains<CardT extends FieldDefConstructor> implements Field<CardT, any> {
readonly computeVia: undefined | (() => unknown);
readonly name: string;
readonly description: string | undefined;
readonly edit?: ComponentLike<any>;
readonly isUsed: undefined | true;
readonly isPolymorphic: undefined | true;
configuration: ConfigurationInput<any> | undefined;
Expand Down Expand Up @@ -1206,7 +1185,6 @@ class LinksTo<CardT extends LinkableDefConstructor> implements Field<CardT> {
readonly computeVia: undefined | (() => unknown);
readonly name: string;
readonly description: string | undefined;
readonly edit?: ComponentLike<any>;
readonly isUsed: undefined | true;
readonly isPolymorphic: undefined | true;
readonly configuration?: ConfigurationInput<any>;
Expand Down Expand Up @@ -1599,25 +1577,14 @@ class LinksTo<CardT extends LinkableDefConstructor> implements Field<CardT> {
{{#if
(shouldRenderEditor @format defaultFormats.cardDef isComputed)
}}
{{#if linksToField.edit}}
<linksToField.edit
@model={{(getInnerModel)}}
@field={{linksToField}}
@brokenLink={{broken}}
@typeConstraint={{@typeConstraint}}
@createCard={{cardCrudFunctions.createCard}}
...attributes
/>
{{else}}
<LinksToEditor
@model={{(getInnerModel)}}
@field={{linksToField}}
@brokenLink={{broken}}
@typeConstraint={{@typeConstraint}}
@createCard={{cardCrudFunctions.createCard}}
...attributes
/>
{{/if}}
<LinksToEditor
@model={{(getInnerModel)}}
@field={{linksToField}}
@brokenLink={{broken}}
@typeConstraint={{@typeConstraint}}
@createCard={{cardCrudFunctions.createCard}}
...attributes
/>
{{else if broken}}
<BrokenLinkTemplate
@brokenUrl={{broken.reference}}
Expand Down Expand Up @@ -2331,7 +2298,6 @@ export function containsMany<FieldT extends FieldDefConstructor>(
isUsed,
});
(instance as any).configuration = options?.configuration;
(instance as any).edit = options?.edit;
return makeDescriptor(instance);
},
description: options?.description,
Expand All @@ -2352,7 +2318,6 @@ export function contains<FieldT extends FieldDefConstructor>(
isUsed,
});
(instance as any).configuration = options?.configuration;
(instance as any).edit = options?.edit;
return makeDescriptor(instance);
},
description: options?.description,
Expand All @@ -2379,7 +2344,6 @@ export function linksTo<CardT extends LinkableDefConstructor>(
queryDefinition: query,
});
(instance as any).configuration = options?.configuration;
(instance as any).edit = options?.edit;
return makeDescriptor(instance);
},
description: options?.description,
Expand All @@ -2406,7 +2370,6 @@ export function linksToMany<CardT extends LinkableDefConstructor>(
queryDefinition: query,
});
(instance as any).configuration = options?.configuration;
(instance as any).edit = options?.edit;
return makeDescriptor(instance);
},
description: options?.description,
Expand Down
37 changes: 7 additions & 30 deletions packages/base/contains-many-component.gts
Original file line number Diff line number Diff line change
Expand Up @@ -353,36 +353,13 @@ export function getContainsManyComponent({
<DefaultFormatsConsumer as |defaultFormats|>
{{setOverrides model.value}}
{{#if (shouldRenderEditor @format defaultFormats.fieldDef isComputed)}}
{{#if field.edit}}
{{!-- Per-usage edit override on a containsMany.
Contract: the override receives the containing card as
@model, the current values array as @values, and a
pre-bound default ContainsManyEditor as @defaultEditor
so it can wrap (e.g. render a banner above) the standard
iteration + add/remove/sortable UI without
reimplementing it. --}}
<field.edit
@model={{model.value}}
@values={{arrayField.value}}
@defaultEditor={{component
ContainsManyEditor
model=model
arrayField=arrayField
field=field
cardTypeFor=cardTypeFor
typeConstraint=@typeConstraint
}}
...attributes
/>
{{else}}
<ContainsManyEditor
@model={{model}}
@arrayField={{arrayField}}
@field={{field}}
@cardTypeFor={{cardTypeFor}}
@typeConstraint={{@typeConstraint}}
/>
{{/if}}
<ContainsManyEditor
@model={{model}}
@arrayField={{arrayField}}
@field={{field}}
@cardTypeFor={{cardTypeFor}}
@typeConstraint={{@typeConstraint}}
/>
{{else}}
{{#let
(coalesce @format defaultFormats.fieldDef)
Expand Down
25 changes: 3 additions & 22 deletions packages/base/field-component.gts
Original file line number Diff line number Diff line change
Expand Up @@ -234,28 +234,9 @@ export function getBoxComponent(
) {
viewSlot = 'embedded';
}
// Per-usage `edit` override on an atomic field wins over the
// FieldDef's `static edit`. Restricted to `contains` / `linksTo`
// here — collection fields (`containsMany` / `linksToMany`) carry
// their own override path in their component files, where the
// wrap-style contract can pass `@defaultEditor`. Without this
// gate the collection's field descriptor would also reach each
// iterated item and replace its template, blanking the item rows.
// The per-usage override expresses stronger intent than the
// view-slot dedup above: if the consumer explicitly supplied
// `edit:`, they asked for a different component in edit format,
// so it must win even when the FieldDef aliases its embedded /
// isolated slot to the same reference as its `static edit`.
// (Toggling embedded↔edit will remount as a result — that's
// correct; the consumer opted into a different component.)
let isAtomicFieldType =
field?.fieldType === 'contains' || field?.fieldType === 'linksTo';
let CardOrFieldFormatComponent: BaseDefComponent =
effectiveFormat === 'edit' && isAtomicFieldType && field?.edit
? field.edit
: viewSlot
? componentClass[viewSlot]
: componentClass[effectiveFormat];
let CardOrFieldFormatComponent: BaseDefComponent = viewSlot
? componentClass[viewSlot]
: componentClass[effectiveFormat];
return {
CardOrFieldFormatComponent,
fields,
Expand Down
53 changes: 13 additions & 40 deletions packages/base/links-to-many-component.gts
Original file line number Diff line number Diff line change
Expand Up @@ -658,46 +658,19 @@ export function getLinksToManyComponent({
<template>
<DefaultFormatsConsumer as |defaultFormats|>
{{#if (shouldRenderEditor @format defaultFormats.cardDef isComputed)}}
{{#if field.edit}}
{{!-- Per-usage edit override on a linksToMany. Contract
mirrors containsMany: the override receives the
containing card as @model, the current values array
as @values, and a pre-bound default LinksToManyEditor
as @defaultEditor so it can wrap the standard iteration
/ add / remove UI without reimplementing it. --}}
<field.edit
@model={{model.value}}
@values={{arrayField.value}}
@defaultEditor={{component
LinksToManyEditor
model=model
arrayField=arrayField
field=field
cardTypeFor=cardTypeFor
childFormat=(getEditorChildFormat
@format
defaultFormats.cardDef
model
)
typeConstraint=@typeConstraint
}}
...attributes
/>
{{else}}
<LinksToManyEditor
@model={{model}}
@arrayField={{arrayField}}
@field={{field}}
@cardTypeFor={{cardTypeFor}}
@childFormat={{getEditorChildFormat
@format
defaultFormats.cardDef
model
}}
@typeConstraint={{@typeConstraint}}
...attributes
/>
{{/if}}
<LinksToManyEditor
@model={{model}}
@arrayField={{arrayField}}
@field={{field}}
@cardTypeFor={{cardTypeFor}}
@childFormat={{getEditorChildFormat
@format
defaultFormats.cardDef
model
}}
@typeConstraint={{@typeConstraint}}
...attributes
/>
{{else}}
{{#let
(coalesce @format defaultFormats.cardDef)
Expand Down
Loading
Loading