import { LimeWebComponentContext } from './context'; import { LimeWebComponentPlatform } from './platform'; /** * Base interface that all Lime Web Components must implement. * * This interface ensures that every component has access to the {@link LimeWebComponentPlatform} * service container and understands its {@link LimeWebComponentContext} within the application. * In Stencil components, these are injected as properties using the `@Prop` decorator. * * @example * ```ts * import { PlatformServiceName } from '@limetech/lime-web-components'; * * // Access services through the platform * const repository = platform.get(PlatformServiceName.LimeObjectRepository); * const translate = platform.get(PlatformServiceName.Translate); * * // Use the context to load the record the component is running for * if (context.limetype && context.id) { * const limeObject = await repository.loadObject( * context.limetype, * context.id * ); * * const heading = limeObject * ? limeObject.getValue('name') * : translate.get('missing_record'); * } * ``` * * @example Check if running in a nested context * ```ts * import { PlatformServiceName } from '@limetech/lime-web-components'; * * const loggerFactory = platform.get(PlatformServiceName.Logger); * const logger = loggerFactory.createLogger('my-component'); * * if (context.parent) { * logger.debug('Running in a nested context', { * current: context.limetype, * parent: context.parent.limetype, * }); * * // Load the record the parent context points at * if (context.parent.limetype && context.parent.id) { * const repository = platform.get( * PlatformServiceName.LimeObjectRepository * ); * * const parentObject = await repository.loadObject( * context.parent.limetype, * context.parent.id * ); * } * } * ``` * * @remarks * The platform and context properties are fundamental to component operation: * - `platform` provides access to all services (repositories, HTTP, command bus, etc.) * - `context` describes where the component is running (which limetype, which record) * * @public * @group Core */ export interface LimeWebComponent { /** * Reference to the platform service container. * * Use this to access all platform services like repositories, HTTP client, * command bus, navigator, and more. The platform instance is shared across * all components in the same application context. * * @example * ```ts * import { PlatformServiceName } from '@limetech/lime-web-components'; * * const http = platform.get(PlatformServiceName.Http); * const commandBus = platform.get(PlatformServiceName.CommandBus); * const repository = platform.get(PlatformServiceName.LimeObjectRepository); * ``` */ platform: LimeWebComponentPlatform; /** * The context describing where this component is running. * * The context provides information about the current limetype and record ID * (if viewing/editing a specific record). Components can use this to load * relevant data and understand their operating environment. * * @example * ```ts * import { PlatformServiceName } from '@limetech/lime-web-components'; * * const repository = platform.get(PlatformServiceName.LimeObjectRepository); * * if (context.limetype && context.id) { * const limeObject = await repository.loadObject( * context.limetype, * context.id * ); * } * ``` */ context: LimeWebComponentContext; }