@salesforce/storefront-next-runtime 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +181 -0
- package/README.md +158 -0
- package/dist/ComponentContext.js +14 -0
- package/dist/ComponentContext.js.map +1 -0
- package/dist/DesignContext.js +769 -0
- package/dist/DesignContext.js.map +1 -0
- package/dist/DesignContext2.js +6 -0
- package/dist/PageDesignerProvider.js +53 -0
- package/dist/PageDesignerProvider.js.map +1 -0
- package/dist/PageRegistration.js +29 -0
- package/dist/PageRegistration.js.map +1 -0
- package/dist/PreviewContext.js +18 -0
- package/dist/PreviewContext.js.map +1 -0
- package/dist/design-messaging.d.ts +3 -0
- package/dist/design-messaging.js +3 -0
- package/dist/design-mode.d.ts +40 -0
- package/dist/design-mode.d.ts.map +1 -0
- package/dist/design-mode.js +3 -0
- package/dist/design-react-core.d.ts +69 -0
- package/dist/design-react-core.d.ts.map +1 -0
- package/dist/design-react-core.js +23 -0
- package/dist/design-react-core.js.map +1 -0
- package/dist/design-react.d.ts +130 -0
- package/dist/design-react.d.ts.map +1 -0
- package/dist/design-react.js +488 -0
- package/dist/design-react.js.map +1 -0
- package/dist/design-styles.css +232 -0
- package/dist/design.d.ts +2 -0
- package/dist/design.js +219 -0
- package/dist/design.js.map +1 -0
- package/dist/events.d.ts +208 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +104 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +215 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index2.d.ts +1171 -0
- package/dist/index2.d.ts.map +1 -0
- package/dist/messaging-api.js +340 -0
- package/dist/messaging-api.js.map +1 -0
- package/dist/modeDetection.js +50 -0
- package/dist/modeDetection.js.map +1 -0
- package/dist/scapi.d.ts +29278 -0
- package/dist/scapi.d.ts.map +1 -0
- package/dist/scapi.js +2 -0
- package/dist/scapi.js.map +1 -0
- package/dist/types.d.ts +13293 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +108 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","names":[],"sources":["../src/events/types.ts","../src/events/events.ts","../src/events/mediator.ts"],"sourcesContent":[],"mappings":"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"}
|
package/dist/events.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
//#region src/events/events.ts
|
|
2
|
+
/**
|
|
3
|
+
* Type-safe event creation function
|
|
4
|
+
*
|
|
5
|
+
* This generic function allows creating any event type under AnalyticsEvent
|
|
6
|
+
* with full type safety. The event type is inferred from the string literal
|
|
7
|
+
* passed as the first parameter, and TypeScript will enforce the correct
|
|
8
|
+
* data properties for that specific event type.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const viewPageEvent = createEvent('view_page', { path: '/products', payload });
|
|
13
|
+
* const viewProductEvent = createEvent('view_product', { product, payload });
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
function createEvent(eventType, data) {
|
|
17
|
+
return {
|
|
18
|
+
eventType,
|
|
19
|
+
...data
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Send a view page event to the event mediator
|
|
24
|
+
*
|
|
25
|
+
* This wrapper function is used in the automated page view event tracking client middleware.
|
|
26
|
+
* This function exists to support build-time checks and type safety.
|
|
27
|
+
*
|
|
28
|
+
* @param event - The view page event to send
|
|
29
|
+
* @param eventMediator - The event mediator to send the event to
|
|
30
|
+
*/
|
|
31
|
+
function sendViewPageEvent(event, eventMediator) {
|
|
32
|
+
eventMediator.track(event);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/events/mediator.ts
|
|
37
|
+
let mediatorInstance;
|
|
38
|
+
/**
|
|
39
|
+
* Create an event mediator instance
|
|
40
|
+
*
|
|
41
|
+
* Creates a new EventMediator that processes events through the provided adapters.
|
|
42
|
+
* The mediator uses the getAdapters function on each track() invocation to ensure
|
|
43
|
+
* it always uses the latest adapters from the adapter registry.
|
|
44
|
+
*
|
|
45
|
+
* @param getAdapters - Function that returns the current array of engagement adapters.
|
|
46
|
+
* This function is called on each track() invocation to ensure
|
|
47
|
+
* the mediator always uses the latest adapters from the adapter registry.
|
|
48
|
+
* @returns EventMediator instance
|
|
49
|
+
*/
|
|
50
|
+
function createEventMediator(getAdapters) {
|
|
51
|
+
return { track: (event) => {
|
|
52
|
+
processEventWithAdapters(event, getAdapters).catch((error) => {
|
|
53
|
+
console.error("Analytics tracking failed:", error);
|
|
54
|
+
});
|
|
55
|
+
} };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get the event mediator singleton instance
|
|
59
|
+
*
|
|
60
|
+
* Returns the singleton EventMediator instance, creating it if it doesn't exist.
|
|
61
|
+
*
|
|
62
|
+
* @param getAdapters - Function that returns the current array of engagement adapters.
|
|
63
|
+
* @returns EventMediator instance (singleton) or undefined if not on client side
|
|
64
|
+
*/
|
|
65
|
+
function getEventMediator(getAdapters) {
|
|
66
|
+
if (mediatorInstance) return mediatorInstance;
|
|
67
|
+
if (typeof window === "undefined") return;
|
|
68
|
+
mediatorInstance = createEventMediator(getAdapters);
|
|
69
|
+
return mediatorInstance;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Reset the event mediator singleton (for testing only)
|
|
73
|
+
*
|
|
74
|
+
* This function clears the singleton instance, allowing tests to create a fresh mediator.
|
|
75
|
+
*/
|
|
76
|
+
function resetEventMediator() {
|
|
77
|
+
mediatorInstance = void 0;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Process an event with all registered adapters
|
|
81
|
+
*
|
|
82
|
+
* @param event - The analytics event to process
|
|
83
|
+
* @param getAdapters - Function that returns the current array of event adapters
|
|
84
|
+
*/
|
|
85
|
+
async function processEventWithAdapters(event, getAdapters) {
|
|
86
|
+
const eventAdapters = getAdapters();
|
|
87
|
+
if (eventAdapters.length === 0) {
|
|
88
|
+
console.warn(`There are no active adapters to send the event to`);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const promises = eventAdapters.map(async (adapter) => {
|
|
92
|
+
try {
|
|
93
|
+
if (typeof adapter.sendEvent === "function") await adapter.sendEvent(event);
|
|
94
|
+
else console.warn(`Adapter ${adapter.name} does not implement sendEvent`);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error(`Failed to send event to ${adapter.name}:`, error);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
await Promise.allSettled(promises);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
export { createEvent, getEventMediator, resetEventMediator, sendViewPageEvent };
|
|
104
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","names":["mediatorInstance: EventMediator | undefined"],"sources":["../src/events/events.ts","../src/events/mediator.ts"],"sourcesContent":["/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { AnalyticsEvent, EventMediator, EventPayload, EventTypeMap, ViewPageEvent } from './types';\n\n/**\n * Type-safe event creation function\n *\n * This generic function allows creating any event type under AnalyticsEvent\n * with full type safety. The event type is inferred from the string literal\n * passed as the first parameter, and TypeScript will enforce the correct\n * data properties for that specific event type.\n *\n * @example\n * ```typescript\n * const viewPageEvent = createEvent('view_page', { path: '/products', payload });\n * const viewProductEvent = createEvent('view_product', { product, payload });\n * ```\n */\nexport function createEvent<T extends AnalyticsEvent['eventType']>(\n eventType: T,\n data: EventPayload<T>\n): EventTypeMap[T] {\n return {\n eventType,\n ...data,\n } as EventTypeMap[T];\n}\n\n/**\n * Send a view page event to the event mediator\n *\n * This wrapper function is used in the automated page view event tracking client middleware.\n * This function exists to support build-time checks and type safety.\n *\n * @param event - The view page event to send\n * @param eventMediator - The event mediator to send the event to\n */\nexport function sendViewPageEvent(event: ViewPageEvent, eventMediator: EventMediator): void {\n eventMediator.track(event);\n}\n","/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { EventMediator, AnalyticsEvent, EventAdapter } from './types';\n\n// Module-level storage for the event mediator singleton\n// This ensures a single mediator instance across all usages\nlet mediatorInstance: EventMediator | undefined;\n\n/**\n * Create an event mediator instance\n *\n * Creates a new EventMediator that processes events through the provided adapters.\n * The mediator uses the getAdapters function on each track() invocation to ensure\n * it always uses the latest adapters from the adapter registry.\n *\n * @param getAdapters - Function that returns the current array of engagement adapters.\n * This function is called on each track() invocation to ensure\n * the mediator always uses the latest adapters from the adapter registry.\n * @returns EventMediator instance\n */\nfunction createEventMediator(getAdapters: () => EventAdapter[]): EventMediator {\n return {\n track: (event: AnalyticsEvent) => {\n processEventWithAdapters(event, getAdapters).catch((error) => {\n // eslint-disable-next-line no-console\n console.error('Analytics tracking failed:', error);\n });\n },\n };\n}\n\n/**\n * Get the event mediator singleton instance\n *\n * Returns the singleton EventMediator instance, creating it if it doesn't exist.\n *\n * @param getAdapters - Function that returns the current array of engagement adapters.\n * @returns EventMediator instance (singleton) or undefined if not on client side\n */\nexport function getEventMediator(getAdapters: () => EventAdapter[]): EventMediator | undefined {\n // If mediator already exists, return it\n if (mediatorInstance) {\n return mediatorInstance;\n }\n\n // Only create on client side\n if (typeof window === 'undefined') {\n return undefined;\n }\n\n // Create the event mediator singleton\n mediatorInstance = createEventMediator(getAdapters);\n return mediatorInstance;\n}\n\n/**\n * Reset the event mediator singleton (for testing only)\n *\n * This function clears the singleton instance, allowing tests to create a fresh mediator.\n */\nexport function resetEventMediator(): void {\n mediatorInstance = undefined;\n}\n\n/**\n * Process an event with all registered adapters\n *\n * @param event - The analytics event to process\n * @param getAdapters - Function that returns the current array of event adapters\n */\nasync function processEventWithAdapters(event: AnalyticsEvent, getAdapters: () => EventAdapter[]): Promise<void> {\n // Get the current array of event adapters\n const eventAdapters = getAdapters();\n if (eventAdapters.length === 0) {\n // eslint-disable-next-line no-console\n console.warn(`There are no active adapters to send the event to`);\n return;\n }\n\n // Send event to all registered adapters that implement sendEvent in parallel\n const promises = eventAdapters.map(async (adapter) => {\n try {\n if (typeof adapter.sendEvent === 'function') {\n await adapter.sendEvent(event);\n } else {\n // eslint-disable-next-line no-console\n console.warn(`Adapter ${adapter.name} does not implement sendEvent`);\n }\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(`Failed to send event to ${adapter.name}:`, error);\n }\n });\n\n await Promise.allSettled(promises);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgCA,SAAgB,YACZ,WACA,MACe;AACf,QAAO;EACH;EACA,GAAG;EACN;;;;;;;;;;;AAYL,SAAgB,kBAAkB,OAAsB,eAAoC;AACxF,eAAc,MAAM,MAAM;;;;;AChC9B,IAAIA;;;;;;;;;;;;;AAcJ,SAAS,oBAAoB,aAAkD;AAC3E,QAAO,EACH,QAAQ,UAA0B;AAC9B,2BAAyB,OAAO,YAAY,CAAC,OAAO,UAAU;AAE1D,WAAQ,MAAM,8BAA8B,MAAM;IACpD;IAET;;;;;;;;;;AAWL,SAAgB,iBAAiB,aAA8D;AAE3F,KAAI,iBACA,QAAO;AAIX,KAAI,OAAO,WAAW,YAClB;AAIJ,oBAAmB,oBAAoB,YAAY;AACnD,QAAO;;;;;;;AAQX,SAAgB,qBAA2B;AACvC,oBAAmB;;;;;;;;AASvB,eAAe,yBAAyB,OAAuB,aAAkD;CAE7G,MAAM,gBAAgB,aAAa;AACnC,KAAI,cAAc,WAAW,GAAG;AAE5B,UAAQ,KAAK,oDAAoD;AACjE;;CAIJ,MAAM,WAAW,cAAc,IAAI,OAAO,YAAY;AAClD,MAAI;AACA,OAAI,OAAO,QAAQ,cAAc,WAC7B,OAAM,QAAQ,UAAU,MAAM;OAG9B,SAAQ,KAAK,WAAW,QAAQ,KAAK,+BAA+B;WAEnE,OAAO;AAEZ,WAAQ,MAAM,2BAA2B,QAAQ,KAAK,IAAI,MAAM;;GAEtE;AAEF,OAAM,QAAQ,WAAW,SAAS"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
//#region src/design/registry/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Copyright 2026 Salesforce, Inc.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/* ==================== Framework Agnostic Types ==================== */
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Unique identifier for a component type.
|
|
22
|
+
*/
|
|
23
|
+
type ComponentId = string;
|
|
24
|
+
/**
|
|
25
|
+
* Loader and fallback function names for external invocation.
|
|
26
|
+
*/
|
|
27
|
+
interface LoaderNames {
|
|
28
|
+
/** Server-side loader function name */
|
|
29
|
+
loader?: string;
|
|
30
|
+
/** Client-side loader function name */
|
|
31
|
+
clientLoader?: string;
|
|
32
|
+
/** Fallback component function name */
|
|
33
|
+
fallback?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Shape of a dynamically imported component module.
|
|
37
|
+
* This is what import.meta.glob() returns for each component.
|
|
38
|
+
*/
|
|
39
|
+
interface ComponentModule<TProps, TFrameworkComponent = unknown> {
|
|
40
|
+
/** The main component export */
|
|
41
|
+
default: TFrameworkComponent;
|
|
42
|
+
/** Optional fallback component for Suspense boundaries */
|
|
43
|
+
fallback?: TFrameworkComponent;
|
|
44
|
+
/** Any additional exports (loaders, etc.) */
|
|
45
|
+
[key: string]: unknown;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Generic design metadata interface - framework agnostic.
|
|
49
|
+
* Different frameworks can extend this with their specific metadata.
|
|
50
|
+
*/
|
|
51
|
+
interface DesignMetadata {
|
|
52
|
+
/** Component identifier */
|
|
53
|
+
id?: string;
|
|
54
|
+
/** Component name for display */
|
|
55
|
+
name?: string;
|
|
56
|
+
/** Component group/category */
|
|
57
|
+
group?: string;
|
|
58
|
+
/** Component description */
|
|
59
|
+
description?: string;
|
|
60
|
+
/** Additional framework-specific metadata */
|
|
61
|
+
[key: string]: any;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Internal registry entry for a component.
|
|
65
|
+
* Framework agnostic - no specific component types.
|
|
66
|
+
*/
|
|
67
|
+
interface Entry<TProps, TFrameworkComponent = unknown> {
|
|
68
|
+
/** Component identifier */
|
|
69
|
+
id: ComponentId;
|
|
70
|
+
/** Eagerly loaded component (if registered directly) */
|
|
71
|
+
raw: TFrameworkComponent | null;
|
|
72
|
+
/** Lazily loaded component (if discovered via dynamic import) */
|
|
73
|
+
lazy?: TFrameworkComponent;
|
|
74
|
+
/** Dynamic importer function */
|
|
75
|
+
import?: () => Promise<ComponentModule<TProps, TFrameworkComponent>>;
|
|
76
|
+
/** Fallback component for loading states */
|
|
77
|
+
fallback?: TFrameworkComponent;
|
|
78
|
+
/** Loader function names for external invocation */
|
|
79
|
+
loaderNames?: LoaderNames;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Framework adapter interface.
|
|
83
|
+
* Each framework implements this to provide framework-specific behavior.
|
|
84
|
+
*/
|
|
85
|
+
interface FrameworkAdapter<TProps, TFrameworkComponent = unknown> {
|
|
86
|
+
/**
|
|
87
|
+
* Creates a lazy-loaded component from an importer function.
|
|
88
|
+
*/
|
|
89
|
+
createLazyComponent(importer: () => Promise<ComponentModule<TProps, TFrameworkComponent>>): TFrameworkComponent;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Decorates a component with design-time capabilities.
|
|
93
|
+
* Each framework adapter implements its own decoration logic.
|
|
94
|
+
*/
|
|
95
|
+
decorateComponent(component: TFrameworkComponent): TFrameworkComponent;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Configuration options for ComponentRegistry.
|
|
99
|
+
* Framework agnostic with adapter injection.
|
|
100
|
+
*/
|
|
101
|
+
interface ComponentRegistryOptions<TProps, TFrameworkComponent> {
|
|
102
|
+
/**
|
|
103
|
+
* Framework adapter for framework-specific operations.
|
|
104
|
+
* The adapter handles all framework-specific behavior including decoration.
|
|
105
|
+
*/
|
|
106
|
+
adapter: FrameworkAdapter<TProps, TFrameworkComponent>;
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/design/registry/registry.d.ts
|
|
110
|
+
/**
|
|
111
|
+
* Framework-agnostic ComponentRegistry manages component loading with static registration.
|
|
112
|
+
*
|
|
113
|
+
* Features:
|
|
114
|
+
* - Framework agnostic core with adapter pattern
|
|
115
|
+
* - Lazy loading via framework adapters for code splitting
|
|
116
|
+
* - Static component registration via build plugins (no dynamic discovery)
|
|
117
|
+
* - Design mode decoration via framework adapters
|
|
118
|
+
* - Request deduplication for concurrent component loads
|
|
119
|
+
* - Component metadata handled via API (not stored in registry)
|
|
120
|
+
*
|
|
121
|
+
* @template TProps - Component props type
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```tsx
|
|
125
|
+
* const registry = new ComponentRegistry({
|
|
126
|
+
* adapter: new ReactAdapter(),
|
|
127
|
+
* designDecorator: createDesignDecorator,
|
|
128
|
+
* });
|
|
129
|
+
*
|
|
130
|
+
* // Components are pre-registered via static registry plugin
|
|
131
|
+
* // Get a component
|
|
132
|
+
* const Hero = registry.getComponent('hero');
|
|
133
|
+
*
|
|
134
|
+
* // Preload for SSR
|
|
135
|
+
* await registry.preload('hero');
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
declare class ComponentRegistry<TProps, TFrameworkComponent = unknown> {
|
|
139
|
+
private readonly registry;
|
|
140
|
+
private readonly pending;
|
|
141
|
+
private readonly cancelled;
|
|
142
|
+
private readonly adapter;
|
|
143
|
+
constructor({
|
|
144
|
+
adapter
|
|
145
|
+
}: ComponentRegistryOptions<TProps, TFrameworkComponent>);
|
|
146
|
+
/**
|
|
147
|
+
* Registers a component in the registry with the specified id.
|
|
148
|
+
* If a component with the same id already exists, it will be overwritten.
|
|
149
|
+
*/
|
|
150
|
+
registerComponent(id: ComponentId, component: TFrameworkComponent): void;
|
|
151
|
+
/**
|
|
152
|
+
* Registers a dynamic importer for a component id. Useful if you don't want to rely on scanning.
|
|
153
|
+
*/
|
|
154
|
+
registerImporter(id: ComponentId, importer: () => Promise<ComponentModule<TProps, TFrameworkComponent>>, loaderNames?: LoaderNames): void;
|
|
155
|
+
/**
|
|
156
|
+
* Retrieves a component by id. Returns a framework-specific component type.
|
|
157
|
+
* In lazy loading scenarios, this will be a lazy component if the component
|
|
158
|
+
* is discovered via dynamic import. In design mode, the returned component
|
|
159
|
+
* is decorated via `designDecorator`.
|
|
160
|
+
*/
|
|
161
|
+
getComponent(id: ComponentId): TFrameworkComponent | null;
|
|
162
|
+
/**
|
|
163
|
+
* Preload the JS chunk for a component id (use in route loaders/SSR to avoid waterfalls).
|
|
164
|
+
*
|
|
165
|
+
* This method ensures the component module is loaded and cached. Concurrent calls
|
|
166
|
+
* for the same component ID are automatically deduplicated via the pending map
|
|
167
|
+
* in ensureDiscovered().
|
|
168
|
+
*
|
|
169
|
+
* @throws Error if the component cannot be discovered
|
|
170
|
+
*/
|
|
171
|
+
preload(id: ComponentId): Promise<void>;
|
|
172
|
+
/** Get loader function names for external invocation. */
|
|
173
|
+
getLoaderNames(id: ComponentId): LoaderNames | undefined;
|
|
174
|
+
hasLoaders(id: ComponentId): boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Call a loader function for a component externally.
|
|
177
|
+
*
|
|
178
|
+
* @param id - Component ID
|
|
179
|
+
* @param loaderArgs - Arguments to pass to the loader function
|
|
180
|
+
* @param loaderType - Type of loader to call ('loader' or 'clientLoader')
|
|
181
|
+
* @returns Promise resolving to the loader result
|
|
182
|
+
*/
|
|
183
|
+
callLoader(id: ComponentId, loaderArgs: unknown, loaderType?: keyof LoaderNames): Promise<unknown>;
|
|
184
|
+
/** Get fallback component if available. */
|
|
185
|
+
getFallback(id: ComponentId): TFrameworkComponent | undefined;
|
|
186
|
+
/**
|
|
187
|
+
* Returns all registered component IDs.
|
|
188
|
+
* Useful for debugging and introspection.
|
|
189
|
+
*/
|
|
190
|
+
getRegisteredIds(): ComponentId[];
|
|
191
|
+
/**
|
|
192
|
+
* Checks if a component is registered.
|
|
193
|
+
*/
|
|
194
|
+
has(id: ComponentId): boolean;
|
|
195
|
+
/**
|
|
196
|
+
* Clears all cached components and cancels pending discoveries.
|
|
197
|
+
* In-flight async operations will be cancelled and their promises will reject.
|
|
198
|
+
* Useful for testing or hot module replacement.
|
|
199
|
+
*/
|
|
200
|
+
clear(): void;
|
|
201
|
+
private ensureLocalEntry;
|
|
202
|
+
/**
|
|
203
|
+
* Ensures a component is discovered and cached.
|
|
204
|
+
* Only returns early if a raw (eagerly loaded) component exists.
|
|
205
|
+
* Otherwise, attempts to discover via registered importer.
|
|
206
|
+
*
|
|
207
|
+
* @throws Error if the discovery is cancelled via clear()
|
|
208
|
+
*/
|
|
209
|
+
private ensureDiscovered;
|
|
210
|
+
private buildFromImporter;
|
|
211
|
+
private buildFromLoadedModule;
|
|
212
|
+
}
|
|
213
|
+
//#endregion
|
|
214
|
+
export { DesignMetadata as a, LoaderNames as c, ComponentRegistryOptions as i, ComponentId as n, Entry as o, ComponentModule as r, FrameworkAdapter as s, ComponentRegistry as t };
|
|
215
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["ComponentId","LoaderNames","ComponentModule","TProps","TFrameworkComponent","DesignMetadata","Entry","Promise","FrameworkAdapter","ComponentRegistryOptions"],"sources":["../src/design/registry/types.d.ts","../src/design/registry/registry.ts"],"sourcesContent":["/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/* ==================== Framework Agnostic Types ==================== */\n\n/**\n * Unique identifier for a component type.\n */\nexport type ComponentId = string;\n\n/**\n * Loader and fallback function names for external invocation.\n */\nexport interface LoaderNames {\n /** Server-side loader function name */\n loader?: string;\n /** Client-side loader function name */\n clientLoader?: string;\n /** Fallback component function name */\n fallback?: string;\n}\n\n/**\n * Shape of a dynamically imported component module.\n * This is what import.meta.glob() returns for each component.\n */\nexport interface ComponentModule<TProps, TFrameworkComponent = unknown> {\n /** The main component export */\n default: TFrameworkComponent;\n /** Optional fallback component for Suspense boundaries */\n fallback?: TFrameworkComponent;\n /** Any additional exports (loaders, etc.) */\n [key: string]: unknown;\n}\n\n/**\n * Generic design metadata interface - framework agnostic.\n * Different frameworks can extend this with their specific metadata.\n */\nexport interface DesignMetadata {\n /** Component identifier */\n id?: string;\n /** Component name for display */\n name?: string;\n /** Component group/category */\n group?: string;\n /** Component description */\n description?: string;\n /** Additional framework-specific metadata */\n [key: string]: any;\n}\n\n/**\n * Internal registry entry for a component.\n * Framework agnostic - no specific component types.\n */\nexport interface Entry<TProps, TFrameworkComponent = unknown> {\n /** Component identifier */\n id: ComponentId;\n /** Eagerly loaded component (if registered directly) */\n raw: TFrameworkComponent | null;\n /** Lazily loaded component (if discovered via dynamic import) */\n lazy?: TFrameworkComponent;\n /** Dynamic importer function */\n import?: () => Promise<ComponentModule<TProps, TFrameworkComponent>>;\n /** Fallback component for loading states */\n fallback?: TFrameworkComponent;\n /** Loader function names for external invocation */\n loaderNames?: LoaderNames;\n}\n\n/**\n * Framework adapter interface.\n * Each framework implements this to provide framework-specific behavior.\n */\nexport interface FrameworkAdapter<TProps, TFrameworkComponent = unknown> {\n /**\n * Creates a lazy-loaded component from an importer function.\n */\n createLazyComponent(importer: () => Promise<ComponentModule<TProps, TFrameworkComponent>>): TFrameworkComponent;\n\n /**\n * Decorates a component with design-time capabilities.\n * Each framework adapter implements its own decoration logic.\n */\n decorateComponent(component: TFrameworkComponent): TFrameworkComponent;\n}\n\n/**\n * Configuration options for ComponentRegistry.\n * Framework agnostic with adapter injection.\n */\nexport interface ComponentRegistryOptions<TProps, TFrameworkComponent> {\n /**\n * Framework adapter for framework-specific operations.\n * The adapter handles all framework-specific behavior including decoration.\n */\n adapter: FrameworkAdapter<TProps, TFrameworkComponent>;\n}\n"],"mappings":";;AAqBA;AAKA;AAaA;AAaA;AAiBA;;;;;;;;;;;AAmBA;;;;;AAIgGI,KAvEpFJ,WAAAA,GAuEoFI,MAAAA;;;AAahG;AAK8BD,UApFbF,WAAAA,CAoFaE;EAAQC;EAAzBI,MAAAA,CAAAA,EAAAA,MAAAA;EAAgB;;;;ACzD7B;;;;;AAekD,UD7BjCN,eC6BiC,CAAA,MAAA,EAAA,sBAAA,OAAA,CAAA,CAAA;EAStC;EACoC,OAAA,EDrCnCE,mBCqCmC;EAAQ;EAAxB,QAAA,CAAA,EDnCjBA,mBCmCiB;EAAR;EACF,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,OAAA;;;;;;AAmDH,UD9EFC,cAAAA,CC8EE;EAYM;EAAoD,EAAA,CAAA,EAAA,MAAA;EAAyB;EAgClF,IAAA,CAAA,EAAA,MAAA;EAAc;EAQV,KAAA,CAAA,EAAA,MAAA;EAOZ;EAAW,WAAA,CAAA,EAAA,MAAA;;;;;;;;UDxHNC;;MAETN;;OAECI;;SAEEA;;iBAEQG,QAAQL,gBAAgBC,QAAQC;;aAEpCA;;gBAEGH;;;;;;UAODO;;;;sCAIuBD,QAAQL,gBAAgBC,QAAQC,wBAAwBA;;;;;;+BAM/DA,sBAAsBA;;;;;;UAOtCK;;;;;WAKJD,iBAAiBL,QAAQC;;;;AAtBtC;;;;;;;;;AAiBA;;;;;;;;ACpDA;;;;;;;;;;;AAyBwB,cAzBX,iBAyBW,CAAA,MAAA,EAAA,sBAAA,OAAA,CAAA,CAAA;EACF,iBAAA,QAAA;EAYD,iBAAA,OAAA;EAAc,iBAAA,SAAA;EAmBb,iBAAA,OAAA;EAAc,WAAA,CAAA;IAAA;EAAA,CAAA,EAlDP,wBAkDO,CAlDkB,MAkDlB,EAlD0B,mBAkD1B,CAAA;EAgBb;;;;EAgBsD,iBAAA,CAAA,EAAA,EA1EnD,WA0EmD,EAAA,SAAA,EA1E3B,mBA0E2B,CAAA,EAAA,IAAA;EAAyB;;;EAwC9E,gBAAA,CAAA,EAAA,EAzGZ,WAyGY,EAAA,QAAA,EAAA,GAAA,GAxGA,OAwGA,CAxGQ,eAwGR,CAxGwB,MAwGxB,EAxGgC,mBAwGhC,CAAA,CAAA,EAAA,WAAA,CAAA,EAvGF,WAuGE,CAAA,EAAA,IAAA;EAOZ;;;;;;mBAlGS,cAAc;;;;;;;;;;cAmBb,cAAc;;qBAgBb,cAAc;iBAIlB;;;;;;;;;iBAYM,qDAAoD,cAAyB;;kBAgClF,cAAc;;;;;sBAQV;;;;UAOZ"}
|