@anywidget/deno
Advanced tools
Comparing version 0.0.2 to 0.0.3
# @anywidget/deno | ||
## 0.0.3 | ||
### Patch Changes | ||
- feat: Try to discover installed anywidget version ([#326](https://github.com/manzt/anywidget/pull/326)) | ||
- feat: Add Install/Uninstall scripts for widget front end ([#329](https://github.com/manzt/anywidget/pull/329)) | ||
```sh | ||
deno run -A https://deno.land/x/anywidget/install.ts | ||
``` | ||
## 0.0.2 | ||
@@ -4,0 +16,0 @@ |
54
mod.ts
@@ -0,6 +1,46 @@ | ||
import * as path from "https://deno.land/std@0.203.0/path/mod.ts"; | ||
import mitt, { type Emitter } from "npm:mitt@3"; | ||
import { find_data_dir } from "./jupyter_paths.ts"; | ||
// TODO: Find this automatically from where the jupyter assets are installed? | ||
const ANYWIDGET_VERSION = "0.6.5"; | ||
let COMMS = new WeakMap<object, Comm>(); | ||
let DEFAULT_VERSION = "0.6.5"; | ||
let ANYWIDGET_VERSION = await find_anywidget_version() | ||
.catch(() => DEFAULT_VERSION); | ||
async function find_anywidget_version(): Promise<string> { | ||
let data_dir = await find_data_dir(); | ||
let contents = await Deno.readTextFile( | ||
path.resolve(data_dir, "labextensions/anywidget/package.json"), | ||
); | ||
return JSON.parse(contents).version; | ||
} | ||
type Broadcast = ( | ||
type: string, | ||
content: Record<string, unknown>, | ||
extra?: { | ||
metadata?: Record<string, unknown>; | ||
}, | ||
) => Promise<void>; | ||
let jupyter_broadcast: Broadcast = (() => { | ||
try { | ||
// @ts-expect-error - Only available in Jupyter context | ||
return Deno.jupyter.broadcast; | ||
} catch (_) { | ||
return async () => {}; | ||
} | ||
})(); | ||
export const _internals = { | ||
jupyter_broadcast, | ||
get_comm(model: object): Comm { | ||
let comm = COMMS.get(model); | ||
if (!comm) { | ||
throw new Error("No comm found for model"); | ||
} | ||
return comm; | ||
}, | ||
}; | ||
class Comm { | ||
@@ -24,3 +64,3 @@ #id: string; | ||
async init() { | ||
await Deno.jupyter.broadcast( | ||
await _internals.jupyter_broadcast( | ||
"comm_open", | ||
@@ -52,3 +92,3 @@ { | ||
async send_state(state: object) { | ||
await Deno.jupyter.broadcast("comm_msg", { | ||
await _internals.jupyter_broadcast("comm_msg", { | ||
"comm_id": this.id, | ||
@@ -124,3 +164,3 @@ "data": { "method": "update", "state": state }, | ||
function to_esm<State>( | ||
{ imports, render }: Pick<WidgetProps<State>, "imports" | "render">, | ||
{ imports = "", render }: Pick<WidgetProps<State>, "imports" | "render">, | ||
) { | ||
@@ -142,3 +182,3 @@ return `${imports}\nexport const render = ${render.toString()}`; | ||
} | ||
return new Proxy(model, { | ||
let obj = new Proxy(model, { | ||
get(target, prop, receiver) { | ||
@@ -151,2 +191,4 @@ if (prop === Symbol.for("Jupyter.display")) { | ||
}); | ||
COMMS.set(obj, comm); | ||
return obj; | ||
} |
{ | ||
"name": "@anywidget/deno", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "A stub-package for making releases of the Deno anywidget mod.ts with changesets" | ||
} |
@@ -70,3 +70,3 @@ # anywidget (deno) | ||
```typescript | ||
let dict = await Deno.readTextFile("/usr/share/dict/words").split("\n"); | ||
let dict = await Deno.readTextFile("/usr/share/dict/words"); | ||
for (let word of dict.split("\n")) { | ||
@@ -73,0 +73,0 @@ model.set("letters", word); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17774
10
496
1