forked from microsoft/fast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(design-system): make FoundationElement.compose safe to use direct…
…ly (microsoft#5157) * fix(design=system): don't allow FoundationElement to be defined directly * fix(design-system): don't allow FoundationElement to be defined directly * chore: correct the change file * fix(design-system): move files to remove circular module references * chore: fixing after merge from resolving changes incompletely Co-authored-by: EisenbergEffect <roeisenb@microsoft.com>
- Loading branch information
1 parent
3e85a30
commit a508e1e
Showing
6 changed files
with
184 additions
and
141 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@microsoft-fast-foundation-fb2bff9c-3129-4433-bf60-2b85c82258d4.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "fix(design-system): make FoundationElement.compose safe to use directly", | ||
"packageName": "@microsoft/fast-foundation", | ||
"email": "roeisenb@microsoft.com", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/web-components/fast-foundation/src/design-system/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./design-system"; | ||
export * from "./component-presentation"; | ||
export * from "./registration-context"; |
137 changes: 137 additions & 0 deletions
137
packages/web-components/fast-foundation/src/design-system/registration-context.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import { Container, DI, InterfaceSymbol } from "../di/di"; | ||
import type { | ||
Constructable, | ||
PartialFASTElementDefinition, | ||
} from "@microsoft/fast-element"; | ||
import type { ComponentPresentation } from "./component-presentation"; | ||
|
||
/** | ||
* Enables defining an element within the context of a design system. | ||
* @public | ||
*/ | ||
export type ContextualElementDefinition = Omit<PartialFASTElementDefinition, "name">; | ||
|
||
/** | ||
* The design system context in which an element can be defined. | ||
* @public | ||
*/ | ||
export interface ElementDefinitionContext { | ||
/** | ||
* The name that the element will be defined as. | ||
* @public | ||
*/ | ||
readonly name: string; | ||
|
||
/** | ||
* The type that will be defined. | ||
* @public | ||
*/ | ||
readonly type: Constructable; | ||
|
||
/** | ||
* The dependency injection container associated with the design system. | ||
* @public | ||
*/ | ||
readonly container: Container; | ||
|
||
/** | ||
* Indicates whether or not a platform define call will be made in order | ||
* to define the element. | ||
* @public | ||
*/ | ||
readonly willDefine: boolean; | ||
|
||
/** | ||
* The shadow root mode specified by the design system's configuration. | ||
* @public | ||
*/ | ||
readonly shadowRootMode: ShadowRootMode | undefined; | ||
|
||
/** | ||
* Defines the element. | ||
* @param definition - The definition for the element. | ||
* @public | ||
*/ | ||
defineElement(definition?: ContextualElementDefinition): void; | ||
|
||
/** | ||
* Defines a presentation for the element. | ||
* @param presentation - The presentation configuration. | ||
* @public | ||
*/ | ||
definePresentation(presentation: ComponentPresentation): void; | ||
|
||
/** | ||
* Returns the HTML element tag name that the type will be defined as. | ||
* @param type - The type to lookup. | ||
* @public | ||
*/ | ||
tagFor(type: Constructable): string; | ||
} | ||
|
||
/** | ||
* The callback type that is invoked when an element can be defined by a design system. | ||
* @public | ||
*/ | ||
export type ElementDefinitionCallback = (ctx: ElementDefinitionContext) => void; | ||
|
||
/** | ||
* The element definition context interface. Designed to be used in `tryDefineElement` | ||
* @public | ||
*/ | ||
export interface ElementDefinitionParams | ||
extends Pick<ElementDefinitionContext, "name" | "type"> { | ||
/** | ||
* FAST actual base class instance. | ||
* @public | ||
*/ | ||
readonly baseClass?: Constructable; | ||
/** | ||
* A callback to invoke if definition will happen. | ||
* @public | ||
*/ | ||
callback: ElementDefinitionCallback; | ||
} | ||
|
||
/** | ||
* Design system contextual APIs and configuration usable within component | ||
* registries. | ||
* @public | ||
*/ | ||
export interface DesignSystemRegistrationContext { | ||
/** | ||
* The element prefix specified by the design system's configuration. | ||
* @public | ||
*/ | ||
readonly elementPrefix: string; | ||
|
||
/** | ||
* Used to attempt to define a custom element. | ||
* @param name - The name of the element to define. | ||
* @param type - The type of the constructor to use to define the element. | ||
* @param callback - A callback to invoke if definition will happen. | ||
* @public | ||
* @deprecated - Use the signature with the ElementDefinitionParams param type instead | ||
*/ | ||
tryDefineElement( | ||
name: string, | ||
type: Constructable, | ||
callback: ElementDefinitionCallback | ||
); | ||
|
||
/** | ||
* Used to attempt to define a custom element. | ||
* @param params - The custom element definition. | ||
* @public | ||
*/ | ||
tryDefineElement(params: ElementDefinitionParams); | ||
} | ||
|
||
/** | ||
* Design system contextual APIs and configuration usable within component | ||
* registries. | ||
* @public | ||
*/ | ||
export const DesignSystemRegistrationContext: InterfaceSymbol<DesignSystemRegistrationContext> = DI.createInterface< | ||
DesignSystemRegistrationContext | ||
>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters