@curvenote/renderers 0.5.2 → 0.5.3
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/any/index.d.ts +5 -0
- package/dist/any/index.d.ts.map +1 -0
- package/dist/any/index.js +14 -0
- package/dist/any/models.d.ts +18 -0
- package/dist/any/models.d.ts.map +1 -0
- package/dist/any/models.js +49 -0
- package/dist/any/renderers.d.ts +5 -0
- package/dist/any/renderers.d.ts.map +1 -0
- package/dist/any/renderers.js +84 -0
- package/dist/any/types.d.ts +18 -0
- package/dist/any/types.d.ts.map +1 -0
- package/dist/any/types.js +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/package.json +6 -6
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/any/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAK3D,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAU3B,eAAO,MAAM,aAAa,EAAE,aAK3B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { MyST } from 'myst-to-react';
|
|
3
|
+
import { AnyRenderer } from './renderers.js';
|
|
4
|
+
export * from './models.js';
|
|
5
|
+
export * from './types.js';
|
|
6
|
+
function Block({ node }) {
|
|
7
|
+
return (_jsx("div", { children: _jsx(MyST, { ast: node.children }) }));
|
|
8
|
+
}
|
|
9
|
+
export const ANY_RENDERERS = {
|
|
10
|
+
block: {
|
|
11
|
+
base: Block,
|
|
12
|
+
'block[kind=any:bundle]': AnyRenderer,
|
|
13
|
+
},
|
|
14
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forked from https://github.com/manzt/anymyst/commit/d0b2c105397f5b1a0344b4b467c3790c498a84c6
|
|
3
|
+
*
|
|
4
|
+
* A shim for the anywidget model interface
|
|
5
|
+
* @see {@link https://github.com/manzt/anywidget/tree/main/packages/types}
|
|
6
|
+
*/
|
|
7
|
+
export declare class MystAnyModel {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(state: Record<string, unknown>);
|
|
10
|
+
get(name: string): unknown;
|
|
11
|
+
set(key: string, value: unknown): void;
|
|
12
|
+
on(name: string, cb: () => void | Promise<void>): void;
|
|
13
|
+
off(_name: string, _cb: () => void | Promise<void>): void;
|
|
14
|
+
save_changes(): void;
|
|
15
|
+
send(_msg: unknown, _callbacks?: unknown, _buffers?: ArrayBuffer[]): void;
|
|
16
|
+
get widget_manager(): void;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/any/models.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qBAAa,YAAY;;gBAGX,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAG1C,GAAG,CAAC,IAAI,EAAE,MAAM;IAGhB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;IAK/B,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAG/C,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAGlD,YAAY;IAGZ,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,WAAW,EAAE;IAGlE,IAAI,cAAc,SAEjB;CACF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _MystAnyModel_state, _MystAnyModel_target;
|
|
13
|
+
/**
|
|
14
|
+
* Forked from https://github.com/manzt/anymyst/commit/d0b2c105397f5b1a0344b4b467c3790c498a84c6
|
|
15
|
+
*
|
|
16
|
+
* A shim for the anywidget model interface
|
|
17
|
+
* @see {@link https://github.com/manzt/anywidget/tree/main/packages/types}
|
|
18
|
+
*/
|
|
19
|
+
export class MystAnyModel {
|
|
20
|
+
constructor(state) {
|
|
21
|
+
_MystAnyModel_state.set(this, void 0);
|
|
22
|
+
_MystAnyModel_target.set(this, new EventTarget());
|
|
23
|
+
__classPrivateFieldSet(this, _MystAnyModel_state, state, "f");
|
|
24
|
+
}
|
|
25
|
+
get(name) {
|
|
26
|
+
return __classPrivateFieldGet(this, _MystAnyModel_state, "f")[name];
|
|
27
|
+
}
|
|
28
|
+
set(key, value) {
|
|
29
|
+
__classPrivateFieldGet(this, _MystAnyModel_state, "f")[key] = value;
|
|
30
|
+
__classPrivateFieldGet(this, _MystAnyModel_target, "f").dispatchEvent(new CustomEvent(`change:${key}`, { detail: value }));
|
|
31
|
+
__classPrivateFieldGet(this, _MystAnyModel_target, "f").dispatchEvent(new CustomEvent('change', { detail: value }));
|
|
32
|
+
}
|
|
33
|
+
on(name, cb) {
|
|
34
|
+
__classPrivateFieldGet(this, _MystAnyModel_target, "f").addEventListener(name, cb);
|
|
35
|
+
}
|
|
36
|
+
off(_name, _cb) {
|
|
37
|
+
// TODO: should keep ref to listeners and then remove here
|
|
38
|
+
}
|
|
39
|
+
save_changes() {
|
|
40
|
+
// nothing to sync but necessary
|
|
41
|
+
}
|
|
42
|
+
send(_msg, _callbacks, _buffers) {
|
|
43
|
+
throw new Error('MystAnyModel.send not implemented yet.');
|
|
44
|
+
}
|
|
45
|
+
get widget_manager() {
|
|
46
|
+
throw new Error('MystAnyModel.widget_manager does not exist.');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
_MystAnyModel_state = new WeakMap(), _MystAnyModel_target = new WeakMap();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderers.d.ts","sourceRoot":"","sources":["../../src/any/renderers.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGnD,wBAAgB,WAAW,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,2CAwF/D"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
/**
|
|
12
|
+
* Forked from https://github.com/manzt/anymyst/commit/d0b2c105397f5b1a0344b4b467c3790c498a84c6
|
|
13
|
+
*
|
|
14
|
+
* A custom renderer for Myst to support anywidget front-end modules
|
|
15
|
+
* @module
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```
|
|
19
|
+
* <Document renderers={{ ...renderers, any: AnyMystRenderer }}></Document>
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import * as React from 'react';
|
|
23
|
+
import { MystAnyModel } from './models.js';
|
|
24
|
+
export function AnyRenderer({ node }) {
|
|
25
|
+
var _a;
|
|
26
|
+
// basic validation
|
|
27
|
+
const validImport = node.data.import &&
|
|
28
|
+
typeof node.data.import === 'string' &&
|
|
29
|
+
(node.data.import.startsWith('https://') || node.data.import.startsWith('http://'));
|
|
30
|
+
const validJson = node.data.json && typeof node.data.json === 'object';
|
|
31
|
+
const ref = React.useRef(null);
|
|
32
|
+
React.useEffect(() => {
|
|
33
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal#implementing_an_abortable_api
|
|
34
|
+
const controller = new AbortController();
|
|
35
|
+
// if already aborted just ignore
|
|
36
|
+
if (controller.signal.aborted) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
let maybeCleanupInitialize = undefined;
|
|
40
|
+
let maybeCleanupRender = undefined;
|
|
41
|
+
controller.signal.addEventListener('abort', () => __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
yield (maybeCleanupRender === null || maybeCleanupRender === void 0 ? void 0 : maybeCleanupRender());
|
|
43
|
+
yield (maybeCleanupInitialize === null || maybeCleanupInitialize === void 0 ? void 0 : maybeCleanupInitialize());
|
|
44
|
+
}));
|
|
45
|
+
// TODO: validation for import & styles URLs
|
|
46
|
+
import(node.data.import).then((mod) => __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
var _a, _b, _c, _d, _e;
|
|
48
|
+
if (!ref.current)
|
|
49
|
+
return;
|
|
50
|
+
const widget = mod.default;
|
|
51
|
+
// TODO: validate the widget
|
|
52
|
+
const model = new MystAnyModel(node.data.json);
|
|
53
|
+
maybeCleanupInitialize = yield ((_a = widget.initialize) === null || _a === void 0 ? void 0 : _a.call(widget, { model }));
|
|
54
|
+
// clear current contents
|
|
55
|
+
(_b = ref.current) === null || _b === void 0 ? void 0 : _b.replaceChildren();
|
|
56
|
+
// apply container classes
|
|
57
|
+
(_c = node.data.class) === null || _c === void 0 ? void 0 : _c.split(' ').forEach((c) => {
|
|
58
|
+
var _a;
|
|
59
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.classList.add(c);
|
|
60
|
+
});
|
|
61
|
+
// apply styles
|
|
62
|
+
const shadowRoot = (_d = ref.current) === null || _d === void 0 ? void 0 : _d.attachShadow({ mode: 'open' });
|
|
63
|
+
const shadowEl = document.createElement('div');
|
|
64
|
+
shadowRoot.appendChild(shadowEl);
|
|
65
|
+
if (node.data.styles) {
|
|
66
|
+
const link = document.createElement('link');
|
|
67
|
+
link.rel = 'stylesheet';
|
|
68
|
+
link.href = node.data.styles;
|
|
69
|
+
shadowRoot.appendChild(link);
|
|
70
|
+
}
|
|
71
|
+
maybeCleanupRender = yield ((_e = widget.render) === null || _e === void 0 ? void 0 : _e.call(widget, {
|
|
72
|
+
model,
|
|
73
|
+
el: shadowEl,
|
|
74
|
+
}));
|
|
75
|
+
}));
|
|
76
|
+
return () => {
|
|
77
|
+
controller === null || controller === void 0 ? void 0 : controller.abort();
|
|
78
|
+
};
|
|
79
|
+
}, [node]);
|
|
80
|
+
if (!validImport || !validJson) {
|
|
81
|
+
return (_jsxs("div", { className: "p-3 space-y-2 border border-red-500 rounded-md", children: [_jsxs("div", { children: ["Invalid ", _jsx("code", { children: "any:bundle" }), " directive."] }), !validImport && (_jsxs("div", { className: "px-1", children: [_jsx("div", { children: "Invalid import URL" }), _jsx("div", { className: "text-sm text-gray-500", children: node.data.import })] })), !validJson && (_jsxs("div", { className: "px-1", children: [_jsx("div", { children: "Invalid JSON data" }), _jsx("div", { className: "text-sm text-gray-500", children: (_a = node.data.json) === null || _a === void 0 ? void 0 : _a.toString() })] }))] }));
|
|
82
|
+
}
|
|
83
|
+
return _jsx("div", { className: "relative w-full", ref: ref });
|
|
84
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type AnyMystDirective = {
|
|
2
|
+
/** The type of the directive */
|
|
3
|
+
type: 'block';
|
|
4
|
+
/** The kind of the directive */
|
|
5
|
+
kind: 'any:bundle';
|
|
6
|
+
/** The data to pass to the model */
|
|
7
|
+
data: {
|
|
8
|
+
/** The ES module to import */
|
|
9
|
+
import: string;
|
|
10
|
+
/** Tailwind classes to apply to the container element */
|
|
11
|
+
class: string;
|
|
12
|
+
/** URL to a css stylesheet to load for the widget */
|
|
13
|
+
styles: string;
|
|
14
|
+
/** The JSON data to initialize the widget */
|
|
15
|
+
json: Record<string, unknown>;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/any/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,gCAAgC;IAChC,IAAI,EAAE,OAAO,CAAC;IACd,gCAAgC;IAChC,IAAI,EAAE,YAAY,CAAC;IACnB,oCAAoC;IACpC,IAAI,EAAE;QACJ,8BAA8B;QAC9B,MAAM,EAAE,MAAM,CAAC;QACf,yDAAyD;QACzD,KAAK,EAAE,MAAM,CAAC;QACd,qDAAqD;QACrD,MAAM,EAAE,MAAM,CAAC;QACf,6CAA6C;QAC7C,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC/B,CAAC;CACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAUA,eAAO,MAAM,kBAAkB,+CAS7B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { OUTPUT_RENDERERS } from '@curvenote/bridge-jupyter';
|
|
|
6
6
|
import LANDING_RENDERERS from '@curvenote/ext-landing/react';
|
|
7
7
|
import FOOTER_RENDERERS from '@curvenote/ext-footer/react';
|
|
8
8
|
import SCIENCEICON_RENDERERS from '@scienceicons/myst/react';
|
|
9
|
+
import { ANY_RENDERERS } from './any/index.js';
|
|
9
10
|
export const curvenoteRenderers = mergeRenderers([
|
|
10
11
|
OUTPUT_RENDERERS,
|
|
11
12
|
CITE_RENDERERS,
|
|
@@ -14,4 +15,5 @@ export const curvenoteRenderers = mergeRenderers([
|
|
|
14
15
|
LANDING_RENDERERS,
|
|
15
16
|
FOOTER_RENDERERS,
|
|
16
17
|
SCIENCEICON_RENDERERS,
|
|
18
|
+
ANY_RENDERERS,
|
|
17
19
|
]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@curvenote/renderers",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"build": "npm-run-all -l clean -p build:esm"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@curvenote/bridge-jupyter": "^0.5.
|
|
25
|
-
"@curvenote/ext-blog": "^0.5.
|
|
26
|
-
"@curvenote/ext-footer": "^0.5.
|
|
27
|
-
"@curvenote/ext-landing": "^0.5.
|
|
28
|
-
"@curvenote/ext-person": "^0.5.
|
|
24
|
+
"@curvenote/bridge-jupyter": "^0.5.3",
|
|
25
|
+
"@curvenote/ext-blog": "^0.5.3",
|
|
26
|
+
"@curvenote/ext-footer": "^0.5.3",
|
|
27
|
+
"@curvenote/ext-landing": "^0.5.3",
|
|
28
|
+
"@curvenote/ext-person": "^0.5.3",
|
|
29
29
|
"@heroicons/react": "^2.1.5",
|
|
30
30
|
"@myst-theme/providers": "^0.13.6",
|
|
31
31
|
"@scienceicons/myst": "^1.0.4",
|