@widgetic/ui-sdk 0.0.0-stage → 0.1.1
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/README.md +718 -2
- package/dist/index.d.ts +53 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +2525 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +2559 -0
- package/dist/index.js.map +1 -0
- package/dist/sdk/core/component.d.ts +47 -0
- package/dist/sdk/core/component.d.ts.map +1 -0
- package/dist/sdk/core/events.d.ts +26 -0
- package/dist/sdk/core/events.d.ts.map +1 -0
- package/dist/sdk/core/index.d.ts +33 -0
- package/dist/sdk/core/index.d.ts.map +1 -0
- package/dist/sdk/core/lifecycle.d.ts +97 -0
- package/dist/sdk/core/lifecycle.d.ts.map +1 -0
- package/dist/sdk/core/local-events.d.ts +25 -0
- package/dist/sdk/core/local-events.d.ts.map +1 -0
- package/dist/sdk/core/messaging.d.ts +58 -0
- package/dist/sdk/core/messaging.d.ts.map +1 -0
- package/dist/sdk/core/state.d.ts +58 -0
- package/dist/sdk/core/state.d.ts.map +1 -0
- package/dist/sdk/core/theme-mode.d.ts +44 -0
- package/dist/sdk/core/theme-mode.d.ts.map +1 -0
- package/dist/sdk/core/theme.d.ts +58 -0
- package/dist/sdk/core/theme.d.ts.map +1 -0
- package/dist/sdk/index.d.ts +4 -0
- package/dist/sdk/index.d.ts.map +1 -0
- package/dist/sdk/integration/host.d.ts +54 -0
- package/dist/sdk/integration/host.d.ts.map +1 -0
- package/dist/sdk/integration/index.d.ts +19 -0
- package/dist/sdk/integration/index.d.ts.map +1 -0
- package/dist/sdk/layers/index.d.ts +36 -0
- package/dist/sdk/layers/index.d.ts.map +1 -0
- package/dist/sdk/loader/ui.d.ts +165 -0
- package/dist/sdk/loader/ui.d.ts.map +1 -0
- package/dist/sdk/modules/index.d.ts +9 -0
- package/dist/sdk/modules/index.d.ts.map +1 -0
- package/dist/sdk/modules/loader.d.ts +84 -0
- package/dist/sdk/modules/loader.d.ts.map +1 -0
- package/dist/sdk/types/component.d.ts +177 -0
- package/dist/sdk/types/component.d.ts.map +1 -0
- package/dist/sdk/types/events.d.ts +112 -0
- package/dist/sdk/types/events.d.ts.map +1 -0
- package/dist/sdk/types/index.d.ts +42 -0
- package/dist/sdk/types/index.d.ts.map +1 -0
- package/dist/sdk/types/messaging.d.ts +41 -0
- package/dist/sdk/types/messaging.d.ts.map +1 -0
- package/dist/sdk/types/module-language.d.ts +45 -0
- package/dist/sdk/types/module-language.d.ts.map +1 -0
- package/dist/sdk/types/module-theme.d.ts +93 -0
- package/dist/sdk/types/module-theme.d.ts.map +1 -0
- package/dist/sdk/types/state.d.ts +38 -0
- package/dist/sdk/types/state.d.ts.map +1 -0
- package/dist/sdk/types/theme.d.ts +76 -0
- package/dist/sdk/types/theme.d.ts.map +1 -0
- package/dist/sdk/utils/config.d.ts +70 -0
- package/dist/sdk/utils/config.d.ts.map +1 -0
- package/dist/sdk/utils/errors.d.ts +56 -0
- package/dist/sdk/utils/errors.d.ts.map +1 -0
- package/dist/sdk/utils/http.d.ts +21 -0
- package/dist/sdk/utils/http.d.ts.map +1 -0
- package/dist/sdk/utils/security.d.ts +95 -0
- package/dist/sdk/utils/security.d.ts.map +1 -0
- package/dist/sdk/utils/validation.d.ts +64 -0
- package/dist/sdk/utils/validation.d.ts.map +1 -0
- package/dist/sdk/version.d.ts +8 -0
- package/dist/sdk/version.d.ts.map +1 -0
- package/dist/services/dataService.d.ts +10 -0
- package/dist/services/dataService.d.ts.map +1 -0
- package/dist/umd/ui-sdk.js +2 -0
- package/dist/umd/ui-sdk.js.map +1 -0
- package/dist/utils/caseConversion.d.ts +3 -0
- package/dist/utils/caseConversion.d.ts.map +1 -0
- package/package.json +91 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sdk/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,aAAa,CAAC;AAK1D,OAAO,EAAE,aAAa,EAAE,CAAC;AACzB,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host Communication Module
|
|
3
|
+
* Handles secure communication between the SDK and the host application.
|
|
4
|
+
* Implements message validation, secure channel creation, and event routing.
|
|
5
|
+
*/
|
|
6
|
+
import type { IEventEmitter } from '../types';
|
|
7
|
+
import { SecurityManager } from '../utils/security';
|
|
8
|
+
export declare class HostCommunication {
|
|
9
|
+
private origin;
|
|
10
|
+
private events;
|
|
11
|
+
private security;
|
|
12
|
+
private channel?;
|
|
13
|
+
private boundHandleMessage;
|
|
14
|
+
/**
|
|
15
|
+
* Initialize host communication system
|
|
16
|
+
* @param origin - Allowed origin for message validation
|
|
17
|
+
* @param events - Event emitter for SDK-wide communication
|
|
18
|
+
* @param security - Security manager instance
|
|
19
|
+
*/
|
|
20
|
+
constructor(origin: string, events: IEventEmitter, security: SecurityManager);
|
|
21
|
+
/**
|
|
22
|
+
* Set up message event listener for host communication
|
|
23
|
+
* Binds message handler to window events
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
private setupMessageHandling;
|
|
27
|
+
/**
|
|
28
|
+
* Handle incoming messages from host application
|
|
29
|
+
* Validates messages and routes events to appropriate handlers
|
|
30
|
+
* @param event - Message event from host
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
private handleMessage;
|
|
34
|
+
/**
|
|
35
|
+
* Validate incoming messages for security
|
|
36
|
+
* Checks origin and message structure
|
|
37
|
+
* @param event - Message event to validate
|
|
38
|
+
* @returns boolean indicating message validity
|
|
39
|
+
* @private
|
|
40
|
+
*/
|
|
41
|
+
private validateMessage;
|
|
42
|
+
/**
|
|
43
|
+
* Create secure communication channel with host
|
|
44
|
+
* Uses MessageChannel API for secure bi-directional communication
|
|
45
|
+
* @returns Promise that resolves when channel is established
|
|
46
|
+
*/
|
|
47
|
+
createSecureChannel(): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Clean up resources and event listeners
|
|
50
|
+
* Called when host communication is no longer needed
|
|
51
|
+
*/
|
|
52
|
+
destroy(): void;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../../src/sdk/integration/host.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,qBAAa,iBAAiB;IAiBtB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,MAAM;IAhBlB,OAAO,CAAC,QAAQ,CAAkB;IAElC,OAAO,CAAC,OAAO,CAAC,CAAc;IAE9B,OAAO,CAAC,kBAAkB,CAExB;IAEF;;;;;OAKG;gBAES,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,aAAa,EAC7B,QAAQ,EAAE,eAAe;IAO7B;;;;OAIG;IACH,OAAO,CAAC,oBAAoB;IAM5B;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAmBrB;;;;;;OAMG;IACH,OAAO,CAAC,eAAe;IAcvB;;;;OAIG;IACG,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAc1C;;;OAGG;IACH,OAAO,IAAI,IAAI;CAMlB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration Module Index
|
|
3
|
+
* Exports components that handle integration with external systems
|
|
4
|
+
* and the host platform. These components form the bridge between
|
|
5
|
+
* the SDK and its hosting environment.
|
|
6
|
+
*/
|
|
7
|
+
export { HostCommunication } from './host';
|
|
8
|
+
/**
|
|
9
|
+
* Integration Component Architecture:
|
|
10
|
+
*
|
|
11
|
+
* - HostCommunication:
|
|
12
|
+
* - Secure messaging
|
|
13
|
+
* - Cross-origin communication
|
|
14
|
+
* - Event synchronization
|
|
15
|
+
*
|
|
16
|
+
* The platform and SDK-integration classes that used to live here validated an API key in the browser and probed
|
|
17
|
+
* the API with it. They were removed: the SDK holds no credentials (see `WidgeticUI` and its `getToken` option).
|
|
18
|
+
*/
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/sdk/integration/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAE3C;;;;;;;;;;GAUG"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-Level UI API for UI SDK
|
|
3
|
+
*
|
|
4
|
+
* The shortest way to put a Widgetic module on a page: configure once, then mount by name.
|
|
5
|
+
* Perfect for: Quick integration, HTML-first approaches, minimal JavaScript.
|
|
6
|
+
*
|
|
7
|
+
* For anything more (several instances, events, different tokens per module) use `WidgeticUI` or `mountModule`
|
|
8
|
+
* directly. The mid-level and low-level APIs that used to sit beside this one handed out the SDK's internals,
|
|
9
|
+
* including an HTTP client that sent an API key from the browser; they were removed.
|
|
10
|
+
*/
|
|
11
|
+
import { WidgeticUI, type WidgeticUIOptions } from '../loader/ui.js';
|
|
12
|
+
import type { ModuleName, MountConfig } from '../types/index.js';
|
|
13
|
+
/**
|
|
14
|
+
* High-Level UI API - Declarative & Auto-magical
|
|
15
|
+
*
|
|
16
|
+
* Characteristics: one-call initialization, convention over configuration.
|
|
17
|
+
*/
|
|
18
|
+
export declare const HighLevelUIAPI: {
|
|
19
|
+
readonly WidgeticUI: typeof WidgeticUI;
|
|
20
|
+
/**
|
|
21
|
+
* Configure the shared SDK instance. Calling it again replaces the instance and unmounts what the old one mounted.
|
|
22
|
+
*/
|
|
23
|
+
readonly initialize: (options: WidgeticUIOptions) => Promise<WidgeticUI>;
|
|
24
|
+
/**
|
|
25
|
+
* Mount a module into a container, given as an element or a CSS selector.
|
|
26
|
+
* @returns The instance ID to hand to `unmountComponent`
|
|
27
|
+
*/
|
|
28
|
+
readonly mountComponent: (type: ModuleName, container: HTMLElement | string, options?: Omit<MountConfig, "container">) => Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Take a mounted module down.
|
|
31
|
+
* @param instanceId - What `mountComponent` returned
|
|
32
|
+
*/
|
|
33
|
+
readonly unmountComponent: (instanceId: string) => Promise<void>;
|
|
34
|
+
};
|
|
35
|
+
export type HighLevelUIAPIType = typeof HighLevelUIAPI;
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/sdk/layers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAgBjE;;;;GAIG;AACH,eAAO,MAAM,cAAc;;IAIzB;;OAEG;mCACyB,iBAAiB,KAAG,OAAO,CAAC,UAAU,CAAC;IASnE;;;OAGG;oCAEK,UAAU,aACL,WAAW,GAAG,MAAM,YACtB,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,KACtC,OAAO,CAAC,MAAM,CAAC;IAIlB;;;OAGG;4CACkC,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;CAGnD,CAAC;AAGX,MAAM,MAAM,kBAAkB,GAAG,OAAO,cAAc,CAAC"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Widgetic UI SDK Main Class
|
|
3
|
+
* Central entry point for the SDK that:
|
|
4
|
+
* - Loads Widgetic UI modules (File Browser, editors ...) from the CDN and mounts them into the partner's page
|
|
5
|
+
* - Manages their lifecycle
|
|
6
|
+
* - Passes them the partner's `getToken` so they can talk to the Widgetic API
|
|
7
|
+
* - Controls their look: light/dark, a built-in theme, the partner's own colours, corner radius and font
|
|
8
|
+
*
|
|
9
|
+
* The SDK holds no credentials. The partner's server mints a short-lived editor session token
|
|
10
|
+
* (`POST /v1/managed-users/{id}/editor-sessions`, authenticated with the partner's API key, which never leaves
|
|
11
|
+
* that server) and the partner's `getToken` function returns it:
|
|
12
|
+
*
|
|
13
|
+
* const ui = new WidgeticUI({ getToken: async () => (await fetch('/my-server/widgetic-session')).json() });
|
|
14
|
+
* const fileBrowser = await ui.mount('file-browser', { container: '#files', on: { select: ({ files }) => use(files) } });
|
|
15
|
+
* ...
|
|
16
|
+
* await fileBrowser.unmount();
|
|
17
|
+
*/
|
|
18
|
+
import type { EventHandler, GetToken, ModuleName, MountConfig, MountedModule, SDKEvent, SDKEventType, ThemeMode, UIModule } from '../types';
|
|
19
|
+
import { type ThemeOption, type ThemeSettings } from '../core/theme-mode';
|
|
20
|
+
import { ModuleLoader } from '../modules/loader';
|
|
21
|
+
export interface WidgeticUIOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Asks your server for an editor session token. Called when a module starts and again before the token
|
|
24
|
+
* expires. Resolve with the token, or with `{ token, expiresAt }` so the module renews it in time.
|
|
25
|
+
*
|
|
26
|
+
* Needed by every module that shows the visitor's Widgetic data. A module that is given its data by the page
|
|
27
|
+
* (the File Browser with a `mediaLibrary` of your own) never asks for it. A module that needs a token and has
|
|
28
|
+
* none refuses to start, and says so.
|
|
29
|
+
*/
|
|
30
|
+
getToken?: GetToken;
|
|
31
|
+
/** The Widgetic API origin. Default `https://api.widgetic.com`. */
|
|
32
|
+
apiUrl?: string;
|
|
33
|
+
/** Where modules are served from. Default `https://cdn.widgetic.com/modules`. Change it to self-host or to test. */
|
|
34
|
+
moduleBaseUrl?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The look of every module: `'light'`, `'dark'`, `'system'` (follow the visitor's operating system), and/or a built-in
|
|
37
|
+
* `preset`, your `colors`, a `radius` and a `font`. Default: light, the Widgetic look. Can be changed later with
|
|
38
|
+
* `updateTheme`. A mount call can bring a theme of its own, so the modules on one page can look different.
|
|
39
|
+
*/
|
|
40
|
+
theme?: ThemeOption;
|
|
41
|
+
/**
|
|
42
|
+
* A BCP 47 language tag like `en` or `de`, handed to every module. A module that has words to translate (every module
|
|
43
|
+
* today: the File Browser, the composition editor and the widget creator) uses it for plural rules and for how
|
|
44
|
+
* numbers, dates and file sizes are written; the words themselves come from the module's `messages` option, and
|
|
45
|
+
* `mounted.setLanguage(...)` changes both while it is on screen.
|
|
46
|
+
*/
|
|
47
|
+
locale?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Advanced: the loader to use, for control over retries or the fetch used. Without one, every `WidgeticUI` on the
|
|
50
|
+
* page that uses the same `moduleBaseUrl` shares one loader, so a module is downloaded once and every instance
|
|
51
|
+
* runs the same version of it. When given, `moduleBaseUrl` is ignored (the loader already knows where modules are).
|
|
52
|
+
*/
|
|
53
|
+
moduleLoader?: ModuleLoader;
|
|
54
|
+
}
|
|
55
|
+
export declare class WidgeticUI {
|
|
56
|
+
private readonly events;
|
|
57
|
+
private readonly lifecycleManager;
|
|
58
|
+
private readonly loader;
|
|
59
|
+
private themeMode;
|
|
60
|
+
/** What the page-wide theme sets besides the mode (preset, colours, radius, font). */
|
|
61
|
+
private themeSettings;
|
|
62
|
+
private stopWatchingSystemTheme;
|
|
63
|
+
/**
|
|
64
|
+
* Initialize the SDK. Nothing is downloaded and nothing on the page is touched until a module is mounted.
|
|
65
|
+
* @param options - How modules reach the partner's token and the Widgetic API
|
|
66
|
+
*/
|
|
67
|
+
constructor(options?: WidgeticUIOptions);
|
|
68
|
+
/**
|
|
69
|
+
* Mount a module into a container.
|
|
70
|
+
* @param type - Which module, like `file-browser`
|
|
71
|
+
* @param config - The container, SDK options (`version`, `theme`, `on` ...) and the module's own options
|
|
72
|
+
* @returns The mounted module: subscribe with `.on`, take it down with `.unmount()`
|
|
73
|
+
*/
|
|
74
|
+
mount<Module extends UIModule = UIModule>(type: ModuleName, config: MountConfig): Promise<MountedModule<Module>>;
|
|
75
|
+
/**
|
|
76
|
+
* Mount a module and get its instance ID back. `mount` is usually more convenient because it returns the
|
|
77
|
+
* module itself.
|
|
78
|
+
* @param type - Type of component to mount
|
|
79
|
+
* @param config - Component configuration
|
|
80
|
+
* @returns Promise resolving to instance ID
|
|
81
|
+
*/
|
|
82
|
+
mountComponent(type: ModuleName, config: MountConfig): Promise<string>;
|
|
83
|
+
/**
|
|
84
|
+
* Unmount a component instance
|
|
85
|
+
* @param instanceId - ID of instance to unmount
|
|
86
|
+
*/
|
|
87
|
+
unmountComponent(instanceId: string): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* A module that is currently mounted
|
|
90
|
+
* @param instanceId - ID returned by `mountComponent`, or `id` of a mounted module
|
|
91
|
+
*/
|
|
92
|
+
getComponent(instanceId: string): MountedModule | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Download a module ahead of time, so mounting it later is instant. Mounting does this by itself;
|
|
95
|
+
* call it when the page knows the visitor is likely to open the module soon.
|
|
96
|
+
* @param type - Which module
|
|
97
|
+
* @param options.version - Pin an exact version
|
|
98
|
+
*/
|
|
99
|
+
preload(type: ModuleName, options?: {
|
|
100
|
+
version?: string;
|
|
101
|
+
}): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Change the look of every mounted module (and every module mounted later).
|
|
104
|
+
*
|
|
105
|
+
* ui.updateTheme('dark'); // the mode only: every module keeps its colours, radius, font
|
|
106
|
+
* ui.updateTheme({ preset: 'ocean' }); // a new look for the modules that have no theme of their own
|
|
107
|
+
* ui.updateTheme({ mode: 'dark', colors: { primary: '#e0541b' } });
|
|
108
|
+
*
|
|
109
|
+
* A bare mode (or `{ mode }`) changes the mode of every module and keeps the rest of its theme. Settings replace the
|
|
110
|
+
* page-wide theme, which is what every module without settings of its own has; a module whose mount call (or its own
|
|
111
|
+
* `setTheme`) brought settings keeps them, and follows the mode when the call sets one.
|
|
112
|
+
*
|
|
113
|
+
* @param theme - `'light'`, `'dark'`, `'system'`, or an object with some of `mode`, `preset`, `colors`, `radius`, `font`
|
|
114
|
+
* @throws `INVALID_THEME` for anything else. A module that refuses the settings reports it in the console and keeps its look.
|
|
115
|
+
*/
|
|
116
|
+
updateTheme(theme: ThemeOption): void;
|
|
117
|
+
/**
|
|
118
|
+
* Get the current page-wide theme
|
|
119
|
+
* @returns The mode the SDK was asked for (`system` stays `system`), and the preset, colours, radius and font if it was given any
|
|
120
|
+
*/
|
|
121
|
+
getTheme(): {
|
|
122
|
+
mode: ThemeMode;
|
|
123
|
+
} & ThemeSettings;
|
|
124
|
+
/**
|
|
125
|
+
* Subscribe to SDK events
|
|
126
|
+
* @param event - Event type to subscribe to
|
|
127
|
+
* @param handler - Event handler function
|
|
128
|
+
* @returns Unsubscribe function
|
|
129
|
+
*/
|
|
130
|
+
on(event: SDKEventType, handler: EventHandler): () => void;
|
|
131
|
+
/**
|
|
132
|
+
* Unsubscribe from SDK events
|
|
133
|
+
* @param event - Event type to unsubscribe from
|
|
134
|
+
* @param handler - Event handler to remove
|
|
135
|
+
*/
|
|
136
|
+
off(event: SDKEventType, handler: EventHandler): void;
|
|
137
|
+
/**
|
|
138
|
+
* Emit SDK events with type-safe payload
|
|
139
|
+
* @param type - Event type to emit
|
|
140
|
+
* @param data - Event data
|
|
141
|
+
*/
|
|
142
|
+
emit<T extends SDKEvent['type']>(type: T, data: Omit<Extract<SDKEvent, {
|
|
143
|
+
type: T;
|
|
144
|
+
}>, 'type'>): void;
|
|
145
|
+
/**
|
|
146
|
+
* Cleanup and destroy SDK instance
|
|
147
|
+
* Unmounts every module this instance mounted and stops listening for anything.
|
|
148
|
+
*/
|
|
149
|
+
destroy(): Promise<void>;
|
|
150
|
+
/** While the theme is `system`, mounted modules follow the visitor's system; otherwise there is nothing to follow. */
|
|
151
|
+
private followSystemThemeWhenAsked;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Mount one module with a single call: the SDK is created, the module is mounted, and `unmount()` on the result
|
|
155
|
+
* takes both down. Use `new WidgeticUI(...)` when a page mounts several modules.
|
|
156
|
+
*
|
|
157
|
+
* const fileBrowser = await mountModule('file-browser', {
|
|
158
|
+
* container: document.getElementById('files'),
|
|
159
|
+
* getToken: async () => (await fetch('/my-server/widgetic-session')).json(),
|
|
160
|
+
* on: { select: ({ files }) => useFiles(files) },
|
|
161
|
+
* });
|
|
162
|
+
*/
|
|
163
|
+
export declare function mountModule<Module extends UIModule = UIModule>(type: ModuleName, options: WidgeticUIOptions & MountConfig): Promise<MountedModule<Module>>;
|
|
164
|
+
export default WidgeticUI;
|
|
165
|
+
//# sourceMappingURL=ui.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../../../src/sdk/loader/ui.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,EACR,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,WAAW,EACX,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,QAAQ,EACX,MAAM,UAAU,CAAC;AAGlB,OAAO,EAA0F,KAAK,WAAW,EAAE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAClK,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAKjD,MAAM,WAAW,iBAAiB;IAC9B;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oHAAoH;IACpH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;CAC/B;AAkBD,qBAAa,UAAU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AC,CAAC,SAAS,QAAQ,CAAC,MAAM,CAAC,EAC3B,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,EAAE,MAAM,CAAC,GACnD,IAAI;IAIP;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAO9B,sHAAsH;IACtH,OAAO,CAAC,0BAA0B;CAOrC;AAED;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAAC,MAAM,SAAS,QAAQ,GAAG,QAAQ,EAChE,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,iBAAiB,GAAG,WAAW,GACzC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAwBhC;AAkBD,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modules
|
|
3
|
+
* How the SDK finds and loads Widgetic UI modules (File Browser, editors ...).
|
|
4
|
+
*
|
|
5
|
+
* The module classes themselves are not in the SDK: each one is built separately, published to the CDN and
|
|
6
|
+
* imported on demand by the `ModuleLoader`, so the SDK stays small and a module can be updated without a new SDK.
|
|
7
|
+
*/
|
|
8
|
+
export { ModuleLoader, ModuleLoadError, type LoadedModule, type ModuleConstructor, type ModuleLoaderOptions, type ModuleLoadErrorCode, } from './loader';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/sdk/modules/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EACH,YAAY,EACZ,eAAe,EACf,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,GAC3B,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module Loader
|
|
3
|
+
*
|
|
4
|
+
* Finds a Widgetic UI module on the CDN and imports it. This is the one and only way the SDK loads a module.
|
|
5
|
+
*
|
|
6
|
+
* Every module is published as one JavaScript file at an address that never changes:
|
|
7
|
+
*
|
|
8
|
+
* <moduleBaseUrl>/<name>/<version>/index.js e.g. https://cdn.widgetic.com/modules/file-browser/1.2.0/index.js
|
|
9
|
+
*
|
|
10
|
+
* and a small JSON "manifest" next to it names the newest version:
|
|
11
|
+
*
|
|
12
|
+
* <moduleBaseUrl>/<name>/manifest.json { "name": "file-browser", "version": "1.2.0", "entry": "1.2.0/index.js" }
|
|
13
|
+
*
|
|
14
|
+
* - Without a pinned version the loader reads the manifest and imports the version it names.
|
|
15
|
+
* - With a pinned version it goes straight to the immutable address (no manifest, nothing that can change under
|
|
16
|
+
* the partner's feet). Production pages should pin.
|
|
17
|
+
*
|
|
18
|
+
* The loader needs no API key and no network call to the Widgetic API: modules and manifests are static files.
|
|
19
|
+
*/
|
|
20
|
+
import type { ModuleName, UIModule } from '../types';
|
|
21
|
+
/** Everything that can go wrong while finding or importing a module, as a code a page can react to. */
|
|
22
|
+
export type ModuleLoadErrorCode = 'INVALID_MODULE_NAME' | 'INVALID_VERSION' | 'INVALID_MODULE_BASE_URL' | 'MODULE_NOT_FOUND' | 'MANIFEST_UNAVAILABLE' | 'MANIFEST_INVALID' | 'MODULE_LOAD_FAILED' | 'MODULE_INVALID';
|
|
23
|
+
export declare class ModuleLoadError extends Error {
|
|
24
|
+
readonly code: ModuleLoadErrorCode;
|
|
25
|
+
readonly moduleName: string;
|
|
26
|
+
readonly url?: string;
|
|
27
|
+
readonly cause?: unknown;
|
|
28
|
+
constructor(code: ModuleLoadErrorCode, message: string, details: {
|
|
29
|
+
moduleName: string;
|
|
30
|
+
url?: string;
|
|
31
|
+
cause?: unknown;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/** A module class: `new Module(container, config)`, then `mount()`. */
|
|
35
|
+
export type ModuleConstructor = new (container: HTMLElement, config: Record<string, unknown>) => UIModule;
|
|
36
|
+
/** A module that was found and imported. */
|
|
37
|
+
export interface LoadedModule {
|
|
38
|
+
Module: ModuleConstructor;
|
|
39
|
+
name: string;
|
|
40
|
+
/** The version that was imported (the pinned one, or the one the manifest named). */
|
|
41
|
+
version: string;
|
|
42
|
+
/** The address the module file was imported from. */
|
|
43
|
+
url: string;
|
|
44
|
+
}
|
|
45
|
+
export interface ModuleLoaderOptions {
|
|
46
|
+
/** Where modules are served from. Default `https://cdn.widgetic.com/modules`. May be relative to the page. */
|
|
47
|
+
moduleBaseUrl?: string;
|
|
48
|
+
/** `fetch`, replaceable for tests. */
|
|
49
|
+
fetchImpl?: typeof fetch;
|
|
50
|
+
/** Dynamic `import()`, replaceable for tests. */
|
|
51
|
+
importImpl?: (specifier: string) => Promise<unknown>;
|
|
52
|
+
/** Pauses between attempts in milliseconds. One entry per retry; default `[300, 900]` = three attempts. */
|
|
53
|
+
retryDelaysMs?: number[];
|
|
54
|
+
}
|
|
55
|
+
export declare class ModuleLoader {
|
|
56
|
+
private readonly baseUrl;
|
|
57
|
+
private readonly fetchImpl;
|
|
58
|
+
private readonly importImpl;
|
|
59
|
+
private readonly retryDelaysMs;
|
|
60
|
+
private readonly loads;
|
|
61
|
+
constructor(options?: ModuleLoaderOptions);
|
|
62
|
+
/**
|
|
63
|
+
* Finds and imports a module.
|
|
64
|
+
* @param name - The module, like `file-browser`.
|
|
65
|
+
* @param options.version - Pin an exact version like `1.2.0`. Default: the newest one the manifest names.
|
|
66
|
+
*/
|
|
67
|
+
load(name: ModuleName, options?: {
|
|
68
|
+
version?: string;
|
|
69
|
+
}): Promise<LoadedModule>;
|
|
70
|
+
private loadUncached;
|
|
71
|
+
/** Reads `<base>/<name>/manifest.json`. Network failures and server errors are retried; a missing module is not. */
|
|
72
|
+
private fetchManifest;
|
|
73
|
+
private validateManifest;
|
|
74
|
+
/** The module file the manifest points at, which must be a script inside the module's own folder. */
|
|
75
|
+
private resolveEntryUrl;
|
|
76
|
+
/** Imports the module file and checks it exports a class. */
|
|
77
|
+
private importModuleFile;
|
|
78
|
+
/**
|
|
79
|
+
* Runs an operation, trying again after a pause when it throws. A `ModuleLoadError` means "this will not get
|
|
80
|
+
* better by asking again" and is thrown straight away.
|
|
81
|
+
*/
|
|
82
|
+
private withRetries;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/sdk/modules/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,EAAkB,UAAU,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGrE,uGAAuG;AACvG,MAAM,MAAM,mBAAmB,GACzB,qBAAqB,GACrB,iBAAiB,GACjB,yBAAyB,GACzB,kBAAkB,GAClB,sBAAsB,GACtB,kBAAkB,GAClB,oBAAoB,GACpB,gBAAgB,CAAC;AAEvB,qBAAa,eAAgB,SAAQ,KAAK;IACtC,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IACnC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;gBAEb,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAUzH;AAED,uEAAuE;AACvE,MAAM,MAAM,iBAAiB,GAAG,KAAK,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,QAAQ,CAAC;AAE1G,4CAA4C;AAC5C,MAAM,WAAW,YAAY;IACzB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,qFAAqF;IACrF,OAAO,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,GAAG,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,mBAAmB;IAChC,8GAA8G;IAC9G,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,sCAAsC;IACtC,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,iDAAiD;IACjD,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACrD,2GAA2G;IAC3G,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B;AAWD,qBAAa,YAAY;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAM;IAC9B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAe;IACzC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA0C;IACrE,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAW;IAGzC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA4C;gBAEtD,OAAO,GAAE,mBAAwB;IAQ7C;;;;OAIG;IACG,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,GAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,OAAO,CAAC,YAAY,CAAC;YAqBzE,YAAY;IAiB1B,oHAAoH;YACtG,aAAa;IA4C3B,OAAO,CAAC,gBAAgB;IAwBxB,qGAAqG;IACrG,OAAO,CAAC,eAAe;IA2BvB,6DAA6D;YAC/C,gBAAgB;IA2B9B;;;OAGG;YACW,WAAW;CAkB5B"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component Type Definitions
|
|
3
|
+
* Core types for UI component system including:
|
|
4
|
+
* - Component configuration
|
|
5
|
+
* - Component lifecycle
|
|
6
|
+
* - Component interfaces
|
|
7
|
+
*/
|
|
8
|
+
import type { ThemeConfig } from './theme';
|
|
9
|
+
import type { ModuleTheme, ThemeOption } from './module-theme';
|
|
10
|
+
import type { ModuleLanguage } from './module-language';
|
|
11
|
+
import type { IEventEmitter } from './events';
|
|
12
|
+
/**
|
|
13
|
+
* Why a module is asking the partner for a token.
|
|
14
|
+
* - `initial`: the module is starting and has no token yet.
|
|
15
|
+
* - `expiring`: the current token is about to expire and the module wants its replacement.
|
|
16
|
+
* - `expired`: the current token has already expired (the page was asleep, or an earlier refresh failed).
|
|
17
|
+
*/
|
|
18
|
+
export interface TokenRequestContext {
|
|
19
|
+
reason: 'initial' | 'expiring' | 'expired';
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* What the partner's `getToken` resolves with: the bare editor session token, or the token together with the moment
|
|
23
|
+
* it stops working (an ISO 8601 string, epoch milliseconds or a Date). With `expiresAt` the module asks for a
|
|
24
|
+
* replacement shortly before then, so the visitor is never interrupted.
|
|
25
|
+
*/
|
|
26
|
+
export type TokenResult = string | {
|
|
27
|
+
token: string;
|
|
28
|
+
expiresAt?: string | number | Date;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Asks the partner's server for an editor session token.
|
|
32
|
+
* The partner's server mints it (`POST /v1/managed-users/{id}/editor-sessions` with its API key), so the API key
|
|
33
|
+
* never reaches the browser.
|
|
34
|
+
*/
|
|
35
|
+
export type GetToken = (context: TokenRequestContext) => Promise<TokenResult> | TokenResult;
|
|
36
|
+
/**
|
|
37
|
+
* UI Module Interface
|
|
38
|
+
* What the SDK needs from every UI module (File Browser, editors ...). Modules are plain classes built as
|
|
39
|
+
* `new Module(container, config)`; only `mount` is required.
|
|
40
|
+
*/
|
|
41
|
+
export interface UIModule {
|
|
42
|
+
mount(): Promise<void> | void;
|
|
43
|
+
unmount?(): Promise<void> | void;
|
|
44
|
+
/**
|
|
45
|
+
* Change the look: `'light'` or `'dark'` switch the mode and keep the rest of the theme; settings
|
|
46
|
+
* (`{ preset, colors, radius, font }`) replace the whole theme. Throws for a theme that cannot be used.
|
|
47
|
+
*/
|
|
48
|
+
setTheme?(theme: ModuleTheme): void;
|
|
49
|
+
/**
|
|
50
|
+
* Change the language while the module is on screen: `locale` for numbers, dates and plural rules, `messages` for the
|
|
51
|
+
* words. A key of `locale` or `messages` that the call leaves out keeps its current value; a `messages` object
|
|
52
|
+
* replaces all the module's current messages. Throws for a value that cannot be used, and then changes nothing.
|
|
53
|
+
*/
|
|
54
|
+
setLanguage?(language: ModuleLanguage): void;
|
|
55
|
+
on?(eventName: string, handler: (payload: any) => void): () => void;
|
|
56
|
+
off?(eventName: string, handler: (payload: any) => void): void;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Component Status Type
|
|
60
|
+
* All possible component lifecycle states
|
|
61
|
+
*/
|
|
62
|
+
export type ComponentStatus = 'initializing' | 'ready' | 'error' | 'destroyed';
|
|
63
|
+
/**
|
|
64
|
+
* Component State Interface
|
|
65
|
+
* Tracks component status and data
|
|
66
|
+
*/
|
|
67
|
+
export interface ComponentState {
|
|
68
|
+
status: ComponentStatus;
|
|
69
|
+
error: Error | null;
|
|
70
|
+
data?: Record<string, any>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Base mount configuration
|
|
74
|
+
* Settings for mounting any module. Everything that is not listed here is handed to the module itself
|
|
75
|
+
* (the File Browser takes `maxSelections`, `initialFilter`, `selectLabel`, `locale`, `messages` ...).
|
|
76
|
+
*/
|
|
77
|
+
export interface MountConfig {
|
|
78
|
+
container: string | HTMLElement;
|
|
79
|
+
/** Pin an exact module version such as "1.2.0". Default: the newest published version. */
|
|
80
|
+
version?: string;
|
|
81
|
+
/**
|
|
82
|
+
* The look of this module: `'light'`, `'dark'`, `'system'`, or settings (`{ preset, mode, colors, radius, font }`).
|
|
83
|
+
* Default: the SDK's current theme. A module with settings of its own keeps them when the page later calls
|
|
84
|
+
* `ui.updateTheme(...)` with settings; it follows a change of mode.
|
|
85
|
+
*/
|
|
86
|
+
theme?: ThemeOption;
|
|
87
|
+
/** Show a loading placeholder while the module downloads. Default: true. */
|
|
88
|
+
placeholder?: boolean;
|
|
89
|
+
/** The words a screen reader says for that placeholder, in your language. Default: "Loading". */
|
|
90
|
+
loadingLabel?: string;
|
|
91
|
+
/**
|
|
92
|
+
* Cancels the mount. When the signal aborts before the module is running, the download is abandoned, nothing is
|
|
93
|
+
* left in the container and the mount rejects with an `AbortError` (code `MOUNT_ABORTED`). When it aborts
|
|
94
|
+
* while the module is starting, the module is taken down again. Made for components that can be removed before
|
|
95
|
+
* the module has finished loading (React effects, route changes).
|
|
96
|
+
*/
|
|
97
|
+
signal?: AbortSignal;
|
|
98
|
+
/** Listen to module events from the very start, so `ready` is not missed. */
|
|
99
|
+
on?: Record<string, (payload: any) => void>;
|
|
100
|
+
callbacks?: {
|
|
101
|
+
onReady?: () => void;
|
|
102
|
+
onError?: (error: Error) => void;
|
|
103
|
+
};
|
|
104
|
+
[moduleOption: string]: unknown;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Component configuration
|
|
108
|
+
* Full configuration for component initialization
|
|
109
|
+
* @deprecated Part of the legacy component base class (`WidgeticComponent`); UI modules do not use it.
|
|
110
|
+
*/
|
|
111
|
+
export interface ComponentConfig {
|
|
112
|
+
id: string;
|
|
113
|
+
container: HTMLElement;
|
|
114
|
+
events: IEventEmitter;
|
|
115
|
+
theme?: ThemeConfig;
|
|
116
|
+
widgetId?: string;
|
|
117
|
+
compositionId?: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Component instance information
|
|
121
|
+
* Runtime data for mounted components
|
|
122
|
+
*/
|
|
123
|
+
export interface ComponentInstance {
|
|
124
|
+
id: string;
|
|
125
|
+
type: ComponentType;
|
|
126
|
+
container: HTMLElement;
|
|
127
|
+
unmount: () => Promise<void>;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* A mounted UI module
|
|
131
|
+
* What `mount()` resolves with: the module itself plus the controls a page needs.
|
|
132
|
+
*/
|
|
133
|
+
export interface MountedModule<Module extends UIModule = UIModule> {
|
|
134
|
+
id: string;
|
|
135
|
+
type: ModuleName;
|
|
136
|
+
version: string;
|
|
137
|
+
container: HTMLElement;
|
|
138
|
+
module: Module;
|
|
139
|
+
on: (eventName: string, handler: (payload: any) => void) => () => void;
|
|
140
|
+
off: (eventName: string, handler: (payload: any) => void) => void;
|
|
141
|
+
/**
|
|
142
|
+
* Change the look of this module alone: `'light'` or `'dark'` switch the mode and keep the rest of its theme; settings
|
|
143
|
+
* replace its theme, and from then on the module keeps them when the page calls `ui.updateTheme(...)` with settings.
|
|
144
|
+
* Throws for a theme that cannot be used, and then changes nothing.
|
|
145
|
+
*/
|
|
146
|
+
setTheme: (theme: ModuleTheme) => void;
|
|
147
|
+
/**
|
|
148
|
+
* Change the language of this module while it is on screen (`locale`, `messages`). A key the call leaves out keeps its
|
|
149
|
+
* current value; `messages` replaces all of the module's current messages, so a page switching from German to French
|
|
150
|
+
* passes the French ones only. Throws for a value the module cannot use, and then changes nothing. A module that has
|
|
151
|
+
* no words to translate (yet) says so in the console and does nothing.
|
|
152
|
+
*/
|
|
153
|
+
setLanguage: (language: ModuleLanguage) => void;
|
|
154
|
+
unmount: () => Promise<void>;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Available component types
|
|
158
|
+
* Union of all supported UI components
|
|
159
|
+
*/
|
|
160
|
+
export type ComponentType = 'widget-creator' | 'composition-editor' | 'embed-editor' | 'file-browser';
|
|
161
|
+
/**
|
|
162
|
+
* Any module name. The known modules autocomplete; a module published after this SDK release still works because
|
|
163
|
+
* modules are found through the CDN, not through this list.
|
|
164
|
+
*/
|
|
165
|
+
export type ModuleName = ComponentType | (string & {});
|
|
166
|
+
/**
|
|
167
|
+
* Module manifest
|
|
168
|
+
* A small JSON file next to every module (`<base>/<name>/manifest.json`) that names the newest version.
|
|
169
|
+
*/
|
|
170
|
+
export interface ModuleManifest {
|
|
171
|
+
name: string;
|
|
172
|
+
version: string;
|
|
173
|
+
entry: string;
|
|
174
|
+
}
|
|
175
|
+
/** @deprecated Use `ModuleManifest`. */
|
|
176
|
+
export type ComponentManifest = ModuleManifest;
|
|
177
|
+
//# sourceMappingURL=component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../src/sdk/types/component.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAChC,MAAM,EAAE,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;CAC9C;AAED;;;;GAIG;AACH,MAAM,MAAM,WAAW,GACjB,MAAM,GACN;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAE5D;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,EAAE,mBAAmB,KAAK,OAAO,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC;AAE5F;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACrB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC9B,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACjC;;;OAGG;IACH,QAAQ,CAAC,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;IACpC;;;;OAIG;IACH,WAAW,CAAC,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI,CAAC;IAC7C,EAAE,CAA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