pi-sdk-web 0.4.3 → 0.4.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.
- package/dist/ui-context.js +24 -0
- package/package.json +1 -1
package/dist/ui-context.js
CHANGED
|
@@ -68,6 +68,30 @@ export class WebUIContext {
|
|
|
68
68
|
statusMap = new Map();
|
|
69
69
|
constructor(sink) {
|
|
70
70
|
this.sink = sink;
|
|
71
|
+
// Pi's ExtensionRunner wraps the ui context with `{...ui}` (a shallow
|
|
72
|
+
// spread) when building the extension ctx - class prototype members
|
|
73
|
+
// (methods AND the theme getter) would be LOST by that spread (only own
|
|
74
|
+
// enumerable properties survive). Copy prototype methods onto the
|
|
75
|
+
// instance as own bound properties, and expose theme as an own
|
|
76
|
+
// property, so extensions see the same shape as TUI's object-literal
|
|
77
|
+
// UIContext (all methods + theme as own props).
|
|
78
|
+
const proto = Object.getPrototypeOf(this);
|
|
79
|
+
for (const name of Object.getOwnPropertyNames(proto)) {
|
|
80
|
+
if (name === "constructor")
|
|
81
|
+
continue;
|
|
82
|
+
const desc = Object.getOwnPropertyDescriptor(proto, name);
|
|
83
|
+
if (desc && typeof desc.value === "function") {
|
|
84
|
+
this[name] = desc.value.bind(this);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Theme: the prototype getter is not picked up by `{...}` and the own
|
|
88
|
+
// property cannot shadow a getter-only prototype via assignment. Define
|
|
89
|
+
// an own enumerable getter returning webTheme (fresh after setWebTheme).
|
|
90
|
+
Object.defineProperty(this, "theme", {
|
|
91
|
+
configurable: true,
|
|
92
|
+
enumerable: true,
|
|
93
|
+
get: () => this.webTheme,
|
|
94
|
+
});
|
|
71
95
|
}
|
|
72
96
|
/** Current extension status snapshot (key -> text) for new connections. */
|
|
73
97
|
getStatusSnapshot() {
|