@stackable-labs/sdk-extension-react 1.22.0 → 1.22.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/dist/index.d.ts +493 -7
- package/dist/index.js +428 -7
- package/package.json +2 -3
- package/dist/Surface.d.ts +0 -24
- package/dist/Surface.js +0 -176
- package/dist/Surface.js.map +0 -1
- package/dist/context.d.ts +0 -10
- package/dist/context.js +0 -8
- package/dist/context.js.map +0 -1
- package/dist/createExtension.d.ts +0 -21
- package/dist/createExtension.js +0 -35
- package/dist/createExtension.js.map +0 -1
- package/dist/hooks.d.ts +0 -33
- package/dist/hooks.js +0 -52
- package/dist/hooks.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/rpc-client.d.ts +0 -21
- package/dist/rpc-client.js +0 -104
- package/dist/rpc-client.js.map +0 -1
- package/dist/store.d.ts +0 -20
- package/dist/store.js +0 -30
- package/dist/store.js.map +0 -1
- package/dist/ui.d.ts +0 -366
- package/dist/ui.js +0 -50
- package/dist/ui.js.map +0 -1
- package/dist/useContextData.d.ts +0 -9
- package/dist/useContextData.js +0 -27
- package/dist/useContextData.js.map +0 -1
package/dist/context.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* React contexts for the extension runtime.
|
|
3
|
-
*/
|
|
4
|
-
import { createContext } from 'react';
|
|
5
|
-
/** Context for surface-level data (provided by host per surface) */
|
|
6
|
-
export const SurfaceContext = createContext(null);
|
|
7
|
-
export const ExtensionContext = createContext(null);
|
|
8
|
-
//# sourceMappingURL=context.js.map
|
package/dist/context.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAErC,oEAAoE;AACpE,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAAiC,IAAI,CAAC,CAAA;AAOjF,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAA+B,IAAI,CAAC,CAAA"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* createExtension — bootstraps the extension runtime in the iframe sandbox.
|
|
3
|
-
* Sets up Remote DOM, RPC listener, and renders the extension's React tree.
|
|
4
|
-
*/
|
|
5
|
-
import React from 'react';
|
|
6
|
-
interface CreateExtensionOptions {
|
|
7
|
-
extensionId?: string;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Bootstrap an extension. Call this as the entry point of your extension bundle.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* export default createExtension(() => (
|
|
14
|
-
* <>
|
|
15
|
-
* <Surface id="slot.header"><Header /></Surface>
|
|
16
|
-
* <Surface id="slot.content"><Content /></Surface>
|
|
17
|
-
* </>
|
|
18
|
-
* ));
|
|
19
|
-
*/
|
|
20
|
-
export declare const createExtension: (factory: () => React.ReactElement, options?: CreateExtensionOptions) => void;
|
|
21
|
-
export {};
|
package/dist/createExtension.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createRoot } from 'react-dom/client';
|
|
3
|
-
import { ExtensionContext } from './context';
|
|
4
|
-
import { initRpcListener } from './rpc-client';
|
|
5
|
-
/**
|
|
6
|
-
* Bootstrap an extension. Call this as the entry point of your extension bundle.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* export default createExtension(() => (
|
|
10
|
-
* <>
|
|
11
|
-
* <Surface id="slot.header"><Header /></Surface>
|
|
12
|
-
* <Surface id="slot.content"><Content /></Surface>
|
|
13
|
-
* </>
|
|
14
|
-
* ));
|
|
15
|
-
*/
|
|
16
|
-
export const createExtension = (factory, options) => {
|
|
17
|
-
// Resolve extensionId: prefer host-injected value, then options, then fallback
|
|
18
|
-
const injectedId = window.__STACKABLE_EXTENSION_ID__ ??
|
|
19
|
-
new URLSearchParams(window.location.search).get('__extensionId') ??
|
|
20
|
-
undefined;
|
|
21
|
-
const extensionId = injectedId ?? options?.extensionId ?? 'unknown';
|
|
22
|
-
console.debug(`[createExtension] extensionId resolved: "${extensionId}" (injected: ${injectedId ?? 'none'}, options: ${options?.extensionId ?? 'none'})`);
|
|
23
|
-
// Initialize RPC listener for capability responses
|
|
24
|
-
initRpcListener(extensionId);
|
|
25
|
-
const contextValue = {
|
|
26
|
-
extensionId,
|
|
27
|
-
};
|
|
28
|
-
// Mount the extension React tree
|
|
29
|
-
const container = document.getElementById('extension-root') ?? document.body;
|
|
30
|
-
const root = createRoot(container);
|
|
31
|
-
root.render(_jsx(ExtensionContext.Provider, { value: contextValue, children: factory() }));
|
|
32
|
-
// Notify host that the extension is ready
|
|
33
|
-
window.parent.postMessage({ type: 'extension-ready', extensionId }, '*');
|
|
34
|
-
};
|
|
35
|
-
//# sourceMappingURL=createExtension.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createExtension.js","sourceRoot":"","sources":["../src/createExtension.tsx"],"names":[],"mappings":";AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAM9C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,OAAiC,EAAE,OAAgC,EAAQ,EAAE;IAC3G,+EAA+E;IAC/E,MAAM,UAAU,GACb,MAA6C,CAAC,0BAAgD;QAC/F,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC;QAChE,SAAS,CAAA;IACX,MAAM,WAAW,GAAG,UAAU,IAAI,OAAO,EAAE,WAAW,IAAI,SAAS,CAAA;IACnE,OAAO,CAAC,KAAK,CAAC,4CAA4C,WAAW,gBAAgB,UAAU,IAAI,MAAM,cAAc,OAAO,EAAE,WAAW,IAAI,MAAM,GAAG,CAAC,CAAA;IAEzJ,mDAAmD;IACnD,eAAe,CAAC,WAAW,CAAC,CAAA;IAE5B,MAAM,YAAY,GAA0B;QAC1C,WAAW;KACZ,CAAA;IAED,iCAAiC;IACjC,MAAM,SAAS,GAAG,QAAQ,CAAC,cAAc,CAAC,gBAAgB,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAA;IAC5E,MAAM,IAAI,GAAG,UAAU,CAAC,SAAS,CAAC,CAAA;IAElC,IAAI,CAAC,MAAM,CACT,KAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YAC3C,OAAO,EAAE,GACgB,CAC7B,CAAA;IAED,0CAA0C;IAC1C,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,WAAW,EAAE,EAAE,GAAG,CAAC,CAAA;AAC1E,CAAC,CAAA"}
|
package/dist/hooks.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* React hooks for extension developers.
|
|
3
|
-
*/
|
|
4
|
-
import type { ContextData, ApiRequest, FetchRequestInit, FetchResponse, ToastPayload } from '@stackable-labs/sdk-extension-contracts';
|
|
5
|
-
import type { Store } from './store';
|
|
6
|
-
/**
|
|
7
|
-
* Read the host-provided context for the current surface.
|
|
8
|
-
*/
|
|
9
|
-
export declare const useSurfaceContext: () => Record<string, unknown>;
|
|
10
|
-
/**
|
|
11
|
-
* Access host-mediated capabilities (data, actions, context).
|
|
12
|
-
*/
|
|
13
|
-
export declare const useCapabilities: () => {
|
|
14
|
-
data: {
|
|
15
|
-
query: <T = unknown>(payload: ApiRequest) => Promise<T>;
|
|
16
|
-
fetch: (url: string, init?: FetchRequestInit) => Promise<FetchResponse>;
|
|
17
|
-
};
|
|
18
|
-
actions: {
|
|
19
|
-
toast: (payload: ToastPayload) => Promise<void>;
|
|
20
|
-
invoke: <T = unknown>(action: string, payload?: Record<string, unknown>) => Promise<T>;
|
|
21
|
-
};
|
|
22
|
-
context: {
|
|
23
|
-
read: () => Promise<ContextData>;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Subscribe to a shared store with an optional selector.
|
|
28
|
-
*/
|
|
29
|
-
export declare const useStore: <T, S = T>(store: Store<T>, selector?: (state: T) => S) => S;
|
|
30
|
-
/**
|
|
31
|
-
* Access the extension-level context (extension ID, manifest, etc.)
|
|
32
|
-
*/
|
|
33
|
-
export declare const useExtension: () => import("./context").ExtensionContextValue;
|
package/dist/hooks.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* React hooks for extension developers.
|
|
3
|
-
*/
|
|
4
|
-
import { useContext, useSyncExternalStore, useCallback } from 'react';
|
|
5
|
-
import { ExtensionContext, SurfaceContext } from './context';
|
|
6
|
-
import { callCapability } from './rpc-client';
|
|
7
|
-
/**
|
|
8
|
-
* Read the host-provided context for the current surface.
|
|
9
|
-
*/
|
|
10
|
-
export const useSurfaceContext = () => {
|
|
11
|
-
const ctx = useContext(SurfaceContext);
|
|
12
|
-
if (!ctx) {
|
|
13
|
-
throw new Error('useSurfaceContext must be used inside a <Surface> component');
|
|
14
|
-
}
|
|
15
|
-
return ctx;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Access host-mediated capabilities (data, actions, context).
|
|
19
|
-
*/
|
|
20
|
-
export const useCapabilities = () => ({
|
|
21
|
-
data: {
|
|
22
|
-
query: (payload) => callCapability('data.query', payload),
|
|
23
|
-
fetch: (url, init) => callCapability('data.fetch', { url, ...init }),
|
|
24
|
-
},
|
|
25
|
-
actions: {
|
|
26
|
-
toast: (payload) => callCapability('actions.toast', payload),
|
|
27
|
-
invoke: (action, payload) => callCapability('actions.invoke', { action, payload }),
|
|
28
|
-
},
|
|
29
|
-
context: {
|
|
30
|
-
read: () => callCapability('context.read'),
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
/**
|
|
34
|
-
* Subscribe to a shared store with an optional selector.
|
|
35
|
-
*/
|
|
36
|
-
export const useStore = (store, selector) => {
|
|
37
|
-
const select = selector ?? ((s) => s);
|
|
38
|
-
const getSnapshot = useCallback(() => select(store.get()), [store, select]);
|
|
39
|
-
const subscribe = useCallback((onStoreChange) => store.subscribe(onStoreChange), [store]);
|
|
40
|
-
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Access the extension-level context (extension ID, manifest, etc.)
|
|
44
|
-
*/
|
|
45
|
-
export const useExtension = () => {
|
|
46
|
-
const ctx = useContext(ExtensionContext);
|
|
47
|
-
if (!ctx) {
|
|
48
|
-
throw new Error('useExtension must be used inside a createExtension() tree');
|
|
49
|
-
}
|
|
50
|
-
return ctx;
|
|
51
|
-
};
|
|
52
|
-
//# sourceMappingURL=hooks.js.map
|
package/dist/hooks.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AASrE,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAG7C;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAA4B,EAAE;IAC7D,MAAM,GAAG,GAAG,UAAU,CAAC,cAAc,CAAC,CAAA;IACtC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAA;IAChF,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAA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G,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAA;IACxC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAA;IAC9E,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AACrC,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,QAAQ,EACR,YAAY,GACb,MAAM,SAAS,CAAA;AAEhB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,KAAK,EAAE,MAAM,MAAM,CAAA;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA"}
|
package/dist/rpc-client.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RPC Client — sends capability requests from sandbox to host via postMessage.
|
|
3
|
-
* Handles transparent AES-256-GCM encryption for data.fetch payloads when
|
|
4
|
-
* an encryption key is provided by the host.
|
|
5
|
-
*/
|
|
6
|
-
import type { CapabilityType } from '@stackable-labs/sdk-extension-contracts';
|
|
7
|
-
/**
|
|
8
|
-
* Set the encryption key from a base64-encoded string.
|
|
9
|
-
* Called when the host sends an 'extension-encryption-key' message.
|
|
10
|
-
*/
|
|
11
|
-
export declare const setEncryptionKey: (keyBase64: string) => Promise<void>;
|
|
12
|
-
/**
|
|
13
|
-
* Initialize the RPC listener for responses from the host.
|
|
14
|
-
*/
|
|
15
|
-
export declare const initRpcListener: (extensionId: string) => void;
|
|
16
|
-
/**
|
|
17
|
-
* Send a capability request to the host and await the response.
|
|
18
|
-
* For data.fetch, transparently encrypts the request payload and
|
|
19
|
-
* decrypts the response when an encryption key is available.
|
|
20
|
-
*/
|
|
21
|
-
export declare const callCapability: <T = unknown>(capability: CapabilityType, payload?: unknown) => Promise<T>;
|
package/dist/rpc-client.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RPC Client — sends capability requests from sandbox to host via postMessage.
|
|
3
|
-
* Handles transparent AES-256-GCM encryption for data.fetch payloads when
|
|
4
|
-
* an encryption key is provided by the host.
|
|
5
|
-
*/
|
|
6
|
-
import { WebCrypto } from '@agnostack/verifyd';
|
|
7
|
-
import { importKeyForEncryption } from '@stackable-labs/lib-utils-js';
|
|
8
|
-
// Lazy-init to avoid accessing globalThis.crypto at module load time.
|
|
9
|
-
// Uses native crypto to ensure CryptoKey compatibility with importKeyForEncryption.
|
|
10
|
-
let _webCrypto = null;
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
-
const getWebCrypto = () => (_webCrypto ??= new WebCrypto({ crypto: globalThis.crypto }));
|
|
13
|
-
let requestCounter = 0;
|
|
14
|
-
let registeredExtensionId = 'unknown';
|
|
15
|
-
let encryptionKey = null;
|
|
16
|
-
const pendingRequests = new Map();
|
|
17
|
-
const generateRequestId = () => `req_${++requestCounter}_${Date.now()}`;
|
|
18
|
-
/**
|
|
19
|
-
* Set the encryption key from a base64-encoded string.
|
|
20
|
-
* Called when the host sends an 'extension-encryption-key' message.
|
|
21
|
-
*/
|
|
22
|
-
export const setEncryptionKey = async (keyBase64) => {
|
|
23
|
-
encryptionKey = await importKeyForEncryption(keyBase64);
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Initialize the RPC listener for responses from the host.
|
|
27
|
-
*/
|
|
28
|
-
export const initRpcListener = (extensionId) => {
|
|
29
|
-
registeredExtensionId = extensionId;
|
|
30
|
-
window.addEventListener('message', (event) => {
|
|
31
|
-
const msg = event.data;
|
|
32
|
-
// Handle encryption key distribution from host
|
|
33
|
-
if (msg?.type === 'extension-encryption-key') {
|
|
34
|
-
setEncryptionKey(msg.encryptionKey);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
if (msg?.type === 'capability-response') {
|
|
38
|
-
const response = msg;
|
|
39
|
-
const pending = pendingRequests.get(response.id);
|
|
40
|
-
if (pending) {
|
|
41
|
-
pendingRequests.delete(response.id);
|
|
42
|
-
if (response.success) {
|
|
43
|
-
pending.resolve(response.data);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
pending.reject(new Error(response.error || 'Capability call failed'));
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
const isEncryptedPayload = (value) => typeof value === 'object' && value !== null && value.encrypted === true && Array.isArray(value.data);
|
|
53
|
-
/**
|
|
54
|
-
* Send a capability request to the host and await the response.
|
|
55
|
-
* For data.fetch, transparently encrypts the request payload and
|
|
56
|
-
* decrypts the response when an encryption key is available.
|
|
57
|
-
*/
|
|
58
|
-
export const callCapability = async (capability, payload) => {
|
|
59
|
-
let actualPayload = payload;
|
|
60
|
-
// Encrypt data.fetch payloads if we have an encryption key
|
|
61
|
-
if (capability === 'data.fetch' && encryptionKey) {
|
|
62
|
-
const encrypted = await getWebCrypto().encryptMessage(JSON.stringify(payload), encryptionKey);
|
|
63
|
-
if (!encrypted)
|
|
64
|
-
throw new Error('Failed to encrypt data.fetch payload');
|
|
65
|
-
actualPayload = { encrypted: true, data: encrypted };
|
|
66
|
-
}
|
|
67
|
-
const result = await sendCapabilityRequest(capability, actualPayload);
|
|
68
|
-
// Decrypt data.fetch response if it came back encrypted
|
|
69
|
-
if (capability === 'data.fetch' && encryptionKey) {
|
|
70
|
-
const fetchResult = result;
|
|
71
|
-
if (isEncryptedPayload(fetchResult.data)) {
|
|
72
|
-
const decrypted = await getWebCrypto().decryptMessage(fetchResult.data.data, encryptionKey);
|
|
73
|
-
fetchResult.data = JSON.parse(decrypted);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return result;
|
|
77
|
-
};
|
|
78
|
-
/**
|
|
79
|
-
* Low-level: send a capability request to the host and await the response via postMessage.
|
|
80
|
-
*/
|
|
81
|
-
const sendCapabilityRequest = (capability, payload) => (new Promise((resolve, reject) => {
|
|
82
|
-
const id = generateRequestId();
|
|
83
|
-
pendingRequests.set(id, {
|
|
84
|
-
resolve: resolve,
|
|
85
|
-
reject,
|
|
86
|
-
});
|
|
87
|
-
const request = {
|
|
88
|
-
type: 'capability-request',
|
|
89
|
-
id,
|
|
90
|
-
extensionId: registeredExtensionId,
|
|
91
|
-
capability,
|
|
92
|
-
payload,
|
|
93
|
-
};
|
|
94
|
-
// Post to parent (host) window
|
|
95
|
-
window.parent.postMessage(request, '*');
|
|
96
|
-
// Timeout after 30 seconds
|
|
97
|
-
setTimeout(() => {
|
|
98
|
-
if (pendingRequests.has(id)) {
|
|
99
|
-
pendingRequests.delete(id);
|
|
100
|
-
reject(new Error(`Capability call '${capability}' timed out`));
|
|
101
|
-
}
|
|
102
|
-
}, 30000);
|
|
103
|
-
}));
|
|
104
|
-
//# sourceMappingURL=rpc-client.js.map
|
package/dist/rpc-client.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-client.js","sourceRoot":"","sources":["../src/rpc-client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AAErE,sEAAsE;AACtE,oFAAoF;AACpF,IAAI,UAAU,GAA0C,IAAI,CAAA;AAC5D,8DAA8D;AAC9D,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,CAAC,UAAU,KAAK,IAAI,SAAS,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAS,CAAC,CAAC,CAAA;AAE/F,IAAI,cAAc,GAAG,CAAC,CAAA;AACtB,IAAI,qBAAqB,GAAG,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;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,qBAAqB,GAAG,CAAc,UAA0B,EAAE,OAAiB,EAAc,EAAE,CAAC,CACxG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IAC9B,MAAM,EAAE,GAAG,iBAAiB,EAAE,CAAA;IAC9B,eAAe,CAAC,GAAG,CAAC,EAAE,EAAE;QACtB,OAAO,EAAE,OAAkC;QAC3C,MAAM;KACP,CAAC,CAAA;IAEF,MAAM,OAAO,GAAsB;QACjC,IAAI,EAAE,oBAAoB;QAC1B,EAAE;QACF,WAAW,EAAE,qBAAqB;QAClC,UAAU;QACV,OAAO;KACR,CAAA;IAED,+BAA+B;IAC/B,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IAEvC,2BAA2B;IAC3B,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YAC5B,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;YAC1B,MAAM,CAAC,IAAI,KAAK,CAAC,oBAAoB,UAAU,aAAa,CAAC,CAAC,CAAA;QAChE,CAAC;IACH,CAAC,EAAE,KAAK,CAAC,CAAA;AACX,CAAC,CAAC,CACH,CAAA"}
|
package/dist/store.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared Store — cross-surface state coordination.
|
|
3
|
-
* All surfaces in the same extension runtime share a store instance.
|
|
4
|
-
*/
|
|
5
|
-
type Listener<T> = (state: T) => void;
|
|
6
|
-
export interface Store<T> {
|
|
7
|
-
get(): T;
|
|
8
|
-
set(partial: Partial<T>): void;
|
|
9
|
-
subscribe(listener: Listener<T>): () => void;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Create a shared store for cross-surface coordination.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* const store = createStore({ mode: 'account', selectedId: null });
|
|
16
|
-
* store.set({ mode: 'conversations' });
|
|
17
|
-
* store.subscribe((state) => console.log(state));
|
|
18
|
-
*/
|
|
19
|
-
export declare const createStore: <T extends object>(initialState: T) => Store<T>;
|
|
20
|
-
export {};
|
package/dist/store.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared Store — cross-surface state coordination.
|
|
3
|
-
* All surfaces in the same extension runtime share a store instance.
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Create a shared store for cross-surface coordination.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* const store = createStore({ mode: 'account', selectedId: null });
|
|
10
|
-
* store.set({ mode: 'conversations' });
|
|
11
|
-
* store.subscribe((state) => console.log(state));
|
|
12
|
-
*/
|
|
13
|
-
export const createStore = (initialState) => {
|
|
14
|
-
let state = { ...initialState };
|
|
15
|
-
const listeners = new Set();
|
|
16
|
-
return {
|
|
17
|
-
get: () => state,
|
|
18
|
-
set: (partial) => {
|
|
19
|
-
state = { ...state, ...partial };
|
|
20
|
-
listeners.forEach((listener) => listener(state));
|
|
21
|
-
},
|
|
22
|
-
subscribe: (listener) => {
|
|
23
|
-
listeners.add(listener);
|
|
24
|
-
return () => {
|
|
25
|
-
listeners.delete(listener);
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
//# sourceMappingURL=store.js.map
|
package/dist/store.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAmB,YAAe,EAAY,EAAE;IACzE,IAAI,KAAK,GAAG,EAAE,GAAG,YAAY,EAAE,CAAA;IAC/B,MAAM,SAAS,GAAG,IAAI,GAAG,EAAe,CAAA;IAExC,OAAO;QACL,GAAG,EAAE,GAAG,EAAE,CAAC,KAAK;QAEhB,GAAG,EAAE,CAAC,OAAmB,EAAE,EAAE;YAC3B,KAAK,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,OAAO,EAAE,CAAA;YAChC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAA;QAClD,CAAC;QAED,SAAS,EAAE,CAAC,QAAqB,EAAE,EAAE;YACnC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACvB,OAAO,GAAG,EAAE;gBACV,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;YAC5B,CAAC,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
|