@shellui/sdk 0.0.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 ADDED
@@ -0,0 +1,23 @@
1
+ # @shellui/sdk
2
+
3
+ ShellUI SDK - JavaScript SDK for ShellUI integration
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @shellui/sdk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```javascript
14
+ import { init, getVersion } from '@shellui/sdk';
15
+
16
+ const sdk = init({ /* config */ });
17
+ console.log(getVersion());
18
+ ```
19
+
20
+ ## License
21
+
22
+ MIT
23
+
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@shellui/sdk",
3
+ "version": "0.0.1",
4
+ "description": "ShellUI SDK - JavaScript SDK for ShellUI integration",
5
+ "main": "src/index.js",
6
+ "types": "src/index.d.ts",
7
+ "type": "module",
8
+ "files": [
9
+ "src",
10
+ "README.md",
11
+ "package.json"
12
+ ],
13
+ "scripts": {
14
+ "build": "echo 'SDK build complete'",
15
+ "test": "echo \"Error: no test specified\" && exit 1"
16
+ },
17
+ "keywords": [
18
+ "shellui",
19
+ "sdk",
20
+ "javascript",
21
+ "microfrontend"
22
+ ],
23
+ "author": "ShellUI",
24
+ "license": "MIT",
25
+ "dependencies": {
26
+ "@shellui/core": "*"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ }
31
+ }
32
+
package/src/index.d.ts ADDED
@@ -0,0 +1,55 @@
1
+ /**
2
+ * ShellUI SDK Type Definitions
3
+ */
4
+
5
+ export interface ShellUIUrlPayload {
6
+ pathname: string;
7
+ search: string;
8
+ hash: string;
9
+ fullPath: string;
10
+ }
11
+
12
+ export interface ShellUIMessage {
13
+ type: 'SHELLUI_URL_CHANGED';
14
+ payload: ShellUIUrlPayload;
15
+ }
16
+
17
+ export class ShellUISDK {
18
+ private initialized: boolean;
19
+ private currentPath: string;
20
+ private version: string;
21
+
22
+ constructor();
23
+
24
+ /**
25
+ * Initialize the SDK and start monitoring URL changes
26
+ */
27
+ init(): this;
28
+
29
+ /**
30
+ * Sets up listeners for various URL change events
31
+ */
32
+ setupUrlMonitoring(): void;
33
+
34
+ /**
35
+ * Internal handler for URL changes
36
+ */
37
+ handleUrlChange(): void;
38
+
39
+ /**
40
+ * Sends a message to the parent frame with the current path information
41
+ */
42
+ notifyParent(): void;
43
+
44
+ /**
45
+ * Returns the current version of the SDK
46
+ */
47
+ getVersion(): string;
48
+ }
49
+
50
+ export const init: () => ShellUISDK;
51
+ export const getVersion: () => string;
52
+ export const shellui: ShellUISDK;
53
+
54
+ declare const sdk: ShellUISDK;
55
+ export default sdk;
package/src/index.js ADDED
@@ -0,0 +1,104 @@
1
+ /**
2
+ * ShellUI SDK
3
+ * Handles communication between the iframe content and the ShellUI parent frame.
4
+ */
5
+
6
+ class ShellUISDK {
7
+ constructor() {
8
+ this.initialized = false;
9
+ this.currentPath = window.location.pathname + window.location.search + window.location.hash;
10
+ this.version = '0.0.1';
11
+ }
12
+
13
+ /**
14
+ * Initialize the SDK and start monitoring URL changes
15
+ */
16
+ init() {
17
+ if (this.initialized) return this;
18
+
19
+ // Monitor URL changes
20
+ this.setupUrlMonitoring();
21
+
22
+ // Initial sync
23
+ this.notifyParent();
24
+
25
+ this.initialized = true;
26
+ console.log('ShellUI SDK initialized');
27
+ return this;
28
+ }
29
+
30
+ /**
31
+ * Sets up listeners for various URL change events
32
+ */
33
+ setupUrlMonitoring() {
34
+ // Listen for popstate (back/forward buttons)
35
+ window.addEventListener('popstate', () => this.handleUrlChange());
36
+
37
+ // Listen for hashchange
38
+ window.addEventListener('hashchange', () => this.handleUrlChange());
39
+
40
+ // Intercept pushState and replaceState
41
+ const originalPushState = window.history.pushState;
42
+ const originalReplaceState = window.history.replaceState;
43
+
44
+ const self = this;
45
+ window.history.pushState = function(...args) {
46
+ originalPushState.apply(this, args);
47
+ self.handleUrlChange();
48
+ };
49
+
50
+ window.history.replaceState = function(...args) {
51
+ originalReplaceState.apply(this, args);
52
+ self.handleUrlChange();
53
+ };
54
+
55
+ // Monitor clicks on same-origin links to catch re-renders or local routing
56
+ document.addEventListener('click', (e) => {
57
+ const link = e.target.closest('a');
58
+ if (link && link.href && new URL(link.href).origin === window.location.origin) {
59
+ // Wait a bit for the framework to handle the route
60
+ setTimeout(() => this.handleUrlChange(), 0);
61
+ }
62
+ });
63
+ }
64
+
65
+ handleUrlChange() {
66
+ const newPath = window.location.pathname + window.location.search + window.location.hash;
67
+ if (newPath !== this.currentPath) {
68
+ this.currentPath = newPath;
69
+ this.notifyParent();
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Sends a message to the parent frame with the current path information
75
+ */
76
+ notifyParent() {
77
+ const message = {
78
+ type: 'SHELLUI_URL_CHANGED',
79
+ payload: {
80
+ pathname: window.location.pathname,
81
+ search: window.location.search,
82
+ hash: window.location.hash,
83
+ fullPath: window.location.pathname + window.location.search + window.location.hash
84
+ }
85
+ };
86
+
87
+ // Send to parent frame
88
+ if (window.parent !== window) {
89
+ window.parent.postMessage(message, '*');
90
+ }
91
+ }
92
+
93
+ getVersion() {
94
+ return this.version;
95
+ }
96
+ }
97
+
98
+ const sdk = new ShellUISDK();
99
+
100
+ export const init = () => sdk.init();
101
+ export const getVersion = () => sdk.getVersion();
102
+ export const shellui = sdk;
103
+
104
+ export default sdk;