feat: sdks and docs (#239)

* init

* fix

* update docs

* bump: all sdks

* rename types test
This commit is contained in:
Carl-Gerhard Lindesvärd
2025-11-19 21:56:47 +01:00
committed by GitHub
parent 790801b728
commit 83e223a496
50 changed files with 793 additions and 137 deletions

View File

@@ -1,7 +1,7 @@
import { OpenPanel } from './index';
((window) => {
if (window.op && 'q' in window.op) {
if (window.op) {
const queue = window.op.q || [];
// @ts-expect-error
const op = new OpenPanel(queue.shift()[1]);
@@ -12,16 +12,36 @@ import { OpenPanel } from './index';
}
});
window.op = (t, ...args) => {
const fn = op[t] ? op[t].bind(op) : undefined;
if (typeof fn === 'function') {
// @ts-expect-error
fn(...args);
} else {
console.warn(`OpenPanel: ${t} is not a function`);
}
};
// Create a Proxy that supports both window.op('track', ...) and window.op.track(...)
const opCallable = new Proxy(
((method: string, ...args: any[]) => {
const fn = (op as any)[method]
? (op as any)[method].bind(op)
: undefined;
if (typeof fn === 'function') {
fn(...args);
} else {
console.warn(`OpenPanel: ${method} is not a function`);
}
}) as typeof op & ((method: string, ...args: any[]) => void),
{
get(target, prop) {
// Handle special properties
if (prop === 'q') {
return undefined; // q doesn't exist after SDK loads
}
// If accessing a method on op, return the bound method
const value = (op as any)[prop];
if (typeof value === 'function') {
return value.bind(op);
}
// Otherwise return the property from op (for things like options, etc.)
return value;
},
},
);
window.op = opCallable;
window.openpanel = op;
}
})(window);