@shellui/sdk 0.0.2 → 0.0.4

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.
Files changed (46) hide show
  1. package/README.md +3 -2
  2. package/dist/actions/closeDrawer.d.ts +6 -0
  3. package/dist/actions/closeDrawer.d.ts.map +1 -0
  4. package/dist/actions/closeDrawer.js +19 -0
  5. package/dist/actions/dialog.d.ts +9 -0
  6. package/dist/actions/dialog.d.ts.map +1 -0
  7. package/dist/actions/dialog.js +51 -0
  8. package/dist/actions/openDrawer.d.ts +8 -0
  9. package/dist/actions/openDrawer.d.ts.map +1 -0
  10. package/dist/actions/openDrawer.js +27 -0
  11. package/dist/actions/openModal.d.ts +7 -0
  12. package/dist/actions/openModal.d.ts.map +1 -0
  13. package/dist/actions/openModal.js +22 -0
  14. package/dist/actions/toast.d.ts +9 -0
  15. package/dist/actions/toast.d.ts.map +1 -0
  16. package/dist/actions/toast.js +47 -0
  17. package/dist/index.d.ts +58 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +198 -0
  20. package/dist/logger/logger.d.ts +7 -0
  21. package/dist/logger/logger.d.ts.map +1 -0
  22. package/dist/logger/logger.js +175 -0
  23. package/dist/types.d.ts +131 -0
  24. package/dist/types.d.ts.map +1 -0
  25. package/dist/types.js +4 -0
  26. package/dist/utils/callbackRegistry.d.ts +29 -0
  27. package/dist/utils/callbackRegistry.d.ts.map +1 -0
  28. package/dist/utils/callbackRegistry.js +124 -0
  29. package/dist/utils/frameRegistry.d.ts +12 -0
  30. package/dist/utils/frameRegistry.d.ts.map +1 -0
  31. package/dist/utils/frameRegistry.js +59 -0
  32. package/dist/utils/messageListenerRegistry.d.ts +25 -0
  33. package/dist/utils/messageListenerRegistry.d.ts.map +1 -0
  34. package/dist/utils/messageListenerRegistry.js +197 -0
  35. package/dist/utils/setupKeyListener.d.ts +7 -0
  36. package/dist/utils/setupKeyListener.d.ts.map +1 -0
  37. package/dist/utils/setupKeyListener.js +29 -0
  38. package/dist/utils/setupUrlMonitoring.d.ts +12 -0
  39. package/dist/utils/setupUrlMonitoring.d.ts.map +1 -0
  40. package/dist/utils/setupUrlMonitoring.js +57 -0
  41. package/dist/utils/uuid.d.ts +10 -0
  42. package/dist/utils/uuid.d.ts.map +1 -0
  43. package/dist/utils/uuid.js +18 -0
  44. package/package.json +22 -11
  45. package/src/index.d.ts +0 -55
  46. package/src/index.js +0 -104
package/README.md CHANGED
@@ -13,11 +13,12 @@ npm install @shellui/sdk
13
13
  ```javascript
14
14
  import { init, getVersion } from '@shellui/sdk';
15
15
 
16
- const sdk = init({ /* config */ });
16
+ const sdk = init({
17
+ /* config */
18
+ });
17
19
  console.log(getVersion());
18
20
  ```
19
21
 
20
22
  ## License
21
23
 
22
24
  MIT
23
-
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Closes the drawer.
3
+ * If inside an iframe, sends a message to the parent to close the drawer.
4
+ */
5
+ export declare function closeDrawer(): void;
6
+ //# sourceMappingURL=closeDrawer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"closeDrawer.d.ts","sourceRoot":"","sources":["../../src/actions/closeDrawer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAelC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Closes the drawer.
3
+ * If inside an iframe, sends a message to the parent to close the drawer.
4
+ */
5
+ export function closeDrawer() {
6
+ if (typeof window === 'undefined') {
7
+ return;
8
+ }
9
+ const message = {
10
+ type: 'SHELLUI_CLOSE_DRAWER',
11
+ payload: {},
12
+ };
13
+ if (window.parent !== window) {
14
+ window.parent.postMessage(message, '*');
15
+ }
16
+ else {
17
+ window.postMessage(message, '*');
18
+ }
19
+ }
@@ -0,0 +1,9 @@
1
+ import type { DialogOptions } from '../types.js';
2
+ /**
3
+ * Shows a dialog
4
+ * If inside an iframe, sends a message to the parent to show the dialog
5
+ * If not in an iframe, dispatches a custom event that can be handled by the app
6
+ * @returns The dialog ID if created, void if updating or in SSR
7
+ */
8
+ export declare function dialog(options?: DialogOptions): string | void;
9
+ //# sourceMappingURL=dialog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dialog.d.ts","sourceRoot":"","sources":["../../src/actions/dialog.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,GAAG,IAAI,CA+C7D"}
@@ -0,0 +1,51 @@
1
+ import { shellui } from '../index.js';
2
+ import { generateUuid } from '../utils/uuid.js';
3
+ /**
4
+ * Shows a dialog
5
+ * If inside an iframe, sends a message to the parent to show the dialog
6
+ * If not in an iframe, dispatches a custom event that can be handled by the app
7
+ * @returns The dialog ID if created, void if updating or in SSR
8
+ */
9
+ export function dialog(options) {
10
+ if (typeof window === 'undefined' || !options) {
11
+ return;
12
+ }
13
+ const dialogId = options.id ?? generateUuid();
14
+ if (options.onOk || options.onCancel || options.secondaryButton?.onClick) {
15
+ shellui.callbackRegistry.register(dialogId, {
16
+ action: options.onOk,
17
+ cancel: options.onCancel,
18
+ secondary: options.secondaryButton?.onClick,
19
+ });
20
+ }
21
+ const messageType = options.id ? 'SHELLUI_DIALOG_UPDATE' : 'SHELLUI_DIALOG';
22
+ const message = {
23
+ type: messageType,
24
+ payload: {
25
+ id: dialogId,
26
+ title: options.title,
27
+ description: options.description,
28
+ mode: options.mode ?? 'ok',
29
+ okLabel: options.okLabel,
30
+ cancelLabel: options.cancelLabel,
31
+ size: options.size,
32
+ position: options.position,
33
+ secondaryButton: options.secondaryButton
34
+ ? {
35
+ label: options.secondaryButton.label,
36
+ onClick: undefined,
37
+ }
38
+ : undefined,
39
+ icon: options.icon,
40
+ onOk: undefined,
41
+ onCancel: undefined,
42
+ },
43
+ };
44
+ if (window.parent !== window) {
45
+ window.parent.postMessage(message, '*');
46
+ }
47
+ else {
48
+ window.postMessage(message, '*');
49
+ }
50
+ return options.id ? undefined : dialogId;
51
+ }
@@ -0,0 +1,8 @@
1
+ import type { OpenDrawerOptions } from '../types.js';
2
+ /**
3
+ * Opens the drawer with optional url, position (top, bottom, left, right), and size (e.g. "400px", "80vh", "50vw").
4
+ * Size is height for top/bottom drawers, width for left/right drawers.
5
+ * If inside an iframe, sends a message to the parent to open the drawer.
6
+ */
7
+ export declare function openDrawer(options?: OpenDrawerOptions): void;
8
+ //# sourceMappingURL=openDrawer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openDrawer.d.ts","sourceRoot":"","sources":["../../src/actions/openDrawer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAuB5D"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Opens the drawer with optional url, position (top, bottom, left, right), and size (e.g. "400px", "80vh", "50vw").
3
+ * Size is height for top/bottom drawers, width for left/right drawers.
4
+ * If inside an iframe, sends a message to the parent to open the drawer.
5
+ */
6
+ export function openDrawer(options) {
7
+ if (typeof window === 'undefined') {
8
+ return;
9
+ }
10
+ const payload = options
11
+ ? {
12
+ url: options.url ?? undefined,
13
+ position: options.position ?? undefined,
14
+ size: options.size ?? undefined,
15
+ }
16
+ : {};
17
+ const message = {
18
+ type: 'SHELLUI_OPEN_DRAWER',
19
+ payload,
20
+ };
21
+ if (window.parent !== window) {
22
+ window.parent.postMessage(message, '*');
23
+ }
24
+ else {
25
+ window.postMessage(message, '*');
26
+ }
27
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Opens the settings modal with optional URL
3
+ * If inside an iframe, sends a message to the parent to open the modal
4
+ * If not in an iframe, dispatches a custom event that can be handled by the app
5
+ */
6
+ export declare function openModal(url?: string): void;
7
+ //# sourceMappingURL=openModal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openModal.d.ts","sourceRoot":"","sources":["../../src/actions/openModal.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAiB5C"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Opens the settings modal with optional URL
3
+ * If inside an iframe, sends a message to the parent to open the modal
4
+ * If not in an iframe, dispatches a custom event that can be handled by the app
5
+ */
6
+ export function openModal(url) {
7
+ if (typeof window === 'undefined') {
8
+ return;
9
+ }
10
+ const message = {
11
+ type: 'SHELLUI_OPEN_MODAL',
12
+ payload: {
13
+ url: url ?? null,
14
+ },
15
+ };
16
+ if (window.parent !== window) {
17
+ window.parent.postMessage(message, '*');
18
+ }
19
+ else {
20
+ window.postMessage(message, '*');
21
+ }
22
+ }
@@ -0,0 +1,9 @@
1
+ import type { ToastOptions } from '../types.js';
2
+ /**
3
+ * Shows a toast notification
4
+ * If inside an iframe, sends a message to the parent to show the toast
5
+ * If not in an iframe, dispatches a custom event that can be handled by the app
6
+ * @returns The toast ID if created, void if updating or in SSR
7
+ */
8
+ export declare function toast(options?: ToastOptions): string | void;
9
+ //# sourceMappingURL=toast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toast.d.ts","sourceRoot":"","sources":["../../src/actions/toast.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,OAAO,GAAE,YAAiB,GAAG,MAAM,GAAG,IAAI,CA2C/D"}
@@ -0,0 +1,47 @@
1
+ import { shellui } from '../index.js';
2
+ import { generateUuid } from '../utils/uuid.js';
3
+ /**
4
+ * Shows a toast notification
5
+ * If inside an iframe, sends a message to the parent to show the toast
6
+ * If not in an iframe, dispatches a custom event that can be handled by the app
7
+ * @returns The toast ID if created, void if updating or in SSR
8
+ */
9
+ export function toast(options = {}) {
10
+ if (typeof window === 'undefined') {
11
+ return;
12
+ }
13
+ const toastId = options.id ?? generateUuid();
14
+ if (options.action?.onClick || options.cancel?.onClick) {
15
+ shellui.callbackRegistry.register(toastId, {
16
+ action: options.action?.onClick,
17
+ cancel: options.cancel?.onClick,
18
+ });
19
+ }
20
+ const messageType = options.id ? 'SHELLUI_TOAST_UPDATE' : 'SHELLUI_TOAST';
21
+ const message = {
22
+ type: messageType,
23
+ payload: {
24
+ id: toastId,
25
+ title: options.title,
26
+ description: options.description,
27
+ type: options.type ?? 'default',
28
+ duration: options.duration,
29
+ position: options.position,
30
+ action: {
31
+ ...options.action,
32
+ onClick: undefined,
33
+ },
34
+ cancel: {
35
+ ...options.cancel,
36
+ onClick: undefined,
37
+ },
38
+ },
39
+ };
40
+ if (window.parent !== window) {
41
+ window.parent.postMessage(message, '*');
42
+ }
43
+ else {
44
+ window.postMessage(message, '*');
45
+ }
46
+ return options.id ? undefined : toastId;
47
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * ShellUI SDK
3
+ * Handles communication between the iframe content and the ShellUI parent frame.
4
+ */
5
+ import { FrameRegistry } from './utils/frameRegistry.js';
6
+ import { MessageListenerRegistry } from './utils/messageListenerRegistry.js';
7
+ import { CallbackRegistry } from './utils/callbackRegistry.js';
8
+ import type { ShellUIMessage, ToastOptions, DialogOptions, Settings, OpenDrawerOptions } from './types.js';
9
+ export type { ShellUIMessage, ShellUIUrlPayload, ToastOptions, DialogOptions, DialogMode, AlertDialogSize, DialogPosition, DrawerPosition, OpenDrawerOptions, LoggerInstance, Settings, SettingsNavigationItem, } from './types.js';
10
+ export declare class ShellUISDK {
11
+ initialized: boolean;
12
+ currentPath: string;
13
+ version: string;
14
+ frameRegistry: FrameRegistry;
15
+ messageListenerRegistry: MessageListenerRegistry;
16
+ callbackRegistry: CallbackRegistry;
17
+ initialSettings: Settings | null;
18
+ constructor();
19
+ init(): Promise<this>;
20
+ private _setupInitialSettings;
21
+ private _setupCallbackListeners;
22
+ openModal(url?: string): void;
23
+ openDrawer(options?: OpenDrawerOptions): void;
24
+ closeDrawer(): void;
25
+ navigate(url: string): void;
26
+ toast(options?: ToastOptions): string | void;
27
+ dialog(options?: DialogOptions): string | void;
28
+ getVersion(): string;
29
+ getUuidByIframe(windowRef: Window): string | undefined;
30
+ addIframe(iframe: HTMLIFrameElement): string;
31
+ removeIframe(identifier: string | HTMLIFrameElement): boolean;
32
+ addMessageListener(messageType: string, listener: (messageData: ShellUIMessage, originalEvent: MessageEvent) => void): () => void;
33
+ removeMessageListener(messageType: string, listener: (messageData: ShellUIMessage, originalEvent: MessageEvent) => void): boolean;
34
+ sendMessage(message: ShellUIMessage): number;
35
+ propagateMessage(message: ShellUIMessage): number;
36
+ sendMessageToParent(message: ShellUIMessage): boolean;
37
+ }
38
+ declare const sdk: ShellUISDK;
39
+ export declare const init: () => Promise<ShellUISDK>;
40
+ export declare const getVersion: () => string;
41
+ export declare const openModal: (url?: string) => void;
42
+ export declare const openDrawer: (options?: OpenDrawerOptions) => void;
43
+ export declare const closeDrawer: () => void;
44
+ export declare const navigate: (url: string) => void;
45
+ export declare const toast: (options?: ToastOptions) => string | void;
46
+ export declare const dialog: (options?: DialogOptions) => string | void;
47
+ export declare const addIframe: (iframe: HTMLIFrameElement) => string;
48
+ export declare const removeIframe: (identifier: string | HTMLIFrameElement) => boolean;
49
+ export declare const addMessageListener: (messageType: string, listener: (messageData: ShellUIMessage, originalEvent: MessageEvent) => void) => (() => void);
50
+ export declare const removeMessageListener: (messageType: string, listener: (messageData: ShellUIMessage, originalEvent: MessageEvent) => void) => boolean;
51
+ export declare const sendMessage: (message: ShellUIMessage) => number;
52
+ export declare const propagateMessage: (message: ShellUIMessage) => number;
53
+ export declare const sendMessageToParent: (message: ShellUIMessage) => boolean;
54
+ export declare const callbackRegistry: CallbackRegistry;
55
+ export { getLogger } from './logger/logger.js';
56
+ export declare const shellui: ShellUISDK;
57
+ export default sdk;
58
+ //# sourceMapping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GAAG,iBAAiB,KAAG,OACxC,CAAC;AAC/B,eAAO,MAAM,kBAAkB,GAC7B,aAAa,MAAM,EACnB,UAAU,CAAC,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,KAAK,IAAI,KAC3E,CAAC,MAAM,IAAI,CAAkD,CAAC;AACjE,eAAO,MAAM,qBAAqB,GAChC,aAAa,MAAM,EACnB,UAAU,CAAC,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,KAAK,IAAI,KAC3E,OAA2D,CAAC;AAC/D,eAAO,MAAM,WAAW,GAAI,SAAS,cAAc,KAAG,MAAkC,CAAC;AACzF,eAAO,MAAM,gBAAgB,GAAI,SAAS,cAAc,KAAG,MAAuC,CAAC;AACnG,eAAO,MAAM,mBAAmB,GAAI,SAAS,cAAc,KAAG,OAC5B,CAAC;AACnC,eAAO,MAAM,gBAAgB,kBAAuB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,eAAO,MAAM,OAAO,YAAM,CAAC;AAE3B,eAAe,GAAG,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,198 @@
1
+ /**
2
+ * ShellUI SDK
3
+ * Handles communication between the iframe content and the ShellUI parent frame.
4
+ */
5
+ import { setupUrlMonitoring } from './utils/setupUrlMonitoring.js';
6
+ import { setupKeyListener } from './utils/setupKeyListener.js';
7
+ import { openModal as openModalAction } from './actions/openModal.js';
8
+ import { openDrawer as openDrawerAction } from './actions/openDrawer.js';
9
+ import { closeDrawer as closeDrawerAction } from './actions/closeDrawer.js';
10
+ import { toast as toastAction } from './actions/toast.js';
11
+ import { dialog as dialogAction } from './actions/dialog.js';
12
+ import { getLogger } from './logger/logger.js';
13
+ import { FrameRegistry } from './utils/frameRegistry.js';
14
+ import { MessageListenerRegistry } from './utils/messageListenerRegistry.js';
15
+ import { CallbackRegistry } from './utils/callbackRegistry.js';
16
+ import packageJson from '../package.json';
17
+ const logger = getLogger('shellsdk');
18
+ export class ShellUISDK {
19
+ constructor() {
20
+ this.initialized = false;
21
+ this.currentPath =
22
+ typeof window !== 'undefined'
23
+ ? window.location.pathname + window.location.search + window.location.hash
24
+ : '';
25
+ this.version = packageJson.version;
26
+ this.frameRegistry = new FrameRegistry();
27
+ this.messageListenerRegistry = new MessageListenerRegistry(this.frameRegistry);
28
+ this.callbackRegistry = new CallbackRegistry();
29
+ this.initialSettings = null;
30
+ }
31
+ async init() {
32
+ if (this.initialized)
33
+ return this;
34
+ await setupUrlMonitoring(this);
35
+ await this.messageListenerRegistry.setupGlobalListener();
36
+ await setupKeyListener();
37
+ await this._setupCallbackListeners();
38
+ await this._setupInitialSettings();
39
+ this.initialized = true;
40
+ logger.info(`ShellUI SDK ${this.version} initialized`);
41
+ this.sendMessageToParent({
42
+ type: 'SHELLUI_INITIALIZED',
43
+ payload: {},
44
+ });
45
+ return Promise.resolve(this);
46
+ }
47
+ async _setupInitialSettings() {
48
+ if (window.parent === window) {
49
+ return;
50
+ }
51
+ return new Promise((resolve) => {
52
+ const cleanup = this.addMessageListener('SHELLUI_SETTINGS', (data) => {
53
+ const { settings } = data.payload;
54
+ this.initialSettings = settings;
55
+ resolve();
56
+ cleanup();
57
+ });
58
+ this.sendMessageToParent({
59
+ type: 'SHELLUI_SETTINGS_REQUESTED',
60
+ payload: {},
61
+ });
62
+ });
63
+ }
64
+ _setupCallbackListeners() {
65
+ this.addMessageListener('SHELLUI_TOAST_ACTION', (data) => {
66
+ const { id } = data.payload ?? {};
67
+ if (id) {
68
+ this.callbackRegistry.triggerAction(id);
69
+ this.callbackRegistry.clear(id);
70
+ }
71
+ else {
72
+ logger.warn('SHELLUI_TOAST_ACTION message missing id');
73
+ }
74
+ });
75
+ this.addMessageListener('SHELLUI_TOAST_CANCEL', (data) => {
76
+ const { id } = data.payload ?? {};
77
+ if (id) {
78
+ this.callbackRegistry.triggerCancel(id);
79
+ this.callbackRegistry.clear(id);
80
+ }
81
+ else {
82
+ logger.warn('SHELLUI_TOAST_CANCEL message missing id');
83
+ }
84
+ });
85
+ this.addMessageListener('SHELLUI_TOAST_CLEAR', (data) => {
86
+ const { id } = data.payload ?? {};
87
+ if (id) {
88
+ this.callbackRegistry.clear(id);
89
+ }
90
+ else {
91
+ logger.warn('SHELLUI_TOAST_CLEAR message missing id');
92
+ }
93
+ });
94
+ this.addMessageListener('SHELLUI_DIALOG_OK', (data) => {
95
+ const { id } = data.payload ?? {};
96
+ if (id) {
97
+ this.callbackRegistry.triggerAction(id);
98
+ this.callbackRegistry.clear(id);
99
+ }
100
+ else {
101
+ logger.warn('SHELLUI_DIALOG_OK message missing id');
102
+ }
103
+ });
104
+ this.addMessageListener('SHELLUI_DIALOG_CANCEL', (data) => {
105
+ const { id } = data.payload ?? {};
106
+ if (id) {
107
+ this.callbackRegistry.triggerCancel(id);
108
+ this.callbackRegistry.clear(id);
109
+ }
110
+ else {
111
+ logger.warn('SHELLUI_DIALOG_CANCEL message missing id');
112
+ }
113
+ });
114
+ this.addMessageListener('SHELLUI_DIALOG_SECONDARY', (data) => {
115
+ const { id } = data.payload ?? {};
116
+ if (id) {
117
+ this.callbackRegistry.triggerSecondary(id);
118
+ this.callbackRegistry.clear(id);
119
+ }
120
+ else {
121
+ logger.warn('SHELLUI_DIALOG_SECONDARY message missing id');
122
+ }
123
+ });
124
+ this.addMessageListener('SHELLUI_REFRESH_PAGE', () => {
125
+ if (typeof window !== 'undefined' && window.parent === window) {
126
+ window.location.reload();
127
+ }
128
+ });
129
+ }
130
+ openModal(url) {
131
+ openModalAction(url);
132
+ }
133
+ openDrawer(options) {
134
+ openDrawerAction(options);
135
+ }
136
+ closeDrawer() {
137
+ closeDrawerAction();
138
+ }
139
+ navigate(url) {
140
+ this.sendMessageToParent({
141
+ type: 'SHELLUI_NAVIGATE',
142
+ payload: { url },
143
+ });
144
+ }
145
+ toast(options) {
146
+ return toastAction(options);
147
+ }
148
+ dialog(options) {
149
+ return dialogAction(options);
150
+ }
151
+ getVersion() {
152
+ return this.version;
153
+ }
154
+ getUuidByIframe(windowRef) {
155
+ return this.frameRegistry.getUuidByIframe(windowRef);
156
+ }
157
+ addIframe(iframe) {
158
+ return this.frameRegistry.addIframe(iframe);
159
+ }
160
+ removeIframe(identifier) {
161
+ return this.frameRegistry.removeIframe(identifier);
162
+ }
163
+ addMessageListener(messageType, listener) {
164
+ return this.messageListenerRegistry.addMessageListener(messageType, listener);
165
+ }
166
+ removeMessageListener(messageType, listener) {
167
+ return this.messageListenerRegistry.removeMessageListener(messageType, listener);
168
+ }
169
+ sendMessage(message) {
170
+ return this.messageListenerRegistry.sendMessage(message);
171
+ }
172
+ propagateMessage(message) {
173
+ return this.messageListenerRegistry.propagateMessage(message);
174
+ }
175
+ sendMessageToParent(message) {
176
+ return this.messageListenerRegistry.sendMessageToParent(message);
177
+ }
178
+ }
179
+ const sdk = new ShellUISDK();
180
+ export const init = async () => await sdk.init();
181
+ export const getVersion = () => sdk.getVersion();
182
+ export const openModal = (url) => openModalAction(url);
183
+ export const openDrawer = (options) => openDrawerAction(options);
184
+ export const closeDrawer = () => closeDrawerAction();
185
+ export const navigate = (url) => sdk.navigate(url);
186
+ export const toast = (options) => toastAction(options);
187
+ export const dialog = (options) => dialogAction(options);
188
+ export const addIframe = (iframe) => sdk.addIframe(iframe);
189
+ export const removeIframe = (identifier) => sdk.removeIframe(identifier);
190
+ export const addMessageListener = (messageType, listener) => sdk.addMessageListener(messageType, listener);
191
+ export const removeMessageListener = (messageType, listener) => sdk.removeMessageListener(messageType, listener);
192
+ export const sendMessage = (message) => sdk.sendMessage(message);
193
+ export const propagateMessage = (message) => sdk.propagateMessage(message);
194
+ export const sendMessageToParent = (message) => sdk.sendMessageToParent(message);
195
+ export const callbackRegistry = sdk.callbackRegistry;
196
+ export { getLogger } from './logger/logger.js';
197
+ export const shellui = sdk;
198
+ export default sdk;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Logger utility with namespace support
3
+ * Reads logging configuration from localStorage settings
4
+ */
5
+ import type { LoggerInstance } from '../types.js';
6
+ export declare function getLogger(namespace: string): LoggerInstance;
7
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":"AACA;;;GAGG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AA+JlD,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc,CA8C3D"}